Skip to content

Commit bb15b8d

Browse files
phpstan-botclaude
andcommitted
Re-apply get_class() simplification in ObjectType::equals()
The previous revert (9f0da34) was based on a faulty premise that TemplateObjectType has no equals() override. In fact, TemplateObjectType gets its equals() from TemplateTypeTrait, so get_class($type) !== static::class is correct and equivalent to the explicit instanceof checks. All tests (11726) and make phpstan pass with this simpler approach. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent faa8fc9 commit bb15b8d

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

phpstan-baseline.neon

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,22 +1473,16 @@ parameters:
14731473
count: 1
14741474
path: src/Type/ObjectShapeType.php
14751475

1476-
-
1477-
rawMessage: 'Doing instanceof PHPStan\Type\Enum\EnumCaseObjectType is error-prone and deprecated. Use Type::getEnumCases() instead.'
1478-
identifier: phpstanApi.instanceofType
1479-
count: 1
1480-
path: src/Type/ObjectType.php
1481-
14821476
-
14831477
rawMessage: Doing instanceof PHPStan\Type\Generic\GenericObjectType is error-prone and deprecated.
14841478
identifier: phpstanApi.instanceofType
1485-
count: 3
1479+
count: 1
14861480
path: src/Type/ObjectType.php
14871481

14881482
-
14891483
rawMessage: 'Doing instanceof PHPStan\Type\ObjectType is error-prone and deprecated. Use Type::isObject() or Type::getObjectClassNames() instead.'
14901484
identifier: phpstanApi.instanceofType
1491-
count: 3
1485+
count: 2
14921486
path: src/Type/ObjectType.php
14931487

14941488
-

src/Type/ObjectType.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
use function array_map;
5757
use function array_values;
5858
use function count;
59+
use function get_class;
5960
use function implode;
6061
use function in_array;
6162
use function sprintf;
@@ -624,15 +625,7 @@ public function isSuperTypeOf(Type $type): IsSuperTypeOfResult
624625

625626
public function equals(Type $type): bool
626627
{
627-
if (!$type instanceof self) {
628-
return false;
629-
}
630-
631-
if ($type instanceof EnumCaseObjectType) {
632-
return false;
633-
}
634-
635-
if ($type instanceof Generic\GenericObjectType && !$this instanceof Generic\GenericObjectType) {
628+
if (get_class($type) !== static::class) {
636629
return false;
637630
}
638631

0 commit comments

Comments
 (0)