@@ -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 |
@@ -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 | } |
@@ -14,10 +14,10 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * Argument types. |
16 | 16 | */ |
17 | - public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
18 | - public const VARIABLE = 'variable'; //PHP variable |
|
17 | + public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
18 | + public const VARIABLE = 'variable'; //PHP variable |
|
19 | 19 | public const EXPRESSION = 'expression'; //PHP code (expression). |
20 | - public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
20 | + public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * New instance of ReflectionArgument. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function __construct( |
29 | 29 | private string $type, |
30 | 30 | private readonly string $value |
31 | - ) { |
|
31 | + ){ |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | public function getType(): string |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function stringValue(): string |
50 | 50 | { |
51 | - if ($this->type !== self::STRING) { |
|
51 | + if ($this->type !== self::STRING){ |
|
52 | 52 | throw new ReflectionException( |
53 | 53 | \sprintf("Unable to represent value as string, value type is '%s'", $this->type) |
54 | 54 | ); |
@@ -69,33 +69,33 @@ discard block |
||
69 | 69 | $level = 0; |
70 | 70 | |
71 | 71 | $result = []; |
72 | - foreach ($tokens as $token) { |
|
73 | - if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) { |
|
72 | + foreach ($tokens as $token){ |
|
73 | + if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE){ |
|
74 | 74 | continue; |
75 | 75 | } |
76 | 76 | |
77 | - if (empty($definition)) { |
|
77 | + if (empty($definition)){ |
|
78 | 78 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
79 | 79 | } |
80 | 80 | |
81 | - if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') { |
|
81 | + if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '['){ |
|
82 | 82 | ++$level; |
83 | 83 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | - if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') { |
|
87 | + if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']'){ |
|
88 | 88 | --$level; |
89 | 89 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
90 | 90 | continue; |
91 | 91 | } |
92 | 92 | |
93 | - if ($level) { |
|
93 | + if ($level){ |
|
94 | 94 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
95 | 95 | continue; |
96 | 96 | } |
97 | 97 | |
98 | - if ($token[ReflectionFile::TOKEN_TYPE] === ',') { |
|
98 | + if ($token[ReflectionFile::TOKEN_TYPE] === ','){ |
|
99 | 99 | $result[] = self::createArgument($definition); |
100 | 100 | $definition = null; |
101 | 101 | continue; |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | //Last argument |
109 | - if (\is_array($definition)) { |
|
109 | + if (\is_array($definition)){ |
|
110 | 110 | $definition = self::createArgument($definition); |
111 | - if (!empty($definition->getType())) { |
|
111 | + if (!empty($definition->getType())){ |
|
112 | 112 | $result[] = $definition; |
113 | 113 | } |
114 | 114 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | $result = new static(self::EXPRESSION, $definition['value']); |
128 | 128 | |
129 | - if (\count($definition['tokens']) == 1) { |
|
129 | + if (\count($definition['tokens']) == 1){ |
|
130 | 130 | $result->type = match ($definition['tokens'][0][0]) { |
131 | 131 | T_VARIABLE => self::VARIABLE, |
132 | 132 | T_LNUMBER, T_DNUMBER => self::CONSTANT, |
@@ -48,7 +48,8 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public function stringValue(): string |
50 | 50 | { |
51 | - if ($this->type !== self::STRING) { |
|
51 | + if ($this->type !== self::STRING) |
|
52 | + { |
|
52 | 53 | throw new ReflectionException( |
53 | 54 | \sprintf("Unable to represent value as string, value type is '%s'", $this->type) |
54 | 55 | ); |
@@ -69,33 +70,40 @@ discard block |
||
69 | 70 | $level = 0; |
70 | 71 | |
71 | 72 | $result = []; |
72 | - foreach ($tokens as $token) { |
|
73 | - if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) { |
|
73 | + foreach ($tokens as $token) |
|
74 | + { |
|
75 | + if ($token[ReflectionFile::TOKEN_TYPE] === T_WHITESPACE) |
|
76 | + { |
|
74 | 77 | continue; |
75 | 78 | } |
76 | 79 | |
77 | - if (empty($definition)) { |
|
80 | + if (empty($definition)) |
|
81 | + { |
|
78 | 82 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
79 | 83 | } |
80 | 84 | |
81 | - if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') { |
|
85 | + if ($token[ReflectionFile::TOKEN_TYPE] === '(' || $token[ReflectionFile::TOKEN_TYPE] === '[') |
|
86 | + { |
|
82 | 87 | ++$level; |
83 | 88 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
84 | 89 | continue; |
85 | 90 | } |
86 | 91 | |
87 | - if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') { |
|
92 | + if ($token[ReflectionFile::TOKEN_TYPE] === ')' || $token[ReflectionFile::TOKEN_TYPE] === ']') |
|
93 | + { |
|
88 | 94 | --$level; |
89 | 95 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
90 | 96 | continue; |
91 | 97 | } |
92 | 98 | |
93 | - if ($level) { |
|
99 | + if ($level) |
|
100 | + { |
|
94 | 101 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
95 | 102 | continue; |
96 | 103 | } |
97 | 104 | |
98 | - if ($token[ReflectionFile::TOKEN_TYPE] === ',') { |
|
105 | + if ($token[ReflectionFile::TOKEN_TYPE] === ',') |
|
106 | + { |
|
99 | 107 | $result[] = self::createArgument($definition); |
100 | 108 | $definition = null; |
101 | 109 | continue; |
@@ -106,9 +114,11 @@ discard block |
||
106 | 114 | } |
107 | 115 | |
108 | 116 | //Last argument |
109 | - if (\is_array($definition)) { |
|
117 | + if (\is_array($definition)) |
|
118 | + { |
|
110 | 119 | $definition = self::createArgument($definition); |
111 | - if (!empty($definition->getType())) { |
|
120 | + if (!empty($definition->getType())) |
|
121 | + { |
|
112 | 122 | $result[] = $definition; |
113 | 123 | } |
114 | 124 | } |
@@ -126,7 +136,8 @@ discard block |
||
126 | 136 | { |
127 | 137 | $result = new static(self::EXPRESSION, $definition['value']); |
128 | 138 | |
129 | - if (\count($definition['tokens']) == 1) { |
|
139 | + if (\count($definition['tokens']) == 1) |
|
140 | + { |
|
130 | 141 | $result->type = match ($definition['tokens'][0][0]) { |
131 | 142 | T_VARIABLE => self::VARIABLE, |
132 | 143 | T_LNUMBER, T_DNUMBER => self::CONSTANT, |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | private readonly array $arguments, |
30 | 30 | private readonly string $source, |
31 | 31 | private readonly int $level |
32 | - ) { |
|
32 | + ){ |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function getArgument(int $index): ReflectionArgument |
115 | 115 | { |
116 | - if (!isset($this->arguments[$index])) { |
|
116 | + if (!isset($this->arguments[$index])){ |
|
117 | 117 | throw new ReflectionException(\sprintf("No such argument with index '%d'", $index)); |
118 | 118 | } |
119 | 119 |
@@ -113,7 +113,8 @@ |
||
113 | 113 | */ |
114 | 114 | public function getArgument(int $index): ReflectionArgument |
115 | 115 | { |
116 | - if (!isset($this->arguments[$index])) { |
|
116 | + if (!isset($this->arguments[$index])) |
|
117 | + { |
|
117 | 118 | throw new ReflectionException(\sprintf("No such argument with index '%d'", $index)); |
118 | 119 | } |
119 | 120 |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | public function __construct( |
18 | 18 | private readonly Tokenizer $tokenizer |
19 | - ) { |
|
19 | + ){ |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | /** |