Skip to content

Commit

Permalink
Get rid of instanceof TypeWithClassName in GenericClassStringType
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Jan 16, 2023
1 parent 7849841 commit e1695a5
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Type/Generic/GenericClassStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Type\Generic;

use PHPStan\Reflection\ReflectionProviderStaticAccessor;
use PHPStan\TrinaryLogic;
use PHPStan\Type\ClassStringType;
use PHPStan\Type\CompoundType;
Expand All @@ -15,9 +16,9 @@
use PHPStan\Type\StringType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
use function count;
use function sprintf;

/** @api */
Expand Down Expand Up @@ -183,13 +184,10 @@ public function tryRemove(Type $typeToRemove): ?Type
if ($typeToRemove instanceof ConstantStringType && $typeToRemove->isClassStringType()->yes()) {
$generic = $this->getGenericType();

if ($generic instanceof TypeWithClassName) {
$classReflection = $generic->getClassReflection();
if (
$classReflection !== null
&& $classReflection->isFinal()
&& $generic->getClassName() === $typeToRemove->getValue()
) {
$genericObjectClassNames = $generic->getObjectClassNames();
if (count($genericObjectClassNames) === 1) {
$classReflection = ReflectionProviderStaticAccessor::getInstance()->getClass($genericObjectClassNames[0]);
if ($classReflection->isFinal() && $genericObjectClassNames[0] === $typeToRemove->getValue()) {
return new NeverType();
}
}
Expand Down

0 comments on commit e1695a5

Please sign in to comment.