Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trim(), ltrim(), rtrim() now keep lowercase string attribute #8444

Merged
merged 1 commit into from Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion stubs/CoreGenericFunctions.phpstub
Expand Up @@ -566,14 +566,24 @@ function strpos($haystack, $needle, int $offset = 0) : int {}
/**
* @psalm-pure
*
* @return (
* $string is class-string
* ? ($characters is '\\' ? class-string : string)
* : ($string is lowercase-string ? lowercase-string : string)
* )
*
* @psalm-flow ($string) -> return
*/
function trim(string $string, string $characters = " \t\n\r\0\x0B") : string {}

/**
* @psalm-pure
*
* @return ($string is class-string ? ($characters is '\\' ? class-string : string) : string)
* @return (
* $string is class-string
* ? ($characters is '\\' ? class-string : string)
* : ($string is lowercase-string ? lowercase-string : string)
* )
*
* @psalm-flow ($string) -> return
*/
Expand All @@ -582,6 +592,8 @@ function ltrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
/**
* @psalm-pure
*
* @return ($string is lowercase-string ? lowercase-string : string)
*
* @psalm-flow ($string) -> return
*/
function rtrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
Expand Down
27 changes: 27 additions & 0 deletions tests/FunctionCallTest.php
Expand Up @@ -1785,6 +1785,33 @@ function sayHello(string $needle): void {
[],
'8.0',
],
'trimSavesLowercaseAttribute' => [
'<?php
$a = random_bytes(2);
$b = trim(strtolower($a));
',
'assertions' => [
'$b===' => 'lowercase-string',
],
],
'ltrimSavesLowercaseAttribute' => [
'<?php
$a = random_bytes(2);
$b = ltrim(strtolower($a));
',
'assertions' => [
'$b===' => 'lowercase-string',
],
],
'rtrimSavesLowercaseAttribute' => [
'<?php
$a = random_bytes(2);
$b = rtrim(strtolower($a));
',
'assertions' => [
'$b===' => 'lowercase-string',
],
],
];
}

Expand Down