Completed
Push — master ( 2d0943...e84d6e )
by Bill
02:22 queued 01:01
created
src/Codor/Sniffs/ControlStructures/NestedIfSniff.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -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
     /**
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $this->phpcsFile = $phpcsFile;
31 31
         $tokens          = $phpcsFile->getTokens();
32
-        $token           = $tokens[$stackPtr];
33
-        $start           = $token['scope_opener'];
34
-        $end             = $token['scope_closer'];
32
+        $token           = $tokens[ $stackPtr ];
33
+        $start           = $token[ 'scope_opener' ];
34
+        $end             = $token[ 'scope_closer' ];
35 35
 
36
-        $this->errorStack = [];
37
-        for ($index=$start; $index <= $end; $index++) {
38
-            $this->checkForNestedIf($tokens[$index], $stackPtr);
36
+        $this->errorStack = [ ];
37
+        for ($index = $start; $index <= $end; $index++) {
38
+            $this->checkForNestedIf($tokens[ $index ], $stackPtr);
39 39
         }
40 40
     }
41 41
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      */
48 48
     protected function checkForNestedIf(array $token, int $stackPtr)
49 49
     {
50
-        if (! $this->isIfStatement($token)) {
50
+        if (!$this->isIfStatement($token)) {
51 51
             return;
52 52
         }
53 53
 
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         }
57 57
 
58 58
         $this->phpcsFile->addError('Nested if statement found.', $stackPtr);
59
-        $this->errorStack[] = $stackPtr;
59
+        $this->errorStack[ ] = $stackPtr;
60 60
     }
61 61
 
62 62
     /**
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
      */
82 82
     protected function isIfStatement(array $token): bool
83 83
     {
84
-        if ($token['type'] === 'T_IF') {
84
+        if ($token[ 'type' ] === 'T_IF') {
85 85
             return true;
86 86
         }
87 87
 
Please login to merge, or discard this patch.
src/Codor/Sniffs/ControlStructures/NoElseSniff.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 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/Files/ReturnNullSniff.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      */
15 15
     public function register(): array
16 16
     {
17
-        return [T_RETURN];
17
+        return [ T_RETURN ];
18 18
     }
19 19
 
20 20
     /**
@@ -30,13 +30,13 @@  discard block
 block discarded – undo
30 30
         $returnTokenIndex = $stackPtr;
31 31
 
32 32
         $scope = array_slice($tokens, $returnTokenIndex, null, true);
33
-        $semicolons = array_filter($scope, function ($token) {
34
-            return $token['type'] === 'T_SEMICOLON';
33
+        $semicolons = array_filter($scope, function($token) {
34
+            return $token[ 'type' ] === 'T_SEMICOLON';
35 35
         });
36 36
 
37 37
         $returnValueIndex = key($semicolons) - 1;
38 38
 
39
-        if ($scope[$returnValueIndex]['type'] === 'T_NULL') {
39
+        if ($scope[ $returnValueIndex ][ 'type' ] === 'T_NULL') {
40 40
             $error = "Return null value found.";
41 41
             $phpcsFile->addError($error, $returnValueIndex);
42 42
         }
Please login to merge, or discard this patch.
src/Codor/Sniffs/Files/FunctionLengthSniff.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function register(): array
23 23
     {
24
-        return [T_FUNCTION];
24
+        return [ T_FUNCTION ];
25 25
     }
26 26
 
27 27
     /**
@@ -35,19 +35,19 @@  discard block
 block discarded – undo
35 35
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
36 36
     {
37 37
         $tokens = $phpcsFile->getTokens();
38
-        $token = $tokens[$stackPtr];
38
+        $token = $tokens[ $stackPtr ];
39 39
 
40 40
         // Skip function without body.
41
-        if (isset($token['scope_opener']) === false) {
41
+        if (isset($token[ 'scope_opener' ]) === false) {
42 42
             return;
43 43
         }
44 44
 
45
-        $firstToken = $tokens[$token['scope_opener']];
46
-        $lastToken = $tokens[$token['scope_closer']];
47
-        $length = $lastToken['line'] - $firstToken['line'];
45
+        $firstToken = $tokens[ $token[ 'scope_opener' ] ];
46
+        $lastToken = $tokens[ $token[ 'scope_closer' ] ];
47
+        $length = $lastToken[ 'line' ] - $firstToken[ 'line' ];
48 48
 
49 49
         if ($length > $this->maxLength) {
50
-            $tokenType = strtolower(substr($token['type'], 2));
50
+            $tokenType = strtolower(substr($token[ 'type' ], 2));
51 51
             $error = "Function is {$length} lines. Must be {$this->maxLength} lines or fewer.";
52 52
             $phpcsFile->addError($error, $stackPtr, sprintf('%sTooBig', ucfirst($tokenType)));
53 53
         }
Please login to merge, or discard this patch.
src/Codor/Sniffs/Files/IndentationLevelSniff.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * It is increased inside try-catch blocks.
25 25
      * @var array
26 26
      */
27
-    protected $relativeScopeLevels = [];
27
+    protected $relativeScopeLevels = [ ];
28 28
 
29 29
     /**
30 30
      * Returns the token types that this sniff is interested in.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function register(): array
34 34
     {
35
-        return [T_FUNCTION, T_CLOSURE, T_SWITCH];
35
+        return [ T_FUNCTION, T_CLOSURE, T_SWITCH ];
36 36
     }
37 37
 
38 38
     /**
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
47 47
     {
48 48
         $tokens = $phpcsFile->getTokens();
49
-        $token = $tokens[$stackPtr];
49
+        $token = $tokens[ $stackPtr ];
50 50
         $this->maxIndentFound = 0;
51 51
 
52 52
         // Ignore functions with no body
53
-        if (isset($token['scope_opener']) === false) {
53
+        if (isset($token[ 'scope_opener' ]) === false) {
54 54
             return;
55 55
         }
56 56
 
@@ -71,16 +71,16 @@  discard block
 block discarded – undo
71 71
      */
72 72
     protected function inspectScope(array $token, array $tokens)
73 73
     {
74
-        $start = $token['scope_opener'];
75
-        $length = $token['scope_closer'] - $start + 1;
74
+        $start = $token[ 'scope_opener' ];
75
+        $length = $token[ 'scope_closer' ] - $start + 1;
76 76
 
77 77
         $scope = array_slice($tokens, $start, $length, true);
78 78
         $scope = $this->removeTokenScopes($scope, 'T_SWITCH');
79 79
 
80
-        $this->setRelativeScopeLevels($scope, $scope[$start]['level']);
80
+        $this->setRelativeScopeLevels($scope, $scope[ $start ][ 'level' ]);
81 81
 
82 82
         foreach ($scope as $i => $token) {
83
-            $this->maxIndentFound = max($this->maxIndentFound, $token['level'] - $this->relativeScopeLevels[$i]);
83
+            $this->maxIndentFound = max($this->maxIndentFound, $token[ 'level' ] - $this->relativeScopeLevels[ $i ]);
84 84
         }
85 85
     }
86 86
 
@@ -95,16 +95,16 @@  discard block
 block discarded – undo
95 95
     {
96 96
         // first set the base level for all tokens
97 97
         foreach (array_keys($scope) as $i) {
98
-            $this->relativeScopeLevels[$i] = $level;
98
+            $this->relativeScopeLevels[ $i ] = $level;
99 99
         }
100 100
 
101 101
         // then increase the base level by one for all the tokens in a try-catch block
102 102
         foreach (array_keys($this->findNestedTokens($scope, 'T_TRY')) as $i) {
103
-            $this->relativeScopeLevels[$i] += 1;
103
+            $this->relativeScopeLevels[ $i ] += 1;
104 104
         }
105 105
 
106 106
         foreach (array_keys($this->findNestedTokens($scope, 'T_CATCH')) as $i) {
107
-            $this->relativeScopeLevels[$i] += 1;
107
+            $this->relativeScopeLevels[ $i ] += 1;
108 108
         }
109 109
     }
110 110
 
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
      */
128 128
     protected function findNestedTokens(array $scope, string $type): array
129 129
     {
130
-        $typeTokens = array_filter($scope, function ($token) use ($type) {
131
-            return $token['type'] == $type;
130
+        $typeTokens = array_filter($scope, function($token) use ($type) {
131
+            return $token[ 'type' ] == $type;
132 132
         });
133 133
 
134
-        $nestedTokens = [];
134
+        $nestedTokens = [ ];
135 135
         foreach ($typeTokens as $token) {
136
-            $range = array_flip(range($token['scope_opener'], $token['scope_closer']));
136
+            $range = array_flip(range($token[ 'scope_opener' ], $token[ 'scope_closer' ]));
137 137
             $nestedTokens += array_intersect_key($scope, $range);
138 138
         }
139 139
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         // indentation limit.
152 152
         $indentationFound = $this->maxIndentFound - 1;
153 153
         $indentationLimit = $this->indentationLimit - 1;
154
-        return "{$indentationFound} indentation levels found. " .
154
+        return "{$indentationFound} indentation levels found. ".
155 155
         "Maximum of {$indentationLimit} indentation levels allowed.";
156 156
     }
157 157
 }
Please login to merge, or discard this patch.
src/Codor/Sniffs/Files/FunctionParameterSniff.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -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,13 +34,13 @@  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
-        $openParenIndex   = $token['parenthesis_opener'];
39
-        $closedParenIndex = $token['parenthesis_closer'];
37
+        $token            = $tokens[ $stackPtr ];
38
+        $openParenIndex   = $token[ 'parenthesis_opener' ];
39
+        $closedParenIndex = $token[ 'parenthesis_closer' ];
40 40
 
41 41
         $numberOfParameters = 0;
42
-        for ($index=$openParenIndex+1; $index <= $closedParenIndex; $index++) {
43
-            $tokens[$index]['type'] == 'T_VARIABLE' ? $numberOfParameters++ : null;
42
+        for ($index = $openParenIndex + 1; $index <= $closedParenIndex; $index++) {
43
+            $tokens[ $index ][ 'type' ] == 'T_VARIABLE' ? $numberOfParameters++ : null;
44 44
         }
45 45
 
46 46
         if ($numberOfParameters > $this->maxParameters) {
Please login to merge, or discard this patch.
src/Codor/Sniffs/Files/MethodFlagParameterSniff.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * The two token types we're looking for.
13 13
      * @var array
14 14
      */
15
-    protected $booleans = ['T_FALSE', 'T_TRUE'];
15
+    protected $booleans = [ 'T_FALSE', 'T_TRUE' ];
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
     /**
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
     {
36 36
         $tokens           = $phpcsFile->getTokens();
37 37
 
38
-        $token            = $tokens[$stackPtr];
39
-        $openParenIndex   = $token['parenthesis_opener'];
40
-        $closedParenIndex = $token['parenthesis_closer'];
38
+        $token            = $tokens[ $stackPtr ];
39
+        $openParenIndex   = $token[ 'parenthesis_opener' ];
40
+        $closedParenIndex = $token[ 'parenthesis_closer' ];
41 41
 
42
-        for ($index=$openParenIndex+1; $index <= $closedParenIndex; $index++) {
43
-            if (in_array($tokens[$index]['type'], $this->booleans)) {
42
+        for ($index = $openParenIndex + 1; $index <= $closedParenIndex; $index++) {
43
+            if (in_array($tokens[ $index ][ 'type' ], $this->booleans)) {
44 44
                 $phpcsFile->addError("Function/method contains a flag parameter.", $stackPtr);
45 45
                 continue;
46 46
             }
Please login to merge, or discard this patch.
src/Codor/Sniffs/Files/FunctionNameContainsAndOrSniff.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
      * The forbidden strings this sniff looks for.
13 13
      * @var array
14 14
      */
15
-    protected $keywords = ['And', '_and', 'Or', '_or'];
15
+    protected $keywords = [ 'And', '_and', 'Or', '_or' ];
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,14 +34,14 @@  discard block
 block discarded – undo
34 34
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
35 35
     {
36 36
         $tokens = $phpcsFile->getTokens();
37
-        $functionNameToken = $tokens[$stackPtr + 2];
38
-        $functionName = $functionNameToken['content'];
37
+        $functionNameToken = $tokens[ $stackPtr + 2 ];
38
+        $functionName = $functionNameToken[ 'content' ];
39 39
 
40
-        if (! $this->containsKeywords($functionName)) {
40
+        if (!$this->containsKeywords($functionName)) {
41 41
             return;
42 42
         }
43 43
 
44
-        if (! $this->ensuingDelimiter($functionName)) {
44
+        if (!$this->ensuingDelimiter($functionName)) {
45 45
             return;
46 46
         }
47 47
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     protected function ensuingDelimiter(string $string): bool
74 74
     {
75 75
         foreach ($this->keywords as $keyword) {
76
-            if (! $this->contains($keyword, $string)) {
76
+            if (!$this->contains($keyword, $string)) {
77 77
                 continue;
78 78
             }
79 79
 
Please login to merge, or discard this patch.
src/Codor/Sniffs/Classes/ClassLengthSniff.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
      */
22 22
     public function register(): array
23 23
     {
24
-        return [T_CLASS];
24
+        return [ T_CLASS ];
25 25
     }
26 26
 
27 27
     /**
@@ -35,12 +35,12 @@  discard block
 block discarded – undo
35 35
     public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
36 36
     {
37 37
         $tokens = $phpcsFile->getTokens();
38
-        $token = $tokens[$stackPtr];
38
+        $token = $tokens[ $stackPtr ];
39 39
         
40
-        $openParenthesis = $tokens[$token['scope_opener']];
41
-        $closedParenthesis = $tokens[$token['scope_closer']];
40
+        $openParenthesis = $tokens[ $token[ 'scope_opener' ] ];
41
+        $closedParenthesis = $tokens[ $token[ 'scope_closer' ] ];
42 42
 
43
-        $length = $closedParenthesis['line'] - $openParenthesis['line'];
43
+        $length = $closedParenthesis[ 'line' ] - $openParenthesis[ 'line' ];
44 44
 
45 45
         if ($length > $this->maxLength) {
46 46
             $phpcsFile->addError("Class is {$length} lines. Must be {$this->maxLength} lines or fewer.", $stackPtr);
Please login to merge, or discard this patch.