Skip to content

Commit d451b82

Browse files
committed
Simplify FiniteTypeSet
1 parent 0d109aa commit d451b82

3 files changed

Lines changed: 0 additions & 73 deletions

File tree

src/Type/FiniteTypeSet.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ final class FiniteTypeSet
4242

4343
private const ENUM_CASE_KEY_PREFIX = 'enum:';
4444

45-
private ?bool $hasClassStringMember = null;
46-
4745
/**
4846
* @param array<string, Type> $members
4947
* @param array<string, Type> $membersByKind
@@ -256,36 +254,4 @@ public function containedInKey(string $key): TrinaryLogic
256254
return TrinaryLogic::createMaybe();
257255
}
258256

259-
/**
260-
* Whether a constant string member might also be a class-string.
261-
*
262-
* The class-string flag is part of a constant string's representation but not of its
263-
* value, so operations that pick a member to hand back - as opposed to merely comparing
264-
* values - cannot treat two same-valued constant strings as interchangeable. Answering
265-
* this costs a reflection lookup per string member, so it is computed on demand: only
266-
* combining operations ask.
267-
*
268-
* Every member is asked, no matter its kind: a keyed member is an instance of one of the
269-
* five classes key() accepts, and every one of them but ConstantStringType answers
270-
* isClassString() no outright - which is also the only one whose answer costs anything.
271-
*/
272-
public function hasClassStringMember(): bool
273-
{
274-
if ($this->hasClassStringMember !== null) {
275-
return $this->hasClassStringMember;
276-
}
277-
278-
$this->hasClassStringMember = false;
279-
foreach ($this->members as $member) {
280-
if ($member->isClassString()->no()) {
281-
continue;
282-
}
283-
284-
$this->hasClassStringMember = true;
285-
break;
286-
}
287-
288-
return $this->hasClassStringMember;
289-
}
290-
291257
}

src/Type/TypeCombinator.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,10 +1595,6 @@ private static function finiteUnionMembers(UnionType $union): ?array
15951595
return null;
15961596
}
15971597

1598-
if ($finiteTypeSet->hasClassStringMember()) {
1599-
return null;
1600-
}
1601-
16021598
return $finiteTypeSet->getMembers();
16031599
}
16041600

tests/PHPStan/Type/FiniteTypeSetTest.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -666,41 +666,6 @@ public function testUnionComparisonsRequireBothSetsToBeComplete(): void
666666
$this->assertSame('Maybe', $union->isAcceptedBy($otherUnion, true)->result->describe());
667667
}
668668

669-
/**
670-
* @return Iterator<string, array{list<Type>, bool}>
671-
*/
672-
public static function dataHasClassStringMember(): Iterator
673-
{
674-
yield 'plain strings' => [[new ConstantStringType('a'), new ConstantStringType('b')], false];
675-
yield 'a value that names a class' => [[new ConstantStringType('a'), new ConstantStringType('DateTimeImmutable')], true];
676-
yield 'the class-string flag' => [[new ConstantStringType('a'), new ConstantStringType('Zzz', true)], true];
677-
// every member is asked, but only a string one can answer anything but no - not even
678-
// an enum case, whose class name does name a class
679-
yield 'no strings at all' => [
680-
[
681-
new ConstantIntegerType(1),
682-
new ConstantBooleanType(true),
683-
new NullType(),
684-
new EnumCaseObjectType('PHPStan\Fixture\ManyCasesTestEnum', 'A'),
685-
],
686-
false,
687-
];
688-
}
689-
690-
/**
691-
* @param list<Type> $types
692-
*/
693-
#[DataProvider('dataHasClassStringMember')]
694-
public function testHasClassStringMember(array $types, bool $expected): void
695-
{
696-
$set = FiniteTypeSet::create($types);
697-
$this->assertNotNull($set);
698-
699-
$this->assertSame($expected, $set->hasClassStringMember());
700-
// answered from the cache the second time round, with the same answer
701-
$this->assertSame($expected, $set->hasClassStringMember());
702-
}
703-
704669
public function testUnionWithoutFiniteMembersHasNoSet(): void
705670
{
706671
$this->assertNull((new UnionType([new StringType(), new IntegerType()]))->getFiniteTypeSet());

0 commit comments

Comments
 (0)