Skip to content

Commit

Permalink
Str::symmetricSplit(): Make $default only accept string or null
Browse files Browse the repository at this point in the history
After all, it is a Str-based class that should not pad anything other than string or null.

see: https://github.com/Icinga/icingaweb2-module-businessprocess/actions/runs/8466543979/job/23195516401?pr=446
  • Loading branch information
sukhwinder33445 authored and nilmerg committed Apr 22, 2024
1 parent e27166e commit 4b797d5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public static function startsWith(?string $subject, string $start, bool $caseSen
* @param ?string $subject
* @param string $delimiter
* @param int $limit
* @param mixed $default
* @param ?string $default
*
* @return array<int, mixed>
* @return array<int, ?string>
*/
public static function symmetricSplit(?string $subject, string $delimiter, int $limit, $default = null)
public static function symmetricSplit(?string $subject, string $delimiter, int $limit, ?string $default = null)
{
if ($subject === null || empty($delimiter)) {
return array_pad([], $limit, $default);
Expand Down
2 changes: 1 addition & 1 deletion tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testSymmetricSplitReturnsArrayPaddedToTheSizeSpecifiedByLimitUsi

public function testSymmetricSplitReturnsArrayPaddedToTheSizeSpecifiedByLimitUsingCustomValue()
{
$this->assertSame(['foo', 'bar', false, false], Str::symmetricSplit('foo,bar', ',', 4, false));
$this->assertSame(['foo', 'bar', 'default', 'default'], Str::symmetricSplit('foo,bar', ',', 4, 'default'));
}

public function testSymmetricSplitReturnsUnpaddedArrayIfTheSizeOfTheExplodedStringIsLessThanLimit()
Expand Down

0 comments on commit 4b797d5

Please sign in to comment.