Passed
Pull Request — master (#148)
by Fabien
02:23
created
src/Codor/Sniffs/Classes/ConstructorLoopSniff.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\Classes;
4 4
 
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * The loop tokens we're lookin for.
13 13
      * @var array
14 14
      */
15
-    protected $loops = ['T_FOR', 'T_FOREACH', 'T_WHILE'];
15
+    protected $loops = [ 'T_FOR', 'T_FOREACH', 'T_WHILE' ];
16 16
 
17 17
     /**
18 18
      * Returns the token types that this sniff is interested in.
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      */
21 21
     public function register(): array
22 22
     {
23
-        return [T_FUNCTION];
23
+        return [ T_FUNCTION ];
24 24
     }
25 25
 
26 26
     /**
@@ -34,20 +34,20 @@  discard block
 block discarded – undo
34 34
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
35 35
     {
36 36
         $tokens            = $phpcsFile->getTokens();
37
-        $token             = $tokens[$stackPtr];
38
-        $functionNameToken = $tokens[$stackPtr + 2];
39
-        $functionName      = $functionNameToken['content'];
37
+        $token             = $tokens[ $stackPtr ];
38
+        $functionNameToken = $tokens[ $stackPtr + 2 ];
39
+        $functionName      = $functionNameToken[ 'content' ];
40 40
 
41 41
         if ($functionName !== '__construct') {
42 42
             return;
43 43
         }
44 44
         // If this is an interface we don't check it.
45
-        if (! isset($token['scope_opener'])) {
45
+        if (!isset($token[ 'scope_opener' ])) {
46 46
             return;
47 47
         }
48 48
 
49
-        for ($index=$token['scope_opener']; $index <= $token['scope_closer']; $index++) {
50
-            if (in_array($tokens[$index]['type'], $this->loops)) {
49
+        for ($index = $token[ 'scope_opener' ]; $index <= $token[ 'scope_closer' ]; $index++) {
50
+            if (in_array($tokens[ $index ][ 'type' ], $this->loops)) {
51 51
                 $phpcsFile->addError("Class constructor cannot contain a loop.", $stackPtr, __CLASS__);
52 52
                 continue;
53 53
             }
Please login to merge, or discard this patch.
src/Codor/Sniffs/TypeHints/MixedReturnTypeSniff.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\TypeHints;
4 4
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      */
19 19
     public function register(): array
20 20
     {
21
-        return [T_FUNCTION];
21
+        return [ T_FUNCTION ];
22 22
     }
23 23
 
24 24
     /**
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 
37 37
         $commentEnd = $this->findCommentEnd($phpcsFile, $stackPtr, $tokens);
38 38
 
39
-        if (empty($tokens[$commentEnd]['comment_opener'])) {
39
+        if (empty($tokens[ $commentEnd ][ 'comment_opener' ])) {
40 40
             return;
41 41
         }
42 42
 
43
-        $commentStart = $tokens[$commentEnd]['comment_opener'];
43
+        $commentStart = $tokens[ $commentEnd ][ 'comment_opener' ];
44 44
 
45 45
         $this->processReturn($phpcsFile, $commentStart);
46 46
     }
@@ -86,8 +86,8 @@  discard block
 block discarded – undo
86 86
      */
87 87
     private function findReturnTag(array $tokens, int $commentStart)
88 88
     {
89
-        return array_reduce($tokens[$commentStart]['comment_tags'], function ($carry, $tag) use ($tokens) {
90
-            return $carry || ($tokens[$tag]['content'] === self::RETURN_TAG_NAME) ? $tag : false;
89
+        return array_reduce($tokens[ $commentStart ][ 'comment_tags' ], function($carry, $tag) use ($tokens) {
90
+            return $carry || ($tokens[ $tag ][ 'content' ] === self::RETURN_TAG_NAME) ? $tag : false;
91 91
         }, false);
92 92
     }
93 93
 
@@ -99,11 +99,11 @@  discard block
 block discarded – undo
99 99
      */
100 100
     private function parseTagForReturnType(array $tokens, int $returnPosition)
101 101
     {
102
-        $content = $tokens[$returnPosition + 2]['content'];
102
+        $content = $tokens[ $returnPosition + 2 ][ 'content' ];
103 103
         // Support both a return type and a description.
104 104
         preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\a-z0-9\[\]]+))*)( .*)?`i', $content, $returnParts);
105 105
 
106
-        return $returnParts[1] ?? false;
106
+        return $returnParts[ 1 ] ?? false;
107 107
     }
108 108
 
109 109
     /**
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
      */
117 117
     private function findCommentEnd(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $tokens)
118 118
     {
119
-        $find = PHP_CodeSniffer_Tokens::$methodPrefixes + [T_WHITESPACE];
119
+        $find = PHP_CodeSniffer_Tokens::$methodPrefixes + [ T_WHITESPACE ];
120 120
 
121 121
         $commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true);
122
-        if ($tokens[$commentEnd]['code'] !== T_COMMENT) {
122
+        if ($tokens[ $commentEnd ][ 'code' ] !== T_COMMENT) {
123 123
             return $commentEnd;
124 124
         }
125 125
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
         // using the wrong comment type. If there is other code on the line,
129 129
         // assume they relate to that code.
130 130
         $prev = $phpcsFile->findPrevious($find, $commentEnd - 1, null, true);
131
-        if ($prev !== false && $tokens[$prev]['line'] === $tokens[$commentEnd]['line']) {
131
+        if ($prev !== false && $tokens[ $prev ][ 'line' ] === $tokens[ $commentEnd ][ 'line' ]) {
132 132
             $commentEnd = $prev;
133 133
         }
134 134
 
Please login to merge, or discard this patch.
src/Codor/Sniffs/Syntax/NullCoalescingSniff.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\Syntax;
4 4
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      */
15 15
     public function register(): array
16 16
     {
17
-        return [T_ISSET];
17
+        return [ T_ISSET ];
18 18
     }
19 19
 
20 20
     /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
         $semiColinFound = false;
56 56
 
57 57
         while (true) {
58
-            if ($tokens[$index]['type'] == 'T_SEMICOLON') {
58
+            if ($tokens[ $index ][ 'type' ] == 'T_SEMICOLON') {
59 59
                 break;
60 60
             }
61 61
 
62
-            if ($tokens[$index]['type'] == 'T_INLINE_THEN') {
62
+            if ($tokens[ $index ][ 'type' ] == 'T_INLINE_THEN') {
63 63
                 $questionMarkFound = true;
64 64
             }
65 65
 
66
-            if ($tokens[$index]['type'] == 'T_INLINE_ELSE') {
66
+            if ($tokens[ $index ][ 'type' ] == 'T_INLINE_ELSE') {
67 67
                 $semiColinFound = true;
68 68
             }
69 69
             $index++;
Please login to merge, or discard this patch.
src/Codor/Sniffs/ControlStructures/NestedIfSniff.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\ControlStructures;
4 4
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      */
15 15
     public function register(): array
16 16
     {
17
-        return [T_IF];
17
+        return [ T_IF ];
18 18
     }
19 19
 
20 20
     /**
@@ -41,13 +41,13 @@  discard block
 block discarded – undo
41 41
     {
42 42
         $this->phpcsFile = $phpcsFile;
43 43
         $tokens          = $phpcsFile->getTokens();
44
-        $token           = $tokens[$stackPtr];
45
-        $start           = $token['scope_opener'];
46
-        $end             = $token['scope_closer'];
44
+        $token           = $tokens[ $stackPtr ];
45
+        $start           = $token[ 'scope_opener' ];
46
+        $end             = $token[ 'scope_closer' ];
47 47
 
48
-        $this->errorStack = [];
49
-        for ($index=$start; $index <= $end; $index++) {
50
-            $this->checkForNestedIf($tokens[$index], $stackPtr);
48
+        $this->errorStack = [ ];
49
+        for ($index = $start; $index <= $end; $index++) {
50
+            $this->checkForNestedIf($tokens[ $index ], $stackPtr);
51 51
         }
52 52
     }
53 53
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     protected function checkForNestedIf(array $token, int $stackPtr)
61 61
     {
62
-        if (! $this->isIfStatement($token)) {
62
+        if (!$this->isIfStatement($token)) {
63 63
             return;
64 64
         }
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         }
69 69
 
70 70
         $this->phpcsFile->addError('Nested if statement found.', $stackPtr, __CLASS__);
71
-        $this->errorStack[] = $stackPtr;
71
+        $this->errorStack[ ] = $stackPtr;
72 72
     }
73 73
 
74 74
     /**
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      */
94 94
     protected function isIfStatement(array $token): bool
95 95
     {
96
-        if ($token['type'] === 'T_IF') {
96
+        if ($token[ 'type' ] === 'T_IF') {
97 97
             return true;
98 98
         }
99 99
 
Please login to merge, or discard this patch.
src/Codor/Sniffs/ControlStructures/NoElseSniff.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\ControlStructures;
4 4
 
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
      */
18 18
     public function register(): array
19 19
     {
20
-        return [T_ELSE, T_ELSEIF];
20
+        return [ T_ELSE, T_ELSEIF ];
21 21
     }
22 22
 
23 23
     /**
Please login to merge, or discard this patch.
src/Codor/Sniffs/Syntax/LinesAfterMethodSniff.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php declare(strict_types = 1);
1
+<?php declare(strict_types=1);
2 2
 
3 3
 namespace Codor\Sniffs\Syntax;
4 4
 
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      */
15 15
     public function register(): array
16 16
     {
17
-        return [T_FUNCTION];
17
+        return [ T_FUNCTION ];
18 18
     }
19 19
 
20 20
     /**
@@ -27,21 +27,21 @@  discard block
 block discarded – undo
27 27
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
28 28
     {
29 29
         $tokens = $phpcsFile->getTokens();
30
-        if (! isset($tokens[$stackPtr]['scope_closer'])) {
30
+        if (!isset($tokens[ $stackPtr ][ 'scope_closer' ])) {
31 31
             return;
32 32
         }
33 33
 
34
-        $endOfMethodIndex = $tokens[$stackPtr]['scope_closer'];
34
+        $endOfMethodIndex = $tokens[ $stackPtr ][ 'scope_closer' ];
35 35
         $nextCodeLine = 0;
36 36
 
37
-        for ($index=$endOfMethodIndex + 1; $index <= count($tokens); $index++) {
38
-            if (isset($tokens[$index]) && $tokens[$index]['type'] !== 'T_WHITESPACE') {
39
-                $nextCodeLine = $tokens[$index]['line'];
37
+        for ($index = $endOfMethodIndex + 1; $index <= count($tokens); $index++) {
38
+            if (isset($tokens[ $index ]) && $tokens[ $index ][ 'type' ] !== 'T_WHITESPACE') {
39
+                $nextCodeLine = $tokens[ $index ][ 'line' ];
40 40
                 break;
41 41
             }
42 42
         }
43 43
 
44
-        $linesBetween = $nextCodeLine - $tokens[$endOfMethodIndex]['line'] - 1;
44
+        $linesBetween = $nextCodeLine - $tokens[ $endOfMethodIndex ][ 'line' ] - 1;
45 45
         if ($linesBetween > 1) {
46 46
             $phpcsFile->addError("No more than 1 line after a method/function is allowed.", $stackPtr, __CLASS__);
47 47
         }
Please login to merge, or discard this patch.