Skip to content

Commit

Permalink
Follow the 1.11 version of InstantiationRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ebln committed Jun 5, 2024
1 parent 24cf5d8 commit 0a29256
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ForceFactoryRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ private function getFactoriesFromAttributeByClass(\ReflectionClass $reflection):
*
* @psalm-return array<array{string, bool}>
*
* @license https://github.com/phpstan/phpstan/blob/1.1.2/LICENSE
* @author Ondřej Mirtes et al. https://github.com/phpstan/phpstan-src/blob/0.12.x/src/Rules/Classes/InstantiationRule.php#blob_contributors_box
* @license https://github.com/phpstan/phpstan-src/blob/1.11.x/LICENSE
* @author Ondřej Mirtes et al. https://github.com/phpstan/phpstan-src/blame/1.11.x/src/Rules/Classes/InstantiationRule.php
* @author ebln
*
* @see \PHPStan\Rules\Classes\InstantiationRule::getClassNames
Expand All @@ -163,17 +163,19 @@ private function getClassNames(\PhpParser\Node $node, \PHPStan\Analyser\Scope $s
return [[(string)$node->class, \true]];
}
if ($node->class instanceof \PhpParser\Node\Stmt\Class_) {
$anonymousClassType = $scope->getType($node);
if (!$anonymousClassType instanceof \PHPStan\Type\TypeWithClassName) {
$classNames = $scope->getType($node)->getObjectClassNames();
if ([] === $classNames) {
throw new \PHPStan\ShouldNotHappenException();
}
// Report back extended class!
if ($node->class->extends) {
return [[$node->class->extends->toString(), \true]];
}

// we don't care about the anonymous class' name and abort processing early
return [[$anonymousClassType->getClassName(), \false]];
return array_map(
static fn (string $className) => [$className, \false],
$classNames,
);
}
$type = $scope->getType($node->class);

Expand Down

0 comments on commit 0a29256

Please sign in to comment.