Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
rvanvelzen committed Apr 4, 2022
1 parent 986b8f6 commit 2d7ba24
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/PhpDoc/TypeNodeResolver.php
Expand Up @@ -79,8 +79,9 @@
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Traversable;
use function array_key_exists;
use function array_keys;
use function array_map;
use function array_unique;
use function count;
use function get_class;
use function in_array;
Expand Down Expand Up @@ -854,26 +855,24 @@ private function resolveConstTypeNode(ConstTypeNode $typeNode, NameScope $nameSc

private function generateIntMaskType(Type $type): ?Type
{
$ints = TypeUtils::getConstantIntegers($type);
$ints = array_map(static fn (ConstantIntegerType $type) => $type->getValue(), TypeUtils::getConstantIntegers($type));
if (count($ints) === 0) {
return null;
}

$values = [];

foreach ($ints as $int) {
$int = $int->getValue();

if ($int !== 0) {
if ($int !== 0 && !array_key_exists($int, $values)) {
foreach ($values as $value) {
$values[] = $value | $int;
$values[$value | $int] = true;
}
}

$values[] = $int;
$values[$int] = true;
}

$values = array_map(static fn ($value) => new ConstantIntegerType($value), array_unique($values));
$values = array_map(static fn ($value) => new ConstantIntegerType($value), array_keys($values));

return TypeCombinator::union(...$values);
}
Expand Down

0 comments on commit 2d7ba24

Please sign in to comment.