From a296d8acb772bc11e02faaad88bf7cf5c99d694e Mon Sep 17 00:00:00 2001 From: Jesse Kramer Date: Tue, 15 Oct 2019 19:45:22 +0200 Subject: [PATCH] fixed starts with letter (#138) Added psalm assert Added string assertion Added test Added static-analysis class. --- src/Assert.php | 4 ++++ tests/AssertTest.php | 3 +++ tests/static-analysis/assert-startsWithLetter.php | 15 +++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/static-analysis/assert-startsWithLetter.php 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 @@ +