Skip to content

Commit

Permalink
Remove TypeCombinator::CONSTANT_SCALAR_UNION_THRESHOLD
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 18, 2021
1 parent 66fb725 commit c56d866
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
11 changes: 0 additions & 11 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
class TypeCombinator
{

private const CONSTANT_SCALAR_UNION_THRESHOLD = 8;

public static function addNull(Type $type): Type
{
return self::union($type, new NullType());
Expand Down Expand Up @@ -289,15 +287,6 @@ public static function union(Type ...$types): Type
continue;
}
foreach ($scalarTypeItems as $type) {
if (count($scalarTypeItems) > self::CONSTANT_SCALAR_UNION_THRESHOLD) {
$types[] = $type->generalize(GeneralizePrecision::moreSpecific());

if ($type instanceof ConstantStringType) {
continue;
}

break;
}
$types[] = $type;
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Analyser/data/bug-2677.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ function ()
assertType('array(\'Bug2677\\\\A\', \'Bug2677\\\\B\', \'Bug2677\\\\C\', \'Bug2677\\\\D\', \'Bug2677\\\\E\', \'Bug2677\\\\F\', \'Bug2677\\\\G\', \'Bug2677\\\\H\', \'Bug2677\\\\I\', \'Bug2677\\\\J\', \'Bug2677\\\\K\', \'Bug2677\\\\L\', \'Bug2677\\\\M\', \'Bug2677\\\\N\', \'Bug2677\\\\O\', \'Bug2677\\\\P\')', $classes);

foreach ($classes as $class) {
assertType('class-string', $class);
assertType('\'Bug2677\\\\A\'|\'Bug2677\\\\B\'|\'Bug2677\\\\C\'|\'Bug2677\\\\D\'|\'Bug2677\\\\E\'|\'Bug2677\\\\F\'|\'Bug2677\\\\G\'|\'Bug2677\\\\H\'|\'Bug2677\\\\I\'|\'Bug2677\\\\J\'|\'Bug2677\\\\K\'|\'Bug2677\\\\L\'|\'Bug2677\\\\M\'|\'Bug2677\\\\N\'|\'Bug2677\\\\O\'|\'Bug2677\\\\P\'', $class);
}
};
4 changes: 2 additions & 2 deletions tests/PHPStan/Type/TypeCombinatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,8 @@ public function dataUnion(): array
new ConstantStringType('loremm'),
new ConstantStringType('loremmm'),
],
IntersectionType::class,
'non-empty-string',
UnionType::class,
"'bar'|'barr'|'baz'|'bazz'|'foo'|'fooo'|'lorem'|'loremm'|'loremmm'",
],
[
[
Expand Down

0 comments on commit c56d866

Please sign in to comment.