1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Add php8 str_* functions signatures

This commit is contained in:
fluffycondor 2023-03-17 16:39:04 +06:00
parent 531eec6df8
commit c2dae0e43f
2 changed files with 47 additions and 0 deletions

View File

@ -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

View File

@ -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' => '<?php
$a1 = str_starts_with(uniqid(), "");
/** @psalm-suppress InvalidLiteralArgument */
$b1 = str_starts_with("", "random string");
$c1 = str_starts_with(uniqid(), "random string");
$a2 = str_ends_with(uniqid(), "");
/** @psalm-suppress InvalidLiteralArgument */
$b2 = str_ends_with("", "random string");
$c2 = str_ends_with(uniqid(), "random string");
$a3 = str_contains(uniqid(), "");
/** @psalm-suppress InvalidLiteralArgument */
$b3 = str_contains("", "random string");
$c3 = str_contains(uniqid(), "random string");
',
'assertions' => [
'$a1===' => 'true',
'$b1===' => 'false',
'$c1===' => 'bool',
'$a2===' => 'true',
'$b2===' => 'false',
'$c2===' => 'bool',
'$a3===' => 'true',
'$b3===' => 'false',
'$c3===' => 'bool',
],
];
}
public function providerInvalidCodeParse(): iterable