Skip to content

Commit

Permalink
Merge pull request #8444 from SCIF/bugfix-8439
Browse files Browse the repository at this point in the history
trim(), ltrim(), rtrim() now keep lowercase string attribute
  • Loading branch information
AndrolGenhald committed Aug 31, 2022
2 parents 1eeea7c + d709728 commit faf106e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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

0 comments on commit faf106e

Please sign in to comment.