Skip to content

Commit

Permalink
Revert Str::short(appendix: false)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Sep 24, 2023
1 parent ad7de06 commit 13360cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/Toolkit/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public static function safeTemplate(
public static function short(
string $string = null,
int $length = 0,
string|false $appendix = ''
string $appendix = ''
): string {
if ($string === null) {
return '';
Expand All @@ -994,12 +994,7 @@ public static function short(
return $string;
}

$string = static::substr($string, 0, $length);

return match ($appendix) {
false => $string,
default => $string . $appendix
};
return static::substr($string, 0, $length) . $appendix;
}

/**
Expand Down Expand Up @@ -1124,7 +1119,7 @@ public static function slug(
$string = preg_replace('![^a-z0-9]+$!', '', $string);

// cut the string after the given maxlength
return static::short($string, $maxlength, false);
return static::short($string, $maxlength, '');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/Toolkit/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,9 @@ public function testShort()
// with different ellipsis character
$this->assertSame('Super---', Str::short($string, 5, '---'));

// without ellipsis
$this->assertSame('Super', Str::short($string, 5, ''));

// with null
$this->assertSame('', Str::short(null, 5));

Expand Down

0 comments on commit 13360cd

Please sign in to comment.