@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | public function __construct( |
114 | 114 | private readonly string $filename |
115 | - ) { |
|
115 | + ){ |
|
116 | 116 | $this->tokens = Tokenizer::getTokens($filename); |
117 | 117 | $this->countTokens = \count($this->tokens); |
118 | 118 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function getClasses(): array |
143 | 143 | { |
144 | - if (!isset($this->declarations['T_CLASS'])) { |
|
144 | + if (!isset($this->declarations['T_CLASS'])){ |
|
145 | 145 | return []; |
146 | 146 | } |
147 | 147 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function getTraits(): array |
155 | 155 | { |
156 | - if (!isset($this->declarations['T_TRAIT'])) { |
|
156 | + if (!isset($this->declarations['T_TRAIT'])){ |
|
157 | 157 | return []; |
158 | 158 | } |
159 | 159 | |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function getInterfaces(): array |
167 | 167 | { |
168 | - if (!isset($this->declarations['T_INTERFACE'])) { |
|
168 | + if (!isset($this->declarations['T_INTERFACE'])){ |
|
169 | 169 | return []; |
170 | 170 | } |
171 | 171 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public function getInvocations(): array |
198 | 198 | { |
199 | - if (empty($this->invocations)) { |
|
199 | + if (empty($this->invocations)){ |
|
200 | 200 | $this->locateInvocations($this->getTokens()); |
201 | 201 | } |
202 | 202 | |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | */ |
225 | 225 | protected function locateDeclarations() |
226 | 226 | { |
227 | - foreach ($this->getTokens() as $tokenID => $token) { |
|
228 | - if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) { |
|
227 | + foreach ($this->getTokens() as $tokenID => $token){ |
|
228 | + if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)){ |
|
229 | 229 | continue; |
230 | 230 | } |
231 | 231 | |
232 | - switch ($token[self::TOKEN_TYPE]) { |
|
232 | + switch ($token[self::TOKEN_TYPE]){ |
|
233 | 233 | case T_NAMESPACE: |
234 | 234 | $this->registerNamespace($tokenID); |
235 | 235 | break; |
@@ -245,17 +245,17 @@ discard block |
||
245 | 245 | case T_CLASS: |
246 | 246 | case T_TRAIT: |
247 | 247 | case T_INTERFACE: |
248 | - if ($this->isClassNameConst($tokenID)) { |
|
248 | + if ($this->isClassNameConst($tokenID)){ |
|
249 | 249 | // PHP5.5 ClassName::class constant |
250 | 250 | continue 2; |
251 | 251 | } |
252 | 252 | |
253 | - if ($this->isAnonymousClass($tokenID)) { |
|
253 | + if ($this->isAnonymousClass($tokenID)){ |
|
254 | 254 | // PHP7.0 Anonymous classes new class ('foo', 'bar') |
255 | 255 | continue 2; |
256 | 256 | } |
257 | 257 | |
258 | - if (!$this->isCorrectDeclaration($tokenID)) { |
|
258 | + if (!$this->isCorrectDeclaration($tokenID)){ |
|
259 | 259 | // PHP8.0 Named parameters ->foo(class: 'bar') |
260 | 260 | continue 2; |
261 | 261 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | |
274 | 274 | //Dropping empty namespace |
275 | - if (isset($this->namespaces[''])) { |
|
275 | + if (isset($this->namespaces[''])){ |
|
276 | 276 | $this->namespaces['\\'] = $this->namespaces['']; |
277 | 277 | unset($this->namespaces['']); |
278 | 278 | } |
@@ -286,14 +286,14 @@ discard block |
||
286 | 286 | $namespace = ''; |
287 | 287 | $localID = $tokenID + 1; |
288 | 288 | |
289 | - do { |
|
289 | + do{ |
|
290 | 290 | $token = $this->tokens[$localID++]; |
291 | - if ($token[self::TOKEN_CODE] === '{') { |
|
291 | + if ($token[self::TOKEN_CODE] === '{'){ |
|
292 | 292 | break; |
293 | 293 | } |
294 | 294 | |
295 | 295 | $namespace .= $token[self::TOKEN_CODE]; |
296 | - } while ( |
|
296 | + }while ( |
|
297 | 297 | isset($this->tokens[$localID]) |
298 | 298 | && $this->tokens[$localID][self::TOKEN_CODE] !== '{' |
299 | 299 | && $this->tokens[$localID][self::TOKEN_CODE] !== ';' |
@@ -303,13 +303,13 @@ discard block |
||
303 | 303 | $namespace = \trim($namespace); |
304 | 304 | |
305 | 305 | $uses = []; |
306 | - if (isset($this->namespaces[$namespace])) { |
|
306 | + if (isset($this->namespaces[$namespace])){ |
|
307 | 307 | $uses = $this->namespaces[$namespace]; |
308 | 308 | } |
309 | 309 | |
310 | - if ($this->tokens[$localID][self::TOKEN_CODE] === ';') { |
|
310 | + if ($this->tokens[$localID][self::TOKEN_CODE] === ';'){ |
|
311 | 311 | $endingID = \count($this->tokens) - 1; |
312 | - } else { |
|
312 | + }else{ |
|
313 | 313 | $endingID = $this->endingToken($tokenID); |
314 | 314 | } |
315 | 315 | |
@@ -329,20 +329,20 @@ discard block |
||
329 | 329 | |
330 | 330 | $class = ''; |
331 | 331 | $localAlias = null; |
332 | - for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) { |
|
333 | - if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) { |
|
332 | + for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID){ |
|
333 | + if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS){ |
|
334 | 334 | $localAlias = ''; |
335 | 335 | continue; |
336 | 336 | } |
337 | 337 | |
338 | - if ($localAlias === null) { |
|
338 | + if ($localAlias === null){ |
|
339 | 339 | $class .= $this->tokens[$localID][self::TOKEN_CODE]; |
340 | - } else { |
|
340 | + }else{ |
|
341 | 341 | $localAlias .= $this->tokens[$localID][self::TOKEN_CODE]; |
342 | 342 | } |
343 | 343 | } |
344 | 344 | |
345 | - if (empty($localAlias)) { |
|
345 | + if (empty($localAlias)){ |
|
346 | 346 | $names = explode('\\', $class); |
347 | 347 | $localAlias = end($names); |
348 | 348 | } |
@@ -355,9 +355,9 @@ discard block |
||
355 | 355 | */ |
356 | 356 | private function registerFunction(int $tokenID): void |
357 | 357 | { |
358 | - foreach ($this->declarations as $declarations) { |
|
359 | - foreach ($declarations as $location) { |
|
360 | - if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) { |
|
358 | + foreach ($this->declarations as $declarations){ |
|
359 | + foreach ($declarations as $location){ |
|
360 | + if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]){ |
|
361 | 361 | //We are inside class, function is method |
362 | 362 | return; |
363 | 363 | } |
@@ -365,14 +365,14 @@ discard block |
||
365 | 365 | } |
366 | 366 | |
367 | 367 | $localID = $tokenID + 1; |
368 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
368 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){ |
|
369 | 369 | //Fetching function name |
370 | 370 | ++$localID; |
371 | 371 | } |
372 | 372 | |
373 | 373 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
374 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
375 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
374 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
375 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | $this->functions[$name] = [ |
@@ -388,13 +388,13 @@ discard block |
||
388 | 388 | private function registerDeclaration(int $tokenID, int $tokenType): void |
389 | 389 | { |
390 | 390 | $localID = $tokenID + 1; |
391 | - while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) { |
|
391 | + while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){ |
|
392 | 392 | ++$localID; |
393 | 393 | } |
394 | 394 | |
395 | 395 | $name = $this->tokens[$localID][self::TOKEN_CODE]; |
396 | - if (!empty($namespace = $this->activeNamespace($tokenID))) { |
|
397 | - $name = $namespace . self::NS_SEPARATOR . $name; |
|
396 | + if (!empty($namespace = $this->activeNamespace($tokenID))){ |
|
397 | + $name = $namespace.self::NS_SEPARATOR.$name; |
|
398 | 398 | } |
399 | 399 | |
400 | 400 | $this->declarations[\token_name($tokenType)][$name] = [ |
@@ -416,7 +416,7 @@ discard block |
||
416 | 416 | /** |
417 | 417 | * Check if token ID represents anonymous class creation, e.g. `new class ('foo', 'bar')`. |
418 | 418 | */ |
419 | - private function isAnonymousClass(int|string $tokenID): bool |
|
419 | + private function isAnonymousClass(int | string $tokenID): bool |
|
420 | 420 | { |
421 | 421 | return $this->tokens[$tokenID][self::TOKEN_TYPE] === T_CLASS |
422 | 422 | && isset($this->tokens[$tokenID - 2]) |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | /** |
427 | 427 | * Check if token ID represents named parameter with name `class`, e.g. `foo(class: SomeClass::name)`. |
428 | 428 | */ |
429 | - private function isCorrectDeclaration(int|string $tokenID): bool |
|
429 | + private function isCorrectDeclaration(int | string $tokenID): bool |
|
430 | 430 | { |
431 | 431 | return \in_array($this->tokens[$tokenID][self::TOKEN_TYPE], [T_CLASS, T_TRAIT, T_INTERFACE], true) |
432 | 432 | && isset($this->tokens[$tokenID + 2]) |
@@ -459,24 +459,24 @@ discard block |
||
459 | 459 | |
460 | 460 | //Tokens used to re-enable token detection |
461 | 461 | $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR]; |
462 | - foreach ($tokens as $tokenID => $token) { |
|
462 | + foreach ($tokens as $tokenID => $token){ |
|
463 | 463 | $tokenType = $token[self::TOKEN_TYPE]; |
464 | 464 | |
465 | 465 | //We are not indexing function declarations or functions called from $objects. |
466 | - if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) { |
|
466 | + if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])){ |
|
467 | 467 | if ( |
468 | 468 | empty($argumentsTID) |
469 | 469 | && ( |
470 | 470 | empty($invocationTID) |
471 | 471 | || $this->getSource($invocationTID, $tokenID - 1) !== '$this' |
472 | 472 | ) |
473 | - ) { |
|
473 | + ){ |
|
474 | 474 | //Not a call, function declaration, or object method |
475 | 475 | $ignore = true; |
476 | 476 | continue; |
477 | 477 | } |
478 | - } elseif ($ignore) { |
|
479 | - if (!\in_array($tokenType, $stopTokens)) { |
|
478 | + } elseif ($ignore){ |
|
479 | + if (!\in_array($tokenType, $stopTokens)){ |
|
480 | 480 | //Returning to search |
481 | 481 | $ignore = false; |
482 | 482 | } |
@@ -484,13 +484,13 @@ discard block |
||
484 | 484 | } |
485 | 485 | |
486 | 486 | //We are inside function, and there is "(", indexing arguments. |
487 | - if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) { |
|
488 | - if (empty($argumentsTID)) { |
|
487 | + if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')){ |
|
488 | + if (empty($argumentsTID)){ |
|
489 | 489 | $argumentsTID = $tokenID; |
490 | 490 | } |
491 | 491 | |
492 | 492 | ++$level; |
493 | - if ($level != 1) { |
|
493 | + if ($level != 1){ |
|
494 | 494 | //Not arguments beginning, but arguments part |
495 | 495 | $arguments[$tokenID] = $token; |
496 | 496 | } |
@@ -499,16 +499,16 @@ discard block |
||
499 | 499 | } |
500 | 500 | |
501 | 501 | //We are inside function arguments and ")" met. |
502 | - if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) { |
|
502 | + if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')){ |
|
503 | 503 | --$level; |
504 | - if ($level == -1) { |
|
504 | + if ($level == -1){ |
|
505 | 505 | $invocationTID = false; |
506 | 506 | $level = 0; |
507 | 507 | continue; |
508 | 508 | } |
509 | 509 | |
510 | 510 | //Function fully indexed, we can process it now. |
511 | - if ($level == 0) { |
|
511 | + if ($level == 0){ |
|
512 | 512 | $this->registerInvocation( |
513 | 513 | $invocationTID, |
514 | 514 | $argumentsTID, |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | //Closing search |
521 | 521 | $arguments = []; |
522 | 522 | $argumentsTID = $invocationTID = false; |
523 | - } else { |
|
523 | + }else{ |
|
524 | 524 | //Not arguments beginning, but arguments part |
525 | 525 | $arguments[$tokenID] = $token; |
526 | 526 | } |
@@ -529,13 +529,13 @@ discard block |
||
529 | 529 | } |
530 | 530 | |
531 | 531 | //Still inside arguments. |
532 | - if (!empty($invocationTID) && !empty($level)) { |
|
532 | + if (!empty($invocationTID) && !empty($level)){ |
|
533 | 533 | $arguments[$tokenID] = $token; |
534 | 534 | continue; |
535 | 535 | } |
536 | 536 | |
537 | 537 | //Nothing valuable to remember, will be parsed later. |
538 | - if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) { |
|
538 | + if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)){ |
|
539 | 539 | continue; |
540 | 540 | } |
541 | 541 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | || $tokenType == T_STATIC |
546 | 546 | || $tokenType == T_NS_SEPARATOR |
547 | 547 | || ($tokenType == T_VARIABLE && $token[self::TOKEN_CODE] === '$this') |
548 | - ) { |
|
548 | + ){ |
|
549 | 549 | $invocationTID = $tokenID; |
550 | 550 | $level = 0; |
551 | 551 | |
@@ -574,7 +574,7 @@ discard block |
||
574 | 574 | |
575 | 575 | [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID); |
576 | 576 | |
577 | - if (!empty($operator) && empty($class)) { |
|
577 | + if (!empty($operator) && empty($class)){ |
|
578 | 578 | //Non detectable |
579 | 579 | return; |
580 | 580 | } |
@@ -600,17 +600,17 @@ discard block |
||
600 | 600 | $name = \trim($this->getSource($invocationTID, $argumentsTID), '( '); |
601 | 601 | |
602 | 602 | //Let's try to fetch all information we need |
603 | - if (\str_contains($name, '->')) { |
|
603 | + if (\str_contains($name, '->')){ |
|
604 | 604 | $operator = '->'; |
605 | - } elseif (\str_contains($name, '::')) { |
|
605 | + } elseif (\str_contains($name, '::')){ |
|
606 | 606 | $operator = '::'; |
607 | 607 | } |
608 | 608 | |
609 | - if (!empty($operator)) { |
|
609 | + if (!empty($operator)){ |
|
610 | 610 | [$class, $name] = \explode($operator, $name); |
611 | 611 | |
612 | 612 | //We now have to clarify class name |
613 | - if (\in_array($class, ['self', 'static', '$this'])) { |
|
613 | + if (\in_array($class, ['self', 'static', '$this'])){ |
|
614 | 614 | $class = $this->activeDeclaration($invocationTID); |
615 | 615 | } |
616 | 616 | } |
@@ -623,9 +623,9 @@ discard block |
||
623 | 623 | */ |
624 | 624 | private function activeDeclaration(int $tokenID): string |
625 | 625 | { |
626 | - foreach ($this->declarations as $declarations) { |
|
627 | - foreach ($declarations as $name => $position) { |
|
628 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
626 | + foreach ($this->declarations as $declarations){ |
|
627 | + foreach ($declarations as $name => $position){ |
|
628 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
629 | 629 | return $name; |
630 | 630 | } |
631 | 631 | } |
@@ -640,8 +640,8 @@ discard block |
||
640 | 640 | */ |
641 | 641 | private function activeNamespace(int $tokenID): string |
642 | 642 | { |
643 | - foreach ($this->namespaces as $namespace => $position) { |
|
644 | - if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) { |
|
643 | + foreach ($this->namespaces as $namespace => $position){ |
|
644 | + if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){ |
|
645 | 645 | return $namespace; |
646 | 646 | } |
647 | 647 | } |
@@ -662,18 +662,18 @@ discard block |
||
662 | 662 | private function endingToken(int $tokenID): int |
663 | 663 | { |
664 | 664 | $level = null; |
665 | - for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) { |
|
665 | + for ($localID = $tokenID; $localID < $this->countTokens; ++$localID){ |
|
666 | 666 | $token = $this->tokens[$localID]; |
667 | - if ($token[self::TOKEN_CODE] === '{') { |
|
667 | + if ($token[self::TOKEN_CODE] === '{'){ |
|
668 | 668 | ++$level; |
669 | 669 | continue; |
670 | 670 | } |
671 | 671 | |
672 | - if ($token[self::TOKEN_CODE] === '}') { |
|
672 | + if ($token[self::TOKEN_CODE] === '}'){ |
|
673 | 673 | --$level; |
674 | 674 | } |
675 | 675 | |
676 | - if ($level === 0) { |
|
676 | + if ($level === 0){ |
|
677 | 677 | break; |
678 | 678 | } |
679 | 679 | } |
@@ -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 | |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | private function getSource(int $startID, int $endID): string |
700 | 700 | { |
701 | 701 | $result = ''; |
702 | - for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) { |
|
702 | + for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID){ |
|
703 | 703 | //Collecting function usage src |
704 | 704 | $result .= $this->tokens[$tokenID][self::TOKEN_CODE]; |
705 | 705 | } |
@@ -19,13 +19,13 @@ |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | } |
22 | -class;FOO; |
|
22 | +class; FOO; |
|
23 | 23 | |
24 | 24 | <<<'class' |
25 | 25 | class FooBar |
26 | 26 | { |
27 | 27 | |
28 | 28 | } |
29 | -class ;FOO; |
|
29 | +class; FOO; |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | \ No newline at end of file |
@@ -16,17 +16,17 @@ discard block |
||
16 | 16 | $this->assertContains(TestTrait::class, $reflection->getTraits()); |
17 | 17 | $this->assertContains(TestInterface::class, $reflection->getInterfaces()); |
18 | 18 | |
19 | - $this->assertSame([__NAMESPACE__ . '\hello'], $reflection->getFunctions()); |
|
19 | + $this->assertSame([__NAMESPACE__.'\hello'], $reflection->getFunctions()); |
|
20 | 20 | |
21 | 21 | $functionA = null; |
22 | 22 | $functionB = null; |
23 | 23 | |
24 | - foreach ($reflection->getInvocations() as $invocation) { |
|
25 | - if ($invocation->getName() == 'test_function_a') { |
|
24 | + foreach ($reflection->getInvocations() as $invocation){ |
|
25 | + if ($invocation->getName() == 'test_function_a'){ |
|
26 | 26 | $functionA = $invocation; |
27 | 27 | } |
28 | 28 | |
29 | - if ($invocation->getName() == 'test_function_b') { |
|
29 | + if ($invocation->getName() == 'test_function_b'){ |
|
30 | 30 | $functionB = $invocation; |
31 | 31 | } |
32 | 32 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | |
54 | 54 | public function testReflectionFileWithNamedParameters(): void |
55 | 55 | { |
56 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithNamedParameter.php'); |
|
56 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithNamedParameter.php'); |
|
57 | 57 | |
58 | 58 | $this->assertSame([ |
59 | 59 | 'Spiral\Tests\Tokenizer\Classes\ClassWithNamedParameter', |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function testReflectionFileAnonymousClass(): void |
64 | 64 | { |
65 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithAnonymousClass.php'); |
|
65 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithAnonymousClass.php'); |
|
66 | 66 | |
67 | 67 | $this->assertSame([ |
68 | 68 | 'Spiral\Tests\Tokenizer\Classes\ClassWithAnonymousClass', |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | |
72 | 72 | public function testReflectionFileWithHeredoc(): void |
73 | 73 | { |
74 | - $reflection = new ReflectionFile(__DIR__ . '/Classes/ClassWithHeredoc.php'); |
|
74 | + $reflection = new ReflectionFile(__DIR__.'/Classes/ClassWithHeredoc.php'); |
|
75 | 75 | |
76 | 76 | $this->assertSame([ |
77 | 77 | 'Spiral\Tests\Tokenizer\Classes\ClassWithHeredoc', |