From c2dae0e43f22073336c6d19480e8a82c3d606c47 Mon Sep 17 00:00:00 2001 From: fluffycondor <7ionmail@gmail.com> Date: Fri, 17 Mar 2023 16:39:04 +0600 Subject: [PATCH] Add php8 str_* functions signatures --- stubs/CoreGenericFunctions.phpstub | 18 ++++++++++++++++++ tests/CoreStubsTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index eaf02d61a..741290ceb 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -1057,6 +1057,24 @@ function str_shuffle(string $string): string {} */ function str_split(string $string, int $length = 1) {} +/** + * @psalm-pure + * @return ($needle is '' ? true : ($haystack is '' ? false : bool)) + */ +function str_starts_with(string $haystack, string $needle): bool + +/** + * @psalm-pure + * @return ($needle is '' ? true : ($haystack is '' ? false : bool)) + */ +function str_ends_with(string $haystack, string $needle): bool + +/** + * @psalm-pure + * @return ($needle is '' ? true : ($haystack is '' ? false : bool)) + */ +function str_contains(string $haystack, string $needle): bool + /** * @psalm-pure * @return string|false diff --git a/tests/CoreStubsTest.php b/tests/CoreStubsTest.php index fe2ee5ea9..acb48e0ba 100644 --- a/tests/CoreStubsTest.php +++ b/tests/CoreStubsTest.php @@ -151,6 +151,35 @@ class CoreStubsTest extends TestCase '$f===' => 'false|non-empty-string', ], ]; + yield 'str_starts_with/str_ends_with/str_contains redundant condition detection' => [ + 'code' => ' [ + '$a1===' => 'true', + '$b1===' => 'false', + '$c1===' => 'bool', + '$a2===' => 'true', + '$b2===' => 'false', + '$c2===' => 'bool', + '$a3===' => 'true', + '$b3===' => 'false', + '$c3===' => 'bool', + ], + ]; } public function providerInvalidCodeParse(): iterable