Passed
Pull Request — master (#1207)
by Aleksei
10:55
created
src/Console/src/CommandLocatorListener.php 2 patches
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,7 +32,8 @@  discard block
 block discarded – undo
32 32
 
33 33
     public function listen(\ReflectionClass $class): void
34 34
     {
35
-        if (!$this->isTargeted($class, $this->target)) {
35
+        if (!$this->isTargeted($class, $this->target))
36
+        {
36 37
             return;
37 38
         }
38 39
 
@@ -41,8 +42,10 @@  discard block
 block discarded – undo
41 42
 
42 43
     public function finalize(): void
43 44
     {
44
-        foreach ($this->commands as $class) {
45
-            if ($class->isAbstract()) {
45
+        foreach ($this->commands as $class)
46
+        {
47
+            if ($class->isAbstract())
48
+            {
46 49
                 continue;
47 50
             }
48 51
 
@@ -55,7 +58,8 @@  discard block
 block discarded – undo
55 58
      */
56 59
     protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target): bool
57 60
     {
58
-        if (!$target->isTrait()) {
61
+        if (!$target->isTrait())
62
+        {
59 63
             // Target is interface or class
60 64
             return $class->isSubclassOf($target) || $class->getName() === $target->getName();
61 65
         }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,14 +26,14 @@  discard block
 block discarded – undo
26 26
     public function __construct(
27 27
         private readonly ConsoleBootloader $bootloader,
28 28
         ContainerInterface $container,
29
-    ) {
29
+    ){
30 30
         $this->container = $container;
31 31
         $this->target = new \ReflectionClass(SymfonyCommand::class);
32 32
     }
33 33
 
34 34
     public function listen(\ReflectionClass $class): void
35 35
     {
36
-        if (!$this->isTargeted($class, $this->target)) {
36
+        if (!$this->isTargeted($class, $this->target)){
37 37
             return;
38 38
         }
39 39
 
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 
43 43
     public function finalize(): void
44 44
     {
45
-        foreach ($this->commands as $class) {
46
-            if ($class->isAbstract()) {
45
+        foreach ($this->commands as $class){
46
+            if ($class->isAbstract()){
47 47
                 continue;
48 48
             }
49 49
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      */
57 57
     protected function isTargeted(\ReflectionClass $class, \ReflectionClass $target): bool
58 58
     {
59
-        if (!$target->isTrait()) {
59
+        if (!$target->isTrait()){
60 60
             // Target is interface or class
61 61
             return $class->isSubclassOf($target) || $class->getName() === $target->getName();
62 62
         }
Please login to merge, or discard this patch.
src/Tokenizer/tests/Listener/ClassLocatorByTargetTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
     use MockeryPHPUnitIntegration;
19 19
 
20 20
     private ClassLocatorByTarget $locator;
21
-    private ClassesInterface|m\LegacyMockInterface|m\MockInterface $classes;
22
-    private ScopedClassesInterface|m\LegacyMockInterface|m\MockInterface $scopedClasses;
21
+    private ClassesInterface | m\LegacyMockInterface | m\MockInterface $classes;
22
+    private ScopedClassesInterface | m\LegacyMockInterface | m\MockInterface $scopedClasses;
23 23
 
24 24
     protected function setUp(): void
25 25
     {
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
         $attr = $attr->getAttributes()[0];
111 111
         $attribute = $attr->newInstance();
112 112
 
113
-        if ($attribute->getScope() === null) {
113
+        if ($attribute->getScope() === null){
114 114
             $this->classes
115 115
                 ->shouldReceive('getClasses')
116 116
                 ->andReturn($classes);
117
-        } else {
117
+        }else{
118 118
             $this->scopedClasses
119 119
                 ->shouldReceive('getScopedClasses')
120 120
                 ->with($attribute->getScope())
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -110,11 +110,14 @@
 block discarded – undo
110 110
         $attr = $attr->getAttributes()[0];
111 111
         $attribute = $attr->newInstance();
112 112
 
113
-        if ($attribute->getScope() === null) {
113
+        if ($attribute->getScope() === null)
114
+        {
114 115
             $this->classes
115 116
                 ->shouldReceive('getClasses')
116 117
                 ->andReturn($classes);
117
-        } else {
118
+        }
119
+        else
120
+        {
118 121
             $this->scopedClasses
119 122
                 ->shouldReceive('getScopedClasses')
120 123
                 ->with($attribute->getScope())
Please login to merge, or discard this patch.
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/Classes/ClassWithHeredoc.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,13 +19,13 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
     public function __construct()
12 12
     {
13 13
         <<<class
14
-FooBar
14
+foobar
15 15
 class;
16 16
 
17 17
         <<<class
Please login to merge, or discard this patch.
src/Tokenizer/src/Reflection/ReflectionFile.php 2 patches
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.
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
     public function __construct(
117 117
         private readonly string $filename,
118
-    ) {
118
+    ){
119 119
         $this->tokens = Tokenizer::getTokens($filename);
120 120
         $this->countTokens = \count($this->tokens);
121 121
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     public function getClasses(): array
146 146
     {
147
-        if (!isset($this->declarations['T_CLASS'])) {
147
+        if (!isset($this->declarations['T_CLASS'])){
148 148
             return [];
149 149
         }
150 150
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     public function getEnums(): array
158 158
     {
159
-        if (!isset($this->declarations['T_ENUM'])) {
159
+        if (!isset($this->declarations['T_ENUM'])){
160 160
             return [];
161 161
         }
162 162
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      */
169 169
     public function getTraits(): array
170 170
     {
171
-        if (!isset($this->declarations['T_TRAIT'])) {
171
+        if (!isset($this->declarations['T_TRAIT'])){
172 172
             return [];
173 173
         }
174 174
 
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
      */
181 181
     public function getInterfaces(): array
182 182
     {
183
-        if (!isset($this->declarations['T_INTERFACE'])) {
183
+        if (!isset($this->declarations['T_INTERFACE'])){
184 184
             return [];
185 185
         }
186 186
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      */
212 212
     public function getInvocations(): array
213 213
     {
214
-        if (empty($this->invocations)) {
214
+        if (empty($this->invocations)){
215 215
             $this->locateInvocations($this->getTokens());
216 216
         }
217 217
 
@@ -239,12 +239,12 @@  discard block
 block discarded – undo
239 239
      */
240 240
     protected function locateDeclarations()
241 241
     {
242
-        foreach ($this->getTokens() as $tokenID => $token) {
243
-            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)) {
242
+        foreach ($this->getTokens() as $tokenID => $token){
243
+            if (!\in_array($token[self::TOKEN_TYPE], self::$processTokens)){
244 244
                 continue;
245 245
             }
246 246
 
247
-            switch ($token[self::TOKEN_TYPE]) {
247
+            switch ($token[self::TOKEN_TYPE]){
248 248
                 case T_NAMESPACE:
249 249
                     $this->registerNamespace($tokenID);
250 250
                     break;
@@ -261,17 +261,17 @@  discard block
 block discarded – undo
261 261
                 case T_TRAIT:
262 262
                 case T_INTERFACE:
263 263
                 case T_ENUM:
264
-                    if ($this->isClassNameConst($tokenID)) {
264
+                    if ($this->isClassNameConst($tokenID)){
265 265
                         // PHP5.5 ClassName::class constant
266 266
                         continue 2;
267 267
                     }
268 268
 
269
-                    if ($this->isAnonymousClass($tokenID)) {
269
+                    if ($this->isAnonymousClass($tokenID)){
270 270
                         // PHP7.0 Anonymous classes new class ('foo', 'bar')
271 271
                         continue 2;
272 272
                     }
273 273
 
274
-                    if (!$this->isCorrectDeclaration($tokenID)) {
274
+                    if (!$this->isCorrectDeclaration($tokenID)){
275 275
                         // PHP8.0 Named parameters ->foo(class: 'bar')
276 276
                         continue 2;
277 277
                     }
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
         }
289 289
 
290 290
         //Dropping empty namespace
291
-        if (isset($this->namespaces[''])) {
291
+        if (isset($this->namespaces[''])){
292 292
             $this->namespaces['\\'] = $this->namespaces[''];
293 293
             unset($this->namespaces['']);
294 294
         }
@@ -302,14 +302,14 @@  discard block
 block discarded – undo
302 302
         $namespace = '';
303 303
         $localID = $tokenID + 1;
304 304
 
305
-        do {
305
+        do{
306 306
             $token = $this->tokens[$localID++];
307
-            if ($token[self::TOKEN_CODE] === '{') {
307
+            if ($token[self::TOKEN_CODE] === '{'){
308 308
                 break;
309 309
             }
310 310
 
311 311
             $namespace .= $token[self::TOKEN_CODE];
312
-        } while (
312
+        }while (
313 313
             isset($this->tokens[$localID])
314 314
             && $this->tokens[$localID][self::TOKEN_CODE] !== '{'
315 315
             && $this->tokens[$localID][self::TOKEN_CODE] !== ';'
@@ -319,13 +319,13 @@  discard block
 block discarded – undo
319 319
         $namespace = \trim($namespace);
320 320
 
321 321
         $uses = [];
322
-        if (isset($this->namespaces[$namespace])) {
322
+        if (isset($this->namespaces[$namespace])){
323 323
             $uses = $this->namespaces[$namespace];
324 324
         }
325 325
 
326
-        if ($this->tokens[$localID][self::TOKEN_CODE] === ';') {
326
+        if ($this->tokens[$localID][self::TOKEN_CODE] === ';'){
327 327
             $endingID = \count($this->tokens) - 1;
328
-        } else {
328
+        }else{
329 329
             $endingID = $this->endingToken($tokenID);
330 330
         }
331 331
 
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
 
346 346
         $class = '';
347 347
         $localAlias = null;
348
-        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID) {
349
-            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS) {
348
+        for ($localID = $tokenID + 1; $this->tokens[$localID][self::TOKEN_CODE] !== ';'; ++$localID){
349
+            if ($this->tokens[$localID][self::TOKEN_TYPE] == T_AS){
350 350
                 $localAlias = '';
351 351
                 continue;
352 352
             }
353 353
 
354
-            if ($localAlias === null) {
354
+            if ($localAlias === null){
355 355
                 $class .= $this->tokens[$localID][self::TOKEN_CODE];
356
-            } else {
356
+            }else{
357 357
                 $localAlias .= $this->tokens[$localID][self::TOKEN_CODE];
358 358
             }
359 359
         }
360 360
 
361
-        if (empty($localAlias)) {
361
+        if (empty($localAlias)){
362 362
             $names = explode('\\', $class);
363 363
             $localAlias = end($names);
364 364
         }
@@ -371,9 +371,9 @@  discard block
 block discarded – undo
371 371
      */
372 372
     private function registerFunction(int $tokenID): void
373 373
     {
374
-        foreach ($this->declarations as $declarations) {
375
-            foreach ($declarations as $location) {
376
-                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]) {
374
+        foreach ($this->declarations as $declarations){
375
+            foreach ($declarations as $location){
376
+                if ($tokenID >= $location[self::O_TOKEN] && $tokenID <= $location[self::C_TOKEN]){
377 377
                     //We are inside class, function is method
378 378
                     return;
379 379
                 }
@@ -381,14 +381,14 @@  discard block
 block discarded – undo
381 381
         }
382 382
 
383 383
         $localID = $tokenID + 1;
384
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
384
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){
385 385
             //Fetching function name
386 386
             ++$localID;
387 387
         }
388 388
 
389 389
         $name = $this->tokens[$localID][self::TOKEN_CODE];
390
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
391
-            $name = $namespace . self::NS_SEPARATOR . $name;
390
+        if (!empty($namespace = $this->activeNamespace($tokenID))){
391
+            $name = $namespace.self::NS_SEPARATOR.$name;
392 392
         }
393 393
 
394 394
         $this->functions[$name] = [
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
     private function registerDeclaration(int $tokenID, int $tokenType): void
405 405
     {
406 406
         $localID = $tokenID + 1;
407
-        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING) {
407
+        while ($this->tokens[$localID][self::TOKEN_TYPE] !== T_STRING){
408 408
             ++$localID;
409 409
         }
410 410
 
411 411
         $name = $this->tokens[$localID][self::TOKEN_CODE];
412
-        if (!empty($namespace = $this->activeNamespace($tokenID))) {
413
-            $name = $namespace . self::NS_SEPARATOR . $name;
412
+        if (!empty($namespace = $this->activeNamespace($tokenID))){
413
+            $name = $namespace.self::NS_SEPARATOR.$name;
414 414
         }
415 415
 
416 416
         $this->declarations[\token_name($tokenType)][$name] = [
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
     /**
433 433
      * Check if token ID represents anonymous class creation, e.g. `new class ('foo', 'bar')`.
434 434
      */
435
-    private function isAnonymousClass(int|string $tokenID): bool
435
+    private function isAnonymousClass(int | string $tokenID): bool
436 436
     {
437 437
         return $this->tokens[$tokenID][self::TOKEN_TYPE] === T_CLASS
438 438
             && isset($this->tokens[$tokenID - 2])
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
     /**
443 443
      * Check if token ID represents named parameter with name `class`, e.g. `foo(class: SomeClass::name)`.
444 444
      */
445
-    private function isCorrectDeclaration(int|string $tokenID): bool
445
+    private function isCorrectDeclaration(int | string $tokenID): bool
446 446
     {
447 447
         return \in_array($this->tokens[$tokenID][self::TOKEN_TYPE], [T_CLASS, T_TRAIT, T_INTERFACE, T_ENUM], true)
448 448
             && isset($this->tokens[$tokenID + 2])
@@ -474,24 +474,24 @@  discard block
 block discarded – undo
474 474
 
475 475
         //Tokens used to re-enable token detection
476 476
         $stopTokens = [T_STRING, T_WHITESPACE, T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NS_SEPARATOR];
477
-        foreach ($tokens as $tokenID => $token) {
477
+        foreach ($tokens as $tokenID => $token){
478 478
             $tokenType = $token[self::TOKEN_TYPE];
479 479
 
480 480
             //We are not indexing function declarations or functions called from $objects.
481
-            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])) {
481
+            if (\in_array($tokenType, [T_FUNCTION, T_OBJECT_OPERATOR, T_NEW])){
482 482
                 if (
483 483
                     empty($argumentsTID)
484 484
                     && (
485 485
                         empty($invocationTID)
486 486
                         || $this->getSource($invocationTID, $tokenID - 1) !== '$this'
487 487
                     )
488
-                ) {
488
+                ){
489 489
                     //Not a call, function declaration, or object method
490 490
                     $ignore = true;
491 491
                     continue;
492 492
                 }
493
-            } elseif ($ignore) {
494
-                if (!\in_array($tokenType, $stopTokens)) {
493
+            } elseif ($ignore){
494
+                if (!\in_array($tokenType, $stopTokens)){
495 495
                     //Returning to search
496 496
                     $ignore = false;
497 497
                 }
@@ -499,13 +499,13 @@  discard block
 block discarded – undo
499 499
             }
500 500
 
501 501
             //We are inside function, and there is "(", indexing arguments.
502
-            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')) {
503
-                if (empty($argumentsTID)) {
502
+            if (!empty($invocationTID) && ($tokenType === '(' || $tokenType === '[')){
503
+                if (empty($argumentsTID)){
504 504
                     $argumentsTID = $tokenID;
505 505
                 }
506 506
 
507 507
                 ++$level;
508
-                if ($level != 1) {
508
+                if ($level != 1){
509 509
                     //Not arguments beginning, but arguments part
510 510
                     $arguments[$tokenID] = $token;
511 511
                 }
@@ -514,16 +514,16 @@  discard block
 block discarded – undo
514 514
             }
515 515
 
516 516
             //We are inside function arguments and ")" met.
517
-            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')) {
517
+            if (!empty($invocationTID) && ($tokenType === ')' || $tokenType === ']')){
518 518
                 --$level;
519
-                if ($level == -1) {
519
+                if ($level == -1){
520 520
                     $invocationTID = false;
521 521
                     $level = 0;
522 522
                     continue;
523 523
                 }
524 524
 
525 525
                 //Function fully indexed, we can process it now.
526
-                if ($level == 0) {
526
+                if ($level == 0){
527 527
                     $this->registerInvocation(
528 528
                         $invocationTID,
529 529
                         $argumentsTID,
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
                     //Closing search
536 536
                     $arguments = [];
537 537
                     $argumentsTID = $invocationTID = false;
538
-                } else {
538
+                }else{
539 539
                     //Not arguments beginning, but arguments part
540 540
                     $arguments[$tokenID] = $token;
541 541
                 }
@@ -544,13 +544,13 @@  discard block
 block discarded – undo
544 544
             }
545 545
 
546 546
             //Still inside arguments.
547
-            if (!empty($invocationTID) && !empty($level)) {
547
+            if (!empty($invocationTID) && !empty($level)){
548 548
                 $arguments[$tokenID] = $token;
549 549
                 continue;
550 550
             }
551 551
 
552 552
             //Nothing valuable to remember, will be parsed later.
553
-            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)) {
553
+            if (!empty($invocationTID) && \in_array($tokenType, $stopTokens)){
554 554
                 continue;
555 555
             }
556 556
 
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
                 || $tokenType == T_STATIC
561 561
                 || $tokenType == T_NS_SEPARATOR
562 562
                 || ($tokenType == T_VARIABLE && $token[self::TOKEN_CODE] === '$this')
563
-            ) {
563
+            ){
564 564
                 $invocationTID = $tokenID;
565 565
                 $level = 0;
566 566
 
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 
590 590
         [$class, $operator, $name] = $this->fetchContext($invocationID, $argumentsID);
591 591
 
592
-        if (!empty($operator) && empty($class)) {
592
+        if (!empty($operator) && empty($class)){
593 593
             //Non detectable
594 594
             return;
595 595
         }
@@ -615,17 +615,17 @@  discard block
 block discarded – undo
615 615
         $name = \trim($this->getSource($invocationTID, $argumentsTID), '( ');
616 616
 
617 617
         //Let's try to fetch all information we need
618
-        if (\str_contains($name, '->')) {
618
+        if (\str_contains($name, '->')){
619 619
             $operator = '->';
620
-        } elseif (\str_contains($name, '::')) {
620
+        } elseif (\str_contains($name, '::')){
621 621
             $operator = '::';
622 622
         }
623 623
 
624
-        if (!empty($operator)) {
624
+        if (!empty($operator)){
625 625
             [$class, $name] = \explode($operator, $name);
626 626
 
627 627
             //We now have to clarify class name
628
-            if (\in_array($class, ['self', 'static', '$this'])) {
628
+            if (\in_array($class, ['self', 'static', '$this'])){
629 629
                 $class = $this->activeDeclaration($invocationTID);
630 630
             }
631 631
         }
@@ -638,9 +638,9 @@  discard block
 block discarded – undo
638 638
      */
639 639
     private function activeDeclaration(int $tokenID): string
640 640
     {
641
-        foreach ($this->declarations as $declarations) {
642
-            foreach ($declarations as $name => $position) {
643
-                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
641
+        foreach ($this->declarations as $declarations){
642
+            foreach ($declarations as $name => $position){
643
+                if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){
644 644
                     return $name;
645 645
                 }
646 646
             }
@@ -655,8 +655,8 @@  discard block
 block discarded – undo
655 655
      */
656 656
     private function activeNamespace(int $tokenID): string
657 657
     {
658
-        foreach ($this->namespaces as $namespace => $position) {
659
-            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]) {
658
+        foreach ($this->namespaces as $namespace => $position){
659
+            if ($tokenID >= $position[self::O_TOKEN] && $tokenID <= $position[self::C_TOKEN]){
660 660
                 return $namespace;
661 661
             }
662 662
         }
@@ -677,18 +677,18 @@  discard block
 block discarded – undo
677 677
     private function endingToken(int $tokenID): int
678 678
     {
679 679
         $level = null;
680
-        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID) {
680
+        for ($localID = $tokenID; $localID < $this->countTokens; ++$localID){
681 681
             $token = $this->tokens[$localID];
682
-            if ($token[self::TOKEN_CODE] === '{') {
682
+            if ($token[self::TOKEN_CODE] === '{'){
683 683
                 ++$level;
684 684
                 continue;
685 685
             }
686 686
 
687
-            if ($token[self::TOKEN_CODE] === '}') {
687
+            if ($token[self::TOKEN_CODE] === '}'){
688 688
                 --$level;
689 689
             }
690 690
 
691
-            if ($level === 0) {
691
+            if ($level === 0){
692 692
                 break;
693 693
             }
694 694
         }
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
      */
702 702
     private function lineNumber(int $tokenID): int
703 703
     {
704
-        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])) {
704
+        while (empty($this->tokens[$tokenID][self::TOKEN_LINE])){
705 705
             --$tokenID;
706 706
         }
707 707
 
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
     private function getSource(int $startID, int $endID): string
715 715
     {
716 716
         $result = '';
717
-        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID) {
717
+        for ($tokenID = $startID; $tokenID <= $endID; ++$tokenID){
718 718
             //Collecting function usage src
719 719
             $result .= $this->tokens[$tokenID][self::TOKEN_CODE];
720 720
         }
Please login to merge, or discard this patch.
src/Scaffolder/tests/Command/CommandTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
             'alias' => $alias,
25 25
             '--description' => 'My sample command description',
26 26
         ];
27
-        if ($alias === null) {
27
+        if ($alias === null){
28 28
             unset($input['alias']);
29 29
         }
30 30
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@
 block discarded – undo
24 24
             'alias' => $alias,
25 25
             '--description' => 'My sample command description',
26 26
         ];
27
-        if ($alias === null) {
27
+        if ($alias === null)
28
+        {
28 29
             unset($input['alias']);
29 30
         }
30 31
 
Please login to merge, or discard this patch.
src/Scaffolder/src/Declaration/CommandDeclaration.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
         ?string $namespace = null,
23 23
         private readonly ?string $alias = null,
24 24
         private readonly ?string $description = null,
25
-    ) {
25
+    ){
26 26
         parent::__construct($config, $name, $comment, $namespace);
27 27
     }
28 28
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
             'name' => $this->alias,
70 70
         ];
71 71
 
72
-        if ($this->description) {
72
+        if ($this->description){
73 73
             $commandDefinition['description'] = $this->description;
74 74
         }
75 75
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,8 @@
 block discarded – undo
69 69
             'name' => $this->alias,
70 70
         ];
71 71
 
72
-        if ($this->description) {
72
+        if ($this->description)
73
+        {
73 74
             $commandDefinition['description'] = $this->description;
74 75
         }
75 76
 
Please login to merge, or discard this patch.
src/Scaffolder/src/Command/ControllerCommand.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@
 block discarded – undo
33 33
     {
34 34
         $declaration = $this->createDeclaration(ControllerDeclaration::class);
35 35
 
36
-        foreach ($this->actions as $action) {
36
+        foreach ($this->actions as $action){
37 37
             $declaration->addAction($action);
38 38
         }
39 39
 
40
-        if ($this->usePrototype) {
40
+        if ($this->usePrototype){
41 41
             $declaration->addPrototypeTrait();
42 42
         }
43 43
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,13 @@
 block discarded – undo
33 33
     {
34 34
         $declaration = $this->createDeclaration(ControllerDeclaration::class);
35 35
 
36
-        foreach ($this->actions as $action) {
36
+        foreach ($this->actions as $action)
37
+        {
37 38
             $declaration->addAction($action);
38 39
         }
39 40
 
40
-        if ($this->usePrototype) {
41
+        if ($this->usePrototype)
42
+        {
41 43
             $declaration->addPrototypeTrait();
42 44
         }
43 45
 
Please login to merge, or discard this patch.
src/Scaffolder/src/Command/FilterCommand.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@
 block discarded – undo
33 33
     {
34 34
         $declaration = $this->createDeclaration(FilterDeclaration::class);
35 35
 
36
-        foreach ($this->properties as $property) {
36
+        foreach ($this->properties as $property){
37 37
             $declaration->addProperty($property);
38 38
         }
39 39
 
40
-        if ($this->useValidator) {
40
+        if ($this->useValidator){
41 41
             $declaration->addFilterDefinition();
42 42
         }
43 43
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,11 +33,13 @@
 block discarded – undo
33 33
     {
34 34
         $declaration = $this->createDeclaration(FilterDeclaration::class);
35 35
 
36
-        foreach ($this->properties as $property) {
36
+        foreach ($this->properties as $property)
37
+        {
37 38
             $declaration->addProperty($property);
38 39
         }
39 40
 
40
-        if ($this->useValidator) {
41
+        if ($this->useValidator)
42
+        {
41 43
             $declaration->addFilterDefinition();
42 44
         }
43 45
 
Please login to merge, or discard this patch.