Skip to content

Commit

Permalink
[PHPStanStaticTypeMapper] Improve UnionTypeMapper performance (#3686)
Browse files Browse the repository at this point in the history
early in_array instead of in loop
  • Loading branch information
samsonasik committed Apr 25, 2023
1 parent 92d38cf commit bd478cc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,17 @@ private function resolveUnionTypes(PhpParserUnionType $phpParserUnionType): ?Php
$identifierNames[] = $type->toString();
}
}

if (! in_array('bool', $identifierNames, true)) {
return $phpParserUnionType;
}

if (! in_array('false', $identifierNames, true)) {
return $phpParserUnionType;
}

foreach ($phpParserUnionType->types as $key => $type) {
if ($type instanceof Identifier && in_array('bool', $identifierNames, true) && $type->toString() === 'false') {
if ($type instanceof Identifier && $type->toString() === 'false') {
unset($phpParserUnionType->types[$key]);
$phpParserUnionType->types = array_values($phpParserUnionType->types);

Expand Down

0 comments on commit bd478cc

Please sign in to comment.