Total Complexity | 19 |
Total Lines | 120 |
Duplicated Lines | 0 % |
Coverage | 92.16% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
20 | final class DocBlockResolvable |
||
21 | { |
||
22 | /** @var array<string,string> [fileName => fileContent] cached */ |
||
23 | private static array $fileContentCache = []; |
||
24 | |||
25 | /** @var class-string */ |
||
1 ignored issue
–
show
|
|||
26 | private string $callerClass; |
||
27 | |||
28 | /** @var class-string|string */ |
||
1 ignored issue
–
show
|
|||
29 | private string $callerParentClass; |
||
30 | |||
31 | /** |
||
32 | * @param class-string $callerClass |
||
1 ignored issue
–
show
|
|||
33 | * @param class-string|string $callerParentClass |
||
34 | */ |
||
35 | 13 | private function __construct(string $callerClass, string $callerParentClass) |
|
36 | { |
||
37 | 13 | $this->callerClass = $callerClass; |
|
38 | 13 | $this->callerParentClass = $callerParentClass; |
|
39 | } |
||
40 | |||
41 | 13 | public static function fromCaller(object $caller): self |
|
42 | { |
||
43 | 13 | return new self( |
|
44 | 13 | get_class($caller), |
|
45 | 13 | get_parent_class($caller) ?: '' |
|
46 | ); |
||
47 | } |
||
48 | |||
49 | 13 | public function getClassName(string $method): string |
|
61 | } |
||
62 | |||
63 | |||
64 | public function hasParentClass(): bool |
||
65 | { |
||
66 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
67 | return $this->callerParentClass !== '' |
||
68 | && method_exists($this->callerParentClass, '__call'); |
||
69 | } |
||
70 | |||
71 | 11 | public function normalizeResolvableType(string $resolvableType): string |
|
72 | { |
||
73 | /** @var list<string> $resolvableTypeParts */ |
||
74 | 11 | $resolvableTypeParts = explode('\\', ltrim($resolvableType, '\\')); |
|
75 | 11 | $normalizedResolvableType = end($resolvableTypeParts); |
|
76 | |||
77 | 11 | return is_string($normalizedResolvableType) |
|
78 | 11 | ? $normalizedResolvableType |
|
79 | 11 | : $resolvableType; |
|
80 | } |
||
81 | |||
82 | 13 | public function createCustomServicesCache(): ClassNameCacheInterface |
|
83 | { |
||
84 | 13 | if (!$this->isProjectCacheEnabled()) { |
|
85 | 4 | return new InMemoryCache(CustomServicesCache::class); |
|
86 | } |
||
87 | |||
88 | 9 | return new CustomServicesCache( |
|
89 | 9 | Config::getInstance()->getCacheDir() |
|
90 | ); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @return class-string |
||
1 ignored issue
–
show
|
|||
95 | */ |
||
96 | 11 | private function getClassFromDoc(string $method): string |
|
108 | } |
||
109 | |||
110 | 11 | private function searchClassOverDocBlock(ReflectionClass $reflectionClass, string $method): string |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Look the uses, to find the fully-qualified class name for the className. |
||
119 | */ |
||
120 | 11 | private function searchClassOverUseStatements(ReflectionClass $reflectionClass, string $className): string |
|
121 | { |
||
122 | 11 | $fileName = (string)$reflectionClass->getFileName(); |
|
123 | 11 | if (!isset(self::$fileContentCache[$fileName])) { |
|
124 | 9 | self::$fileContentCache[$fileName] = (string)file_get_contents($fileName); |
|
125 | } |
||
126 | 11 | $phpFile = self::$fileContentCache[$fileName]; |
|
127 | |||
128 | 11 | return (new UseBlockParser())->getUseStatement($className, $phpFile); |
|
129 | } |
||
130 | |||
131 | 13 | private function generateCacheKey(string $method): string |
|
134 | } |
||
135 | |||
136 | 13 | private function isProjectCacheEnabled(): bool |
|
140 | } |
||
141 | } |
||
142 |