diff --git a/src/Type/FiniteTypeSet.php b/src/Type/FiniteTypeSet.php index 4ed2714ef95..fc7c9de02f0 100644 --- a/src/Type/FiniteTypeSet.php +++ b/src/Type/FiniteTypeSet.php @@ -42,8 +42,6 @@ final class FiniteTypeSet private const ENUM_CASE_KEY_PREFIX = 'enum:'; - private ?bool $hasClassStringMember = null; - /** * @param array $members * @param array $membersByKind @@ -256,36 +254,4 @@ public function containedInKey(string $key): TrinaryLogic return TrinaryLogic::createMaybe(); } - /** - * Whether a constant string member might also be a class-string. - * - * The class-string flag is part of a constant string's representation but not of its - * value, so operations that pick a member to hand back - as opposed to merely comparing - * values - cannot treat two same-valued constant strings as interchangeable. Answering - * this costs a reflection lookup per string member, so it is computed on demand: only - * combining operations ask. - * - * Every member is asked, no matter its kind: a keyed member is an instance of one of the - * five classes key() accepts, and every one of them but ConstantStringType answers - * isClassString() no outright - which is also the only one whose answer costs anything. - */ - public function hasClassStringMember(): bool - { - if ($this->hasClassStringMember !== null) { - return $this->hasClassStringMember; - } - - $this->hasClassStringMember = false; - foreach ($this->members as $member) { - if ($member->isClassString()->no()) { - continue; - } - - $this->hasClassStringMember = true; - break; - } - - return $this->hasClassStringMember; - } - } diff --git a/src/Type/TypeCombinator.php b/src/Type/TypeCombinator.php index 736c9aec7e6..dd298be650e 100644 --- a/src/Type/TypeCombinator.php +++ b/src/Type/TypeCombinator.php @@ -1595,10 +1595,6 @@ private static function finiteUnionMembers(UnionType $union): ?array return null; } - if ($finiteTypeSet->hasClassStringMember()) { - return null; - } - return $finiteTypeSet->getMembers(); } diff --git a/tests/PHPStan/Type/FiniteTypeSetTest.php b/tests/PHPStan/Type/FiniteTypeSetTest.php index c3fae75fe6a..3465b440baf 100644 --- a/tests/PHPStan/Type/FiniteTypeSetTest.php +++ b/tests/PHPStan/Type/FiniteTypeSetTest.php @@ -666,41 +666,6 @@ public function testUnionComparisonsRequireBothSetsToBeComplete(): void $this->assertSame('Maybe', $union->isAcceptedBy($otherUnion, true)->result->describe()); } - /** - * @return Iterator, bool}> - */ - public static function dataHasClassStringMember(): Iterator - { - yield 'plain strings' => [[new ConstantStringType('a'), new ConstantStringType('b')], false]; - yield 'a value that names a class' => [[new ConstantStringType('a'), new ConstantStringType('DateTimeImmutable')], true]; - yield 'the class-string flag' => [[new ConstantStringType('a'), new ConstantStringType('Zzz', true)], true]; - // every member is asked, but only a string one can answer anything but no - not even - // an enum case, whose class name does name a class - yield 'no strings at all' => [ - [ - new ConstantIntegerType(1), - new ConstantBooleanType(true), - new NullType(), - new EnumCaseObjectType('PHPStan\Fixture\ManyCasesTestEnum', 'A'), - ], - false, - ]; - } - - /** - * @param list $types - */ - #[DataProvider('dataHasClassStringMember')] - public function testHasClassStringMember(array $types, bool $expected): void - { - $set = FiniteTypeSet::create($types); - $this->assertNotNull($set); - - $this->assertSame($expected, $set->hasClassStringMember()); - // answered from the cache the second time round, with the same answer - $this->assertSame($expected, $set->hasClassStringMember()); - } - public function testUnionWithoutFiniteMembersHasNoSet(): void { $this->assertNull((new UnionType([new StringType(), new IntegerType()]))->getFiniteTypeSet());