Skip to content

Commit b35db46

Browse files
committed
support mb_r/l/trim
1 parent 0cc03f6 commit b35db46

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,10 @@ private function specifyTypesForConstantStringBinaryExpression(
13071307
$context->false()
13081308
&& $exprNode instanceof FuncCall
13091309
&& $exprNode->name instanceof Name
1310-
&& in_array(strtolower((string) $exprNode->name), ['trim', 'ltrim', 'rtrim'], true)
1310+
&& in_array(strtolower((string) $exprNode->name), [
1311+
'trim', 'ltrim', 'rtrim',
1312+
'mb_trim', 'mb_ltrim', 'mb_rtrim',
1313+
], true)
13111314
&& isset($exprNode->getArgs()[0])
13121315
&& $constantStringValue === ''
13131316
) {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php // lint >= 8.4
2+
3+
namespace Bug12973Php84;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function mbtrim($value): void
8+
{
9+
if (mb_trim($value) === '') {
10+
assertType('mixed', $value);
11+
} else {
12+
assertType('non-empty-string', $value);
13+
}
14+
assertType('mixed', $value);
15+
16+
if (mb_ltrim($value) === '') {
17+
assertType('mixed', $value);
18+
} else {
19+
assertType('non-empty-string', $value);
20+
}
21+
assertType('mixed', $value);
22+
23+
if (mb_rtrim($value) === '') {
24+
assertType('mixed', $value);
25+
} else {
26+
assertType('non-empty-string', $value);
27+
}
28+
assertType('mixed', $value);
29+
}

0 commit comments

Comments
 (0)