Test Failed
Pull Request — master (#895)
by butschster
19:39 queued 10:00
created
src/Tokenizer/tests/Classes/ClassWithAnonymousClass.php 1 patch
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,8 @@
 block discarded – undo
8 8
 {
9 9
     public function __construct()
10 10
     {
11
-        $class = new class ('foo', 'bar') {
11
+        $class = new class ('foo', 'bar')
12
+        {
12 13
             private function someFunc(): void
13 14
             {
14 15
             }
Please login to merge, or discard this patch.
src/Tokenizer/tests/ReflectionFileTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -16,17 +16,17 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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',
Please login to merge, or discard this patch.
src/Tokenizer/src/Reflection/ReflectionFile.php 2 patches
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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->isNamedParameter($tokenID)) {
258
+                    if ($this->isNamedParameter($tokenID)){
259 259
                         // PHP8.0 Named parameters
260 260
                         continue 2;
261 261
                     }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 isNamedParameter(int|string $tokenID): bool
429
+    private function isNamedParameter(int | string $tokenID): bool
430 430
     {
431 431
         return $this->tokens[$tokenID][self::TOKEN_TYPE] === T_CLASS
432 432
             && isset($this->tokens[$tokenID + 1])
@@ -458,24 +458,24 @@  discard block
 block discarded – undo
458 458
 
459 459
         //Tokens used to re-enable token detection
460 460
         $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR];
461
-        foreach ($tokens as $tokenID => $token) {
461
+        foreach ($tokens as $tokenID => $token){
462 462
             $tokenType = $token[self::TOKEN_TYPE];
463 463
 
464 464
             //We are not indexing function declarations or functions called from $objects.
465
-            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) {
465
+            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])){
466 466
                 if (
467 467
                     empty($argumentsTID)
468 468
                     && (
469 469
                         empty($invocationTID)
470 470
                         || $this->getSource($invocationTID, $tokenID - 1) !== '$this'
471 471
                     )
472
-                ) {
472
+                ){
473 473
                     //Not a call, function declaration, or object method
474 474
                     $ignore = true;
475 475
                     continue;
476 476
                 }
477
-            } elseif ($ignore) {
478
-                if (!\in_array($tokenType, $stopTokens)) {
477
+            } elseif ($ignore){
478
+                if (!\in_array($tokenType, $stopTokens)){
479 479
                     //Returning to search
480 480
                     $ignore = false;
481 481
                 }
@@ -483,13 +483,13 @@  discard block
 block discarded – undo
483 483
             }
484 484
 
485 485
             //We are inside function, and there is "(", indexing arguments.
486
-            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) {
487
-                if (empty($argumentsTID)) {
486
+            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')){
487
+                if (empty($argumentsTID)){
488 488
                     $argumentsTID = $tokenID;
489 489
                 }
490 490
 
491 491
                 ++$level;
492
-                if ($level != 1) {
492
+                if ($level != 1){
493 493
                     //Not arguments beginning, but arguments part
494 494
                     $arguments[$tokenID] = $token;
495 495
                 }
@@ -498,16 +498,16 @@  discard block
 block discarded – undo
498 498
             }
499 499
 
500 500
             //We are inside function arguments and ")" met.
501
-            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) {
501
+            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')){
502 502
                 --$level;
503
-                if ($level == -1) {
503
+                if ($level == -1){
504 504
                     $invocationTID = false;
505 505
                     $level = 0;
506 506
                     continue;
507 507
                 }
508 508
 
509 509
                 //Function fully indexed, we can process it now.
510
-                if ($level == 0) {
510
+                if ($level == 0){
511 511
                     $this->registerInvocation(
512 512
                         $invocationTID,
513 513
                         $argumentsTID,
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
                     //Closing search
520 520
                     $arguments = [];
521 521
                     $argumentsTID = $invocationTID = false;
522
-                } else {
522
+                }else{
523 523
                     //Not arguments beginning, but arguments part
524 524
                     $arguments[$tokenID] = $token;
525 525
                 }
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
             }
529 529
 
530 530
             //Still inside arguments.
531
-            if (!empty($invocationTID) && !empty($level)) {
531
+            if (!empty($invocationTID) && !empty($level)){
532 532
                 $arguments[$tokenID] = $token;
533 533
                 continue;
534 534
             }
535 535
 
536 536
             //Nothing valuable to remember, will be parsed later.
537
-            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) {
537
+            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)){
538 538
                 continue;
539 539
             }
540 540
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
                 || $tokenType == T_STATIC
545 545
                 || $tokenType == T_NS_SEPARATOR
546 546
                 || ($tokenType == T_VARIABLE && $token[self::TOKEN_CODE] === '$this')
547
-            ) {
547
+            ){
548 548
                 $invocationTID = $tokenID;
549 549
                 $level = 0;
550 550
 
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 
574 574
         [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID);
575 575
 
576
-        if (!empty($operator) && empty($class)) {
576
+        if (!empty($operator) && empty($class)){
577 577
             //Non detectable
578 578
             return;
579 579
         }
@@ -599,17 +599,17 @@  discard block
 block discarded – undo
599 599
         $name = \trim($this->getSource($invocationTID, $argumentsTID), '( ');
600 600
 
601 601
         //Let's try to fetch all information we need
602
-        if (\str_contains($name, '->')) {
602
+        if (\str_contains($name, '->')){
603 603
             $operator = '->';
604
-        } elseif (\str_contains($name, '::')) {
604
+        } elseif (\str_contains($name, '::')){
605 605
             $operator = '::';
606 606
         }
607 607
 
608
-        if (!empty($operator)) {
608
+        if (!empty($operator)){
609 609
             [$class, $name] = \explode($operator, $name);
610 610
 
611 611
             //We now have to clarify class name
612
-            if (\in_array($class, ['self', 'static', '$this'])) {
612
+            if (\in_array($class, ['self', 'static', '$this'])){
613 613
                 $class = $this->activeDeclaration($invocationTID);
614 614
             }
615 615
         }
@@ -622,9 +622,9 @@  discard block
 block discarded – undo
622 622
      */
623 623
     private function activeDeclaration(int $tokenID): string
624 624
     {
625
-        foreach ($this->declarations as $declarations) {
626
-            foreach ($declarations as $name => $position) {
627
-                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
625
+        foreach ($this->declarations as $declarations){
626
+            foreach ($declarations as $name => $position){
627
+                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){
628 628
                     return $name;
629 629
                 }
630 630
             }
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
      */
640 640
     private function activeNamespace(int $tokenID): string
641 641
     {
642
-        foreach ($this->namespaces as $namespace => $position) {
643
-            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
642
+        foreach ($this->namespaces as $namespace => $position){
643
+            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){
644 644
                 return $namespace;
645 645
             }
646 646
         }
@@ -661,18 +661,18 @@  discard block
 block discarded – undo
661 661
     private function endingToken(int $tokenID): int
662 662
     {
663 663
         $level = null;
664
-        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) {
664
+        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID){
665 665
             $token = $this->tokens[$localID];
666
-            if ($token[self::TOKEN_CODE] === '{') {
666
+            if ($token[self::TOKEN_CODE] === '{'){
667 667
                 ++$level;
668 668
                 continue;
669 669
             }
670 670
 
671
-            if ($token[self::TOKEN_CODE] === '}') {
671
+            if ($token[self::TOKEN_CODE] === '}'){
672 672
                 --$level;
673 673
             }
674 674
 
675
-            if ($level === 0) {
675
+            if ($level === 0){
676 676
                 break;
677 677
             }
678 678
         }
@@ -685,7 +685,7 @@  discard block
 block discarded – undo
685 685
      */
686 686
     private function lineNumber(int $tokenID): int
687 687
     {
688
-        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) {
688
+        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])){
689 689
             --$tokenID;
690 690
         }
691 691
 
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
     private function getSource(int $startID, int $endID): string
699 699
     {
700 700
         $result = '';
701
-        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) {
701
+        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID){
702 702
             //Collecting function usage src
703 703
             $result .= $this->tokens[$tokenID][self::TOKEN_CODE];
704 704
         }
Please login to merge, or discard this patch.
Braces   +119 added lines, -57 removed lines patch added patch discarded remove patch
@@ -141,7 +141,8 @@  discard block
 block discarded – undo
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 146
             return [];
146 147
         }
147 148
 
@@ -153,7 +154,8 @@  discard block
 block discarded – undo
153 154
      */
154 155
     public function getTraits(): array
155 156
     {
156
-        if (!isset($this->declarations['T_TRAIT'])) {
157
+        if (!isset($this->declarations['T_TRAIT']))
158
+        {
157 159
             return [];
158 160
         }
159 161
 
@@ -165,7 +167,8 @@  discard block
 block discarded – undo
165 167
      */
166 168
     public function getInterfaces(): array
167 169
     {
168
-        if (!isset($this->declarations['T_INTERFACE'])) {
170
+        if (!isset($this->declarations['T_INTERFACE']))
171
+        {
169 172
             return [];
170 173
         }
171 174
 
@@ -196,7 +199,8 @@  discard block
 block discarded – undo
196 199
      */
197 200
     public function getInvocations(): array
198 201
     {
199
-        if (empty($this->invocations)) {
202
+        if (empty($this->invocations))
203
+        {
200 204
             $this->locateInvocations($this->getTokens());
201 205
         }
202 206
 
@@ -224,12 +228,15 @@  discard block
 block discarded – undo
224 228
      */
225 229
     protected function locateDeclarations()
226 230
     {
227
-        foreach ($this->getTokens() as $tokenID => $token) {
228
-            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) {
231
+        foreach ($this->getTokens() as $tokenID => $token)
232
+        {
233
+            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens))
234
+            {
229 235
                 continue;
230 236
             }
231 237
 
232
-            switch ($token[self::TOKEN_TYPE]) {
238
+            switch ($token[self::TOKEN_TYPE])
239
+            {
233 240
                 case T_NAMESPACE:
234 241
                     $this->registerNamespace($tokenID);
235 242
                     break;
@@ -245,17 +252,20 @@  discard block
 block discarded – undo
245 252
                 case T_CLASS:
246 253
                 case T_TRAIT:
247 254
                 case T_INTERFACE:
248
-                    if ($this->isClassNameConst($tokenID)) {
255
+                    if ($this->isClassNameConst($tokenID))
256
+                    {
249 257
                         // PHP5.5 ClassName::class constant
250 258
                         continue 2;
251 259
                     }
252 260
 
253
-                    if ($this->isAnonymousClass($tokenID)) {
261
+                    if ($this->isAnonymousClass($tokenID))
262
+                    {
254 263
                         // PHP7.0 Anonymous classes new class ('foo', 'bar')
255 264
                         continue 2;
256 265
                     }
257 266
 
258
-                    if ($this->isNamedParameter($tokenID)) {
267
+                    if ($this->isNamedParameter($tokenID))
268
+                    {
259 269
                         // PHP8.0 Named parameters
260 270
                         continue 2;
261 271
                     }
@@ -272,7 +282,8 @@  discard block
 block discarded – undo
272 282
         }
273 283
 
274 284
         //Dropping empty namespace
275
-        if (isset($this->namespaces[''])) {
285
+        if (isset($this->namespaces['']))
286
+        {
276 287
             $this->namespaces['\\'] = $this->namespaces[''];
277 288
             unset($this->namespaces['']);
278 289
         }
@@ -286,9 +297,11 @@  discard block
 block discarded – undo
286 297
         $namespace = '';
287 298
         $localID = $tokenID + 1;
288 299
 
289
-        do {
300
+        do
301
+        {
290 302
             $token = $this->tokens[$localID++];
291
-            if ($token[self::TOKEN_CODE] === '{') {
303
+            if ($token[self::TOKEN_CODE] === '{')
304
+            {
292 305
                 break;
293 306
             }
294 307
 
@@ -303,13 +316,17 @@  discard block
 block discarded – undo
303 316
         $namespace = \trim($namespace);
304 317
 
305 318
         $uses = [];
306
-        if (isset($this->namespaces[$namespace])) {
319
+        if (isset($this->namespaces[$namespace]))
320
+        {
307 321
             $uses = $this->namespaces[$namespace];
308 322
         }
309 323
 
310
-        if ($this->tokens[$localID][self::TOKEN_CODE] === ';') {
324
+        if ($this->tokens[$localID][self::TOKEN_CODE] === ';')
325
+        {
311 326
             $endingID = \count($this->tokens) - 1;
312
-        } else {
327
+        }
328
+        else
329
+        {
313 330
             $endingID = $this->endingToken($tokenID);
314 331
         }
315 332
 
@@ -329,20 +346,26 @@  discard block
 block discarded – undo
329 346
 
330 347
         $class = '';
331 348
         $localAlias = null;
332
-        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) {
333
-            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) {
349
+        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID)
350
+        {
351
+            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS)
352
+            {
334 353
                 $localAlias = '';
335 354
                 continue;
336 355
             }
337 356
 
338
-            if ($localAlias === null) {
357
+            if ($localAlias === null)
358
+            {
339 359
                 $class .= $this->tokens[$localID][self::TOKEN_CODE];
340
-            } else {
360
+            }
361
+            else
362
+            {
341 363
                 $localAlias .= $this->tokens[$localID][self::TOKEN_CODE];
342 364
             }
343 365
         }
344 366
 
345
-        if (empty($localAlias)) {
367
+        if (empty($localAlias))
368
+        {
346 369
             $names = explode('\\', $class);
347 370
             $localAlias = end($names);
348 371
         }
@@ -355,9 +378,12 @@  discard block
 block discarded – undo
355 378
      */
356 379
     private function registerFunction(int $tokenID): void
357 380
     {
358
-        foreach ($this->declarations as $declarations) {
359
-            foreach ($declarations as $location) {
360
-                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) {
381
+        foreach ($this->declarations as $declarations)
382
+        {
383
+            foreach ($declarations as $location)
384
+            {
385
+                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN])
386
+                {
361 387
                     //We are inside class, function is method
362 388
                     return;
363 389
                 }
@@ -365,13 +391,15 @@  discard block
 block discarded – undo
365 391
         }
366 392
 
367 393
         $localID = $tokenID + 1;
368
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
394
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING)
395
+        {
369 396
             //Fetching function name
370 397
             ++$localID;
371 398
         }
372 399
 
373 400
         $name = $this->tokens[$localID][self::TOKEN_CODE];
374
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
401
+        if (!empty($namespace = $this->activeNamespace($tokenID)))
402
+        {
375 403
             $name = $namespace . self::NS_SEPARATOR . $name;
376 404
         }
377 405
 
@@ -388,12 +416,14 @@  discard block
 block discarded – undo
388 416
     private function registerDeclaration(int $tokenID, int $tokenType): void
389 417
     {
390 418
         $localID = $tokenID + 1;
391
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
419
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING)
420
+        {
392 421
             ++$localID;
393 422
         }
394 423
 
395 424
         $name = $this->tokens[$localID][self::TOKEN_CODE];
396
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
425
+        if (!empty($namespace = $this->activeNamespace($tokenID)))
426
+        {
397 427
             $name = $namespace . self::NS_SEPARATOR . $name;
398 428
         }
399 429
 
@@ -458,11 +488,13 @@  discard block
 block discarded – undo
458 488
 
459 489
         //Tokens used to re-enable token detection
460 490
         $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR];
461
-        foreach ($tokens as $tokenID => $token) {
491
+        foreach ($tokens as $tokenID => $token)
492
+        {
462 493
             $tokenType = $token[self::TOKEN_TYPE];
463 494
 
464 495
             //We are not indexing function declarations or functions called from $objects.
465
-            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) {
496
+            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW]))
497
+            {
466 498
                 if (
467 499
                     empty($argumentsTID)
468 500
                     && (
@@ -474,8 +506,11 @@  discard block
 block discarded – undo
474 506
                     $ignore = true;
475 507
                     continue;
476 508
                 }
477
-            } elseif ($ignore) {
478
-                if (!\in_array($tokenType, $stopTokens)) {
509
+            }
510
+            elseif ($ignore)
511
+            {
512
+                if (!\in_array($tokenType, $stopTokens))
513
+                {
479 514
                     //Returning to search
480 515
                     $ignore = false;
481 516
                 }
@@ -483,13 +518,16 @@  discard block
 block discarded – undo
483 518
             }
484 519
 
485 520
             //We are inside function, and there is "(", indexing arguments.
486
-            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) {
487
-                if (empty($argumentsTID)) {
521
+            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '['))
522
+            {
523
+                if (empty($argumentsTID))
524
+                {
488 525
                     $argumentsTID = $tokenID;
489 526
                 }
490 527
 
491 528
                 ++$level;
492
-                if ($level != 1) {
529
+                if ($level != 1)
530
+                {
493 531
                     //Not arguments beginning, but arguments part
494 532
                     $arguments[$tokenID] = $token;
495 533
                 }
@@ -498,16 +536,19 @@  discard block
 block discarded – undo
498 536
             }
499 537
 
500 538
             //We are inside function arguments and ")" met.
501
-            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) {
539
+            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']'))
540
+            {
502 541
                 --$level;
503
-                if ($level == -1) {
542
+                if ($level == -1)
543
+                {
504 544
                     $invocationTID = false;
505 545
                     $level = 0;
506 546
                     continue;
507 547
                 }
508 548
 
509 549
                 //Function fully indexed, we can process it now.
510
-                if ($level == 0) {
550
+                if ($level == 0)
551
+                {
511 552
                     $this->registerInvocation(
512 553
                         $invocationTID,
513 554
                         $argumentsTID,
@@ -519,7 +560,9 @@  discard block
 block discarded – undo
519 560
                     //Closing search
520 561
                     $arguments = [];
521 562
                     $argumentsTID = $invocationTID = false;
522
-                } else {
563
+                }
564
+                else
565
+                {
523 566
                     //Not arguments beginning, but arguments part
524 567
                     $arguments[$tokenID] = $token;
525 568
                 }
@@ -528,13 +571,15 @@  discard block
 block discarded – undo
528 571
             }
529 572
 
530 573
             //Still inside arguments.
531
-            if (!empty($invocationTID) && !empty($level)) {
574
+            if (!empty($invocationTID) && !empty($level))
575
+            {
532 576
                 $arguments[$tokenID] = $token;
533 577
                 continue;
534 578
             }
535 579
 
536 580
             //Nothing valuable to remember, will be parsed later.
537
-            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) {
581
+            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens))
582
+            {
538 583
                 continue;
539 584
             }
540 585
 
@@ -573,7 +618,8 @@  discard block
 block discarded – undo
573 618
 
574 619
         [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID);
575 620
 
576
-        if (!empty($operator) && empty($class)) {
621
+        if (!empty($operator) && empty($class))
622
+        {
577 623
             //Non detectable
578 624
             return;
579 625
         }
@@ -599,17 +645,22 @@  discard block
 block discarded – undo
599 645
         $name = \trim($this->getSource($invocationTID, $argumentsTID), '( ');
600 646
 
601 647
         //Let's try to fetch all information we need
602
-        if (\str_contains($name, '->')) {
648
+        if (\str_contains($name, '->'))
649
+        {
603 650
             $operator = '->';
604
-        } elseif (\str_contains($name, '::')) {
651
+        }
652
+        elseif (\str_contains($name, '::'))
653
+        {
605 654
             $operator = '::';
606 655
         }
607 656
 
608
-        if (!empty($operator)) {
657
+        if (!empty($operator))
658
+        {
609 659
             [$class, $name] = \explode($operator, $name);
610 660
 
611 661
             //We now have to clarify class name
612
-            if (\in_array($class, ['self', 'static', '$this'])) {
662
+            if (\in_array($class, ['self', 'static', '$this']))
663
+            {
613 664
                 $class = $this->activeDeclaration($invocationTID);
614 665
             }
615 666
         }
@@ -622,9 +673,12 @@  discard block
 block discarded – undo
622 673
      */
623 674
     private function activeDeclaration(int $tokenID): string
624 675
     {
625
-        foreach ($this->declarations as $declarations) {
626
-            foreach ($declarations as $name => $position) {
627
-                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
676
+        foreach ($this->declarations as $declarations)
677
+        {
678
+            foreach ($declarations as $name => $position)
679
+            {
680
+                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN])
681
+                {
628 682
                     return $name;
629 683
                 }
630 684
             }
@@ -639,8 +693,10 @@  discard block
 block discarded – undo
639 693
      */
640 694
     private function activeNamespace(int $tokenID): string
641 695
     {
642
-        foreach ($this->namespaces as $namespace => $position) {
643
-            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
696
+        foreach ($this->namespaces as $namespace => $position)
697
+        {
698
+            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN])
699
+            {
644 700
                 return $namespace;
645 701
             }
646 702
         }
@@ -661,18 +717,22 @@  discard block
 block discarded – undo
661 717
     private function endingToken(int $tokenID): int
662 718
     {
663 719
         $level = null;
664
-        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) {
720
+        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID)
721
+        {
665 722
             $token = $this->tokens[$localID];
666
-            if ($token[self::TOKEN_CODE] === '{') {
723
+            if ($token[self::TOKEN_CODE] === '{')
724
+            {
667 725
                 ++$level;
668 726
                 continue;
669 727
             }
670 728
 
671
-            if ($token[self::TOKEN_CODE] === '}') {
729
+            if ($token[self::TOKEN_CODE] === '}')
730
+            {
672 731
                 --$level;
673 732
             }
674 733
 
675
-            if ($level === 0) {
734
+            if ($level === 0)
735
+            {
676 736
                 break;
677 737
             }
678 738
         }
@@ -685,7 +745,8 @@  discard block
 block discarded – undo
685 745
      */
686 746
     private function lineNumber(int $tokenID): int
687 747
     {
688
-        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) {
748
+        while (empty($this->tokens[$tokenID][self::TOKEN_LINE]))
749
+        {
689 750
             --$tokenID;
690 751
         }
691 752
 
@@ -698,7 +759,8 @@  discard block
 block discarded – undo
698 759
     private function getSource(int $startID, int $endID): string
699 760
     {
700 761
         $result = '';
701
-        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) {
762
+        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID)
763
+        {
702 764
             //Collecting function usage src
703 765
             $result .= $this->tokens[$tokenID][self::TOKEN_CODE];
704 766
         }
Please login to merge, or discard this patch.