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