@@ -19,8 +19,8 @@ |
||
19 | 19 | public function setTags(array $tags): void |
20 | 20 | { |
21 | 21 | $setTags = []; |
22 | - foreach ($tags as $key => $value) { |
|
23 | - if (!\is_string($value)) { |
|
22 | + foreach ($tags as $key => $value){ |
|
23 | + if (!\is_string($value)){ |
|
24 | 24 | throw new StateException(\sprintf( |
25 | 25 | 'Invalid tag value, string expected got %s', |
26 | 26 | get_debug_type($value) |
@@ -19,8 +19,10 @@ |
||
19 | 19 | public function setTags(array $tags): void |
20 | 20 | { |
21 | 21 | $setTags = []; |
22 | - foreach ($tags as $key => $value) { |
|
23 | - if (!\is_string($value)) { |
|
22 | + foreach ($tags as $key => $value) |
|
23 | + { |
|
24 | + if (!\is_string($value)) |
|
25 | + { |
|
24 | 26 | throw new StateException(\sprintf( |
25 | 27 | 'Invalid tag value, string expected got %s', |
26 | 28 | get_debug_type($value) |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | |
38 | 38 | public function isDebug(): bool |
39 | 39 | { |
40 | - return (bool) ($this->config['debug'] ?? false); |
|
40 | + return (bool)($this->config['debug'] ?? false); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function getDirectories(): array |
47 | 47 | { |
48 | - return $this->config['directories'] ?? [(string) \getcwd()]; |
|
48 | + return $this->config['directories'] ?? [(string)\getcwd()]; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -8,10 +8,10 @@ |
||
8 | 8 | { |
9 | 9 | public function __construct( |
10 | 10 | private readonly Tokenizer $tokenizer |
11 | - ) { |
|
11 | + ){ |
|
12 | 12 | } |
13 | 13 | |
14 | - public function getScopedClasses(string $scope, object|string|null $target = null): array |
|
14 | + public function getScopedClasses(string $scope, object | string | null $target = null): array |
|
15 | 15 | { |
16 | 16 | return $this->tokenizer->scopedClassLocator($scope)->getClasses($target); |
17 | 17 | } |
@@ -21,5 +21,5 @@ |
||
21 | 21 | * results. |
22 | 22 | * @return array<class-string, ReflectionClass> |
23 | 23 | */ |
24 | - public function getClasses(object|string|null $target = null): array; |
|
24 | + public function getClasses(object | string | null $target = null): array; |
|
25 | 25 | } |
@@ -16,13 +16,13 @@ |
||
16 | 16 | { |
17 | 17 | $traits = []; |
18 | 18 | |
19 | - do { |
|
19 | + do{ |
|
20 | 20 | $traits = \array_merge(\class_uses($class), $traits); |
21 | 21 | $class = \get_parent_class($class); |
22 | - } while ($class !== false); |
|
22 | + }while ($class !== false); |
|
23 | 23 | |
24 | 24 | //Traits from traits |
25 | - foreach (\array_flip($traits) as $trait) { |
|
25 | + foreach (\array_flip($traits) as $trait){ |
|
26 | 26 | $traits = \array_merge(\class_uses($trait), $traits); |
27 | 27 | } |
28 | 28 |
@@ -16,13 +16,15 @@ |
||
16 | 16 | { |
17 | 17 | $traits = []; |
18 | 18 | |
19 | - do { |
|
19 | + do |
|
20 | + { |
|
20 | 21 | $traits = \array_merge(\class_uses($class), $traits); |
21 | 22 | $class = \get_parent_class($class); |
22 | 23 | } while ($class !== false); |
23 | 24 | |
24 | 25 | //Traits from traits |
25 | - foreach (\array_flip($traits) as $trait) { |
|
26 | + foreach (\array_flip($traits) as $trait) |
|
27 | + { |
|
26 | 28 | $traits = \array_merge(\class_uses($trait), $traits); |
27 | 29 | } |
28 | 30 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct( |
26 | 26 | protected Finder $finder, |
27 | 27 | protected readonly bool $debug = false |
28 | - ) { |
|
28 | + ){ |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | /** |
@@ -37,13 +37,13 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function availableReflections(): \Generator |
39 | 39 | { |
40 | - foreach ($this->finder->getIterator() as $file) { |
|
40 | + foreach ($this->finder->getIterator() as $file){ |
|
41 | 41 | $reflection = new ReflectionFile((string)$file); |
42 | 42 | |
43 | - if ($reflection->hasIncludes()) { |
|
43 | + if ($reflection->hasIncludes()){ |
|
44 | 44 | // We are not analyzing files which has includes, it's not safe to require such reflections |
45 | 45 | $this->getLogger()->warning( |
46 | - \sprintf('File `%s` has includes and excluded from analysis', (string) $file), |
|
46 | + \sprintf('File `%s` has includes and excluded from analysis', (string)$file), |
|
47 | 47 | ['file' => $file] |
48 | 48 | ); |
49 | 49 | |
@@ -66,8 +66,8 @@ discard block |
||
66 | 66 | */ |
67 | 67 | protected function classReflection(string $class): \ReflectionClass |
68 | 68 | { |
69 | - $loader = static function ($class) { |
|
70 | - if ($class === LocatorException::class) { |
|
69 | + $loader = static function ($class){ |
|
70 | + if ($class === LocatorException::class){ |
|
71 | 71 | return; |
72 | 72 | } |
73 | 73 | |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | //To suspend class dependency exception |
78 | 78 | \spl_autoload_register($loader); |
79 | 79 | |
80 | - try { |
|
80 | + try{ |
|
81 | 81 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
82 | 82 | //we are going to handle such exception and convert it soft exception |
83 | 83 | return new \ReflectionClass($class); |
84 | - } catch (\Throwable $e) { |
|
85 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
84 | + }catch (\Throwable $e){ |
|
85 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
86 | 86 | $e = $e->getPrevious(); |
87 | 87 | } |
88 | 88 | |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | ['error' => $e] |
98 | 98 | ); |
99 | 99 | |
100 | - throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
|
101 | - } finally { |
|
100 | + throw new LocatorException($e->getMessage(), (int)$e->getCode(), $e); |
|
101 | + }finally{ |
|
102 | 102 | \spl_autoload_unregister($loader); |
103 | 103 | } |
104 | 104 | } |
@@ -37,10 +37,12 @@ discard block |
||
37 | 37 | */ |
38 | 38 | protected function availableReflections(): \Generator |
39 | 39 | { |
40 | - foreach ($this->finder->getIterator() as $file) { |
|
40 | + foreach ($this->finder->getIterator() as $file) |
|
41 | + { |
|
41 | 42 | $reflection = new ReflectionFile((string)$file); |
42 | 43 | |
43 | - if ($reflection->hasIncludes()) { |
|
44 | + if ($reflection->hasIncludes()) |
|
45 | + { |
|
44 | 46 | // We are not analyzing files which has includes, it's not safe to require such reflections |
45 | 47 | $this->getLogger()->warning( |
46 | 48 | \sprintf('File `%s` has includes and excluded from analysis', (string) $file), |
@@ -66,8 +68,10 @@ discard block |
||
66 | 68 | */ |
67 | 69 | protected function classReflection(string $class): \ReflectionClass |
68 | 70 | { |
69 | - $loader = static function ($class) { |
|
70 | - if ($class === LocatorException::class) { |
|
71 | + $loader = static function ($class) |
|
72 | + { |
|
73 | + if ($class === LocatorException::class) |
|
74 | + { |
|
71 | 75 | return; |
72 | 76 | } |
73 | 77 | |
@@ -77,12 +81,16 @@ discard block |
||
77 | 81 | //To suspend class dependency exception |
78 | 82 | \spl_autoload_register($loader); |
79 | 83 | |
80 | - try { |
|
84 | + try |
|
85 | + { |
|
81 | 86 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
82 | 87 | //we are going to handle such exception and convert it soft exception |
83 | 88 | return new \ReflectionClass($class); |
84 | - } catch (\Throwable $e) { |
|
85 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
89 | + } |
|
90 | + catch (\Throwable $e) |
|
91 | + { |
|
92 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
93 | + { |
|
86 | 94 | $e = $e->getPrevious(); |
87 | 95 | } |
88 | 96 | |
@@ -98,7 +106,9 @@ discard block |
||
98 | 106 | ); |
99 | 107 | |
100 | 108 | throw new LocatorException($e->getMessage(), (int) $e->getCode(), $e); |
101 | - } finally { |
|
109 | + } |
|
110 | + finally |
|
111 | + { |
|
102 | 112 | \spl_autoload_unregister($loader); |
103 | 113 | } |
104 | 114 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
22 | 22 | { |
23 | 23 | $result = []; |
24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
25 | - if ($this->isTargeted($invocation, $function)) { |
|
24 | + foreach ($this->availableInvocations($function->getName()) as $invocation){ |
|
25 | + if ($this->isTargeted($invocation, $function)){ |
|
26 | 26 | $result[] = $invocation; |
27 | 27 | } |
28 | 28 | } |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | protected function availableInvocations(string $signature = ''): \Generator |
40 | 40 | { |
41 | 41 | $signature = \strtolower(\trim($signature, '\\')); |
42 | - foreach ($this->availableReflections() as $reflection) { |
|
43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
42 | + foreach ($this->availableReflections() as $reflection){ |
|
43 | + foreach ($reflection->getInvocations() as $invocation){ |
|
44 | 44 | if ( |
45 | 45 | !empty($signature) |
46 | 46 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
47 | - ) { |
|
47 | + ){ |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | |
56 | 56 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
57 | 57 | { |
58 | - if ($function instanceof \ReflectionFunction) { |
|
58 | + if ($function instanceof \ReflectionFunction){ |
|
59 | 59 | return !$invocation->isMethod(); |
60 | 60 | } |
61 | 61 | |
62 | - try { |
|
62 | + try{ |
|
63 | 63 | $reflection = $this->classReflection($invocation->getClass()); |
64 | - } catch (LocatorException $e) { |
|
65 | - if ($this->debug) { |
|
64 | + }catch (LocatorException $e){ |
|
65 | + if ($this->debug){ |
|
66 | 66 | throw $e; |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | $target = $function->getDeclaringClass(); |
76 | 76 | |
77 | - if ($target->isTrait()) { |
|
77 | + if ($target->isTrait()){ |
|
78 | 78 | //Let's compare traits |
79 | 79 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
80 | 80 | } |
@@ -21,8 +21,10 @@ discard block |
||
21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
22 | 22 | { |
23 | 23 | $result = []; |
24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
25 | - if ($this->isTargeted($invocation, $function)) { |
|
24 | + foreach ($this->availableInvocations($function->getName()) as $invocation) |
|
25 | + { |
|
26 | + if ($this->isTargeted($invocation, $function)) |
|
27 | + { |
|
26 | 28 | $result[] = $invocation; |
27 | 29 | } |
28 | 30 | } |
@@ -39,8 +41,10 @@ discard block |
||
39 | 41 | protected function availableInvocations(string $signature = ''): \Generator |
40 | 42 | { |
41 | 43 | $signature = \strtolower(\trim($signature, '\\')); |
42 | - foreach ($this->availableReflections() as $reflection) { |
|
43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
44 | + foreach ($this->availableReflections() as $reflection) |
|
45 | + { |
|
46 | + foreach ($reflection->getInvocations() as $invocation) |
|
47 | + { |
|
44 | 48 | if ( |
45 | 49 | !empty($signature) |
46 | 50 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
@@ -55,14 +59,19 @@ discard block |
||
55 | 59 | |
56 | 60 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
57 | 61 | { |
58 | - if ($function instanceof \ReflectionFunction) { |
|
62 | + if ($function instanceof \ReflectionFunction) |
|
63 | + { |
|
59 | 64 | return !$invocation->isMethod(); |
60 | 65 | } |
61 | 66 | |
62 | - try { |
|
67 | + try |
|
68 | + { |
|
63 | 69 | $reflection = $this->classReflection($invocation->getClass()); |
64 | - } catch (LocatorException $e) { |
|
65 | - if ($this->debug) { |
|
70 | + } |
|
71 | + catch (LocatorException $e) |
|
72 | + { |
|
73 | + if ($this->debug) |
|
74 | + { |
|
66 | 75 | throw $e; |
67 | 76 | } |
68 | 77 | |
@@ -74,7 +83,8 @@ discard block |
||
74 | 83 | */ |
75 | 84 | $target = $function->getDeclaringClass(); |
76 | 85 | |
77 | - if ($target->isTrait()) { |
|
86 | + if ($target->isTrait()) |
|
87 | + { |
|
78 | 88 | //Let's compare traits |
79 | 89 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
80 | 90 | } |
@@ -13,18 +13,18 @@ discard block |
||
13 | 13 | { |
14 | 14 | public const INJECTOR = ClassLocatorInjector::class; |
15 | 15 | |
16 | - public function getClasses(object|string|null $target = null): array |
|
16 | + public function getClasses(object | string | null $target = null): array |
|
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)){ |
|
19 | 19 | $target = new \ReflectionClass($target); |
20 | 20 | } |
21 | 21 | |
22 | 22 | $result = []; |
23 | - foreach ($this->availableClasses() as $class) { |
|
24 | - try { |
|
23 | + foreach ($this->availableClasses() as $class){ |
|
24 | + try{ |
|
25 | 25 | $reflection = $this->classReflection($class); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
26 | + }catch (LocatorException $e){ |
|
27 | + if ($this->debug){ |
|
28 | 28 | throw $e; |
29 | 29 | } |
30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | continue; |
33 | 33 | } |
34 | 34 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
35 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | { |
52 | 52 | $classes = []; |
53 | 53 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
54 | + foreach ($this->availableReflections() as $reflection){ |
|
55 | 55 | $classes = \array_merge($classes, $reflection->getClasses()); |
56 | 56 | } |
57 | 57 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
67 | 67 | { |
68 | - if (empty($target)) { |
|
68 | + if (empty($target)){ |
|
69 | 69 | return true; |
70 | 70 | } |
71 | 71 | |
72 | - if (!$target->isTrait()) { |
|
72 | + if (!$target->isTrait()){ |
|
73 | 73 | //Target is interface or class |
74 | 74 | return $class->isSubclassOf($target) || $class->getName() === $target->getName(); |
75 | 75 | } |
@@ -15,16 +15,22 @@ discard block |
||
15 | 15 | |
16 | 16 | public function getClasses(object|string|null $target = null): array |
17 | 17 | { |
18 | - if (!empty($target)) { |
|
18 | + if (!empty($target)) |
|
19 | + { |
|
19 | 20 | $target = new \ReflectionClass($target); |
20 | 21 | } |
21 | 22 | |
22 | 23 | $result = []; |
23 | - foreach ($this->availableClasses() as $class) { |
|
24 | - try { |
|
24 | + foreach ($this->availableClasses() as $class) |
|
25 | + { |
|
26 | + try |
|
27 | + { |
|
25 | 28 | $reflection = $this->classReflection($class); |
26 | - } catch (LocatorException $e) { |
|
27 | - if ($this->debug) { |
|
29 | + } |
|
30 | + catch (LocatorException $e) |
|
31 | + { |
|
32 | + if ($this->debug) |
|
33 | + { |
|
28 | 34 | throw $e; |
29 | 35 | } |
30 | 36 | |
@@ -32,7 +38,8 @@ discard block |
||
32 | 38 | continue; |
33 | 39 | } |
34 | 40 | |
35 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
41 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
42 | + { |
|
36 | 43 | continue; |
37 | 44 | } |
38 | 45 | |
@@ -51,7 +58,8 @@ discard block |
||
51 | 58 | { |
52 | 59 | $classes = []; |
53 | 60 | |
54 | - foreach ($this->availableReflections() as $reflection) { |
|
61 | + foreach ($this->availableReflections() as $reflection) |
|
62 | + { |
|
55 | 63 | $classes = \array_merge($classes, $reflection->getClasses()); |
56 | 64 | } |
57 | 65 | |
@@ -65,11 +73,13 @@ discard block |
||
65 | 73 | */ |
66 | 74 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
67 | 75 | { |
68 | - if (empty($target)) { |
|
76 | + if (empty($target)) |
|
77 | + { |
|
69 | 78 | return true; |
70 | 79 | } |
71 | 80 | |
72 | - if (!$target->isTrait()) { |
|
81 | + if (!$target->isTrait()) |
|
82 | + { |
|
73 | 83 | //Target is interface or class |
74 | 84 | return $class->isSubclassOf($target) || $class->getName() === $target->getName(); |
75 | 85 | } |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * results. |
18 | 18 | * @return \ReflectionClass[] |
19 | 19 | */ |
20 | - public function getScopedClasses(string $scope, object|string|null $target = null): array; |
|
20 | + public function getScopedClasses(string $scope, object | string | null $target = null): array; |
|
21 | 21 | } |