Skip to content

Commit 88b7f50

Browse files
committed
After trim($s) !== '' the $s can still be mixed
1 parent f6ed272 commit 88b7f50

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,15 +1314,19 @@ private function specifyTypesForConstantStringBinaryExpression(
13141314
&& isset($exprNode->getArgs()[0])
13151315
&& $constantStringValue === ''
13161316
) {
1317-
return $this->create(
1318-
$exprNode->getArgs()[0]->value,
1319-
TypeCombinator::intersect(
1320-
new StringType(),
1321-
new AccessoryNonEmptyStringType(),
1322-
),
1323-
$context->negate(),
1324-
$scope,
1325-
)->setRootExpr($rootExpr);
1317+
$argValue = $exprNode->getArgs()[0]->value;
1318+
$argType = $scope->getType($argValue);
1319+
if ($argType->isString()->yes()) {
1320+
return $this->create(
1321+
$argValue,
1322+
TypeCombinator::intersect(
1323+
new StringType(),
1324+
new AccessoryNonEmptyStringType(),
1325+
),
1326+
$context->negate(),
1327+
$scope,
1328+
)->setRootExpr($rootExpr);
1329+
}
13261330
}
13271331

13281332
return null;

tests/PHPStan/Analyser/nsrt/bug-12973-php84.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ function mbtrim($value): void
99
if (mb_trim($value) === '') {
1010
assertType('mixed', $value);
1111
} else {
12-
assertType('non-empty-string', $value);
12+
assertType('mixed', $value);
1313
}
1414
assertType('mixed', $value);
1515

1616
if (mb_ltrim($value) === '') {
1717
assertType('mixed', $value);
1818
} else {
19-
assertType('non-empty-string', $value);
19+
assertType('mixed', $value);
2020
}
2121
assertType('mixed', $value);
2222

2323
if (mb_rtrim($value) === '') {
2424
assertType('mixed', $value);
2525
} else {
26-
assertType('non-empty-string', $value);
26+
assertType('mixed', $value);
2727
}
2828
assertType('mixed', $value);
2929
}

tests/PHPStan/Analyser/nsrt/bug-12973.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function trimMixed($value): void
2121
if (trim($value) === '') {
2222
assertType('mixed', $value);
2323
} else {
24-
assertType('non-empty-string', $value);
24+
assertType('mixed', $value);
2525
}
2626
assertType('mixed', $value);
2727

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php // lint >= 8.0
2+
3+
namespace Bug13552;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
function doSomething(mixed $value): void
8+
{
9+
if (trim($value) === '') {
10+
return;
11+
}
12+
assertType('mixed', $value);
13+
}

0 commit comments

Comments
 (0)