Skip to content

Commit c8b3077

Browse files
committed
check if the input is longer than the limit. if not, simply return the input
1 parent eb3f2bd commit c8b3077

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/Truncate.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,19 @@ private function compile(string $input, string $limit): string
2121
{
2222
return <<<PHP
2323
(
24-
!\\is_string({$input}) ?
25-
null :
24+
mb_strlen({$input}) > {$limit} ?
2625
(
2726
rtrim(mb_substr({$input}, 0, {$limit} - 1)) . '…'
28-
)
27+
) : {$input}
2928
)
3029
PHP;
3130
}
3231

3332
private function evaluate(array $context, string $input, int $limit)
3433
{
35-
return !\is_string($input) ?
36-
null :
34+
return mb_strlen($input) > $limit ?
3735
(
3836
rtrim(mb_substr($input, 0, $limit - 1)).''
39-
);
37+
) : $input;
4038
}
4139
}

0 commit comments

Comments
 (0)