Skip to content

Commit

Permalink
Get rid of instanceof TypeWithClassName in InstantiationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Jan 16, 2023
1 parent 67575b6 commit 1c6deb1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Rules/Classes/InstantiationRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\ShouldNotHappenException;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\TypeWithClassName;
use function array_map;
use function array_merge;
use function count;
Expand Down Expand Up @@ -220,12 +219,15 @@ private function getClassNames(Node $node, Scope $scope): array
}

if ($node->class instanceof Node\Stmt\Class_) {
$anonymousClassType = $scope->getType($node);
if (!$anonymousClassType instanceof TypeWithClassName) {
$classNames = $scope->getType($node)->getObjectClassNames();
if ($classNames === []) {
throw new ShouldNotHappenException();
}

return [[$anonymousClassType->getClassName(), true]];
return array_map(
static fn (string $className) => [$className, true],
$classNames,
);
}

$type = $scope->getType($node->class);
Expand Down

0 comments on commit 1c6deb1

Please sign in to comment.