Skip to content

Commit

Permalink
Simplified concatenating strings to prevent combinatorial explosion
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 6, 2018
1 parent c29225f commit 7190ec9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
14 changes: 2 additions & 12 deletions src/Analyser/Scope.php
Expand Up @@ -616,18 +616,8 @@ private function resolveType(Expr $node): Type
return new ErrorType();
}

$leftConstantStrings = TypeUtils::getConstantStrings($leftStringType);
$rightConstantStrings = TypeUtils::getConstantStrings($rightStringType);

if (count($leftConstantStrings) > 0 && count($rightConstantStrings) > 0) {
$resultTypes = [];
foreach ($leftConstantStrings as $leftType) {
foreach ($rightConstantStrings as $rightType) {
$resultTypes[] = $leftType->append($rightType);
}
}

return TypeCombinator::union(...$resultTypes);
if ($leftStringType instanceof ConstantStringType && $rightStringType instanceof ConstantStringType) {
return $leftStringType->append($rightStringType);
}

return new StringType();
Expand Down
6 changes: 3 additions & 3 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Expand Up @@ -2588,15 +2588,15 @@ public function dataBinaryOperations(): array
'$decrementedFooString',
],
[
'\'barbar\'|\'barfoo\'|\'foobar\'|\'foofoo\'',
'string',
'$conditionalString . $conditionalString',
],
[
'\'baripsum\'|\'barlorem\'|\'fooipsum\'|\'foolorem\'',
'string',
'$conditionalString . $anotherConditionalString',
],
[
'\'ipsumbar\'|\'ipsumfoo\'|\'lorembar\'|\'loremfoo\'',
'string',
'$anotherConditionalString . $conditionalString',
],
[
Expand Down

0 comments on commit 7190ec9

Please sign in to comment.