Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -669,18 +669,6 @@ parameters:
count: 1
path: src/Rules/Generics/TemplateTypeCheck.php

-
rawMessage: 'Function class_implements() is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine. Use objects retrieved from ReflectionProvider instead.'
identifier: phpstanApi.runtimeReflection
count: 1
path: src/Rules/LazyRegistry.php

-
rawMessage: 'Function class_parents() is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine. Use objects retrieved from ReflectionProvider instead.'
identifier: phpstanApi.runtimeReflection
count: 1
path: src/Rules/LazyRegistry.php

-
rawMessage: 'Method PHPStan\Rules\LazyRegistry::getRulesByNodeType() return type with generic interface PHPStan\Rules\Rule does not specify its types: TNodeType'
identifier: missingType.generics
Expand Down
5 changes: 2 additions & 3 deletions src/Collectors/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

use PhpParser\Node;
use PHPStan\DependencyInjection\AutowiredService;
use function class_implements;
use function class_parents;
use PHPStan\Type\ExtensionClassHelper;

#[AutowiredService(factory: '@PHPStan\Collectors\RegistryFactory::create')]
final class Registry
Expand Down Expand Up @@ -35,7 +34,7 @@ public function __construct(array $collectors)
public function getCollectors(string $nodeType): array
{
if (!isset($this->cache[$nodeType])) {
$parentNodeTypes = [$nodeType] + class_parents($nodeType) + class_implements($nodeType);
$parentNodeTypes = ExtensionClassHelper::getExtensionClassNamesByRuntimeReflection($nodeType);

$collectors = [];
foreach ($parentNodeTypes as $parentNodeType) {
Expand Down
5 changes: 2 additions & 3 deletions src/Rules/LazyRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
use PHPStan\DependencyInjection\AutowiredExtensions;
use PHPStan\DependencyInjection\AutowiredService;
use PHPStan\DependencyInjection\ExtensionsCollection;
use function class_implements;
use function class_parents;
use PHPStan\Type\ExtensionClassHelper;

#[AutowiredService(name: 'registry', as: Registry::class)]
final class LazyRegistry implements Registry
Expand Down Expand Up @@ -39,7 +38,7 @@ public function __construct(
public function getRules(string $nodeType): array
{
if (!isset($this->cache[$nodeType])) {
$parentNodeTypes = [$nodeType] + class_parents($nodeType) + class_implements($nodeType);
$parentNodeTypes = ExtensionClassHelper::getExtensionClassNamesByRuntimeReflection($nodeType);

$rules = [];
$rulesFromContainer = $this->getRulesByNodeType();
Expand Down
19 changes: 19 additions & 0 deletions src/Type/ExtensionClassHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@

namespace PHPStan\Type;

use PhpParser\Node;
use PHPStan\Reflection\ReflectionProvider;
use function array_key_exists;
use function array_merge;
use function class_implements;
use function class_parents;

final class ExtensionClassHelper
{

/** @var array<string, array<string>> */
private static array $extensionClassNames = [];

/** @var array<class-string<Node>, array<class-string<Node>>> */
private static array $extensionClassNamesRuntimeReflections = [];

/**
* @return string[]
*/
Expand All @@ -25,4 +31,17 @@ public static function getExtensionClassNames(ReflectionProvider $reflectionProv
return self::$extensionClassNames[$className];
}

/**
* @param class-string<Node> $className
* @return array<class-string<Node>>
*/
public static function getExtensionClassNamesByRuntimeReflection(string $className): array
{
if (!array_key_exists($className, self::$extensionClassNamesRuntimeReflections)) {
self::$extensionClassNamesRuntimeReflections[$className] = [$className] + class_parents($className) + class_implements($className);
}

return self::$extensionClassNamesRuntimeReflections[$className];
}

}
Loading