Test Failed
Pull Request — master (#899)
by butschster
16:01 queued 07:56
created
src/Tokenizer/src/Reflection/ReflectionFile.php 1 patch
Braces   +121 added lines, -58 removed lines patch added patch discarded remove patch
@@ -142,7 +142,8 @@  discard block
 block discarded – undo
142 142
      */
143 143
     public function getClasses(): array
144 144
     {
145
-        if (!isset($this->declarations['T_CLASS'])) {
145
+        if (!isset($this->declarations['T_CLASS']))
146
+        {
146 147
             return [];
147 148
         }
148 149
 
@@ -154,7 +155,8 @@  discard block
 block discarded – undo
154 155
      */
155 156
     public function getEnums(): array
156 157
     {
157
-        if (!isset($this->declarations['T_ENUM'])) {
158
+        if (!isset($this->declarations['T_ENUM']))
159
+        {
158 160
             return [];
159 161
         }
160 162
 
@@ -166,7 +168,8 @@  discard block
 block discarded – undo
166 168
      */
167 169
     public function getTraits(): array
168 170
     {
169
-        if (!isset($this->declarations['T_TRAIT'])) {
171
+        if (!isset($this->declarations['T_TRAIT']))
172
+        {
170 173
             return [];
171 174
         }
172 175
 
@@ -178,7 +181,8 @@  discard block
 block discarded – undo
178 181
      */
179 182
     public function getInterfaces(): array
180 183
     {
181
-        if (!isset($this->declarations['T_INTERFACE'])) {
184
+        if (!isset($this->declarations['T_INTERFACE']))
185
+        {
182 186
             return [];
183 187
         }
184 188
 
@@ -209,7 +213,8 @@  discard block
 block discarded – undo
209 213
      */
210 214
     public function getInvocations(): array
211 215
     {
212
-        if (empty($this->invocations)) {
216
+        if (empty($this->invocations))
217
+        {
213 218
             $this->locateInvocations($this->getTokens());
214 219
         }
215 220
 
@@ -237,12 +242,15 @@  discard block
 block discarded – undo
237 242
      */
238 243
     protected function locateDeclarations()
239 244
     {
240
-        foreach ($this->getTokens() as $tokenID => $token) {
241
-            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) {
245
+        foreach ($this->getTokens() as $tokenID => $token)
246
+        {
247
+            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens))
248
+            {
242 249
                 continue;
243 250
             }
244 251
 
245
-            switch ($token[self::TOKEN_TYPE]) {
252
+            switch ($token[self::TOKEN_TYPE])
253
+            {
246 254
                 case T_NAMESPACE:
247 255
                     $this->registerNamespace($tokenID);
248 256
                     break;
@@ -259,17 +267,20 @@  discard block
 block discarded – undo
259 267
                 case T_TRAIT:
260 268
                 case T_INTERFACE:
261 269
                 case T_ENUM:
262
-                    if ($this->isClassNameConst($tokenID)) {
270
+                    if ($this->isClassNameConst($tokenID))
271
+                    {
263 272
                         // PHP5.5 ClassName::class constant
264 273
                         continue 2;
265 274
                     }
266 275
 
267
-                    if ($this->isAnonymousClass($tokenID)) {
276
+                    if ($this->isAnonymousClass($tokenID))
277
+                    {
268 278
                         // PHP7.0 Anonymous classes new class ('foo', 'bar')
269 279
                         continue 2;
270 280
                     }
271 281
 
272
-                    if (!$this->isCorrectDeclaration($tokenID)) {
282
+                    if (!$this->isCorrectDeclaration($tokenID))
283
+                    {
273 284
                         // PHP8.0 Named parameters ->foo(class: 'bar')
274 285
                         continue 2;
275 286
                     }
@@ -286,7 +297,8 @@  discard block
 block discarded – undo
286 297
         }
287 298
 
288 299
         //Dropping empty namespace
289
-        if (isset($this->namespaces[''])) {
300
+        if (isset($this->namespaces['']))
301
+        {
290 302
             $this->namespaces['\\'] = $this->namespaces[''];
291 303
             unset($this->namespaces['']);
292 304
         }
@@ -300,9 +312,11 @@  discard block
 block discarded – undo
300 312
         $namespace = '';
301 313
         $localID = $tokenID + 1;
302 314
 
303
-        do {
315
+        do
316
+        {
304 317
             $token = $this->tokens[$localID++];
305
-            if ($token[self::TOKEN_CODE] === '{') {
318
+            if ($token[self::TOKEN_CODE] === '{')
319
+            {
306 320
                 break;
307 321
             }
308 322
 
@@ -317,13 +331,17 @@  discard block
 block discarded – undo
317 331
         $namespace = \trim($namespace);
318 332
 
319 333
         $uses = [];
320
-        if (isset($this->namespaces[$namespace])) {
334
+        if (isset($this->namespaces[$namespace]))
335
+        {
321 336
             $uses = $this->namespaces[$namespace];
322 337
         }
323 338
 
324
-        if ($this->tokens[$localID][self::TOKEN_CODE] === ';') {
339
+        if ($this->tokens[$localID][self::TOKEN_CODE] === ';')
340
+        {
325 341
             $endingID = \count($this->tokens) - 1;
326
-        } else {
342
+        }
343
+        else
344
+        {
327 345
             $endingID = $this->endingToken($tokenID);
328 346
         }
329 347
 
@@ -343,20 +361,26 @@  discard block
 block discarded – undo
343 361
 
344 362
         $class = '';
345 363
         $localAlias = null;
346
-        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) {
347
-            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) {
364
+        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID)
365
+        {
366
+            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS)
367
+            {
348 368
                 $localAlias = '';
349 369
                 continue;
350 370
             }
351 371
 
352
-            if ($localAlias === null) {
372
+            if ($localAlias === null)
373
+            {
353 374
                 $class .= $this->tokens[$localID][self::TOKEN_CODE];
354
-            } else {
375
+            }
376
+            else
377
+            {
355 378
                 $localAlias .= $this->tokens[$localID][self::TOKEN_CODE];
356 379
             }
357 380
         }
358 381
 
359
-        if (empty($localAlias)) {
382
+        if (empty($localAlias))
383
+        {
360 384
             $names = explode('\\', $class);
361 385
             $localAlias = end($names);
362 386
         }
@@ -369,9 +393,12 @@  discard block
 block discarded – undo
369 393
      */
370 394
     private function registerFunction(int $tokenID): void
371 395
     {
372
-        foreach ($this->declarations as $declarations) {
373
-            foreach ($declarations as $location) {
374
-                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) {
396
+        foreach ($this->declarations as $declarations)
397
+        {
398
+            foreach ($declarations as $location)
399
+            {
400
+                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN])
401
+                {
375 402
                     //We are inside class, function is method
376 403
                     return;
377 404
                 }
@@ -379,13 +406,15 @@  discard block
 block discarded – undo
379 406
         }
380 407
 
381 408
         $localID = $tokenID + 1;
382
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
409
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING)
410
+        {
383 411
             //Fetching function name
384 412
             ++$localID;
385 413
         }
386 414
 
387 415
         $name = $this->tokens[$localID][self::TOKEN_CODE];
388
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
416
+        if (!empty($namespace = $this->activeNamespace($tokenID)))
417
+        {
389 418
             $name = $namespace . self::NS_SEPARATOR . $name;
390 419
         }
391 420
 
@@ -402,12 +431,14 @@  discard block
 block discarded – undo
402 431
     private function registerDeclaration(int $tokenID, int $tokenType): void
403 432
     {
404 433
         $localID = $tokenID + 1;
405
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
434
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING)
435
+        {
406 436
             ++$localID;
407 437
         }
408 438
 
409 439
         $name = $this->tokens[$localID][self::TOKEN_CODE];
410
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
440
+        if (!empty($namespace = $this->activeNamespace($tokenID)))
441
+        {
411 442
             $name = $namespace . self::NS_SEPARATOR . $name;
412 443
         }
413 444
 
@@ -473,11 +504,13 @@  discard block
 block discarded – undo
473 504
 
474 505
         //Tokens used to re-enable token detection
475 506
         $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR];
476
-        foreach ($tokens as $tokenID => $token) {
507
+        foreach ($tokens as $tokenID => $token)
508
+        {
477 509
             $tokenType = $token[self::TOKEN_TYPE];
478 510
 
479 511
             //We are not indexing function declarations or functions called from $objects.
480
-            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) {
512
+            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW]))
513
+            {
481 514
                 if (
482 515
                     empty($argumentsTID)
483 516
                     && (
@@ -489,8 +522,11 @@  discard block
 block discarded – undo
489 522
                     $ignore = true;
490 523
                     continue;
491 524
                 }
492
-            } elseif ($ignore) {
493
-                if (!\in_array($tokenType, $stopTokens)) {
525
+            }
526
+            elseif ($ignore)
527
+            {
528
+                if (!\in_array($tokenType, $stopTokens))
529
+                {
494 530
                     //Returning to search
495 531
                     $ignore = false;
496 532
                 }
@@ -498,13 +534,16 @@  discard block
 block discarded – undo
498 534
             }
499 535
 
500 536
             //We are inside function, and there is "(", indexing arguments.
501
-            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) {
502
-                if (empty($argumentsTID)) {
537
+            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '['))
538
+            {
539
+                if (empty($argumentsTID))
540
+                {
503 541
                     $argumentsTID = $tokenID;
504 542
                 }
505 543
 
506 544
                 ++$level;
507
-                if ($level != 1) {
545
+                if ($level != 1)
546
+                {
508 547
                     //Not arguments beginning, but arguments part
509 548
                     $arguments[$tokenID] = $token;
510 549
                 }
@@ -513,16 +552,19 @@  discard block
 block discarded – undo
513 552
             }
514 553
 
515 554
             //We are inside function arguments and ")" met.
516
-            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) {
555
+            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']'))
556
+            {
517 557
                 --$level;
518
-                if ($level == -1) {
558
+                if ($level == -1)
559
+                {
519 560
                     $invocationTID = false;
520 561
                     $level = 0;
521 562
                     continue;
522 563
                 }
523 564
 
524 565
                 //Function fully indexed, we can process it now.
525
-                if ($level == 0) {
566
+                if ($level == 0)
567
+                {
526 568
                     $this->registerInvocation(
527 569
                         $invocationTID,
528 570
                         $argumentsTID,
@@ -534,7 +576,9 @@  discard block
 block discarded – undo
534 576
                     //Closing search
535 577
                     $arguments = [];
536 578
                     $argumentsTID = $invocationTID = false;
537
-                } else {
579
+                }
580
+                else
581
+                {
538 582
                     //Not arguments beginning, but arguments part
539 583
                     $arguments[$tokenID] = $token;
540 584
                 }
@@ -543,13 +587,15 @@  discard block
 block discarded – undo
543 587
             }
544 588
 
545 589
             //Still inside arguments.
546
-            if (!empty($invocationTID) && !empty($level)) {
590
+            if (!empty($invocationTID) && !empty($level))
591
+            {
547 592
                 $arguments[$tokenID] = $token;
548 593
                 continue;
549 594
             }
550 595
 
551 596
             //Nothing valuable to remember, will be parsed later.
552
-            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) {
597
+            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens))
598
+            {
553 599
                 continue;
554 600
             }
555 601
 
@@ -588,7 +634,8 @@  discard block
 block discarded – undo
588 634
 
589 635
         [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID);
590 636
 
591
-        if (!empty($operator) && empty($class)) {
637
+        if (!empty($operator) && empty($class))
638
+        {
592 639
             //Non detectable
593 640
             return;
594 641
         }
@@ -614,17 +661,22 @@  discard block
 block discarded – undo
614 661
         $name = \trim($this->getSource($invocationTID, $argumentsTID), '( ');
615 662
 
616 663
         //Let's try to fetch all information we need
617
-        if (\str_contains($name, '->')) {
664
+        if (\str_contains($name, '->'))
665
+        {
618 666
             $operator = '->';
619
-        } elseif (\str_contains($name, '::')) {
667
+        }
668
+        elseif (\str_contains($name, '::'))
669
+        {
620 670
             $operator = '::';
621 671
         }
622 672
 
623
-        if (!empty($operator)) {
673
+        if (!empty($operator))
674
+        {
624 675
             [$class, $name] = \explode($operator, $name);
625 676
 
626 677
             //We now have to clarify class name
627
-            if (\in_array($class, ['self', 'static', '$this'])) {
678
+            if (\in_array($class, ['self', 'static', '$this']))
679
+            {
628 680
                 $class = $this->activeDeclaration($invocationTID);
629 681
             }
630 682
         }
@@ -637,9 +689,12 @@  discard block
 block discarded – undo
637 689
      */
638 690
     private function activeDeclaration(int $tokenID): string
639 691
     {
640
-        foreach ($this->declarations as $declarations) {
641
-            foreach ($declarations as $name => $position) {
642
-                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
692
+        foreach ($this->declarations as $declarations)
693
+        {
694
+            foreach ($declarations as $name => $position)
695
+            {
696
+                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN])
697
+                {
643 698
                     return $name;
644 699
                 }
645 700
             }
@@ -654,8 +709,10 @@  discard block
 block discarded – undo
654 709
      */
655 710
     private function activeNamespace(int $tokenID): string
656 711
     {
657
-        foreach ($this->namespaces as $namespace => $position) {
658
-            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
712
+        foreach ($this->namespaces as $namespace => $position)
713
+        {
714
+            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN])
715
+            {
659 716
                 return $namespace;
660 717
             }
661 718
         }
@@ -676,18 +733,22 @@  discard block
 block discarded – undo
676 733
     private function endingToken(int $tokenID): int
677 734
     {
678 735
         $level = null;
679
-        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) {
736
+        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID)
737
+        {
680 738
             $token = $this->tokens[$localID];
681
-            if ($token[self::TOKEN_CODE] === '{') {
739
+            if ($token[self::TOKEN_CODE] === '{')
740
+            {
682 741
                 ++$level;
683 742
                 continue;
684 743
             }
685 744
 
686
-            if ($token[self::TOKEN_CODE] === '}') {
745
+            if ($token[self::TOKEN_CODE] === '}')
746
+            {
687 747
                 --$level;
688 748
             }
689 749
 
690
-            if ($level === 0) {
750
+            if ($level === 0)
751
+            {
691 752
                 break;
692 753
             }
693 754
         }
@@ -700,7 +761,8 @@  discard block
 block discarded – undo
700 761
      */
701 762
     private function lineNumber(int $tokenID): int
702 763
     {
703
-        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) {
764
+        while (empty($this->tokens[$tokenID][self::TOKEN_LINE]))
765
+        {
704 766
             --$tokenID;
705 767
         }
706 768
 
@@ -713,7 +775,8 @@  discard block
 block discarded – undo
713 775
     private function getSource(int $startID, int $endID): string
714 776
     {
715 777
         $result = '';
716
-        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) {
778
+        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID)
779
+        {
717 780
             //Collecting function usage src
718 781
             $result .= $this->tokens[$tokenID][self::TOKEN_CODE];
719 782
         }
Please login to merge, or discard this patch.