@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | public function getActor(TokenInterface $token): ?object |
20 | 20 | { |
21 | - if ($token->getPayload()['ok']) { |
|
21 | + if ($token->getPayload()['ok']){ |
|
22 | 22 | return new \stdClass(); |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,8 @@ |
||
18 | 18 | { |
19 | 19 | public function getActor(TokenInterface $token): ?object |
20 | 20 | { |
21 | - if ($token->getPayload()['ok']) { |
|
21 | + if ($token->getPayload()['ok']) |
|
22 | + { |
|
22 | 23 | return new \stdClass(); |
23 | 24 | } |
24 | 25 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | public function getActor(TokenInterface $token): ?object |
20 | 20 | { |
21 | - if ($token->getID() === 'ok') { |
|
21 | + if ($token->getID() === 'ok'){ |
|
22 | 22 | return new \stdClass(); |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,8 @@ |
||
18 | 18 | { |
19 | 19 | public function getActor(TokenInterface $token): ?object |
20 | 20 | { |
21 | - if ($token->getID() === 'ok') { |
|
21 | + if ($token->getID() === 'ok') |
|
22 | + { |
|
22 | 23 | return new \stdClass(); |
23 | 24 | } |
24 | 25 |
@@ -18,7 +18,7 @@ |
||
18 | 18 | { |
19 | 19 | public function load(string $id): ?TokenInterface |
20 | 20 | { |
21 | - if ($id === 'bad') { |
|
21 | + if ($id === 'bad'){ |
|
22 | 22 | return null; |
23 | 23 | } |
24 | 24 |
@@ -18,7 +18,8 @@ |
||
18 | 18 | { |
19 | 19 | public function load(string $id): ?TokenInterface |
20 | 20 | { |
21 | - if ($id === 'bad') { |
|
21 | + if ($id === 'bad') |
|
22 | + { |
|
22 | 23 | return null; |
23 | 24 | } |
24 | 25 |
@@ -23,20 +23,20 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function getClasses($target = null): array |
25 | 25 | { |
26 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
26 | + if (!empty($target) && (is_object($target) || is_string($target))){ |
|
27 | 27 | $target = new \ReflectionClass($target); |
28 | 28 | } |
29 | 29 | |
30 | 30 | $result = []; |
31 | - foreach ($this->availableClasses() as $class) { |
|
32 | - try { |
|
31 | + foreach ($this->availableClasses() as $class){ |
|
32 | + try{ |
|
33 | 33 | $reflection = $this->classReflection($class); |
34 | - } catch (LocatorException $e) { |
|
34 | + }catch (LocatorException $e){ |
|
35 | 35 | //Ignoring |
36 | 36 | continue; |
37 | 37 | } |
38 | 38 | |
39 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
39 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()){ |
|
40 | 40 | continue; |
41 | 41 | } |
42 | 42 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | { |
56 | 56 | $classes = []; |
57 | 57 | |
58 | - foreach ($this->availableReflections() as $reflection) { |
|
58 | + foreach ($this->availableReflections() as $reflection){ |
|
59 | 59 | $classes = array_merge($classes, $reflection->getClasses()); |
60 | 60 | } |
61 | 61 | |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | */ |
72 | 72 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
73 | 73 | { |
74 | - if (empty($target)) { |
|
74 | + if (empty($target)){ |
|
75 | 75 | return true; |
76 | 76 | } |
77 | 77 | |
78 | - if (!$target->isTrait()) { |
|
78 | + if (!$target->isTrait()){ |
|
79 | 79 | //Target is interface or class |
80 | 80 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
81 | 81 | } |
@@ -23,20 +23,26 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function getClasses($target = null): array |
25 | 25 | { |
26 | - if (!empty($target) && (is_object($target) || is_string($target))) { |
|
26 | + if (!empty($target) && (is_object($target) || is_string($target))) |
|
27 | + { |
|
27 | 28 | $target = new \ReflectionClass($target); |
28 | 29 | } |
29 | 30 | |
30 | 31 | $result = []; |
31 | - foreach ($this->availableClasses() as $class) { |
|
32 | - try { |
|
32 | + foreach ($this->availableClasses() as $class) |
|
33 | + { |
|
34 | + try |
|
35 | + { |
|
33 | 36 | $reflection = $this->classReflection($class); |
34 | - } catch (LocatorException $e) { |
|
37 | + } |
|
38 | + catch (LocatorException $e) |
|
39 | + { |
|
35 | 40 | //Ignoring |
36 | 41 | continue; |
37 | 42 | } |
38 | 43 | |
39 | - if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) { |
|
44 | + if (!$this->isTargeted($reflection, $target) || $reflection->isInterface()) |
|
45 | + { |
|
40 | 46 | continue; |
41 | 47 | } |
42 | 48 | |
@@ -55,7 +61,8 @@ discard block |
||
55 | 61 | { |
56 | 62 | $classes = []; |
57 | 63 | |
58 | - foreach ($this->availableReflections() as $reflection) { |
|
64 | + foreach ($this->availableReflections() as $reflection) |
|
65 | + { |
|
59 | 66 | $classes = array_merge($classes, $reflection->getClasses()); |
60 | 67 | } |
61 | 68 | |
@@ -71,11 +78,13 @@ discard block |
||
71 | 78 | */ |
72 | 79 | protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target = null): bool |
73 | 80 | { |
74 | - if (empty($target)) { |
|
81 | + if (empty($target)) |
|
82 | + { |
|
75 | 83 | return true; |
76 | 84 | } |
77 | 85 | |
78 | - if (!$target->isTrait()) { |
|
86 | + if (!$target->isTrait()) |
|
87 | + { |
|
79 | 88 | //Target is interface or class |
80 | 89 | return $class->isSubclassOf($target) || $class->getName() == $target->getName(); |
81 | 90 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function createInjection(\ReflectionClass $class, string $context = null) |
79 | 79 | { |
80 | - if ($class->isSubclassOf(ClassesInterface::class)) { |
|
80 | + if ($class->isSubclassOf(ClassesInterface::class)){ |
|
81 | 81 | return $this->classLocator(); |
82 | - } elseif ($class->isSubclassOf(InvocationsInterface::class)) { |
|
82 | + } elseif ($class->isSubclassOf(InvocationsInterface::class)){ |
|
83 | 83 | return $this->invocationLocator(); |
84 | 84 | } |
85 | 85 | |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | $tokens = token_get_all(file_get_contents($filename)); |
98 | 98 | |
99 | 99 | $line = 0; |
100 | - foreach ($tokens as &$token) { |
|
101 | - if (isset($token[self::LINE])) { |
|
100 | + foreach ($tokens as &$token){ |
|
101 | + if (isset($token[self::LINE])){ |
|
102 | 102 | $line = $token[self::LINE]; |
103 | 103 | } |
104 | 104 | |
105 | - if (!is_array($token)) { |
|
105 | + if (!is_array($token)){ |
|
106 | 106 | $token = [$token, $token, $line]; |
107 | 107 | } |
108 | 108 | |
@@ -122,11 +122,11 @@ discard block |
||
122 | 122 | { |
123 | 123 | $finder = new Finder(); |
124 | 124 | |
125 | - if (empty($directories)) { |
|
125 | + if (empty($directories)){ |
|
126 | 126 | $directories = $this->config->getDirectories(); |
127 | 127 | } |
128 | 128 | |
129 | - if (empty($exclude)) { |
|
129 | + if (empty($exclude)){ |
|
130 | 130 | $exclude = $this->config->getExcludes(); |
131 | 131 | } |
132 | 132 |
@@ -77,9 +77,12 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function createInjection(\ReflectionClass $class, string $context = null) |
79 | 79 | { |
80 | - if ($class->isSubclassOf(ClassesInterface::class)) { |
|
80 | + if ($class->isSubclassOf(ClassesInterface::class)) |
|
81 | + { |
|
81 | 82 | return $this->classLocator(); |
82 | - } elseif ($class->isSubclassOf(InvocationsInterface::class)) { |
|
83 | + } |
|
84 | + elseif ($class->isSubclassOf(InvocationsInterface::class)) |
|
85 | + { |
|
83 | 86 | return $this->invocationLocator(); |
84 | 87 | } |
85 | 88 | |
@@ -97,12 +100,15 @@ discard block |
||
97 | 100 | $tokens = token_get_all(file_get_contents($filename)); |
98 | 101 | |
99 | 102 | $line = 0; |
100 | - foreach ($tokens as &$token) { |
|
101 | - if (isset($token[self::LINE])) { |
|
103 | + foreach ($tokens as &$token) |
|
104 | + { |
|
105 | + if (isset($token[self::LINE])) |
|
106 | + { |
|
102 | 107 | $line = $token[self::LINE]; |
103 | 108 | } |
104 | 109 | |
105 | - if (!is_array($token)) { |
|
110 | + if (!is_array($token)) |
|
111 | + { |
|
106 | 112 | $token = [$token, $token, $line]; |
107 | 113 | } |
108 | 114 | |
@@ -122,11 +128,13 @@ discard block |
||
122 | 128 | { |
123 | 129 | $finder = new Finder(); |
124 | 130 | |
125 | - if (empty($directories)) { |
|
131 | + if (empty($directories)) |
|
132 | + { |
|
126 | 133 | $directories = $this->config->getDirectories(); |
127 | 134 | } |
128 | 135 | |
129 | - if (empty($exclude)) { |
|
136 | + if (empty($exclude)) |
|
137 | + { |
|
130 | 138 | $exclude = $this->config->getExcludes(); |
131 | 139 | } |
132 | 140 |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | array $arguments, |
70 | 70 | string $source, |
71 | 71 | int $level |
72 | - ) { |
|
72 | + ){ |
|
73 | 73 | $this->filename = $filename; |
74 | 74 | $this->line = $line; |
75 | 75 | $this->class = $class; |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function getArgument(int $index): ReflectionArgument |
181 | 181 | { |
182 | - if (!isset($this->arguments[$index])) { |
|
182 | + if (!isset($this->arguments[$index])){ |
|
183 | 183 | throw new ReflectionException("No such argument with index '{$index}'"); |
184 | 184 | } |
185 | 185 |
@@ -179,7 +179,8 @@ |
||
179 | 179 | */ |
180 | 180 | public function getArgument(int $index): ReflectionArgument |
181 | 181 | { |
182 | - if (!isset($this->arguments[$index])) { |
|
182 | + if (!isset($this->arguments[$index])) |
|
183 | + { |
|
183 | 184 | throw new ReflectionException("No such argument with index '{$index}'"); |
184 | 185 | } |
185 | 186 |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Argument types. |
23 | 23 | */ |
24 | - public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
25 | - public const VARIABLE = 'variable'; //PHP variable |
|
24 | + public const CONSTANT = 'constant'; //Scalar constant and not variable. |
|
25 | + public const VARIABLE = 'variable'; //PHP variable |
|
26 | 26 | public const EXPRESSION = 'expression'; //PHP code (expression). |
27 | - public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
27 | + public const STRING = 'string'; //Simple scalar string, can be fetched using stringValue(). |
|
28 | 28 | |
29 | 29 | /** @var string */ |
30 | 30 | private $type; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function stringValue(): string |
71 | 71 | { |
72 | - if ($this->type != self::STRING) { |
|
72 | + if ($this->type != self::STRING){ |
|
73 | 73 | throw new ReflectionException( |
74 | 74 | "Unable to represent value as string, value type is '{$this->type}'" |
75 | 75 | ); |
@@ -91,19 +91,19 @@ discard block |
||
91 | 91 | $level = 0; |
92 | 92 | |
93 | 93 | $result = []; |
94 | - foreach ($tokens as $token) { |
|
95 | - if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) { |
|
94 | + foreach ($tokens as $token){ |
|
95 | + if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE){ |
|
96 | 96 | continue; |
97 | 97 | } |
98 | 98 | |
99 | - if (empty($definition)) { |
|
99 | + if (empty($definition)){ |
|
100 | 100 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
101 | 101 | } |
102 | 102 | |
103 | 103 | if ( |
104 | 104 | $token[ReflectionFile::TOKEN_TYPE] == '(' |
105 | 105 | || $token[ReflectionFile::TOKEN_TYPE] == '[' |
106 | - ) { |
|
106 | + ){ |
|
107 | 107 | ++$level; |
108 | 108 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
109 | 109 | continue; |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | if ( |
113 | 113 | $token[ReflectionFile::TOKEN_TYPE] == ')' |
114 | 114 | || $token[ReflectionFile::TOKEN_TYPE] == ']' |
115 | - ) { |
|
115 | + ){ |
|
116 | 116 | --$level; |
117 | 117 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
118 | 118 | continue; |
119 | 119 | } |
120 | 120 | |
121 | - if ($level) { |
|
121 | + if ($level){ |
|
122 | 122 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
123 | 123 | continue; |
124 | 124 | } |
125 | 125 | |
126 | - if ($token[ReflectionFile::TOKEN_TYPE] == ',') { |
|
126 | + if ($token[ReflectionFile::TOKEN_TYPE] == ','){ |
|
127 | 127 | $result[] = self::createArgument($definition); |
128 | 128 | $definition = null; |
129 | 129 | continue; |
@@ -134,9 +134,9 @@ discard block |
||
134 | 134 | } |
135 | 135 | |
136 | 136 | //Last argument |
137 | - if (is_array($definition)) { |
|
137 | + if (is_array($definition)){ |
|
138 | 138 | $definition = self::createArgument($definition); |
139 | - if (!empty($definition->getType())) { |
|
139 | + if (!empty($definition->getType())){ |
|
140 | 140 | $result[] = $definition; |
141 | 141 | } |
142 | 142 | } |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | { |
156 | 156 | $result = new static(self::EXPRESSION, $definition['value']); |
157 | 157 | |
158 | - if (count($definition['tokens']) == 1) { |
|
158 | + if (count($definition['tokens']) == 1){ |
|
159 | 159 | //If argument represent by one token we can try to resolve it's type more precisely |
160 | - switch ($definition['tokens'][0][0]) { |
|
160 | + switch ($definition['tokens'][0][0]){ |
|
161 | 161 | case T_VARIABLE: |
162 | 162 | $result->type = self::VARIABLE; |
163 | 163 | break; |
@@ -69,7 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function stringValue(): string |
71 | 71 | { |
72 | - if ($this->type != self::STRING) { |
|
72 | + if ($this->type != self::STRING) |
|
73 | + { |
|
73 | 74 | throw new ReflectionException( |
74 | 75 | "Unable to represent value as string, value type is '{$this->type}'" |
75 | 76 | ); |
@@ -91,12 +92,15 @@ discard block |
||
91 | 92 | $level = 0; |
92 | 93 | |
93 | 94 | $result = []; |
94 | - foreach ($tokens as $token) { |
|
95 | - if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) { |
|
95 | + foreach ($tokens as $token) |
|
96 | + { |
|
97 | + if ($token[ReflectionFile::TOKEN_TYPE] == T_WHITESPACE) |
|
98 | + { |
|
96 | 99 | continue; |
97 | 100 | } |
98 | 101 | |
99 | - if (empty($definition)) { |
|
102 | + if (empty($definition)) |
|
103 | + { |
|
100 | 104 | $definition = ['type' => self::EXPRESSION, 'value' => '', 'tokens' => []]; |
101 | 105 | } |
102 | 106 | |
@@ -118,12 +122,14 @@ discard block |
||
118 | 122 | continue; |
119 | 123 | } |
120 | 124 | |
121 | - if ($level) { |
|
125 | + if ($level) |
|
126 | + { |
|
122 | 127 | $definition['value'] .= $token[ReflectionFile::TOKEN_CODE]; |
123 | 128 | continue; |
124 | 129 | } |
125 | 130 | |
126 | - if ($token[ReflectionFile::TOKEN_TYPE] == ',') { |
|
131 | + if ($token[ReflectionFile::TOKEN_TYPE] == ',') |
|
132 | + { |
|
127 | 133 | $result[] = self::createArgument($definition); |
128 | 134 | $definition = null; |
129 | 135 | continue; |
@@ -134,9 +140,11 @@ discard block |
||
134 | 140 | } |
135 | 141 | |
136 | 142 | //Last argument |
137 | - if (is_array($definition)) { |
|
143 | + if (is_array($definition)) |
|
144 | + { |
|
138 | 145 | $definition = self::createArgument($definition); |
139 | - if (!empty($definition->getType())) { |
|
146 | + if (!empty($definition->getType())) |
|
147 | + { |
|
140 | 148 | $result[] = $definition; |
141 | 149 | } |
142 | 150 | } |
@@ -155,9 +163,11 @@ discard block |
||
155 | 163 | { |
156 | 164 | $result = new static(self::EXPRESSION, $definition['value']); |
157 | 165 | |
158 | - if (count($definition['tokens']) == 1) { |
|
166 | + if (count($definition['tokens']) == 1) |
|
167 | + { |
|
159 | 168 | //If argument represent by one token we can try to resolve it's type more precisely |
160 | - switch ($definition['tokens'][0][0]) { |
|
169 | + switch ($definition['tokens'][0][0]) |
|
170 | + { |
|
161 | 171 | case T_VARIABLE: |
162 | 172 | $result->type = self::VARIABLE; |
163 | 173 | break; |
@@ -19,7 +19,7 @@ |
||
19 | 19 | protected function someFunction() |
20 | 20 | { |
21 | 21 | $result = $this->sampleMethod('hello world'); |
22 | - print_r(self::sampleMethod($result . 'plus')); |
|
22 | + print_r(self::sampleMethod($result.'plus')); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public function testInstance() |
@@ -22,17 +22,17 @@ |
||
22 | 22 | $this->assertContains(TestTrait::class, $reflection->getTraits()); |
23 | 23 | $this->assertContains(TestInterface::class, $reflection->getInterfaces()); |
24 | 24 | |
25 | - $this->assertSame([__NAMESPACE__ . '\hello'], $reflection->getFunctions()); |
|
25 | + $this->assertSame([__NAMESPACE__.'\hello'], $reflection->getFunctions()); |
|
26 | 26 | |
27 | 27 | $functionA = null; |
28 | 28 | $functionB = null; |
29 | 29 | |
30 | - foreach ($reflection->getInvocations() as $invocation) { |
|
31 | - if ($invocation->getName() == 'test_function_a') { |
|
30 | + foreach ($reflection->getInvocations() as $invocation){ |
|
31 | + if ($invocation->getName() == 'test_function_a'){ |
|
32 | 32 | $functionA = $invocation; |
33 | 33 | } |
34 | 34 | |
35 | - if ($invocation->getName() == 'test_function_b') { |
|
35 | + if ($invocation->getName() == 'test_function_b'){ |
|
36 | 36 | $functionB = $invocation; |
37 | 37 | } |
38 | 38 | } |
@@ -27,12 +27,15 @@ |
||
27 | 27 | $functionA = null; |
28 | 28 | $functionB = null; |
29 | 29 | |
30 | - foreach ($reflection->getInvocations() as $invocation) { |
|
31 | - if ($invocation->getName() == 'test_function_a') { |
|
30 | + foreach ($reflection->getInvocations() as $invocation) |
|
31 | + { |
|
32 | + if ($invocation->getName() == 'test_function_a') |
|
33 | + { |
|
32 | 34 | $functionA = $invocation; |
33 | 35 | } |
34 | 36 | |
35 | - if ($invocation->getName() == 'test_function_b') { |
|
37 | + if ($invocation->getName() == 'test_function_b') |
|
38 | + { |
|
36 | 39 | $functionB = $invocation; |
37 | 40 | } |
38 | 41 | } |