@@ -46,39 +46,39 @@ discard block |
||
46 | 46 | $this->body = null; |
47 | 47 | $hasWhitespace = false; |
48 | 48 | |
49 | - while ($n = $src->next()) { |
|
50 | - if (!$n instanceof Byte) { |
|
49 | + while ($n = $src->next()){ |
|
50 | + if (!$n instanceof Byte){ |
|
51 | 51 | // no other grammars are allowed |
52 | 52 | break; |
53 | 53 | } |
54 | 54 | |
55 | - switch ($n->char) { |
|
55 | + switch ($n->char){ |
|
56 | 56 | case '(': |
57 | 57 | $this->flushName(); |
58 | 58 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
59 | 59 | |
60 | 60 | return $this->parseBody($src); |
61 | 61 | default: |
62 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
62 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
63 | 63 | $hasWhitespace = true; |
64 | - if ($this->name !== []) { |
|
64 | + if ($this->name !== []){ |
|
65 | 65 | $this->flushName(); |
66 | 66 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
67 | 67 | break; |
68 | 68 | } |
69 | 69 | |
70 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
70 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE){ |
|
71 | 71 | $this->getLastToken()->content .= $n->char; |
72 | 72 | break; |
73 | 73 | } |
74 | 74 | |
75 | 75 | // invalid directive |
76 | 76 | return false; |
77 | - } elseif ($hasWhitespace) { |
|
77 | + } elseif ($hasWhitespace){ |
|
78 | 78 | return $this->finalize(); |
79 | 79 | } |
80 | 80 | |
81 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
81 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)){ |
|
82 | 82 | $this->flushName(); |
83 | 83 | |
84 | 84 | return $this->finalize(); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function getIterator(): \Traversable |
102 | 102 | { |
103 | - if ($this->tokens === []) { |
|
103 | + if ($this->tokens === []){ |
|
104 | 104 | throw new \LogicException('Directive not parsed'); |
105 | 105 | } |
106 | 106 | |
@@ -120,8 +120,8 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getKeyword(): string |
122 | 122 | { |
123 | - foreach ($this->tokens as $token) { |
|
124 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
123 | + foreach ($this->tokens as $token){ |
|
124 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD){ |
|
125 | 125 | return $token->content; |
126 | 126 | } |
127 | 127 | } |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public function getBody(): ?string |
138 | 138 | { |
139 | - foreach ($this->tokens as $token) { |
|
140 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
139 | + foreach ($this->tokens as $token){ |
|
140 | + if ($token->type === DynamicGrammar::TYPE_BODY){ |
|
141 | 141 | return $token->content; |
142 | 142 | } |
143 | 143 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function flushName(): void |
152 | 152 | { |
153 | - if ($this->name === []) { |
|
153 | + if ($this->name === []){ |
|
154 | 154 | return; |
155 | 155 | } |
156 | 156 | |
@@ -166,17 +166,17 @@ discard block |
||
166 | 166 | $this->body = []; |
167 | 167 | $level = 1; |
168 | 168 | |
169 | - while ($nn = $src->next()) { |
|
170 | - if (!$nn instanceof Byte) { |
|
169 | + while ($nn = $src->next()){ |
|
170 | + if (!$nn instanceof Byte){ |
|
171 | 171 | $this->flushBody(); |
172 | 172 | return $this->finalize(); |
173 | 173 | } |
174 | 174 | |
175 | - if (in_array($nn->char, ['"', '"'])) { |
|
175 | + if (in_array($nn->char, ['"', '"'])){ |
|
176 | 176 | $this->body[] = $nn; |
177 | - while ($nnn = $src->next()) { |
|
177 | + while ($nnn = $src->next()){ |
|
178 | 178 | $this->body[] = $nnn; |
179 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
179 | + if ($nnn instanceof Byte && $nnn->char === $nn->char){ |
|
180 | 180 | break; |
181 | 181 | } |
182 | 182 | } |
@@ -185,15 +185,15 @@ discard block |
||
185 | 185 | |
186 | 186 | $this->body[] = $nn; |
187 | 187 | |
188 | - if ($nn->char === '(') { |
|
188 | + if ($nn->char === '('){ |
|
189 | 189 | $level++; |
190 | 190 | continue; |
191 | 191 | } |
192 | 192 | |
193 | - if ($nn->char === ')') { |
|
193 | + if ($nn->char === ')'){ |
|
194 | 194 | $level--; |
195 | 195 | |
196 | - if ($level === 0) { |
|
196 | + if ($level === 0){ |
|
197 | 197 | $n = array_pop($this->body); |
198 | 198 | |
199 | 199 | $this->flushBody(); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | private function flushBody(): void |
216 | 216 | { |
217 | - if ($this->body === []) { |
|
217 | + if ($this->body === []){ |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | private function getLastToken(): Token |
226 | 226 | { |
227 | - if ($this->tokens === []) { |
|
227 | + if ($this->tokens === []){ |
|
228 | 228 | throw new \LogicException('Directive not parsed'); |
229 | 229 | } |
230 | 230 | |
@@ -238,8 +238,8 @@ discard block |
||
238 | 238 | { |
239 | 239 | $tokens = $this->tokens; |
240 | 240 | |
241 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
242 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
241 | + foreach (array_reverse($tokens, true) as $i => $t){ |
|
242 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE){ |
|
243 | 243 | break; |
244 | 244 | } |
245 | 245 | |
@@ -247,19 +247,19 @@ discard block |
||
247 | 247 | } |
248 | 248 | |
249 | 249 | $body = null; |
250 | - foreach ($tokens as $t) { |
|
251 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
250 | + foreach ($tokens as $t){ |
|
251 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN){ |
|
252 | 252 | $body = false; |
253 | 253 | continue; |
254 | 254 | } |
255 | 255 | |
256 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
256 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE){ |
|
257 | 257 | $body = null; |
258 | 258 | continue; |
259 | 259 | } |
260 | 260 | } |
261 | 261 | |
262 | - if ($body !== null) { |
|
262 | + if ($body !== null){ |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 |
@@ -46,39 +46,48 @@ discard block |
||
46 | 46 | $this->body = null; |
47 | 47 | $hasWhitespace = false; |
48 | 48 | |
49 | - while ($n = $src->next()) { |
|
50 | - if (!$n instanceof Byte) { |
|
49 | + while ($n = $src->next()) |
|
50 | + { |
|
51 | + if (!$n instanceof Byte) |
|
52 | + { |
|
51 | 53 | // no other grammars are allowed |
52 | 54 | break; |
53 | 55 | } |
54 | 56 | |
55 | - switch ($n->char) { |
|
57 | + switch ($n->char) |
|
58 | + { |
|
56 | 59 | case '(': |
57 | 60 | $this->flushName(); |
58 | 61 | $this->tokens[] = new Token(DynamicGrammar::TYPE_BODY_OPEN, $n->offset, $n->char); |
59 | 62 | |
60 | 63 | return $this->parseBody($src); |
61 | 64 | default: |
62 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
65 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
66 | + { |
|
63 | 67 | $hasWhitespace = true; |
64 | - if ($this->name !== []) { |
|
68 | + if ($this->name !== []) |
|
69 | + { |
|
65 | 70 | $this->flushName(); |
66 | 71 | $this->tokens[] = new Token(DynamicGrammar::TYPE_WHITESPACE, $n->offset, $n->char); |
67 | 72 | break; |
68 | 73 | } |
69 | 74 | |
70 | - if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) { |
|
75 | + if ($this->getLastToken()->type === DynamicGrammar::TYPE_WHITESPACE) |
|
76 | + { |
|
71 | 77 | $this->getLastToken()->content .= $n->char; |
72 | 78 | break; |
73 | 79 | } |
74 | 80 | |
75 | 81 | // invalid directive |
76 | 82 | return false; |
77 | - } elseif ($hasWhitespace) { |
|
83 | + } |
|
84 | + elseif ($hasWhitespace) |
|
85 | + { |
|
78 | 86 | return $this->finalize(); |
79 | 87 | } |
80 | 88 | |
81 | - if (!preg_match(self::REGEXP_KEYWORD, $n->char)) { |
|
89 | + if (!preg_match(self::REGEXP_KEYWORD, $n->char)) |
|
90 | + { |
|
82 | 91 | $this->flushName(); |
83 | 92 | |
84 | 93 | return $this->finalize(); |
@@ -100,7 +109,8 @@ discard block |
||
100 | 109 | */ |
101 | 110 | public function getIterator(): \Traversable |
102 | 111 | { |
103 | - if ($this->tokens === []) { |
|
112 | + if ($this->tokens === []) |
|
113 | + { |
|
104 | 114 | throw new \LogicException('Directive not parsed'); |
105 | 115 | } |
106 | 116 | |
@@ -120,8 +130,10 @@ discard block |
||
120 | 130 | */ |
121 | 131 | public function getKeyword(): string |
122 | 132 | { |
123 | - foreach ($this->tokens as $token) { |
|
124 | - if ($token->type === DynamicGrammar::TYPE_KEYWORD) { |
|
133 | + foreach ($this->tokens as $token) |
|
134 | + { |
|
135 | + if ($token->type === DynamicGrammar::TYPE_KEYWORD) |
|
136 | + { |
|
125 | 137 | return $token->content; |
126 | 138 | } |
127 | 139 | } |
@@ -136,8 +148,10 @@ discard block |
||
136 | 148 | */ |
137 | 149 | public function getBody(): ?string |
138 | 150 | { |
139 | - foreach ($this->tokens as $token) { |
|
140 | - if ($token->type === DynamicGrammar::TYPE_BODY) { |
|
151 | + foreach ($this->tokens as $token) |
|
152 | + { |
|
153 | + if ($token->type === DynamicGrammar::TYPE_BODY) |
|
154 | + { |
|
141 | 155 | return $token->content; |
142 | 156 | } |
143 | 157 | } |
@@ -150,7 +164,8 @@ discard block |
||
150 | 164 | */ |
151 | 165 | private function flushName(): void |
152 | 166 | { |
153 | - if ($this->name === []) { |
|
167 | + if ($this->name === []) |
|
168 | + { |
|
154 | 169 | return; |
155 | 170 | } |
156 | 171 | |
@@ -166,17 +181,22 @@ discard block |
||
166 | 181 | $this->body = []; |
167 | 182 | $level = 1; |
168 | 183 | |
169 | - while ($nn = $src->next()) { |
|
170 | - if (!$nn instanceof Byte) { |
|
184 | + while ($nn = $src->next()) |
|
185 | + { |
|
186 | + if (!$nn instanceof Byte) |
|
187 | + { |
|
171 | 188 | $this->flushBody(); |
172 | 189 | return $this->finalize(); |
173 | 190 | } |
174 | 191 | |
175 | - if (in_array($nn->char, ['"', '"'])) { |
|
192 | + if (in_array($nn->char, ['"', '"'])) |
|
193 | + { |
|
176 | 194 | $this->body[] = $nn; |
177 | - while ($nnn = $src->next()) { |
|
195 | + while ($nnn = $src->next()) |
|
196 | + { |
|
178 | 197 | $this->body[] = $nnn; |
179 | - if ($nnn instanceof Byte && $nnn->char === $nn->char) { |
|
198 | + if ($nnn instanceof Byte && $nnn->char === $nn->char) |
|
199 | + { |
|
180 | 200 | break; |
181 | 201 | } |
182 | 202 | } |
@@ -185,15 +205,18 @@ discard block |
||
185 | 205 | |
186 | 206 | $this->body[] = $nn; |
187 | 207 | |
188 | - if ($nn->char === '(') { |
|
208 | + if ($nn->char === '(') |
|
209 | + { |
|
189 | 210 | $level++; |
190 | 211 | continue; |
191 | 212 | } |
192 | 213 | |
193 | - if ($nn->char === ')') { |
|
214 | + if ($nn->char === ')') |
|
215 | + { |
|
194 | 216 | $level--; |
195 | 217 | |
196 | - if ($level === 0) { |
|
218 | + if ($level === 0) |
|
219 | + { |
|
197 | 220 | $n = array_pop($this->body); |
198 | 221 | |
199 | 222 | $this->flushBody(); |
@@ -214,7 +237,8 @@ discard block |
||
214 | 237 | */ |
215 | 238 | private function flushBody(): void |
216 | 239 | { |
217 | - if ($this->body === []) { |
|
240 | + if ($this->body === []) |
|
241 | + { |
|
218 | 242 | return; |
219 | 243 | } |
220 | 244 | |
@@ -224,7 +248,8 @@ discard block |
||
224 | 248 | |
225 | 249 | private function getLastToken(): Token |
226 | 250 | { |
227 | - if ($this->tokens === []) { |
|
251 | + if ($this->tokens === []) |
|
252 | + { |
|
228 | 253 | throw new \LogicException('Directive not parsed'); |
229 | 254 | } |
230 | 255 | |
@@ -238,8 +263,10 @@ discard block |
||
238 | 263 | { |
239 | 264 | $tokens = $this->tokens; |
240 | 265 | |
241 | - foreach (array_reverse($tokens, true) as $i => $t) { |
|
242 | - if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) { |
|
266 | + foreach (array_reverse($tokens, true) as $i => $t) |
|
267 | + { |
|
268 | + if ($t->type !== DynamicGrammar::TYPE_WHITESPACE) |
|
269 | + { |
|
243 | 270 | break; |
244 | 271 | } |
245 | 272 | |
@@ -247,19 +274,23 @@ discard block |
||
247 | 274 | } |
248 | 275 | |
249 | 276 | $body = null; |
250 | - foreach ($tokens as $t) { |
|
251 | - if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) { |
|
277 | + foreach ($tokens as $t) |
|
278 | + { |
|
279 | + if ($t->type === DynamicGrammar::TYPE_BODY_OPEN) |
|
280 | + { |
|
252 | 281 | $body = false; |
253 | 282 | continue; |
254 | 283 | } |
255 | 284 | |
256 | - if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) { |
|
285 | + if ($t->type === DynamicGrammar::TYPE_BODY_CLOSE) |
|
286 | + { |
|
257 | 287 | $body = null; |
258 | 288 | continue; |
259 | 289 | } |
260 | 290 | } |
261 | 291 | |
262 | - if ($body !== null) { |
|
292 | + if ($body !== null) |
|
293 | + { |
|
263 | 294 | return false; |
264 | 295 | } |
265 | 296 |
@@ -41,19 +41,19 @@ discard block |
||
41 | 41 | public function parse(Buffer $src): \Generator |
42 | 42 | { |
43 | 43 | $quoted = []; |
44 | - while ($n = $src->next()) { |
|
45 | - switch ($n->char) { |
|
44 | + while ($n = $src->next()){ |
|
45 | + switch ($n->char){ |
|
46 | 46 | case '"': |
47 | 47 | case "'": |
48 | - if ($this->keyword !== []) { |
|
48 | + if ($this->keyword !== []){ |
|
49 | 49 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
50 | 50 | $this->keyword = []; |
51 | 51 | } |
52 | 52 | |
53 | 53 | $quoted[] = $n; |
54 | - while ($nn = $src->next()) { |
|
54 | + while ($nn = $src->next()){ |
|
55 | 55 | $quoted[] = $nn; |
56 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
56 | + if ($nn instanceof Byte && $nn->char === $n->char){ |
|
57 | 57 | break; |
58 | 58 | } |
59 | 59 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | break; |
65 | 65 | case '=': |
66 | - if ($this->keyword !== []) { |
|
66 | + if ($this->keyword !== []){ |
|
67 | 67 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
68 | 68 | $this->keyword = []; |
69 | 69 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | yield new Token(self::TYPE_EQUAL, $n->offset, '='); |
72 | 72 | break; |
73 | 73 | case ',': |
74 | - if ($this->keyword !== []) { |
|
74 | + if ($this->keyword !== []){ |
|
75 | 75 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
76 | 76 | $this->keyword = []; |
77 | 77 | } |
@@ -79,8 +79,8 @@ discard block |
||
79 | 79 | yield new Token(self::TYPE_COMMA, $n->offset, ','); |
80 | 80 | break; |
81 | 81 | default: |
82 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
83 | - if ($this->keyword !== []) { |
|
82 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)){ |
|
83 | + if ($this->keyword !== []){ |
|
84 | 84 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
85 | 85 | $this->keyword = []; |
86 | 86 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
95 | - if ($this->keyword !== []) { |
|
95 | + if ($this->keyword !== []){ |
|
96 | 96 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
97 | 97 | } |
98 | 98 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public static function tokenName(int $token): string |
104 | 104 | { |
105 | - switch ($token) { |
|
105 | + switch ($token){ |
|
106 | 106 | case self::TYPE_KEYWORD: |
107 | 107 | return 'DECLARE:KEYWORD'; |
108 | 108 | case self::TYPE_EQUAL: |
@@ -41,19 +41,24 @@ discard block |
||
41 | 41 | public function parse(Buffer $src): \Generator |
42 | 42 | { |
43 | 43 | $quoted = []; |
44 | - while ($n = $src->next()) { |
|
45 | - switch ($n->char) { |
|
44 | + while ($n = $src->next()) |
|
45 | + { |
|
46 | + switch ($n->char) |
|
47 | + { |
|
46 | 48 | case '"': |
47 | 49 | case "'": |
48 | - if ($this->keyword !== []) { |
|
50 | + if ($this->keyword !== []) |
|
51 | + { |
|
49 | 52 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
50 | 53 | $this->keyword = []; |
51 | 54 | } |
52 | 55 | |
53 | 56 | $quoted[] = $n; |
54 | - while ($nn = $src->next()) { |
|
57 | + while ($nn = $src->next()) |
|
58 | + { |
|
55 | 59 | $quoted[] = $nn; |
56 | - if ($nn instanceof Byte && $nn->char === $n->char) { |
|
60 | + if ($nn instanceof Byte && $nn->char === $n->char) |
|
61 | + { |
|
57 | 62 | break; |
58 | 63 | } |
59 | 64 | } |
@@ -63,7 +68,8 @@ discard block |
||
63 | 68 | |
64 | 69 | break; |
65 | 70 | case '=': |
66 | - if ($this->keyword !== []) { |
|
71 | + if ($this->keyword !== []) |
|
72 | + { |
|
67 | 73 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
68 | 74 | $this->keyword = []; |
69 | 75 | } |
@@ -71,7 +77,8 @@ discard block |
||
71 | 77 | yield new Token(self::TYPE_EQUAL, $n->offset, '='); |
72 | 78 | break; |
73 | 79 | case ',': |
74 | - if ($this->keyword !== []) { |
|
80 | + if ($this->keyword !== []) |
|
81 | + { |
|
75 | 82 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
76 | 83 | $this->keyword = []; |
77 | 84 | } |
@@ -79,8 +86,10 @@ discard block |
||
79 | 86 | yield new Token(self::TYPE_COMMA, $n->offset, ','); |
80 | 87 | break; |
81 | 88 | default: |
82 | - if (preg_match(self::REGEXP_WHITESPACE, $n->char)) { |
|
83 | - if ($this->keyword !== []) { |
|
89 | + if (preg_match(self::REGEXP_WHITESPACE, $n->char)) |
|
90 | + { |
|
91 | + if ($this->keyword !== []) |
|
92 | + { |
|
84 | 93 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
85 | 94 | $this->keyword = []; |
86 | 95 | } |
@@ -92,7 +101,8 @@ discard block |
||
92 | 101 | } |
93 | 102 | } |
94 | 103 | |
95 | - if ($this->keyword !== []) { |
|
104 | + if ($this->keyword !== []) |
|
105 | + { |
|
96 | 106 | yield $this->packToken($this->keyword, self::TYPE_KEYWORD); |
97 | 107 | } |
98 | 108 | } |
@@ -102,7 +112,8 @@ discard block |
||
102 | 112 | */ |
103 | 113 | public static function tokenName(int $token): string |
104 | 114 | { |
105 | - switch ($token) { |
|
115 | + switch ($token) |
|
116 | + { |
|
106 | 117 | case self::TYPE_KEYWORD: |
107 | 118 | return 'DECLARE:KEYWORD'; |
108 | 119 | case self::TYPE_EQUAL: |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function getClasses(): array |
161 | 161 | { |
162 | - if (!isset($this->declarations['T_CLASS'])) { |
|
162 | + if (!isset($this->declarations['T_CLASS'])){ |
|
163 | 163 | return []; |
164 | 164 | } |
165 | 165 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function getTraits(): array |
173 | 173 | { |
174 | - if (!isset($this->declarations['T_TRAIT'])) { |
|
174 | + if (!isset($this->declarations['T_TRAIT'])){ |
|
175 | 175 | return []; |
176 | 176 | } |
177 | 177 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getInterfaces(): array |
185 | 185 | { |
186 | - if (!isset($this->declarations['T_INTERFACE'])) { |
|
186 | + if (!isset($this->declarations['T_INTERFACE'])){ |
|
187 | 187 | return []; |
188 | 188 | } |
189 | 189 | |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function getInvocations(): array |
216 | 216 | { |
217 | - if (empty($this->invocations)) { |
|
217 | + if (empty($this->invocations)){ |
|
218 | 218 | $this->locateInvocations($this->getTokens()); |
219 | 219 | } |
220 | 220 | |
@@ -242,12 +242,12 @@ discard block |
||
242 | 242 | */ |
243 | 243 | protected function locateDeclarations() |
244 | 244 | { |
245 | - foreach ($this->getTokens() as $tokenID => $token) { |
|
246 | - if (!in_array($token[self::TOKEN_TYPE], self::$processTokens)) { |
|
245 | + foreach ($this->getTokens() as $tokenID => $token){ |
|
246 | + if (!in_array($token[self::TOKEN_TYPE], self::$processTokens)){ |
|
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | |
250 | - switch ($token[self::TOKEN_TYPE]) { |
|
250 | + switch ($token[self::TOKEN_TYPE]){ |
|
251 | 251 | case T_NAMESPACE: |
252 | 252 | $this->registerNamespace($tokenID); |
253 | 253 | break; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | case T_CLASS: |
264 | 264 | case T_TRAIT: |
265 | 265 | case T_INTERFACE: |
266 | - if ($this->isClassNameConst($tokenID)) { |
|
266 | + if ($this->isClassNameConst($tokenID)){ |
|
267 | 267 | //PHP5.5 ClassName::class constant |
268 | 268 | continue 2; |
269 | 269 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | |
282 | 282 | //Dropping empty namespace |
283 | - if (isset($this->namespaces[''])) { |
|
283 | + if (isset($this->namespaces[''])){ |
|
284 | 284 | $this->namespaces['\\'] = $this->namespaces['']; |
285 | 285 | unset($this->namespaces['']); |
286 | 286 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | $namespace = ''; |
295 | 295 | $localID = $tokenID + 1; |
296 | 296 | |
297 | - do { |
|
297 | + do{ |
|
298 | 298 | $token = $this->tokens[$localID++]; |
299 | - if ($token[self::TOKEN_CODE] == '{') { |
|
299 | + if ($token[self::TOKEN_CODE] == '{'){ |
|
300 | 300 | break; |
301 | 301 | } |
302 | 302 | |
303 | 303 | $namespace .= $token[self::TOKEN_CODE]; |
304 | - } while ( |
|
304 | + }while ( |
|
305 | 305 | isset($this->tokens[$localID]) |
306 | 306 | && $this->tokens[$localID][self::TOKEN_CODE] != '{' |
307 | 307 | && $this->tokens[$localID][self::TOKEN_CODE] != ';' |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | $namespace = trim($namespace); |
312 | 312 | |
313 | 313 | $uses = []; |
314 | - if (isset($this->namespaces[$namespace])) { |
|
314 | + if (isset($this->namespaces[$namespace])){ |
|
315 | 315 | $uses = $this->namespaces[$namespace]; |
316 | 316 | } |
317 | 317 | |
318 | - if ($this->tokens[$localID][self::TOKEN_CODE] == ';') { |
|
318 | + if ($this->tokens[$localID][self::TOKEN_CODE] == ';'){ |
|
319 | 319 | $endingID = count($this->tokens) - 1; |
320 | - } else { |
|
320 | + }else{ |
|
321 | 321 | $endingID = $this->endingToken($tokenID); |
322 | 322 | } |
323 | 323 | |
@@ -337,20 +337,20 @@ discard block |
||
337 | 337 | |
338 | 338 | $class = ''; |
339 | 339 | $localAlias = null; |
340 | - for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] != ';'; ++$localID) { |
|
341 | - if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) { |
|
340 | + for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] != ';'; ++$localID){ |
|
341 | + if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS){ |
|
342 | 342 | $localAlias = ''; |
343 | 343 | continue; |
344 | 344 | } |
345 | 345 | |
346 | - if ($localAlias === null) { |
|
346 | + if ($localAlias === null){ |
|
347 | 347 | $class .= $this->tokens[$localID][self::TOKEN_CODE]; |
348 | - } else { |
|
348 | + }else{ |
|
349 | 349 | $localAlias .= $this->tokens[$localID][self::TOKEN_CODE]; |
350 | 350 | } |
351 | 351 | } |
352 | 352 | |
353 | - if (empty($localAlias)) { |
|
353 | + if (empty($localAlias)){ |
|
354 | 354 | $names = explode('\\', $class); |
355 | 355 | $localAlias = end($names); |
356 | 356 | } |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | */ |
364 | 364 | private function registerFunction(int $tokenID) |
365 | 365 | { |
366 | - foreach ($this->declarations as $declarations) { |
|
367 | - foreach ($declarations as $location) { |
|
368 | - if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) { |
|
366 | + foreach ($this->declarations as $declarations){ |
|
367 | + foreach ($declarations as $location){ |
|
368 | + if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]){ |
|
369 | 369 | //We are inside class, function is method |
370 | 370 | return; |
371 | 371 | } |
@@ -373,14 +373,14 @@ discard block |
||
373 | 373 | } |
374 | 374 | |
375 | 375 | $localID = $tokenID + 1; |
376 | - while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) { |
|
376 | + while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING){ |
|
377 | 377 | //Fetching function name |
378 | 378 | ++$localID; |
379 | 379 | } |
380 | 380 | |
381 | 381 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
382 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
383 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
382 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
383 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | $this->functions[$name] = [ |
@@ -396,13 +396,13 @@ discard block |
||
396 | 396 | private function registerDeclaration(int $tokenID, int $tokenType) |
397 | 397 | { |
398 | 398 | $localID = $tokenID + 1; |
399 | - while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) { |
|
399 | + while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING){ |
|
400 | 400 | ++$localID; |
401 | 401 | } |
402 | 402 | |
403 | 403 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
404 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
405 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
404 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
405 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | $this->declarations[token_name($tokenType)][$name] = [ |
@@ -448,24 +448,24 @@ discard block |
||
448 | 448 | |
449 | 449 | //Tokens used to re-enable token detection |
450 | 450 | $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR]; |
451 | - foreach ($tokens as $tokenID => $token) { |
|
451 | + foreach ($tokens as $tokenID => $token){ |
|
452 | 452 | $tokenType = $token[self::TOKEN_TYPE]; |
453 | 453 | |
454 | 454 | //We are not indexing function declarations or functions called from $objects. |
455 | - if (in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) { |
|
455 | + if (in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])){ |
|
456 | 456 | if ( |
457 | 457 | empty($argumentsTID) |
458 | 458 | && ( |
459 | 459 | empty($invocationTID) |
460 | 460 | || $this->getSource($invocationTID, $tokenID - 1) != '$this' |
461 | 461 | ) |
462 | - ) { |
|
462 | + ){ |
|
463 | 463 | //Not a call, function declaration, or object method |
464 | 464 | $ignore = true; |
465 | 465 | continue; |
466 | 466 | } |
467 | - } elseif ($ignore) { |
|
468 | - if (!in_array($tokenType, $stopTokens)) { |
|
467 | + } elseif ($ignore){ |
|
468 | + if (!in_array($tokenType, $stopTokens)){ |
|
469 | 469 | //Returning to search |
470 | 470 | $ignore = false; |
471 | 471 | } |
@@ -473,13 +473,13 @@ discard block |
||
473 | 473 | } |
474 | 474 | |
475 | 475 | //We are inside function, and there is "(", indexing arguments. |
476 | - if (!empty($invocationTID) && ($tokenType == '(' || $tokenType == '[')) { |
|
477 | - if (empty($argumentsTID)) { |
|
476 | + if (!empty($invocationTID) && ($tokenType == '(' || $tokenType == '[')){ |
|
477 | + if (empty($argumentsTID)){ |
|
478 | 478 | $argumentsTID = $tokenID; |
479 | 479 | } |
480 | 480 | |
481 | 481 | ++$level; |
482 | - if ($level != 1) { |
|
482 | + if ($level != 1){ |
|
483 | 483 | //Not arguments beginning, but arguments part |
484 | 484 | $arguments[$tokenID] = $token; |
485 | 485 | } |
@@ -488,16 +488,16 @@ discard block |
||
488 | 488 | } |
489 | 489 | |
490 | 490 | //We are inside function arguments and ")" met. |
491 | - if (!empty($invocationTID) && ($tokenType == ')' || $tokenType == ']')) { |
|
491 | + if (!empty($invocationTID) && ($tokenType == ')' || $tokenType == ']')){ |
|
492 | 492 | --$level; |
493 | - if ($level == -1) { |
|
493 | + if ($level == -1){ |
|
494 | 494 | $invocationTID = false; |
495 | 495 | $level = 0; |
496 | 496 | continue; |
497 | 497 | } |
498 | 498 | |
499 | 499 | //Function fully indexed, we can process it now. |
500 | - if ($level == 0) { |
|
500 | + if ($level == 0){ |
|
501 | 501 | $this->registerInvocation( |
502 | 502 | $invocationTID, |
503 | 503 | $argumentsTID, |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | //Closing search |
510 | 510 | $arguments = []; |
511 | 511 | $argumentsTID = $invocationTID = false; |
512 | - } else { |
|
512 | + }else{ |
|
513 | 513 | //Not arguments beginning, but arguments part |
514 | 514 | $arguments[$tokenID] = $token; |
515 | 515 | } |
@@ -518,13 +518,13 @@ discard block |
||
518 | 518 | } |
519 | 519 | |
520 | 520 | //Still inside arguments. |
521 | - if (!empty($invocationTID) && !empty($level)) { |
|
521 | + if (!empty($invocationTID) && !empty($level)){ |
|
522 | 522 | $arguments[$tokenID] = $token; |
523 | 523 | continue; |
524 | 524 | } |
525 | 525 | |
526 | 526 | //Nothing valuable to remember, will be parsed later. |
527 | - if (!empty($invocationTID) && in_array($tokenType, $stopTokens)) { |
|
527 | + if (!empty($invocationTID) && in_array($tokenType, $stopTokens)){ |
|
528 | 528 | continue; |
529 | 529 | } |
530 | 530 | |
@@ -534,7 +534,7 @@ discard block |
||
534 | 534 | || $tokenType == T_STATIC |
535 | 535 | || $tokenType == T_NS_SEPARATOR |
536 | 536 | || ($tokenType == T_VARIABLE && $token[self::TOKEN_CODE] == '$this') |
537 | - ) { |
|
537 | + ){ |
|
538 | 538 | $invocationTID = $tokenID; |
539 | 539 | $level = 0; |
540 | 540 | |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | int $endID, |
558 | 558 | array $arguments, |
559 | 559 | int $invocationLevel |
560 | - ) { |
|
560 | + ){ |
|
561 | 561 | //Nested invocations |
562 | 562 | $this->locateInvocations($arguments, $invocationLevel + 1); |
563 | 563 | |
564 | 564 | [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID); |
565 | 565 | |
566 | - if (!empty($operator) && empty($class)) { |
|
566 | + if (!empty($operator) && empty($class)){ |
|
567 | 567 | //Non detectable |
568 | 568 | return; |
569 | 569 | } |
@@ -591,17 +591,17 @@ discard block |
||
591 | 591 | $name = trim($this->getSource($invocationTID, $argumentsTID), '( '); |
592 | 592 | |
593 | 593 | //Let's try to fetch all information we need |
594 | - if (strpos($name, '->') !== false) { |
|
594 | + if (strpos($name, '->') !== false){ |
|
595 | 595 | $operator = '->'; |
596 | - } elseif (strpos($name, '::') !== false) { |
|
596 | + } elseif (strpos($name, '::') !== false){ |
|
597 | 597 | $operator = '::'; |
598 | 598 | } |
599 | 599 | |
600 | - if (!empty($operator)) { |
|
600 | + if (!empty($operator)){ |
|
601 | 601 | [$class, $name] = explode($operator, $name); |
602 | 602 | |
603 | 603 | //We now have to clarify class name |
604 | - if (in_array($class, ['self', 'static', '$this'])) { |
|
604 | + if (in_array($class, ['self', 'static', '$this'])){ |
|
605 | 605 | $class = $this->activeDeclaration($invocationTID); |
606 | 606 | } |
607 | 607 | } |
@@ -617,9 +617,9 @@ discard block |
||
617 | 617 | */ |
618 | 618 | private function activeDeclaration(int $tokenID): string |
619 | 619 | { |
620 | - foreach ($this->declarations as $declarations) { |
|
621 | - foreach ($declarations as $name => $position) { |
|
622 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
620 | + foreach ($this->declarations as $declarations){ |
|
621 | + foreach ($declarations as $name => $position){ |
|
622 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
623 | 623 | return $name; |
624 | 624 | } |
625 | 625 | } |
@@ -636,8 +636,8 @@ discard block |
||
636 | 636 | */ |
637 | 637 | private function activeNamespace(int $tokenID): string |
638 | 638 | { |
639 | - foreach ($this->namespaces as $namespace => $position) { |
|
640 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
639 | + foreach ($this->namespaces as $namespace => $position){ |
|
640 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
641 | 641 | return $namespace; |
642 | 642 | } |
643 | 643 | } |
@@ -660,18 +660,18 @@ discard block |
||
660 | 660 | private function endingToken(int $tokenID): int |
661 | 661 | { |
662 | 662 | $level = null; |
663 | - for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) { |
|
663 | + for ($localID = $tokenID; $localID < $this->countTokens; ++$localID){ |
|
664 | 664 | $token = $this->tokens[$localID]; |
665 | - if ($token[self::TOKEN_CODE] == '{') { |
|
665 | + if ($token[self::TOKEN_CODE] == '{'){ |
|
666 | 666 | ++$level; |
667 | 667 | continue; |
668 | 668 | } |
669 | 669 | |
670 | - if ($token[self::TOKEN_CODE] == '}') { |
|
670 | + if ($token[self::TOKEN_CODE] == '}'){ |
|
671 | 671 | --$level; |
672 | 672 | } |
673 | 673 | |
674 | - if ($level === 0) { |
|
674 | + if ($level === 0){ |
|
675 | 675 | break; |
676 | 676 | } |
677 | 677 | } |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | */ |
687 | 687 | private function lineNumber(int $tokenID): int |
688 | 688 | { |
689 | - while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) { |
|
689 | + while (empty($this->tokens[$tokenID][self::TOKEN_LINE])){ |
|
690 | 690 | --$tokenID; |
691 | 691 | } |
692 | 692 | |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | private function getSource(int $startID, int $endID): string |
702 | 702 | { |
703 | 703 | $result = ''; |
704 | - for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) { |
|
704 | + for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID){ |
|
705 | 705 | //Collecting function usage src |
706 | 706 | $result .= $this->tokens[$tokenID][self::TOKEN_CODE]; |
707 | 707 | } |
@@ -159,7 +159,8 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public function getClasses(): array |
161 | 161 | { |
162 | - if (!isset($this->declarations['T_CLASS'])) { |
|
162 | + if (!isset($this->declarations['T_CLASS'])) |
|
163 | + { |
|
163 | 164 | return []; |
164 | 165 | } |
165 | 166 | |
@@ -171,7 +172,8 @@ discard block |
||
171 | 172 | */ |
172 | 173 | public function getTraits(): array |
173 | 174 | { |
174 | - if (!isset($this->declarations['T_TRAIT'])) { |
|
175 | + if (!isset($this->declarations['T_TRAIT'])) |
|
176 | + { |
|
175 | 177 | return []; |
176 | 178 | } |
177 | 179 | |
@@ -183,7 +185,8 @@ discard block |
||
183 | 185 | */ |
184 | 186 | public function getInterfaces(): array |
185 | 187 | { |
186 | - if (!isset($this->declarations['T_INTERFACE'])) { |
|
188 | + if (!isset($this->declarations['T_INTERFACE'])) |
|
189 | + { |
|
187 | 190 | return []; |
188 | 191 | } |
189 | 192 | |
@@ -214,7 +217,8 @@ discard block |
||
214 | 217 | */ |
215 | 218 | public function getInvocations(): array |
216 | 219 | { |
217 | - if (empty($this->invocations)) { |
|
220 | + if (empty($this->invocations)) |
|
221 | + { |
|
218 | 222 | $this->locateInvocations($this->getTokens()); |
219 | 223 | } |
220 | 224 | |
@@ -242,12 +246,15 @@ discard block |
||
242 | 246 | */ |
243 | 247 | protected function locateDeclarations() |
244 | 248 | { |
245 | - foreach ($this->getTokens() as $tokenID => $token) { |
|
246 | - if (!in_array($token[self::TOKEN_TYPE], self::$processTokens)) { |
|
249 | + foreach ($this->getTokens() as $tokenID => $token) |
|
250 | + { |
|
251 | + if (!in_array($token[self::TOKEN_TYPE], self::$processTokens)) |
|
252 | + { |
|
247 | 253 | continue; |
248 | 254 | } |
249 | 255 | |
250 | - switch ($token[self::TOKEN_TYPE]) { |
|
256 | + switch ($token[self::TOKEN_TYPE]) |
|
257 | + { |
|
251 | 258 | case T_NAMESPACE: |
252 | 259 | $this->registerNamespace($tokenID); |
253 | 260 | break; |
@@ -263,7 +270,8 @@ discard block |
||
263 | 270 | case T_CLASS: |
264 | 271 | case T_TRAIT: |
265 | 272 | case T_INTERFACE: |
266 | - if ($this->isClassNameConst($tokenID)) { |
|
273 | + if ($this->isClassNameConst($tokenID)) |
|
274 | + { |
|
267 | 275 | //PHP5.5 ClassName::class constant |
268 | 276 | continue 2; |
269 | 277 | } |
@@ -280,7 +288,8 @@ discard block |
||
280 | 288 | } |
281 | 289 | |
282 | 290 | //Dropping empty namespace |
283 | - if (isset($this->namespaces[''])) { |
|
291 | + if (isset($this->namespaces[''])) |
|
292 | + { |
|
284 | 293 | $this->namespaces['\\'] = $this->namespaces['']; |
285 | 294 | unset($this->namespaces['']); |
286 | 295 | } |
@@ -294,9 +303,11 @@ discard block |
||
294 | 303 | $namespace = ''; |
295 | 304 | $localID = $tokenID + 1; |
296 | 305 | |
297 | - do { |
|
306 | + do |
|
307 | + { |
|
298 | 308 | $token = $this->tokens[$localID++]; |
299 | - if ($token[self::TOKEN_CODE] == '{') { |
|
309 | + if ($token[self::TOKEN_CODE] == '{') |
|
310 | + { |
|
300 | 311 | break; |
301 | 312 | } |
302 | 313 | |
@@ -311,13 +322,17 @@ discard block |
||
311 | 322 | $namespace = trim($namespace); |
312 | 323 | |
313 | 324 | $uses = []; |
314 | - if (isset($this->namespaces[$namespace])) { |
|
325 | + if (isset($this->namespaces[$namespace])) |
|
326 | + { |
|
315 | 327 | $uses = $this->namespaces[$namespace]; |
316 | 328 | } |
317 | 329 | |
318 | - if ($this->tokens[$localID][self::TOKEN_CODE] == ';') { |
|
330 | + if ($this->tokens[$localID][self::TOKEN_CODE] == ';') |
|
331 | + { |
|
319 | 332 | $endingID = count($this->tokens) - 1; |
320 | - } else { |
|
333 | + } |
|
334 | + else |
|
335 | + { |
|
321 | 336 | $endingID = $this->endingToken($tokenID); |
322 | 337 | } |
323 | 338 | |
@@ -337,20 +352,26 @@ discard block |
||
337 | 352 | |
338 | 353 | $class = ''; |
339 | 354 | $localAlias = null; |
340 | - for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] != ';'; ++$localID) { |
|
341 | - if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) { |
|
355 | + for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] != ';'; ++$localID) |
|
356 | + { |
|
357 | + if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) |
|
358 | + { |
|
342 | 359 | $localAlias = ''; |
343 | 360 | continue; |
344 | 361 | } |
345 | 362 | |
346 | - if ($localAlias === null) { |
|
363 | + if ($localAlias === null) |
|
364 | + { |
|
347 | 365 | $class .= $this->tokens[$localID][self::TOKEN_CODE]; |
348 | - } else { |
|
366 | + } |
|
367 | + else |
|
368 | + { |
|
349 | 369 | $localAlias .= $this->tokens[$localID][self::TOKEN_CODE]; |
350 | 370 | } |
351 | 371 | } |
352 | 372 | |
353 | - if (empty($localAlias)) { |
|
373 | + if (empty($localAlias)) |
|
374 | + { |
|
354 | 375 | $names = explode('\\', $class); |
355 | 376 | $localAlias = end($names); |
356 | 377 | } |
@@ -363,9 +384,12 @@ discard block |
||
363 | 384 | */ |
364 | 385 | private function registerFunction(int $tokenID) |
365 | 386 | { |
366 | - foreach ($this->declarations as $declarations) { |
|
367 | - foreach ($declarations as $location) { |
|
368 | - if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) { |
|
387 | + foreach ($this->declarations as $declarations) |
|
388 | + { |
|
389 | + foreach ($declarations as $location) |
|
390 | + { |
|
391 | + if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) |
|
392 | + { |
|
369 | 393 | //We are inside class, function is method |
370 | 394 | return; |
371 | 395 | } |
@@ -373,13 +397,15 @@ discard block |
||
373 | 397 | } |
374 | 398 | |
375 | 399 | $localID = $tokenID + 1; |
376 | - while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) { |
|
400 | + while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) |
|
401 | + { |
|
377 | 402 | //Fetching function name |
378 | 403 | ++$localID; |
379 | 404 | } |
380 | 405 | |
381 | 406 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
382 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
407 | + if (!empty($namespace = $this->activeNamespace($tokenID))) |
|
408 | + { |
|
383 | 409 | $name = $namespace . self::NS_SEPARATOR . $name; |
384 | 410 | } |
385 | 411 | |
@@ -396,12 +422,14 @@ discard block |
||
396 | 422 | private function registerDeclaration(int $tokenID, int $tokenType) |
397 | 423 | { |
398 | 424 | $localID = $tokenID + 1; |
399 | - while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) { |
|
425 | + while ($this->tokens[$localID][self::TOKEN_TYPE] != T_STRING) |
|
426 | + { |
|
400 | 427 | ++$localID; |
401 | 428 | } |
402 | 429 | |
403 | 430 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
404 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
431 | + if (!empty($namespace = $this->activeNamespace($tokenID))) |
|
432 | + { |
|
405 | 433 | $name = $namespace . self::NS_SEPARATOR . $name; |
406 | 434 | } |
407 | 435 | |
@@ -448,11 +476,13 @@ discard block |
||
448 | 476 | |
449 | 477 | //Tokens used to re-enable token detection |
450 | 478 | $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR]; |
451 | - foreach ($tokens as $tokenID => $token) { |
|
479 | + foreach ($tokens as $tokenID => $token) |
|
480 | + { |
|
452 | 481 | $tokenType = $token[self::TOKEN_TYPE]; |
453 | 482 | |
454 | 483 | //We are not indexing function declarations or functions called from $objects. |
455 | - if (in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) { |
|
484 | + if (in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) |
|
485 | + { |
|
456 | 486 | if ( |
457 | 487 | empty($argumentsTID) |
458 | 488 | && ( |
@@ -464,8 +494,11 @@ discard block |
||
464 | 494 | $ignore = true; |
465 | 495 | continue; |
466 | 496 | } |
467 | - } elseif ($ignore) { |
|
468 | - if (!in_array($tokenType, $stopTokens)) { |
|
497 | + } |
|
498 | + elseif ($ignore) |
|
499 | + { |
|
500 | + if (!in_array($tokenType, $stopTokens)) |
|
501 | + { |
|
469 | 502 | //Returning to search |
470 | 503 | $ignore = false; |
471 | 504 | } |
@@ -473,13 +506,16 @@ discard block |
||
473 | 506 | } |
474 | 507 | |
475 | 508 | //We are inside function, and there is "(", indexing arguments. |
476 | - if (!empty($invocationTID) && ($tokenType == '(' || $tokenType == '[')) { |
|
477 | - if (empty($argumentsTID)) { |
|
509 | + if (!empty($invocationTID) && ($tokenType == '(' || $tokenType == '[')) |
|
510 | + { |
|
511 | + if (empty($argumentsTID)) |
|
512 | + { |
|
478 | 513 | $argumentsTID = $tokenID; |
479 | 514 | } |
480 | 515 | |
481 | 516 | ++$level; |
482 | - if ($level != 1) { |
|
517 | + if ($level != 1) |
|
518 | + { |
|
483 | 519 | //Not arguments beginning, but arguments part |
484 | 520 | $arguments[$tokenID] = $token; |
485 | 521 | } |
@@ -488,16 +524,19 @@ discard block |
||
488 | 524 | } |
489 | 525 | |
490 | 526 | //We are inside function arguments and ")" met. |
491 | - if (!empty($invocationTID) && ($tokenType == ')' || $tokenType == ']')) { |
|
527 | + if (!empty($invocationTID) && ($tokenType == ')' || $tokenType == ']')) |
|
528 | + { |
|
492 | 529 | --$level; |
493 | - if ($level == -1) { |
|
530 | + if ($level == -1) |
|
531 | + { |
|
494 | 532 | $invocationTID = false; |
495 | 533 | $level = 0; |
496 | 534 | continue; |
497 | 535 | } |
498 | 536 | |
499 | 537 | //Function fully indexed, we can process it now. |
500 | - if ($level == 0) { |
|
538 | + if ($level == 0) |
|
539 | + { |
|
501 | 540 | $this->registerInvocation( |
502 | 541 | $invocationTID, |
503 | 542 | $argumentsTID, |
@@ -509,7 +548,9 @@ discard block |
||
509 | 548 | //Closing search |
510 | 549 | $arguments = []; |
511 | 550 | $argumentsTID = $invocationTID = false; |
512 | - } else { |
|
551 | + } |
|
552 | + else |
|
553 | + { |
|
513 | 554 | //Not arguments beginning, but arguments part |
514 | 555 | $arguments[$tokenID] = $token; |
515 | 556 | } |
@@ -518,13 +559,15 @@ discard block |
||
518 | 559 | } |
519 | 560 | |
520 | 561 | //Still inside arguments. |
521 | - if (!empty($invocationTID) && !empty($level)) { |
|
562 | + if (!empty($invocationTID) && !empty($level)) |
|
563 | + { |
|
522 | 564 | $arguments[$tokenID] = $token; |
523 | 565 | continue; |
524 | 566 | } |
525 | 567 | |
526 | 568 | //Nothing valuable to remember, will be parsed later. |
527 | - if (!empty($invocationTID) && in_array($tokenType, $stopTokens)) { |
|
569 | + if (!empty($invocationTID) && in_array($tokenType, $stopTokens)) |
|
570 | + { |
|
528 | 571 | continue; |
529 | 572 | } |
530 | 573 | |
@@ -563,7 +606,8 @@ discard block |
||
563 | 606 | |
564 | 607 | [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID); |
565 | 608 | |
566 | - if (!empty($operator) && empty($class)) { |
|
609 | + if (!empty($operator) && empty($class)) |
|
610 | + { |
|
567 | 611 | //Non detectable |
568 | 612 | return; |
569 | 613 | } |
@@ -591,17 +635,22 @@ discard block |
||
591 | 635 | $name = trim($this->getSource($invocationTID, $argumentsTID), '( '); |
592 | 636 | |
593 | 637 | //Let's try to fetch all information we need |
594 | - if (strpos($name, '->') !== false) { |
|
638 | + if (strpos($name, '->') !== false) |
|
639 | + { |
|
595 | 640 | $operator = '->'; |
596 | - } elseif (strpos($name, '::') !== false) { |
|
641 | + } |
|
642 | + elseif (strpos($name, '::') !== false) |
|
643 | + { |
|
597 | 644 | $operator = '::'; |
598 | 645 | } |
599 | 646 | |
600 | - if (!empty($operator)) { |
|
647 | + if (!empty($operator)) |
|
648 | + { |
|
601 | 649 | [$class, $name] = explode($operator, $name); |
602 | 650 | |
603 | 651 | //We now have to clarify class name |
604 | - if (in_array($class, ['self', 'static', '$this'])) { |
|
652 | + if (in_array($class, ['self', 'static', '$this'])) |
|
653 | + { |
|
605 | 654 | $class = $this->activeDeclaration($invocationTID); |
606 | 655 | } |
607 | 656 | } |
@@ -617,9 +666,12 @@ discard block |
||
617 | 666 | */ |
618 | 667 | private function activeDeclaration(int $tokenID): string |
619 | 668 | { |
620 | - foreach ($this->declarations as $declarations) { |
|
621 | - foreach ($declarations as $name => $position) { |
|
622 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
669 | + foreach ($this->declarations as $declarations) |
|
670 | + { |
|
671 | + foreach ($declarations as $name => $position) |
|
672 | + { |
|
673 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) |
|
674 | + { |
|
623 | 675 | return $name; |
624 | 676 | } |
625 | 677 | } |
@@ -636,8 +688,10 @@ discard block |
||
636 | 688 | */ |
637 | 689 | private function activeNamespace(int $tokenID): string |
638 | 690 | { |
639 | - foreach ($this->namespaces as $namespace => $position) { |
|
640 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
691 | + foreach ($this->namespaces as $namespace => $position) |
|
692 | + { |
|
693 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) |
|
694 | + { |
|
641 | 695 | return $namespace; |
642 | 696 | } |
643 | 697 | } |
@@ -660,18 +714,22 @@ discard block |
||
660 | 714 | private function endingToken(int $tokenID): int |
661 | 715 | { |
662 | 716 | $level = null; |
663 | - for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) { |
|
717 | + for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) |
|
718 | + { |
|
664 | 719 | $token = $this->tokens[$localID]; |
665 | - if ($token[self::TOKEN_CODE] == '{') { |
|
720 | + if ($token[self::TOKEN_CODE] == '{') |
|
721 | + { |
|
666 | 722 | ++$level; |
667 | 723 | continue; |
668 | 724 | } |
669 | 725 | |
670 | - if ($token[self::TOKEN_CODE] == '}') { |
|
726 | + if ($token[self::TOKEN_CODE] == '}') |
|
727 | + { |
|
671 | 728 | --$level; |
672 | 729 | } |
673 | 730 | |
674 | - if ($level === 0) { |
|
731 | + if ($level === 0) |
|
732 | + { |
|
675 | 733 | break; |
676 | 734 | } |
677 | 735 | } |
@@ -686,7 +744,8 @@ discard block |
||
686 | 744 | */ |
687 | 745 | private function lineNumber(int $tokenID): int |
688 | 746 | { |
689 | - while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) { |
|
747 | + while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) |
|
748 | + { |
|
690 | 749 | --$tokenID; |
691 | 750 | } |
692 | 751 | |
@@ -701,7 +760,8 @@ discard block |
||
701 | 760 | private function getSource(int $startID, int $endID): string |
702 | 761 | { |
703 | 762 | $result = ''; |
704 | - for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) { |
|
763 | + for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) |
|
764 | + { |
|
705 | 765 | //Collecting function usage src |
706 | 766 | $result .= $this->tokens[$tokenID][self::TOKEN_CODE]; |
707 | 767 | } |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function availableReflections(): \Generator |
46 | 46 | { |
47 | - foreach ($this->finder->getIterator() as $file) { |
|
47 | + foreach ($this->finder->getIterator() as $file){ |
|
48 | 48 | $reflection = new ReflectionFile((string)$file); |
49 | 49 | |
50 | - if ($reflection->hasIncludes()) { |
|
50 | + if ($reflection->hasIncludes()){ |
|
51 | 51 | // We are not analyzing files which has includes, it's not safe to require such reflections |
52 | 52 | $this->getLogger()->warning( |
53 | 53 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | */ |
74 | 74 | protected function classReflection(string $class): \ReflectionClass |
75 | 75 | { |
76 | - $loader = static function ($class) { |
|
77 | - if ($class === LocatorException::class) { |
|
76 | + $loader = static function ($class){ |
|
77 | + if ($class === LocatorException::class){ |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | //To suspend class dependency exception |
85 | 85 | spl_autoload_register($loader); |
86 | 86 | |
87 | - try { |
|
87 | + try{ |
|
88 | 88 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
89 | 89 | //we are going to handle such exception and convert it soft exception |
90 | 90 | return new \ReflectionClass($class); |
91 | - } catch (\Throwable $e) { |
|
92 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
91 | + }catch (\Throwable $e){ |
|
92 | + if ($e instanceof LocatorException && $e->getPrevious() != null){ |
|
93 | 93 | $e = $e->getPrevious(); |
94 | 94 | } |
95 | 95 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | ); |
106 | 106 | |
107 | 107 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
108 | - } finally { |
|
108 | + }finally{ |
|
109 | 109 | spl_autoload_unregister($loader); |
110 | 110 | } |
111 | 111 | } |
@@ -121,13 +121,13 @@ discard block |
||
121 | 121 | { |
122 | 122 | $traits = []; |
123 | 123 | |
124 | - do { |
|
124 | + do{ |
|
125 | 125 | $traits = \array_merge(\class_uses($class), $traits); |
126 | 126 | $class = \get_parent_class($class); |
127 | - } while ($class !== false); |
|
127 | + }while ($class !== false); |
|
128 | 128 | |
129 | 129 | //Traits from traits |
130 | - foreach (\array_flip($traits) as $trait) { |
|
130 | + foreach (\array_flip($traits) as $trait){ |
|
131 | 131 | $traits = \array_merge(\class_uses($trait), $traits); |
132 | 132 | } |
133 | 133 |
@@ -44,10 +44,12 @@ discard block |
||
44 | 44 | */ |
45 | 45 | protected function availableReflections(): \Generator |
46 | 46 | { |
47 | - foreach ($this->finder->getIterator() as $file) { |
|
47 | + foreach ($this->finder->getIterator() as $file) |
|
48 | + { |
|
48 | 49 | $reflection = new ReflectionFile((string)$file); |
49 | 50 | |
50 | - if ($reflection->hasIncludes()) { |
|
51 | + if ($reflection->hasIncludes()) |
|
52 | + { |
|
51 | 53 | // We are not analyzing files which has includes, it's not safe to require such reflections |
52 | 54 | $this->getLogger()->warning( |
53 | 55 | sprintf('File `%s` has includes and excluded from analysis', $file), |
@@ -73,8 +75,10 @@ discard block |
||
73 | 75 | */ |
74 | 76 | protected function classReflection(string $class): \ReflectionClass |
75 | 77 | { |
76 | - $loader = static function ($class) { |
|
77 | - if ($class === LocatorException::class) { |
|
78 | + $loader = static function ($class) |
|
79 | + { |
|
80 | + if ($class === LocatorException::class) |
|
81 | + { |
|
78 | 82 | return; |
79 | 83 | } |
80 | 84 | |
@@ -84,12 +88,16 @@ discard block |
||
84 | 88 | //To suspend class dependency exception |
85 | 89 | spl_autoload_register($loader); |
86 | 90 | |
87 | - try { |
|
91 | + try |
|
92 | + { |
|
88 | 93 | //In some cases reflection can thrown an exception if class invalid or can not be loaded, |
89 | 94 | //we are going to handle such exception and convert it soft exception |
90 | 95 | return new \ReflectionClass($class); |
91 | - } catch (\Throwable $e) { |
|
92 | - if ($e instanceof LocatorException && $e->getPrevious() != null) { |
|
96 | + } |
|
97 | + catch (\Throwable $e) |
|
98 | + { |
|
99 | + if ($e instanceof LocatorException && $e->getPrevious() != null) |
|
100 | + { |
|
93 | 101 | $e = $e->getPrevious(); |
94 | 102 | } |
95 | 103 | |
@@ -105,7 +113,9 @@ discard block |
||
105 | 113 | ); |
106 | 114 | |
107 | 115 | throw new LocatorException($e->getMessage(), $e->getCode(), $e); |
108 | - } finally { |
|
116 | + } |
|
117 | + finally |
|
118 | + { |
|
109 | 119 | spl_autoload_unregister($loader); |
110 | 120 | } |
111 | 121 | } |
@@ -121,13 +131,15 @@ discard block |
||
121 | 131 | { |
122 | 132 | $traits = []; |
123 | 133 | |
124 | - do { |
|
134 | + do |
|
135 | + { |
|
125 | 136 | $traits = \array_merge(\class_uses($class), $traits); |
126 | 137 | $class = \get_parent_class($class); |
127 | 138 | } while ($class !== false); |
128 | 139 | |
129 | 140 | //Traits from traits |
130 | - foreach (\array_flip($traits) as $trait) { |
|
141 | + foreach (\array_flip($traits) as $trait) |
|
142 | + { |
|
131 | 143 | $traits = \array_merge(\class_uses($trait), $traits); |
132 | 144 | } |
133 | 145 |
@@ -28,8 +28,8 @@ discard block |
||
28 | 28 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
29 | 29 | { |
30 | 30 | $result = []; |
31 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
32 | - if ($this->isTargeted($invocation, $function)) { |
|
31 | + foreach ($this->availableInvocations($function->getName()) as $invocation){ |
|
32 | + if ($this->isTargeted($invocation, $function)){ |
|
33 | 33 | $result[] = $invocation; |
34 | 34 | } |
35 | 35 | } |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | protected function availableInvocations(string $signature = ''): \Generator |
47 | 47 | { |
48 | 48 | $signature = strtolower(trim($signature, '\\')); |
49 | - foreach ($this->availableReflections() as $reflection) { |
|
50 | - foreach ($reflection->getInvocations() as $invocation) { |
|
49 | + foreach ($this->availableReflections() as $reflection){ |
|
50 | + foreach ($reflection->getInvocations() as $invocation){ |
|
51 | 51 | if ( |
52 | 52 | !empty($signature) |
53 | 53 | && strtolower(trim($invocation->getName(), '\\')) != $signature |
54 | - ) { |
|
54 | + ){ |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | |
63 | 63 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
64 | 64 | { |
65 | - if ($function instanceof \ReflectionFunction) { |
|
65 | + if ($function instanceof \ReflectionFunction){ |
|
66 | 66 | return !$invocation->isMethod(); |
67 | 67 | } |
68 | 68 | |
69 | - try { |
|
69 | + try{ |
|
70 | 70 | $reflection = $this->classReflection($invocation->getClass()); |
71 | - } catch (LocatorException $e) { |
|
71 | + }catch (LocatorException $e){ |
|
72 | 72 | return false; |
73 | 73 | } |
74 | 74 | |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | $target = $function->getDeclaringClass(); |
79 | 79 | |
80 | - if ($target->isTrait()) { |
|
80 | + if ($target->isTrait()){ |
|
81 | 81 | //Let's compare traits |
82 | 82 | return in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
83 | 83 | } |
@@ -28,8 +28,10 @@ discard block |
||
28 | 28 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
29 | 29 | { |
30 | 30 | $result = []; |
31 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
32 | - if ($this->isTargeted($invocation, $function)) { |
|
31 | + foreach ($this->availableInvocations($function->getName()) as $invocation) |
|
32 | + { |
|
33 | + if ($this->isTargeted($invocation, $function)) |
|
34 | + { |
|
33 | 35 | $result[] = $invocation; |
34 | 36 | } |
35 | 37 | } |
@@ -46,8 +48,10 @@ discard block |
||
46 | 48 | protected function availableInvocations(string $signature = ''): \Generator |
47 | 49 | { |
48 | 50 | $signature = strtolower(trim($signature, '\\')); |
49 | - foreach ($this->availableReflections() as $reflection) { |
|
50 | - foreach ($reflection->getInvocations() as $invocation) { |
|
51 | + foreach ($this->availableReflections() as $reflection) |
|
52 | + { |
|
53 | + foreach ($reflection->getInvocations() as $invocation) |
|
54 | + { |
|
51 | 55 | if ( |
52 | 56 | !empty($signature) |
53 | 57 | && strtolower(trim($invocation->getName(), '\\')) != $signature |
@@ -62,13 +66,17 @@ discard block |
||
62 | 66 | |
63 | 67 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
64 | 68 | { |
65 | - if ($function instanceof \ReflectionFunction) { |
|
69 | + if ($function instanceof \ReflectionFunction) |
|
70 | + { |
|
66 | 71 | return !$invocation->isMethod(); |
67 | 72 | } |
68 | 73 | |
69 | - try { |
|
74 | + try |
|
75 | + { |
|
70 | 76 | $reflection = $this->classReflection($invocation->getClass()); |
71 | - } catch (LocatorException $e) { |
|
77 | + } |
|
78 | + catch (LocatorException $e) |
|
79 | + { |
|
72 | 80 | return false; |
73 | 81 | } |
74 | 82 | |
@@ -77,7 +85,8 @@ discard block |
||
77 | 85 | */ |
78 | 86 | $target = $function->getDeclaringClass(); |
79 | 87 | |
80 | - if ($target->isTrait()) { |
|
88 | + if ($target->isTrait()) |
|
89 | + { |
|
81 | 90 | //Let's compare traits |
82 | 91 | return in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
83 | 92 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | |
22 | 22 | public function addListener(callable $listener): void |
23 | 23 | { |
24 | - if (!array_search($listener, $this->listeners, true)) { |
|
24 | + if (!array_search($listener, $this->listeners, true)){ |
|
25 | 25 | $this->listeners[] = $listener; |
26 | 26 | } |
27 | 27 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | public function removeListener(callable $listener): void |
30 | 30 | { |
31 | 31 | $key = array_search($listener, $this->listeners, true); |
32 | - if ($key !== null) { |
|
32 | + if ($key !== null){ |
|
33 | 33 | unset($this->listeners[$key]); |
34 | 34 | } |
35 | 35 | } |
@@ -21,7 +21,8 @@ discard block |
||
21 | 21 | |
22 | 22 | public function addListener(callable $listener): void |
23 | 23 | { |
24 | - if (!array_search($listener, $this->listeners, true)) { |
|
24 | + if (!array_search($listener, $this->listeners, true)) |
|
25 | + { |
|
25 | 26 | $this->listeners[] = $listener; |
26 | 27 | } |
27 | 28 | } |
@@ -29,7 +30,8 @@ discard block |
||
29 | 30 | public function removeListener(callable $listener): void |
30 | 31 | { |
31 | 32 | $key = array_search($listener, $this->listeners, true); |
32 | - if ($key !== null) { |
|
33 | + if ($key !== null) |
|
34 | + { |
|
33 | 35 | unset($this->listeners[$key]); |
34 | 36 | } |
35 | 37 | } |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public function __construct( |
27 | 27 | HandlerRegistryInterface $registry, |
28 | 28 | FailedJobHandlerInterface $failedJobHandler |
29 | - ) { |
|
29 | + ){ |
|
30 | 30 | $this->registry = $registry; |
31 | 31 | $this->failedJobHandler = $failedJobHandler; |
32 | 32 | } |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | /** @inheritdoc */ |
35 | 35 | public function push(string $name, array $payload = [], OptionsInterface $options = null): string |
36 | 36 | { |
37 | - if ($options !== null && $options->getDelay()) { |
|
37 | + if ($options !== null && $options->getDelay()){ |
|
38 | 38 | sleep($options->getDelay()); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $id = (string)Uuid::uuid4(); |
42 | 42 | |
43 | - try { |
|
43 | + try{ |
|
44 | 44 | $this->registry->getHandler($name)->handle($name, $id, $payload); |
45 | - } catch (\Throwable $e) { |
|
45 | + }catch (\Throwable $e){ |
|
46 | 46 | $this->failedJobHandler->handle( |
47 | 47 | 'sync', |
48 | 48 | 'default', |
@@ -34,15 +34,19 @@ |
||
34 | 34 | /** @inheritdoc */ |
35 | 35 | public function push(string $name, array $payload = [], OptionsInterface $options = null): string |
36 | 36 | { |
37 | - if ($options !== null && $options->getDelay()) { |
|
37 | + if ($options !== null && $options->getDelay()) |
|
38 | + { |
|
38 | 39 | sleep($options->getDelay()); |
39 | 40 | } |
40 | 41 | |
41 | 42 | $id = (string)Uuid::uuid4(); |
42 | 43 | |
43 | - try { |
|
44 | + try |
|
45 | + { |
|
44 | 46 | $this->registry->getHandler($name)->handle($name, $id, $payload); |
45 | - } catch (\Throwable $e) { |
|
47 | + } |
|
48 | + catch (\Throwable $e) |
|
49 | + { |
|
46 | 50 | $this->failedJobHandler->handle( |
47 | 51 | 'sync', |
48 | 52 | 'default', |
@@ -32,12 +32,12 @@ |
||
32 | 32 | */ |
33 | 33 | public function handle(string $name, string $id, array $payload): void |
34 | 34 | { |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $this->invoker->invoke( |
37 | 37 | [$this, $this->getHandlerMethod()], |
38 | 38 | \array_merge(['payload' => $payload, 'id' => $id], $payload) |
39 | 39 | ); |
40 | - } catch (\Throwable $e) { |
|
40 | + }catch (\Throwable $e){ |
|
41 | 41 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
42 | 42 | throw new JobException($message, (int)$e->getCode(), $e); |
43 | 43 | } |
@@ -32,12 +32,15 @@ |
||
32 | 32 | */ |
33 | 33 | public function handle(string $name, string $id, array $payload): void |
34 | 34 | { |
35 | - try { |
|
35 | + try |
|
36 | + { |
|
36 | 37 | $this->invoker->invoke( |
37 | 38 | [$this, $this->getHandlerMethod()], |
38 | 39 | \array_merge(['payload' => $payload, 'id' => $id], $payload) |
39 | 40 | ); |
40 | - } catch (\Throwable $e) { |
|
41 | + } |
|
42 | + catch (\Throwable $e) |
|
43 | + { |
|
41 | 44 | $message = \sprintf('[%s] %s', \get_class($this), $e->getMessage()); |
42 | 45 | throw new JobException($message, (int)$e->getCode(), $e); |
43 | 46 | } |
@@ -32,11 +32,11 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function getDefaultDriver(): string |
34 | 34 | { |
35 | - if (!isset($this->config['default']) || empty($this->config['default'])) { |
|
35 | + if (!isset($this->config['default']) || empty($this->config['default'])){ |
|
36 | 36 | throw new InvalidArgumentException('Default queue connection is not defined.'); |
37 | 37 | } |
38 | 38 | |
39 | - if (!\is_string($this->config['default'])) { |
|
39 | + if (!\is_string($this->config['default'])){ |
|
40 | 40 | throw new InvalidArgumentException('Default queue connection config value must be a string'); |
41 | 41 | } |
42 | 42 | |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | { |
59 | 59 | $connections = $this->config['connections'] ?? []; |
60 | 60 | |
61 | - if ($driver === null) { |
|
61 | + if ($driver === null){ |
|
62 | 62 | return $connections; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $driverAliases = $this->getDriverAliases(); |
66 | 66 | |
67 | - if (isset($driverAliases[$driver])) { |
|
68 | - if (!\is_string($this->config['driverAliases'][$driver])) { |
|
67 | + if (isset($driverAliases[$driver])){ |
|
68 | + if (!\is_string($this->config['driverAliases'][$driver])){ |
|
69 | 69 | throw new InvalidArgumentException( |
70 | 70 | sprintf('Driver alias for `%s` value must be a string', $driver) |
71 | 71 | ); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | return array_filter($connections, static function (array $connection) use ($driverAliases, $driver): bool { |
78 | - if (empty($connection['driver'])) { |
|
78 | + if (empty($connection['driver'])){ |
|
79 | 79 | return false; |
80 | 80 | } |
81 | 81 | |
@@ -93,28 +93,28 @@ discard block |
||
93 | 93 | { |
94 | 94 | $connections = $this->getConnections(); |
95 | 95 | |
96 | - if (!isset($connections[$name])) { |
|
96 | + if (!isset($connections[$name])){ |
|
97 | 97 | throw new InvalidArgumentException(sprintf('Queue connection with given name `%s` is not defined.', $name)); |
98 | 98 | } |
99 | 99 | |
100 | - if (!isset($connections[$name]['driver'])) { |
|
100 | + if (!isset($connections[$name]['driver'])){ |
|
101 | 101 | throw new InvalidArgumentException(sprintf('Driver for queue connection `%s` is not defined.', $name)); |
102 | 102 | } |
103 | 103 | |
104 | 104 | $connection = $connections[$name]; |
105 | 105 | $driver = $connection['driver']; |
106 | 106 | |
107 | - if (!\is_string($driver)) { |
|
107 | + if (!\is_string($driver)){ |
|
108 | 108 | throw new InvalidArgumentException( |
109 | 109 | sprintf('Driver for queue connection `%s` value must be a string', $name) |
110 | 110 | ); |
111 | 111 | } |
112 | 112 | |
113 | - if (isset($this->config['driverAliases'][$driver])) { |
|
113 | + if (isset($this->config['driverAliases'][$driver])){ |
|
114 | 114 | $connection['driver'] = $this->config['driverAliases'][$driver]; |
115 | 115 | } |
116 | 116 | |
117 | - if (!\is_string($connection['driver'])) { |
|
117 | + if (!\is_string($connection['driver'])){ |
|
118 | 118 | throw new InvalidArgumentException( |
119 | 119 | sprintf('Driver alias for queue connection `%s` value must be a string', $name) |
120 | 120 | ); |
@@ -32,11 +32,13 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function getDefaultDriver(): string |
34 | 34 | { |
35 | - if (!isset($this->config['default']) || empty($this->config['default'])) { |
|
35 | + if (!isset($this->config['default']) || empty($this->config['default'])) |
|
36 | + { |
|
36 | 37 | throw new InvalidArgumentException('Default queue connection is not defined.'); |
37 | 38 | } |
38 | 39 | |
39 | - if (!\is_string($this->config['default'])) { |
|
40 | + if (!\is_string($this->config['default'])) |
|
41 | + { |
|
40 | 42 | throw new InvalidArgumentException('Default queue connection config value must be a string'); |
41 | 43 | } |
42 | 44 | |
@@ -58,14 +60,17 @@ discard block |
||
58 | 60 | { |
59 | 61 | $connections = $this->config['connections'] ?? []; |
60 | 62 | |
61 | - if ($driver === null) { |
|
63 | + if ($driver === null) |
|
64 | + { |
|
62 | 65 | return $connections; |
63 | 66 | } |
64 | 67 | |
65 | 68 | $driverAliases = $this->getDriverAliases(); |
66 | 69 | |
67 | - if (isset($driverAliases[$driver])) { |
|
68 | - if (!\is_string($this->config['driverAliases'][$driver])) { |
|
70 | + if (isset($driverAliases[$driver])) |
|
71 | + { |
|
72 | + if (!\is_string($this->config['driverAliases'][$driver])) |
|
73 | + { |
|
69 | 74 | throw new InvalidArgumentException( |
70 | 75 | sprintf('Driver alias for `%s` value must be a string', $driver) |
71 | 76 | ); |
@@ -75,7 +80,8 @@ discard block |
||
75 | 80 | } |
76 | 81 | |
77 | 82 | return array_filter($connections, static function (array $connection) use ($driverAliases, $driver): bool { |
78 | - if (empty($connection['driver'])) { |
|
83 | + if (empty($connection['driver'])) |
|
84 | + { |
|
79 | 85 | return false; |
80 | 86 | } |
81 | 87 | |
@@ -93,28 +99,33 @@ discard block |
||
93 | 99 | { |
94 | 100 | $connections = $this->getConnections(); |
95 | 101 | |
96 | - if (!isset($connections[$name])) { |
|
102 | + if (!isset($connections[$name])) |
|
103 | + { |
|
97 | 104 | throw new InvalidArgumentException(sprintf('Queue connection with given name `%s` is not defined.', $name)); |
98 | 105 | } |
99 | 106 | |
100 | - if (!isset($connections[$name]['driver'])) { |
|
107 | + if (!isset($connections[$name]['driver'])) |
|
108 | + { |
|
101 | 109 | throw new InvalidArgumentException(sprintf('Driver for queue connection `%s` is not defined.', $name)); |
102 | 110 | } |
103 | 111 | |
104 | 112 | $connection = $connections[$name]; |
105 | 113 | $driver = $connection['driver']; |
106 | 114 | |
107 | - if (!\is_string($driver)) { |
|
115 | + if (!\is_string($driver)) |
|
116 | + { |
|
108 | 117 | throw new InvalidArgumentException( |
109 | 118 | sprintf('Driver for queue connection `%s` value must be a string', $name) |
110 | 119 | ); |
111 | 120 | } |
112 | 121 | |
113 | - if (isset($this->config['driverAliases'][$driver])) { |
|
122 | + if (isset($this->config['driverAliases'][$driver])) |
|
123 | + { |
|
114 | 124 | $connection['driver'] = $this->config['driverAliases'][$driver]; |
115 | 125 | } |
116 | 126 | |
117 | - if (!\is_string($connection['driver'])) { |
|
127 | + if (!\is_string($connection['driver'])) |
|
128 | + { |
|
118 | 129 | throw new InvalidArgumentException( |
119 | 130 | sprintf('Driver alias for queue connection `%s` value must be a string', $name) |
120 | 131 | ); |