Skip to content

Commit

Permalink
Allow int parts in StringUtil::joinNonEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Jan 21, 2025
1 parent f279248 commit b8a7b48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ See [GitHub releases](https://github.com/mll-lab/php-utils/releases).

## Unreleased

## v5.11.0

### Added

- Allow `int` parts in `StringUtil::joinNonEmpty`

## v5.10.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StringUtil
/** https://en.wikipedia.org/wiki/Byte_order_mark#UTF-32 */
public const UTF_32_LITTLE_ENDIAN_BOM = "\xFF\xFE\x00\x00";

/** @param iterable<string|null> $parts */
/** @param iterable<string|int|null> $parts */
public static function joinNonEmpty(string $glue, iterable $parts): string
{
$nonEmptyParts = [];
Expand Down
10 changes: 5 additions & 5 deletions tests/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final class StringUtilTest extends TestCase
/**
* @dataProvider joinNonEmpty
*
* @param iterable<string|null> $parts
* @param iterable<string|int|null> $parts
*/
#[DataProvider('joinNonEmpty')]
public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable $parts): void
Expand All @@ -23,12 +23,12 @@ public function testJoinNonEmpty(string $expectedJoined, string $glue, iterable
);
}

/** @return iterable<array{string, string, iterable<string|null>}> */
/** @return iterable<array{string, string, iterable<string|int|null>}> */
public static function joinNonEmpty(): iterable
{
yield ['a b', ' ', ['a', null, '', 'b']];
yield ['ab', '', ['a', null, '', 'b']];
yield ['a,b', ',', new Collection(['a', null, '', 'b'])];
yield ['a b 0', ' ', ['a', null, 'b', '', 0]];
yield ['ab1', '', ['a', null, '', 'b', 1]];
yield ['a,b,2', ',', new Collection(['a', 'b', 2, null, ''])];
}

/** @dataProvider shortenFirstname */
Expand Down

0 comments on commit b8a7b48

Please sign in to comment.