diff --git a/src/Assert.php b/src/Assert.php index 91afaa0b..09e69ab1 100644 --- a/src/Assert.php +++ b/src/Assert.php @@ -1045,6 +1045,8 @@ public static function startsWith($value, $prefix, $message = '') } /** + * @psalm-assert string $value + * * @param mixed $value * @param string $message * @@ -1052,6 +1054,8 @@ public static function startsWith($value, $prefix, $message = '') */ public static function startsWithLetter($value, $message = '') { + static::string($value); + $valid = isset($value[0]); if ($valid) { diff --git a/tests/AssertTest.php b/tests/AssertTest.php index 4a23b061..4546dab5 100644 --- a/tests/AssertTest.php +++ b/tests/AssertTest.php @@ -265,11 +265,14 @@ public function getTests() array('startsWith', array('😄😑☹ī¸', '😑'), false), array('startsWith', array('', '😑'), false), array('startsWithLetter', array('abcd'), true), + array('startsWithLetter', array(array(66)), false), array('startsWithLetter', array('a'), true), array('startsWithLetter', array('a1'), true), array('startsWithLetter', array('1abcd'), false), array('startsWithLetter', array('1'), false), array('startsWithLetter', array(''), false), + array('startsWithLetter', array(null), false), + array('startsWithLetter', array(66), false), array('endsWith', array('abcd', 'cd'), true), array('endsWith', array('abcd', 'bc'), false), array('endsWith', array('', 'bc'), false), diff --git a/tests/static-analysis/assert-startsWithLetter.php b/tests/static-analysis/assert-startsWithLetter.php new file mode 100644 index 00000000..78defd19 --- /dev/null +++ b/tests/static-analysis/assert-startsWithLetter.php @@ -0,0 +1,15 @@ +