Skip to content

Commit

Permalink
Add maxStringLength
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Jul 17, 2019
1 parent 2115844 commit 1d96096
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@
class Assert
{
protected static $throwException = true;
protected static $maxStringLength = 1024;

public static function setThrowException(bool $b)
{
Expand Down Expand Up @@ -1332,7 +1333,11 @@ protected static function valueToString($value): string
}

if (is_string($value)) {
return 'string(' . strlen($value) . ') "' . $value . '"';
$length = strlen($value);
if ($length > static::$maxStringLength) {
$value = substr($value, 0, static::$maxStringLength) . '...';
}
return 'string(' . $length . ') "' . $value . '"';
}

return (string)$value;
Expand Down

0 comments on commit 1d96096

Please sign in to comment.