Skip to content

Commit

Permalink
Removing from UnionType - use unionTypes() protected method
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 22, 2022
1 parent 6bc1fb5 commit 74ae46c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,7 @@ public function traverse(callable $cb): Type

public function tryRemove(Type $typeToRemove): ?Type
{
$innerTypes = [];
foreach ($this->getTypes() as $innerType) {
$innerTypes[] = TypeCombinator::remove($innerType, $typeToRemove);
}

return TypeCombinator::union(...$innerTypes);
return $this->unionTypes(static fn (Type $type): Type => TypeCombinator::remove($type, $typeToRemove));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ public function testStrictComparison(): void
426,
],
[
'Strict comparison using === between int<min, 0>|int<2, max>|string and 1.0 will always evaluate to false.',
'Strict comparison using === between (int<min, 0>|int<2, max>|string) and 1.0 will always evaluate to false.',
464,
],
[
'Strict comparison using === between int<min, 0>|int<2, max>|string and stdClass will always evaluate to false.',
'Strict comparison using === between (int<min, 0>|int<2, max>|string) and stdClass will always evaluate to false.',
466,
],
[
Expand Down Expand Up @@ -333,11 +333,11 @@ public function testStrictComparisonWithoutAlwaysTrue(): void
408,
],
[
'Strict comparison using === between int<min, 0>|int<2, max>|string and 1.0 will always evaluate to false.',
'Strict comparison using === between (int<min, 0>|int<2, max>|string) and 1.0 will always evaluate to false.',
464,
],
[
'Strict comparison using === between int<min, 0>|int<2, max>|string and stdClass will always evaluate to false.',
'Strict comparison using === between (int<min, 0>|int<2, max>|string) and stdClass will always evaluate to false.',
466,
],
[
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Type/TypeCombinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3669,13 +3669,13 @@ public function dataRemove(): array
new BenevolentUnionType([new IntegerType(), new StringType()]),
new ConstantStringType('foo'),
UnionType::class,
'int|string',
'(int|string)',
],
[
new BenevolentUnionType([new IntegerType(), new StringType()]),
new ConstantIntegerType(1),
UnionType::class,
'int<min, 0>|int<2, max>|string',
'(int<min, 0>|int<2, max>|string)',
],
[
new BenevolentUnionType([new IntegerType(), new StringType()]),
Expand Down

0 comments on commit 74ae46c

Please sign in to comment.