We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
chop()
rtrim()
1 parent a81a132 commit d32efcbCopy full SHA for d32efcb
src/Analyser/TypeSpecifier.php
@@ -1506,7 +1506,7 @@ private function specifyTypesForConstantStringBinaryExpression(
1506
&& $exprNode instanceof FuncCall
1507
&& $exprNode->name instanceof Name
1508
&& in_array(strtolower((string) $exprNode->name), [
1509
- 'trim', 'ltrim', 'rtrim',
+ 'trim', 'ltrim', 'rtrim', 'chop',
1510
'mb_trim', 'mb_ltrim', 'mb_rtrim',
1511
], true)
1512
&& isset($exprNode->getArgs()[0])
src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php
@@ -27,7 +27,7 @@ final class TrimFunctionDynamicReturnTypeExtension implements DynamicFunctionRet
27
28
public function isFunctionSupported(FunctionReflection $functionReflection): bool
29
{
30
- return in_array($functionReflection->getName(), ['trim', 'rtrim'], true);
+ return in_array($functionReflection->getName(), ['trim', 'rtrim', 'chop'], true);
31
}
32
33
public function getTypeFromFunctionCall(
tests/PHPStan/Analyser/nsrt/bug-12973.php
@@ -77,3 +77,20 @@ function rtrimTypes(string $value): void
77
78
assertType('string', $value);
79
80
+
81
+function chopTypes(string $value): void
82
+{
83
+ if (chop($value) === '') {
84
+ assertType('string', $value);
85
+ } else {
86
+ assertType('non-empty-string', $value);
87
+ }
88
89
90
+ if (chop($value) !== '') {
91
92
93
94
95
96
+}
tests/PHPStan/Analyser/nsrt/lowercase-string-trim.php
@@ -15,15 +15,19 @@ public function doTrim(string $lowercase, string $string): void
15
assertType('lowercase-string', trim($lowercase));
16
assertType('lowercase-string', ltrim($lowercase));
17
assertType('lowercase-string', rtrim($lowercase));
18
+ assertType('lowercase-string', chop($lowercase));
19
assertType('lowercase-string', trim($lowercase, $string));
20
assertType('lowercase-string', ltrim($lowercase, $string));
21
assertType('lowercase-string', rtrim($lowercase, $string));
22
23
assertType('string', trim($string));
24
assertType('string', ltrim($string));
25
assertType('string', rtrim($string));
26
+ assertType('string', chop($string));
assertType('string', trim($string, $lowercase));
assertType('string', ltrim($string, $lowercase));
assertType('string', rtrim($string, $lowercase));
+ assertType('string', chop($string, $lowercase));
tests/PHPStan/Analyser/nsrt/uppercase-string-trim.php
@@ -15,15 +15,19 @@ public function doTrim(string $uppercase, string $string): void
assertType('uppercase-string', trim($uppercase));
assertType('uppercase-string', ltrim($uppercase));
assertType('uppercase-string', rtrim($uppercase));
+ assertType('uppercase-string', chop($uppercase));
assertType('uppercase-string', trim($uppercase, $string));
assertType('uppercase-string', ltrim($uppercase, $string));
assertType('uppercase-string', rtrim($uppercase, $string));
+ assertType('uppercase-string', chop($uppercase, $string));
assertType('string', trim($string, $uppercase));
assertType('string', ltrim($string, $uppercase));
assertType('string', rtrim($string, $uppercase));
+ assertType('string', chop($string, $uppercase));
0 commit comments