Skip to content

Commit d709728

Browse files
committed
trim(), ltrim(), rtrim() now keep lowercase string attribute
1 parent 1eeea7c commit d709728

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

stubs/CoreGenericFunctions.phpstub

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,14 +566,24 @@ function strpos($haystack, $needle, int $offset = 0) : int {}
566566
/**
567567
* @psalm-pure
568568
*
569+
* @return (
570+
* $string is class-string
571+
* ? ($characters is '\\' ? class-string : string)
572+
* : ($string is lowercase-string ? lowercase-string : string)
573+
* )
574+
*
569575
* @psalm-flow ($string) -> return
570576
*/
571577
function trim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
572578

573579
/**
574580
* @psalm-pure
575581
*
576-
* @return ($string is class-string ? ($characters is '\\' ? class-string : string) : string)
582+
* @return (
583+
* $string is class-string
584+
* ? ($characters is '\\' ? class-string : string)
585+
* : ($string is lowercase-string ? lowercase-string : string)
586+
* )
577587
*
578588
* @psalm-flow ($string) -> return
579589
*/
@@ -582,6 +592,8 @@ function ltrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}
582592
/**
583593
* @psalm-pure
584594
*
595+
* @return ($string is lowercase-string ? lowercase-string : string)
596+
*
585597
* @psalm-flow ($string) -> return
586598
*/
587599
function rtrim(string $string, string $characters = " \t\n\r\0\x0B") : string {}

tests/FunctionCallTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,33 @@ function sayHello(string $needle): void {
17851785
[],
17861786
'8.0',
17871787
],
1788+
'trimSavesLowercaseAttribute' => [
1789+
'<?php
1790+
$a = random_bytes(2);
1791+
$b = trim(strtolower($a));
1792+
',
1793+
'assertions' => [
1794+
'$b===' => 'lowercase-string',
1795+
],
1796+
],
1797+
'ltrimSavesLowercaseAttribute' => [
1798+
'<?php
1799+
$a = random_bytes(2);
1800+
$b = ltrim(strtolower($a));
1801+
',
1802+
'assertions' => [
1803+
'$b===' => 'lowercase-string',
1804+
],
1805+
],
1806+
'rtrimSavesLowercaseAttribute' => [
1807+
'<?php
1808+
$a = random_bytes(2);
1809+
$b = rtrim(strtolower($a));
1810+
',
1811+
'assertions' => [
1812+
'$b===' => 'lowercase-string',
1813+
],
1814+
],
17881815
];
17891816
}
17901817

0 commit comments

Comments
 (0)