forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtensionClassHelper.php
More file actions
47 lines (37 loc) · 1.43 KB
/
Copy pathExtensionClassHelper.php
File metadata and controls
47 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php declare(strict_types = 1);
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[]
*/
public static function getExtensionClassNames(ReflectionProvider $reflectionProvider, string $className): array
{
if (!array_key_exists($className, self::$extensionClassNames)) {
$class = $reflectionProvider->getClass($className);
self::$extensionClassNames[$className] = array_merge([$className], $class->getParentClassesNames(), $class->getNativeReflection()->getInterfaceNames());
}
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];
}
}