Skip to content

Commit 6b49219

Browse files
committed
trim MixedType
1 parent ec7d510 commit 6b49219

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,14 +1313,15 @@ private function specifyTypesForConstantStringBinaryExpression(
13131313
) {
13141314
$argType = $scope->getType($exprNode->getArgs()[0]->value);
13151315

1316-
if ($argType->isString()->yes()) {
1317-
return $this->create(
1318-
$exprNode->getArgs()[0]->value,
1316+
return $this->create(
1317+
$exprNode->getArgs()[0]->value,
1318+
TypeCombinator::intersect(
1319+
new StringType(),
13191320
new AccessoryNonEmptyStringType(),
1320-
$context->negate(),
1321-
$scope,
1322-
)->setRootExpr($rootExpr);
1323-
}
1321+
),
1322+
$context->negate(),
1323+
$scope,
1324+
)->setRootExpr($rootExpr);
13241325
}
13251326

13261327
return null;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ function nullIfBlank(?string $value): ?string
1616
return null;
1717
}
1818

19+
function trimMixed($value): void
20+
{
21+
if (trim($value) === '') {
22+
assertType('mixed', $value);
23+
} else {
24+
assertType('non-empty-string', $value);
25+
}
26+
assertType('mixed', $value);
27+
28+
}
29+
1930
function trimTypes(string $value): void
2031
{
2132
if (trim($value) === '') {

0 commit comments

Comments
 (0)