Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
Sniffs/ControlStructures/DiscouragedSwitchContinueSniff.php 4 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -29,195 +29,195 @@
 block discarded – undo
29 29
 class DiscouragedSwitchContinueSniff extends Sniff
30 30
 {
31 31
 
32
-    /**
33
-     * Token codes of control structures which can be targeted using continue.
34
-     *
35
-     * @var array
36
-     */
37
-    protected $loopStructures = array(
38
-        \T_FOR     => \T_FOR,
39
-        \T_FOREACH => \T_FOREACH,
40
-        \T_WHILE   => \T_WHILE,
41
-        \T_DO      => \T_DO,
42
-        \T_SWITCH  => \T_SWITCH,
43
-    );
44
-
45
-    /**
46
-     * Tokens which start a new case within a switch.
47
-     *
48
-     * @var array
49
-     */
50
-    protected $caseTokens = array(
51
-        \T_CASE    => \T_CASE,
52
-        \T_DEFAULT => \T_DEFAULT,
53
-    );
54
-
55
-    /**
56
-     * Token codes which are accepted to determine the level for the continue.
57
-     *
58
-     * This array is enriched with the arithmetic operators in the register() method.
59
-     *
60
-     * @var array
61
-     */
62
-    protected $acceptedLevelTokens = array(
63
-        \T_LNUMBER           => \T_LNUMBER,
64
-        \T_OPEN_PARENTHESIS  => \T_OPEN_PARENTHESIS,
65
-        \T_CLOSE_PARENTHESIS => \T_CLOSE_PARENTHESIS,
66
-    );
67
-
68
-
69
-    /**
70
-     * Returns an array of tokens this test wants to listen for.
71
-     *
72
-     * @return array
73
-     */
74
-    public function register()
75
-    {
76
-        $this->acceptedLevelTokens += Tokens::$arithmeticTokens;
77
-        $this->acceptedLevelTokens += Tokens::$emptyTokens;
78
-
79
-        return array(\T_SWITCH);
80
-    }
81
-
82
-    /**
83
-     * Processes this test, when one of its tokens is encountered.
84
-     *
85
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
86
-     * @param int                   $stackPtr  The position of the current token in the
87
-     *                                         stack passed in $tokens.
88
-     *
89
-     * @return void
90
-     */
91
-    public function process(File $phpcsFile, $stackPtr)
92
-    {
93
-        if ($this->supportsAbove('7.3') === false) {
94
-            return;
95
-        }
96
-
97
-        $tokens = $phpcsFile->getTokens();
98
-
99
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
100
-            return;
101
-        }
102
-
103
-        $switchOpener = $tokens[$stackPtr]['scope_opener'];
104
-        $switchCloser = $tokens[$stackPtr]['scope_closer'];
105
-
106
-        // Quick check whether we need to bother with the more complex logic.
107
-        $hasContinue = $phpcsFile->findNext(\T_CONTINUE, ($switchOpener + 1), $switchCloser);
108
-        if ($hasContinue === false) {
109
-            return;
110
-        }
111
-
112
-        $caseDefault = $switchOpener;
113
-
114
-        do {
115
-            $caseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
116
-            if ($caseDefault === false) {
117
-                break;
118
-            }
119
-
120
-            if (isset($tokens[$caseDefault]['scope_opener']) === false) {
121
-                // Unknown start of the case, skip.
122
-                continue;
123
-            }
124
-
125
-            $caseOpener      = $tokens[$caseDefault]['scope_opener'];
126
-            $nextCaseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
127
-            if ($nextCaseDefault === false) {
128
-                $caseCloser = $switchCloser;
129
-            } else {
130
-                $caseCloser = $nextCaseDefault;
131
-            }
132
-
133
-            // Check for unscoped control structures within the case.
134
-            $controlStructure = $caseOpener;
135
-            $doCount          = 0;
136
-            while (($controlStructure = $phpcsFile->findNext($this->loopStructures, ($controlStructure + 1), $caseCloser)) !== false) {
137
-                if ($tokens[$controlStructure]['code'] === \T_DO) {
138
-                    $doCount++;
139
-                }
140
-
141
-                if (isset($tokens[$controlStructure]['scope_opener'], $tokens[$controlStructure]['scope_closer']) === false) {
142
-                    if ($tokens[$controlStructure]['code'] === \T_WHILE && $doCount > 0) {
143
-                        // While in a do-while construct.
144
-                        $doCount--;
145
-                        continue;
146
-                    }
147
-
148
-                    // Control structure without braces found within the case, ignore this case.
149
-                    continue 2;
150
-                }
151
-            }
152
-
153
-            // Examine the contents of the case.
154
-            $continue = $caseOpener;
155
-
156
-            do {
157
-                $continue = $phpcsFile->findNext(\T_CONTINUE, ($continue + 1), $caseCloser);
158
-                if ($continue === false) {
159
-                    break;
160
-                }
161
-
162
-                $nextSemicolon = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($continue + 1), $caseCloser);
163
-                $codeString    = '';
164
-                for ($i = ($continue + 1); $i < $nextSemicolon; $i++) {
165
-                    if (isset($this->acceptedLevelTokens[$tokens[$i]['code']]) === false) {
166
-                        // Function call/variable or other token which make numeric level impossible to determine.
167
-                        continue 2;
168
-                    }
169
-
170
-                    if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
171
-                        continue;
172
-                    }
173
-
174
-                    $codeString .= $tokens[$i]['content'];
175
-                }
176
-
177
-                $level = null;
178
-                if ($codeString !== '') {
179
-                    if (is_numeric($codeString)) {
180
-                        $level = (int) $codeString;
181
-                    } else {
182
-                        // With the above logic, the string can only contain digits and operators, eval!
183
-                        $level = eval("return ( $codeString );");
184
-                    }
185
-                }
186
-
187
-                if (isset($level) === false || $level === 0) {
188
-                    $level = 1;
189
-                }
190
-
191
-                // Examine which control structure is being targeted by the continue statement.
192
-                if (isset($tokens[$continue]['conditions']) === false) {
193
-                    continue;
194
-                }
195
-
196
-                $conditions = array_reverse($tokens[$continue]['conditions'], true);
197
-                // PHPCS adds more structures to the conditions array than we want to take into
198
-                // consideration, so clean up the array.
199
-                foreach ($conditions as $tokenPtr => $tokenCode) {
200
-                    if (isset($this->loopStructures[$tokenCode]) === false) {
201
-                        unset($conditions[$tokenPtr]);
202
-                    }
203
-                }
204
-
205
-                $targetCondition = \array_slice($conditions, ($level - 1), 1, true);
206
-                if (empty($targetCondition)) {
207
-                    continue;
208
-                }
209
-
210
-                $conditionToken = key($targetCondition);
211
-                if ($conditionToken === $stackPtr) {
212
-                    $phpcsFile->addWarning(
213
-                        "Targeting a 'switch' control structure with a 'continue' statement is strongly discouraged and will throw a warning as of PHP 7.3.",
214
-                        $continue,
215
-                        'Found'
216
-                    );
217
-                }
218
-
219
-            } while ($continue < $caseCloser);
220
-
221
-        } while ($caseDefault < $switchCloser);
222
-    }
32
+	/**
33
+	 * Token codes of control structures which can be targeted using continue.
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $loopStructures = array(
38
+		\T_FOR     => \T_FOR,
39
+		\T_FOREACH => \T_FOREACH,
40
+		\T_WHILE   => \T_WHILE,
41
+		\T_DO      => \T_DO,
42
+		\T_SWITCH  => \T_SWITCH,
43
+	);
44
+
45
+	/**
46
+	 * Tokens which start a new case within a switch.
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $caseTokens = array(
51
+		\T_CASE    => \T_CASE,
52
+		\T_DEFAULT => \T_DEFAULT,
53
+	);
54
+
55
+	/**
56
+	 * Token codes which are accepted to determine the level for the continue.
57
+	 *
58
+	 * This array is enriched with the arithmetic operators in the register() method.
59
+	 *
60
+	 * @var array
61
+	 */
62
+	protected $acceptedLevelTokens = array(
63
+		\T_LNUMBER           => \T_LNUMBER,
64
+		\T_OPEN_PARENTHESIS  => \T_OPEN_PARENTHESIS,
65
+		\T_CLOSE_PARENTHESIS => \T_CLOSE_PARENTHESIS,
66
+	);
67
+
68
+
69
+	/**
70
+	 * Returns an array of tokens this test wants to listen for.
71
+	 *
72
+	 * @return array
73
+	 */
74
+	public function register()
75
+	{
76
+		$this->acceptedLevelTokens += Tokens::$arithmeticTokens;
77
+		$this->acceptedLevelTokens += Tokens::$emptyTokens;
78
+
79
+		return array(\T_SWITCH);
80
+	}
81
+
82
+	/**
83
+	 * Processes this test, when one of its tokens is encountered.
84
+	 *
85
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
86
+	 * @param int                   $stackPtr  The position of the current token in the
87
+	 *                                         stack passed in $tokens.
88
+	 *
89
+	 * @return void
90
+	 */
91
+	public function process(File $phpcsFile, $stackPtr)
92
+	{
93
+		if ($this->supportsAbove('7.3') === false) {
94
+			return;
95
+		}
96
+
97
+		$tokens = $phpcsFile->getTokens();
98
+
99
+		if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
100
+			return;
101
+		}
102
+
103
+		$switchOpener = $tokens[$stackPtr]['scope_opener'];
104
+		$switchCloser = $tokens[$stackPtr]['scope_closer'];
105
+
106
+		// Quick check whether we need to bother with the more complex logic.
107
+		$hasContinue = $phpcsFile->findNext(\T_CONTINUE, ($switchOpener + 1), $switchCloser);
108
+		if ($hasContinue === false) {
109
+			return;
110
+		}
111
+
112
+		$caseDefault = $switchOpener;
113
+
114
+		do {
115
+			$caseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
116
+			if ($caseDefault === false) {
117
+				break;
118
+			}
119
+
120
+			if (isset($tokens[$caseDefault]['scope_opener']) === false) {
121
+				// Unknown start of the case, skip.
122
+				continue;
123
+			}
124
+
125
+			$caseOpener      = $tokens[$caseDefault]['scope_opener'];
126
+			$nextCaseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
127
+			if ($nextCaseDefault === false) {
128
+				$caseCloser = $switchCloser;
129
+			} else {
130
+				$caseCloser = $nextCaseDefault;
131
+			}
132
+
133
+			// Check for unscoped control structures within the case.
134
+			$controlStructure = $caseOpener;
135
+			$doCount          = 0;
136
+			while (($controlStructure = $phpcsFile->findNext($this->loopStructures, ($controlStructure + 1), $caseCloser)) !== false) {
137
+				if ($tokens[$controlStructure]['code'] === \T_DO) {
138
+					$doCount++;
139
+				}
140
+
141
+				if (isset($tokens[$controlStructure]['scope_opener'], $tokens[$controlStructure]['scope_closer']) === false) {
142
+					if ($tokens[$controlStructure]['code'] === \T_WHILE && $doCount > 0) {
143
+						// While in a do-while construct.
144
+						$doCount--;
145
+						continue;
146
+					}
147
+
148
+					// Control structure without braces found within the case, ignore this case.
149
+					continue 2;
150
+				}
151
+			}
152
+
153
+			// Examine the contents of the case.
154
+			$continue = $caseOpener;
155
+
156
+			do {
157
+				$continue = $phpcsFile->findNext(\T_CONTINUE, ($continue + 1), $caseCloser);
158
+				if ($continue === false) {
159
+					break;
160
+				}
161
+
162
+				$nextSemicolon = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($continue + 1), $caseCloser);
163
+				$codeString    = '';
164
+				for ($i = ($continue + 1); $i < $nextSemicolon; $i++) {
165
+					if (isset($this->acceptedLevelTokens[$tokens[$i]['code']]) === false) {
166
+						// Function call/variable or other token which make numeric level impossible to determine.
167
+						continue 2;
168
+					}
169
+
170
+					if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
171
+						continue;
172
+					}
173
+
174
+					$codeString .= $tokens[$i]['content'];
175
+				}
176
+
177
+				$level = null;
178
+				if ($codeString !== '') {
179
+					if (is_numeric($codeString)) {
180
+						$level = (int) $codeString;
181
+					} else {
182
+						// With the above logic, the string can only contain digits and operators, eval!
183
+						$level = eval("return ( $codeString );");
184
+					}
185
+				}
186
+
187
+				if (isset($level) === false || $level === 0) {
188
+					$level = 1;
189
+				}
190
+
191
+				// Examine which control structure is being targeted by the continue statement.
192
+				if (isset($tokens[$continue]['conditions']) === false) {
193
+					continue;
194
+				}
195
+
196
+				$conditions = array_reverse($tokens[$continue]['conditions'], true);
197
+				// PHPCS adds more structures to the conditions array than we want to take into
198
+				// consideration, so clean up the array.
199
+				foreach ($conditions as $tokenPtr => $tokenCode) {
200
+					if (isset($this->loopStructures[$tokenCode]) === false) {
201
+						unset($conditions[$tokenPtr]);
202
+					}
203
+				}
204
+
205
+				$targetCondition = \array_slice($conditions, ($level - 1), 1, true);
206
+				if (empty($targetCondition)) {
207
+					continue;
208
+				}
209
+
210
+				$conditionToken = key($targetCondition);
211
+				if ($conditionToken === $stackPtr) {
212
+					$phpcsFile->addWarning(
213
+						"Targeting a 'switch' control structure with a 'continue' statement is strongly discouraged and will throw a warning as of PHP 7.3.",
214
+						$continue,
215
+						'Found'
216
+					);
217
+				}
218
+
219
+			} while ($continue < $caseCloser);
220
+
221
+		} while ($caseDefault < $switchCloser);
222
+	}
223 223
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         $this->acceptedLevelTokens += Tokens::$arithmeticTokens;
77 77
         $this->acceptedLevelTokens += Tokens::$emptyTokens;
78 78
 
79
-        return array(\T_SWITCH);
79
+        return array( \T_SWITCH );
80 80
     }
81 81
 
82 82
     /**
@@ -88,43 +88,43 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return void
90 90
      */
91
-    public function process(File $phpcsFile, $stackPtr)
91
+    public function process( File $phpcsFile, $stackPtr )
92 92
     {
93
-        if ($this->supportsAbove('7.3') === false) {
93
+        if ( $this->supportsAbove( '7.3' ) === false ) {
94 94
             return;
95 95
         }
96 96
 
97 97
         $tokens = $phpcsFile->getTokens();
98 98
 
99
-        if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) {
99
+        if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ], $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
100 100
             return;
101 101
         }
102 102
 
103
-        $switchOpener = $tokens[$stackPtr]['scope_opener'];
104
-        $switchCloser = $tokens[$stackPtr]['scope_closer'];
103
+        $switchOpener = $tokens[ $stackPtr ][ 'scope_opener' ];
104
+        $switchCloser = $tokens[ $stackPtr ][ 'scope_closer' ];
105 105
 
106 106
         // Quick check whether we need to bother with the more complex logic.
107
-        $hasContinue = $phpcsFile->findNext(\T_CONTINUE, ($switchOpener + 1), $switchCloser);
108
-        if ($hasContinue === false) {
107
+        $hasContinue = $phpcsFile->findNext( \T_CONTINUE, ( $switchOpener + 1 ), $switchCloser );
108
+        if ( $hasContinue === false ) {
109 109
             return;
110 110
         }
111 111
 
112 112
         $caseDefault = $switchOpener;
113 113
 
114 114
         do {
115
-            $caseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
116
-            if ($caseDefault === false) {
115
+            $caseDefault = $phpcsFile->findNext( $this->caseTokens, ( $caseDefault + 1 ), $switchCloser );
116
+            if ( $caseDefault === false ) {
117 117
                 break;
118 118
             }
119 119
 
120
-            if (isset($tokens[$caseDefault]['scope_opener']) === false) {
120
+            if ( isset( $tokens[ $caseDefault ][ 'scope_opener' ] ) === false ) {
121 121
                 // Unknown start of the case, skip.
122 122
                 continue;
123 123
             }
124 124
 
125
-            $caseOpener      = $tokens[$caseDefault]['scope_opener'];
126
-            $nextCaseDefault = $phpcsFile->findNext($this->caseTokens, ($caseDefault + 1), $switchCloser);
127
-            if ($nextCaseDefault === false) {
125
+            $caseOpener      = $tokens[ $caseDefault ][ 'scope_opener' ];
126
+            $nextCaseDefault = $phpcsFile->findNext( $this->caseTokens, ( $caseDefault + 1 ), $switchCloser );
127
+            if ( $nextCaseDefault === false ) {
128 128
                 $caseCloser = $switchCloser;
129 129
             } else {
130 130
                 $caseCloser = $nextCaseDefault;
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
             // Check for unscoped control structures within the case.
134 134
             $controlStructure = $caseOpener;
135 135
             $doCount          = 0;
136
-            while (($controlStructure = $phpcsFile->findNext($this->loopStructures, ($controlStructure + 1), $caseCloser)) !== false) {
137
-                if ($tokens[$controlStructure]['code'] === \T_DO) {
136
+            while ( ( $controlStructure = $phpcsFile->findNext( $this->loopStructures, ( $controlStructure + 1 ), $caseCloser ) ) !== false ) {
137
+                if ( $tokens[ $controlStructure ][ 'code' ] === \T_DO ) {
138 138
                     $doCount++;
139 139
                 }
140 140
 
141
-                if (isset($tokens[$controlStructure]['scope_opener'], $tokens[$controlStructure]['scope_closer']) === false) {
142
-                    if ($tokens[$controlStructure]['code'] === \T_WHILE && $doCount > 0) {
141
+                if ( isset( $tokens[ $controlStructure ][ 'scope_opener' ], $tokens[ $controlStructure ][ 'scope_closer' ] ) === false ) {
142
+                    if ( $tokens[ $controlStructure ][ 'code' ] === \T_WHILE && $doCount > 0 ) {
143 143
                         // While in a do-while construct.
144 144
                         $doCount--;
145 145
                         continue;
@@ -154,61 +154,61 @@  discard block
 block discarded – undo
154 154
             $continue = $caseOpener;
155 155
 
156 156
             do {
157
-                $continue = $phpcsFile->findNext(\T_CONTINUE, ($continue + 1), $caseCloser);
158
-                if ($continue === false) {
157
+                $continue = $phpcsFile->findNext( \T_CONTINUE, ( $continue + 1 ), $caseCloser );
158
+                if ( $continue === false ) {
159 159
                     break;
160 160
                 }
161 161
 
162
-                $nextSemicolon = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($continue + 1), $caseCloser);
162
+                $nextSemicolon = $phpcsFile->findNext( array( \T_SEMICOLON, \T_CLOSE_TAG ), ( $continue + 1 ), $caseCloser );
163 163
                 $codeString    = '';
164
-                for ($i = ($continue + 1); $i < $nextSemicolon; $i++) {
165
-                    if (isset($this->acceptedLevelTokens[$tokens[$i]['code']]) === false) {
164
+                for ( $i = ( $continue + 1 ); $i < $nextSemicolon; $i++ ) {
165
+                    if ( isset( $this->acceptedLevelTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) {
166 166
                         // Function call/variable or other token which make numeric level impossible to determine.
167 167
                         continue 2;
168 168
                     }
169 169
 
170
-                    if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
170
+                    if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) {
171 171
                         continue;
172 172
                     }
173 173
 
174
-                    $codeString .= $tokens[$i]['content'];
174
+                    $codeString .= $tokens[ $i ][ 'content' ];
175 175
                 }
176 176
 
177 177
                 $level = null;
178
-                if ($codeString !== '') {
179
-                    if (is_numeric($codeString)) {
180
-                        $level = (int) $codeString;
178
+                if ( $codeString !== '' ) {
179
+                    if ( is_numeric( $codeString ) ) {
180
+                        $level = (int)$codeString;
181 181
                     } else {
182 182
                         // With the above logic, the string can only contain digits and operators, eval!
183
-                        $level = eval("return ( $codeString );");
183
+                        $level = eval( "return ( $codeString );" );
184 184
                     }
185 185
                 }
186 186
 
187
-                if (isset($level) === false || $level === 0) {
187
+                if ( isset( $level ) === false || $level === 0 ) {
188 188
                     $level = 1;
189 189
                 }
190 190
 
191 191
                 // Examine which control structure is being targeted by the continue statement.
192
-                if (isset($tokens[$continue]['conditions']) === false) {
192
+                if ( isset( $tokens[ $continue ][ 'conditions' ] ) === false ) {
193 193
                     continue;
194 194
                 }
195 195
 
196
-                $conditions = array_reverse($tokens[$continue]['conditions'], true);
196
+                $conditions = array_reverse( $tokens[ $continue ][ 'conditions' ], true );
197 197
                 // PHPCS adds more structures to the conditions array than we want to take into
198 198
                 // consideration, so clean up the array.
199
-                foreach ($conditions as $tokenPtr => $tokenCode) {
200
-                    if (isset($this->loopStructures[$tokenCode]) === false) {
201
-                        unset($conditions[$tokenPtr]);
199
+                foreach ( $conditions as $tokenPtr => $tokenCode ) {
200
+                    if ( isset( $this->loopStructures[ $tokenCode ] ) === false ) {
201
+                        unset( $conditions[ $tokenPtr ] );
202 202
                     }
203 203
                 }
204 204
 
205
-                $targetCondition = \array_slice($conditions, ($level - 1), 1, true);
206
-                if (empty($targetCondition)) {
205
+                $targetCondition = \array_slice( $conditions, ( $level - 1 ), 1, true );
206
+                if ( empty( $targetCondition ) ) {
207 207
                     continue;
208 208
                 }
209 209
 
210
-                $conditionToken = key($targetCondition);
211
-                if ($conditionToken === $stackPtr) {
210
+                $conditionToken = key( $targetCondition );
211
+                if ( $conditionToken === $stackPtr ) {
212 212
                     $phpcsFile->addWarning(
213 213
                         "Targeting a 'switch' control structure with a 'continue' statement is strongly discouraged and will throw a warning as of PHP 7.3.",
214 214
                         $continue,
@@ -216,8 +216,8 @@  discard block
 block discarded – undo
216 216
                     );
217 217
                 }
218 218
 
219
-            } while ($continue < $caseCloser);
219
+            } while ( $continue < $caseCloser );
220 220
 
221
-        } while ($caseDefault < $switchCloser);
221
+        } while ( $caseDefault < $switchCloser );
222 222
     }
223 223
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
  * @package  PHPCompatibility
27 27
  * @author   Juliette Reinders Folmer <[email protected]>
28 28
  */
29
-class DiscouragedSwitchContinueSniff extends Sniff
30
-{
29
+class DiscouragedSwitchContinueSniff extends Sniff {
31 30
 
32 31
     /**
33 32
      * Token codes of control structures which can be targeted using continue.
@@ -71,8 +70,7 @@  discard block
 block discarded – undo
71 70
      *
72 71
      * @return array
73 72
      */
74
-    public function register()
75
-    {
73
+    public function register() {
76 74
         $this->acceptedLevelTokens += Tokens::$arithmeticTokens;
77 75
         $this->acceptedLevelTokens += Tokens::$emptyTokens;
78 76
 
@@ -88,8 +86,7 @@  discard block
 block discarded – undo
88 86
      *
89 87
      * @return void
90 88
      */
91
-    public function process(File $phpcsFile, $stackPtr)
92
-    {
89
+    public function process(File $phpcsFile, $stackPtr) {
93 90
         if ($this->supportsAbove('7.3') === false) {
94 91
             return;
95 92
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
Sniffs/ControlStructures/ForbiddenBreakContinueVariableArgumentsSniff.php 4 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -30,72 +30,72 @@
 block discarded – undo
30 30
  */
31 31
 class ForbiddenBreakContinueVariableArgumentsSniff extends Sniff
32 32
 {
33
-    /**
34
-     * Error types this sniff handles for forbidden break/continue arguments.
35
-     *
36
-     * Array key is the error code. Array value will be used as part of the error message.
37
-     *
38
-     * @var array
39
-     */
40
-    private $errorTypes = array(
41
-        'variableArgument' => 'a variable argument',
42
-        'zeroArgument'     => '0 as an argument',
43
-    );
33
+	/**
34
+	 * Error types this sniff handles for forbidden break/continue arguments.
35
+	 *
36
+	 * Array key is the error code. Array value will be used as part of the error message.
37
+	 *
38
+	 * @var array
39
+	 */
40
+	private $errorTypes = array(
41
+		'variableArgument' => 'a variable argument',
42
+		'zeroArgument'     => '0 as an argument',
43
+	);
44 44
 
45
-    /**
46
-     * Returns an array of tokens this test wants to listen for.
47
-     *
48
-     * @return array
49
-     */
50
-    public function register()
51
-    {
52
-        return array(\T_BREAK, \T_CONTINUE);
53
-    }
45
+	/**
46
+	 * Returns an array of tokens this test wants to listen for.
47
+	 *
48
+	 * @return array
49
+	 */
50
+	public function register()
51
+	{
52
+		return array(\T_BREAK, \T_CONTINUE);
53
+	}
54 54
 
55
-    /**
56
-     * Processes this test, when one of its tokens is encountered.
57
-     *
58
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
-     * @param int                   $stackPtr  The position of the current token in the
60
-     *                                         stack passed in $tokens.
61
-     *
62
-     * @return void
63
-     */
64
-    public function process(File $phpcsFile, $stackPtr)
65
-    {
66
-        if ($this->supportsAbove('5.4') === false) {
67
-            return;
68
-        }
55
+	/**
56
+	 * Processes this test, when one of its tokens is encountered.
57
+	 *
58
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
59
+	 * @param int                   $stackPtr  The position of the current token in the
60
+	 *                                         stack passed in $tokens.
61
+	 *
62
+	 * @return void
63
+	 */
64
+	public function process(File $phpcsFile, $stackPtr)
65
+	{
66
+		if ($this->supportsAbove('5.4') === false) {
67
+			return;
68
+		}
69 69
 
70
-        $tokens             = $phpcsFile->getTokens();
71
-        $nextSemicolonToken = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr), null, false);
72
-        $errorType          = '';
73
-        for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
74
-            if ($tokens[$curToken]['type'] === 'T_STRING') {
75
-                // If the next non-whitespace token after the string
76
-                // is an opening parenthesis then it's a function call.
77
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $curToken + 1, null, true);
78
-                if ($tokens[$openBracket]['code'] === \T_OPEN_PARENTHESIS) {
79
-                    $errorType = 'variableArgument';
80
-                    break;
81
-                }
70
+		$tokens             = $phpcsFile->getTokens();
71
+		$nextSemicolonToken = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr), null, false);
72
+		$errorType          = '';
73
+		for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
74
+			if ($tokens[$curToken]['type'] === 'T_STRING') {
75
+				// If the next non-whitespace token after the string
76
+				// is an opening parenthesis then it's a function call.
77
+				$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $curToken + 1, null, true);
78
+				if ($tokens[$openBracket]['code'] === \T_OPEN_PARENTHESIS) {
79
+					$errorType = 'variableArgument';
80
+					break;
81
+				}
82 82
 
83
-            } elseif (\in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) {
84
-                $errorType = 'variableArgument';
85
-                break;
83
+			} elseif (\in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) {
84
+				$errorType = 'variableArgument';
85
+				break;
86 86
 
87
-            } elseif ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') {
88
-                $errorType = 'zeroArgument';
89
-                break;
90
-            }
91
-        }
87
+			} elseif ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') {
88
+				$errorType = 'zeroArgument';
89
+				break;
90
+			}
91
+		}
92 92
 
93
-        if ($errorType !== '') {
94
-            $error     = 'Using %s on break or continue is forbidden since PHP 5.4';
95
-            $errorCode = $errorType . 'Found';
96
-            $data      = array($this->errorTypes[$errorType]);
93
+		if ($errorType !== '') {
94
+			$error     = 'Using %s on break or continue is forbidden since PHP 5.4';
95
+			$errorCode = $errorType . 'Found';
96
+			$data      = array($this->errorTypes[$errorType]);
97 97
 
98
-            $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
99
-        }
100
-    }
98
+			$phpcsFile->addError($error, $stackPtr, $errorCode, $data);
99
+		}
100
+	}
101 101
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
      */
50 50
     public function register()
51 51
     {
52
-        return array(\T_BREAK, \T_CONTINUE);
52
+        return array( \T_BREAK, \T_CONTINUE );
53 53
     }
54 54
 
55 55
     /**
@@ -61,41 +61,41 @@  discard block
 block discarded – undo
61 61
      *
62 62
      * @return void
63 63
      */
64
-    public function process(File $phpcsFile, $stackPtr)
64
+    public function process( File $phpcsFile, $stackPtr )
65 65
     {
66
-        if ($this->supportsAbove('5.4') === false) {
66
+        if ( $this->supportsAbove( '5.4' ) === false ) {
67 67
             return;
68 68
         }
69 69
 
70 70
         $tokens             = $phpcsFile->getTokens();
71
-        $nextSemicolonToken = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr), null, false);
71
+        $nextSemicolonToken = $phpcsFile->findNext( array( \T_SEMICOLON, \T_CLOSE_TAG ), ( $stackPtr ), null, false );
72 72
         $errorType          = '';
73
-        for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
74
-            if ($tokens[$curToken]['type'] === 'T_STRING') {
73
+        for ( $curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++ ) {
74
+            if ( $tokens[ $curToken ][ 'type' ] === 'T_STRING' ) {
75 75
                 // If the next non-whitespace token after the string
76 76
                 // is an opening parenthesis then it's a function call.
77
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, $curToken + 1, null, true);
78
-                if ($tokens[$openBracket]['code'] === \T_OPEN_PARENTHESIS) {
77
+                $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, $curToken + 1, null, true );
78
+                if ( $tokens[ $openBracket ][ 'code' ] === \T_OPEN_PARENTHESIS ) {
79 79
                     $errorType = 'variableArgument';
80 80
                     break;
81 81
                 }
82 82
 
83
-            } elseif (\in_array($tokens[$curToken]['type'], array('T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE'), true)) {
83
+            } elseif ( \in_array( $tokens[ $curToken ][ 'type' ], array( 'T_VARIABLE', 'T_FUNCTION', 'T_CLOSURE' ), true ) ) {
84 84
                 $errorType = 'variableArgument';
85 85
                 break;
86 86
 
87
-            } elseif ($tokens[$curToken]['type'] === 'T_LNUMBER' && $tokens[$curToken]['content'] === '0') {
87
+            } elseif ( $tokens[ $curToken ][ 'type' ] === 'T_LNUMBER' && $tokens[ $curToken ][ 'content' ] === '0' ) {
88 88
                 $errorType = 'zeroArgument';
89 89
                 break;
90 90
             }
91 91
         }
92 92
 
93
-        if ($errorType !== '') {
93
+        if ( $errorType !== '' ) {
94 94
             $error     = 'Using %s on break or continue is forbidden since PHP 5.4';
95 95
             $errorCode = $errorType . 'Found';
96
-            $data      = array($this->errorTypes[$errorType]);
96
+            $data      = array( $this->errorTypes[ $errorType ] );
97 97
 
98
-            $phpcsFile->addError($error, $stackPtr, $errorCode, $data);
98
+            $phpcsFile->addError( $error, $stackPtr, $errorCode, $data );
99 99
         }
100 100
     }
101 101
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@  discard block
 block discarded – undo
28 28
  * @author    Wim Godden <[email protected]>
29 29
  * @copyright 2012 Cu.be Solutions bvba
30 30
  */
31
-class ForbiddenBreakContinueVariableArgumentsSniff extends Sniff
32
-{
31
+class ForbiddenBreakContinueVariableArgumentsSniff extends Sniff {
33 32
     /**
34 33
      * Error types this sniff handles for forbidden break/continue arguments.
35 34
      *
@@ -47,8 +46,7 @@  discard block
 block discarded – undo
47 46
      *
48 47
      * @return array
49 48
      */
50
-    public function register()
51
-    {
49
+    public function register() {
52 50
         return array(\T_BREAK, \T_CONTINUE);
53 51
     }
54 52
 
@@ -61,8 +59,7 @@  discard block
 block discarded – undo
61 59
      *
62 60
      * @return void
63 61
      */
64
-    public function process(File $phpcsFile, $stackPtr)
65
-    {
62
+    public function process(File $phpcsFile, $stackPtr) {
66 63
         if ($this->supportsAbove('5.4') === false) {
67 64
             return;
68 65
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
Sniffs/ControlStructures/ForbiddenSwitchWithMultipleDefaultBlocksSniff.php 4 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -28,52 +28,52 @@
 block discarded – undo
28 28
 class ForbiddenSwitchWithMultipleDefaultBlocksSniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * Returns an array of tokens this test wants to listen for.
33
-     *
34
-     * @return array
35
-     */
36
-    public function register()
37
-    {
38
-        return array(\T_SWITCH);
39
-    }
31
+	/**
32
+	 * Returns an array of tokens this test wants to listen for.
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function register()
37
+	{
38
+		return array(\T_SWITCH);
39
+	}
40 40
 
41
-    /**
42
-     * Processes this test, when one of its tokens is encountered.
43
-     *
44
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
-     * @param int                   $stackPtr  The position of the current token
46
-     *                                         in the stack passed in $tokens.
47
-     *
48
-     * @return void
49
-     */
50
-    public function process(File $phpcsFile, $stackPtr)
51
-    {
52
-        if ($this->supportsAbove('7.0') === false) {
53
-            return;
54
-        }
41
+	/**
42
+	 * Processes this test, when one of its tokens is encountered.
43
+	 *
44
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
45
+	 * @param int                   $stackPtr  The position of the current token
46
+	 *                                         in the stack passed in $tokens.
47
+	 *
48
+	 * @return void
49
+	 */
50
+	public function process(File $phpcsFile, $stackPtr)
51
+	{
52
+		if ($this->supportsAbove('7.0') === false) {
53
+			return;
54
+		}
55 55
 
56
-        $tokens = $phpcsFile->getTokens();
57
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
58
-            return;
59
-        }
56
+		$tokens = $phpcsFile->getTokens();
57
+		if (isset($tokens[$stackPtr]['scope_closer']) === false) {
58
+			return;
59
+		}
60 60
 
61
-        $defaultToken = $stackPtr;
62
-        $defaultCount = 0;
63
-        $targetLevel  = $tokens[$stackPtr]['level'] + 1;
64
-        while ($defaultCount < 2 && ($defaultToken = $phpcsFile->findNext(array(\T_DEFAULT), $defaultToken + 1, $tokens[$stackPtr]['scope_closer'])) !== false) {
65
-            // Same level or one below (= two default cases after each other).
66
-            if ($tokens[$defaultToken]['level'] === $targetLevel || $tokens[$defaultToken]['level'] === ($targetLevel + 1)) {
67
-                $defaultCount++;
68
-            }
69
-        }
61
+		$defaultToken = $stackPtr;
62
+		$defaultCount = 0;
63
+		$targetLevel  = $tokens[$stackPtr]['level'] + 1;
64
+		while ($defaultCount < 2 && ($defaultToken = $phpcsFile->findNext(array(\T_DEFAULT), $defaultToken + 1, $tokens[$stackPtr]['scope_closer'])) !== false) {
65
+			// Same level or one below (= two default cases after each other).
66
+			if ($tokens[$defaultToken]['level'] === $targetLevel || $tokens[$defaultToken]['level'] === ($targetLevel + 1)) {
67
+				$defaultCount++;
68
+			}
69
+		}
70 70
 
71
-        if ($defaultCount > 1) {
72
-            $phpcsFile->addError(
73
-                'Switch statements can not have multiple default blocks since PHP 7.0',
74
-                $stackPtr,
75
-                'Found'
76
-            );
77
-        }
78
-    }
71
+		if ($defaultCount > 1) {
72
+			$phpcsFile->addError(
73
+				'Switch statements can not have multiple default blocks since PHP 7.0',
74
+				$stackPtr,
75
+				'Found'
76
+			);
77
+		}
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function register()
37 37
     {
38
-        return array(\T_SWITCH);
38
+        return array( \T_SWITCH );
39 39
     }
40 40
 
41 41
     /**
@@ -47,28 +47,28 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return void
49 49
      */
50
-    public function process(File $phpcsFile, $stackPtr)
50
+    public function process( File $phpcsFile, $stackPtr )
51 51
     {
52
-        if ($this->supportsAbove('7.0') === false) {
52
+        if ( $this->supportsAbove( '7.0' ) === false ) {
53 53
             return;
54 54
         }
55 55
 
56 56
         $tokens = $phpcsFile->getTokens();
57
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
57
+        if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
58 58
             return;
59 59
         }
60 60
 
61 61
         $defaultToken = $stackPtr;
62 62
         $defaultCount = 0;
63
-        $targetLevel  = $tokens[$stackPtr]['level'] + 1;
64
-        while ($defaultCount < 2 && ($defaultToken = $phpcsFile->findNext(array(\T_DEFAULT), $defaultToken + 1, $tokens[$stackPtr]['scope_closer'])) !== false) {
63
+        $targetLevel  = $tokens[ $stackPtr ][ 'level' ] + 1;
64
+        while ( $defaultCount < 2 && ( $defaultToken = $phpcsFile->findNext( array( \T_DEFAULT ), $defaultToken + 1, $tokens[ $stackPtr ][ 'scope_closer' ] ) ) !== false ) {
65 65
             // Same level or one below (= two default cases after each other).
66
-            if ($tokens[$defaultToken]['level'] === $targetLevel || $tokens[$defaultToken]['level'] === ($targetLevel + 1)) {
66
+            if ( $tokens[ $defaultToken ][ 'level' ] === $targetLevel || $tokens[ $defaultToken ][ 'level' ] === ( $targetLevel + 1 ) ) {
67 67
                 $defaultCount++;
68 68
             }
69 69
         }
70 70
 
71
-        if ($defaultCount > 1) {
71
+        if ( $defaultCount > 1 ) {
72 72
             $phpcsFile->addError(
73 73
                 'Switch statements can not have multiple default blocks since PHP 7.0',
74 74
                 $stackPtr,
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,16 +25,14 @@  discard block
 block discarded – undo
25 25
  * @package  PHPCompatibility
26 26
  * @author   Wim Godden <[email protected]>
27 27
  */
28
-class ForbiddenSwitchWithMultipleDefaultBlocksSniff extends Sniff
29
-{
28
+class ForbiddenSwitchWithMultipleDefaultBlocksSniff extends Sniff {
30 29
 
31 30
     /**
32 31
      * Returns an array of tokens this test wants to listen for.
33 32
      *
34 33
      * @return array
35 34
      */
36
-    public function register()
37
-    {
35
+    public function register() {
38 36
         return array(\T_SWITCH);
39 37
     }
40 38
 
@@ -47,8 +45,7 @@  discard block
 block discarded – undo
47 45
      *
48 46
      * @return void
49 47
      */
50
-    public function process(File $phpcsFile, $stackPtr)
51
-    {
48
+    public function process(File $phpcsFile, $stackPtr) {
52 49
         if ($this->supportsAbove('7.0') === false) {
53 50
             return;
54 51
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
Sniffs/ControlStructures/ForbiddenBreakContinueOutsideLoopSniff.php 4 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -28,82 +28,82 @@
 block discarded – undo
28 28
 class ForbiddenBreakContinueOutsideLoopSniff extends Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * Token codes of control structure in which usage of break/continue is valid.
33
-     *
34
-     * @var array
35
-     */
36
-    protected $validLoopStructures = array(
37
-        \T_FOR     => true,
38
-        \T_FOREACH => true,
39
-        \T_WHILE   => true,
40
-        \T_DO      => true,
41
-        \T_SWITCH  => true,
42
-    );
31
+	/**
32
+	 * Token codes of control structure in which usage of break/continue is valid.
33
+	 *
34
+	 * @var array
35
+	 */
36
+	protected $validLoopStructures = array(
37
+		\T_FOR     => true,
38
+		\T_FOREACH => true,
39
+		\T_WHILE   => true,
40
+		\T_DO      => true,
41
+		\T_SWITCH  => true,
42
+	);
43 43
 
44
-    /**
45
-     * Token codes which did not correctly get a condition assigned in older PHPCS versions.
46
-     *
47
-     * @var array
48
-     */
49
-    protected $backCompat = array(
50
-        \T_CASE    => true,
51
-        \T_DEFAULT => true,
52
-    );
44
+	/**
45
+	 * Token codes which did not correctly get a condition assigned in older PHPCS versions.
46
+	 *
47
+	 * @var array
48
+	 */
49
+	protected $backCompat = array(
50
+		\T_CASE    => true,
51
+		\T_DEFAULT => true,
52
+	);
53 53
 
54
-    /**
55
-     * Returns an array of tokens this test wants to listen for.
56
-     *
57
-     * @return array
58
-     */
59
-    public function register()
60
-    {
61
-        return array(
62
-            \T_BREAK,
63
-            \T_CONTINUE,
64
-        );
65
-    }
54
+	/**
55
+	 * Returns an array of tokens this test wants to listen for.
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function register()
60
+	{
61
+		return array(
62
+			\T_BREAK,
63
+			\T_CONTINUE,
64
+		);
65
+	}
66 66
 
67
-    /**
68
-     * Processes this test, when one of its tokens is encountered.
69
-     *
70
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
71
-     * @param int                   $stackPtr  The position of the current token in the
72
-     *                                         stack passed in $tokens.
73
-     *
74
-     * @return void
75
-     */
76
-    public function process(File $phpcsFile, $stackPtr)
77
-    {
78
-        $tokens = $phpcsFile->getTokens();
79
-        $token  = $tokens[$stackPtr];
67
+	/**
68
+	 * Processes this test, when one of its tokens is encountered.
69
+	 *
70
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
71
+	 * @param int                   $stackPtr  The position of the current token in the
72
+	 *                                         stack passed in $tokens.
73
+	 *
74
+	 * @return void
75
+	 */
76
+	public function process(File $phpcsFile, $stackPtr)
77
+	{
78
+		$tokens = $phpcsFile->getTokens();
79
+		$token  = $tokens[$stackPtr];
80 80
 
81
-        // Check if the break/continue is within a valid loop structure.
82
-        if (empty($token['conditions']) === false) {
83
-            foreach ($token['conditions'] as $tokenCode) {
84
-                if (isset($this->validLoopStructures[$tokenCode]) === true) {
85
-                    return;
86
-                }
87
-            }
88
-        } else {
89
-            // Deal with older PHPCS versions.
90
-            if (isset($token['scope_condition']) === true && isset($this->backCompat[$tokens[$token['scope_condition']]['code']]) === true) {
91
-                return;
92
-            }
93
-        }
81
+		// Check if the break/continue is within a valid loop structure.
82
+		if (empty($token['conditions']) === false) {
83
+			foreach ($token['conditions'] as $tokenCode) {
84
+				if (isset($this->validLoopStructures[$tokenCode]) === true) {
85
+					return;
86
+				}
87
+			}
88
+		} else {
89
+			// Deal with older PHPCS versions.
90
+			if (isset($token['scope_condition']) === true && isset($this->backCompat[$tokens[$token['scope_condition']]['code']]) === true) {
91
+				return;
92
+			}
93
+		}
94 94
 
95
-        // If we're still here, no valid loop structure container has been found, so throw an error.
96
-        $error     = "Using '%s' outside of a loop or switch structure is invalid";
97
-        $isError   = false;
98
-        $errorCode = 'Found';
99
-        $data      = array($token['content']);
95
+		// If we're still here, no valid loop structure container has been found, so throw an error.
96
+		$error     = "Using '%s' outside of a loop or switch structure is invalid";
97
+		$isError   = false;
98
+		$errorCode = 'Found';
99
+		$data      = array($token['content']);
100 100
 
101
-        if ($this->supportsAbove('7.0')) {
102
-            $error    .= ' and will throw a fatal error since PHP 7.0';
103
-            $isError   = true;
104
-            $errorCode = 'FatalError';
105
-        }
101
+		if ($this->supportsAbove('7.0')) {
102
+			$error    .= ' and will throw a fatal error since PHP 7.0';
103
+			$isError   = true;
104
+			$errorCode = 'FatalError';
105
+		}
106 106
 
107
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data);
108
-    }
107
+		$this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data);
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -73,21 +73,21 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @return void
75 75
      */
76
-    public function process(File $phpcsFile, $stackPtr)
76
+    public function process( File $phpcsFile, $stackPtr )
77 77
     {
78 78
         $tokens = $phpcsFile->getTokens();
79
-        $token  = $tokens[$stackPtr];
79
+        $token  = $tokens[ $stackPtr ];
80 80
 
81 81
         // Check if the break/continue is within a valid loop structure.
82
-        if (empty($token['conditions']) === false) {
83
-            foreach ($token['conditions'] as $tokenCode) {
84
-                if (isset($this->validLoopStructures[$tokenCode]) === true) {
82
+        if ( empty( $token[ 'conditions' ] ) === false ) {
83
+            foreach ( $token[ 'conditions' ] as $tokenCode ) {
84
+                if ( isset( $this->validLoopStructures[ $tokenCode ] ) === true ) {
85 85
                     return;
86 86
                 }
87 87
             }
88 88
         } else {
89 89
             // Deal with older PHPCS versions.
90
-            if (isset($token['scope_condition']) === true && isset($this->backCompat[$tokens[$token['scope_condition']]['code']]) === true) {
90
+            if ( isset( $token[ 'scope_condition' ] ) === true && isset( $this->backCompat[ $tokens[ $token[ 'scope_condition' ] ][ 'code' ] ] ) === true ) {
91 91
                 return;
92 92
             }
93 93
         }
@@ -96,14 +96,14 @@  discard block
 block discarded – undo
96 96
         $error     = "Using '%s' outside of a loop or switch structure is invalid";
97 97
         $isError   = false;
98 98
         $errorCode = 'Found';
99
-        $data      = array($token['content']);
99
+        $data      = array( $token[ 'content' ] );
100 100
 
101
-        if ($this->supportsAbove('7.0')) {
101
+        if ( $this->supportsAbove( '7.0' ) ) {
102 102
             $error    .= ' and will throw a fatal error since PHP 7.0';
103 103
             $isError   = true;
104 104
             $errorCode = 'FatalError';
105 105
         }
106 106
 
107
-        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data);
107
+        $this->addMessage( $phpcsFile, $error, $stackPtr, $isError, $errorCode, $data );
108 108
     }
109 109
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
  * @package  PHPCompatibility
26 26
  * @author   Juliette Reinders Folmer <[email protected]>
27 27
  */
28
-class ForbiddenBreakContinueOutsideLoopSniff extends Sniff
29
-{
28
+class ForbiddenBreakContinueOutsideLoopSniff extends Sniff {
30 29
 
31 30
     /**
32 31
      * Token codes of control structure in which usage of break/continue is valid.
@@ -56,8 +55,7 @@  discard block
 block discarded – undo
56 55
      *
57 56
      * @return array
58 57
      */
59
-    public function register()
60
-    {
58
+    public function register() {
61 59
         return array(
62 60
             \T_BREAK,
63 61
             \T_CONTINUE,
@@ -73,8 +71,7 @@  discard block
 block discarded – undo
73 71
      *
74 72
      * @return void
75 73
      */
76
-    public function process(File $phpcsFile, $stackPtr)
77
-    {
74
+    public function process(File $phpcsFile, $stackPtr) {
78 75
         $tokens = $phpcsFile->getTokens();
79 76
         $token  = $tokens[$stackPtr];
80 77
 
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/ControlStructures/NewMultiCatchSniff.php 4 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -27,49 +27,49 @@
 block discarded – undo
27 27
  */
28 28
 class NewMultiCatchSniff extends Sniff
29 29
 {
30
-    /**
31
-     * Returns an array of tokens this test wants to listen for.
32
-     *
33
-     * @return array
34
-     */
35
-    public function register()
36
-    {
37
-        return array(\T_CATCH);
38
-    }
30
+	/**
31
+	 * Returns an array of tokens this test wants to listen for.
32
+	 *
33
+	 * @return array
34
+	 */
35
+	public function register()
36
+	{
37
+		return array(\T_CATCH);
38
+	}
39 39
 
40
-    /**
41
-     * Processes this test, when one of its tokens is encountered.
42
-     *
43
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
44
-     * @param int                   $stackPtr  The position of the current token
45
-     *                                         in the stack passed in $tokens.
46
-     *
47
-     * @return void
48
-     */
49
-    public function process(File $phpcsFile, $stackPtr)
50
-    {
51
-        if ($this->supportsBelow('7.0') === false) {
52
-            return;
53
-        }
40
+	/**
41
+	 * Processes this test, when one of its tokens is encountered.
42
+	 *
43
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
44
+	 * @param int                   $stackPtr  The position of the current token
45
+	 *                                         in the stack passed in $tokens.
46
+	 *
47
+	 * @return void
48
+	 */
49
+	public function process(File $phpcsFile, $stackPtr)
50
+	{
51
+		if ($this->supportsBelow('7.0') === false) {
52
+			return;
53
+		}
54 54
 
55
-        $tokens = $phpcsFile->getTokens();
56
-        $token  = $tokens[$stackPtr];
55
+		$tokens = $phpcsFile->getTokens();
56
+		$token  = $tokens[$stackPtr];
57 57
 
58
-        // Bow out during live coding.
59
-        if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
60
-            return;
61
-        }
58
+		// Bow out during live coding.
59
+		if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
60
+			return;
61
+		}
62 62
 
63
-        $hasBitwiseOr = $phpcsFile->findNext(\T_BITWISE_OR, $token['parenthesis_opener'], $token['parenthesis_closer']);
63
+		$hasBitwiseOr = $phpcsFile->findNext(\T_BITWISE_OR, $token['parenthesis_opener'], $token['parenthesis_closer']);
64 64
 
65
-        if ($hasBitwiseOr === false) {
66
-            return;
67
-        }
65
+		if ($hasBitwiseOr === false) {
66
+			return;
67
+		}
68 68
 
69
-        $phpcsFile->addError(
70
-            'Catching multiple exceptions within one statement is not supported in PHP 7.0 or earlier.',
71
-            $hasBitwiseOr,
72
-            'Found'
73
-        );
74
-    }
69
+		$phpcsFile->addError(
70
+			'Catching multiple exceptions within one statement is not supported in PHP 7.0 or earlier.',
71
+			$hasBitwiseOr,
72
+			'Found'
73
+		);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
      */
35 35
     public function register()
36 36
     {
37
-        return array(\T_CATCH);
37
+        return array( \T_CATCH );
38 38
     }
39 39
 
40 40
     /**
@@ -46,23 +46,23 @@  discard block
 block discarded – undo
46 46
      *
47 47
      * @return void
48 48
      */
49
-    public function process(File $phpcsFile, $stackPtr)
49
+    public function process( File $phpcsFile, $stackPtr )
50 50
     {
51
-        if ($this->supportsBelow('7.0') === false) {
51
+        if ( $this->supportsBelow( '7.0' ) === false ) {
52 52
             return;
53 53
         }
54 54
 
55 55
         $tokens = $phpcsFile->getTokens();
56
-        $token  = $tokens[$stackPtr];
56
+        $token  = $tokens[ $stackPtr ];
57 57
 
58 58
         // Bow out during live coding.
59
-        if (isset($token['parenthesis_opener'], $token['parenthesis_closer']) === false) {
59
+        if ( isset( $token[ 'parenthesis_opener' ], $token[ 'parenthesis_closer' ] ) === false ) {
60 60
             return;
61 61
         }
62 62
 
63
-        $hasBitwiseOr = $phpcsFile->findNext(\T_BITWISE_OR, $token['parenthesis_opener'], $token['parenthesis_closer']);
63
+        $hasBitwiseOr = $phpcsFile->findNext( \T_BITWISE_OR, $token[ 'parenthesis_opener' ], $token[ 'parenthesis_closer' ] );
64 64
 
65
-        if ($hasBitwiseOr === false) {
65
+        if ( $hasBitwiseOr === false ) {
66 66
             return;
67 67
         }
68 68
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -25,15 +25,13 @@  discard block
 block discarded – undo
25 25
  * @package  PHPCompatibility
26 26
  * @author   Juliette Reinders Folmer <[email protected]>
27 27
  */
28
-class NewMultiCatchSniff extends Sniff
29
-{
28
+class NewMultiCatchSniff extends Sniff {
30 29
     /**
31 30
      * Returns an array of tokens this test wants to listen for.
32 31
      *
33 32
      * @return array
34 33
      */
35
-    public function register()
36
-    {
34
+    public function register() {
37 35
         return array(\T_CATCH);
38 36
     }
39 37
 
@@ -46,8 +44,7 @@  discard block
 block discarded – undo
46 44
      *
47 45
      * @return void
48 46
      */
49
-    public function process(File $phpcsFile, $stackPtr)
50
-    {
47
+    public function process(File $phpcsFile, $stackPtr) {
51 48
         if ($this->supportsBelow('7.0') === false) {
52 49
             return;
53 50
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
PHPCompatibility/Sniffs/ControlStructures/NewListInForeachSniff.php 4 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -26,54 +26,54 @@
 block discarded – undo
26 26
 class NewListInForeachSniff extends Sniff
27 27
 {
28 28
 
29
-    /**
30
-     * Returns an array of tokens this test wants to listen for.
31
-     *
32
-     * @return array
33
-     */
34
-    public function register()
35
-    {
36
-        return array(\T_FOREACH);
37
-    }
29
+	/**
30
+	 * Returns an array of tokens this test wants to listen for.
31
+	 *
32
+	 * @return array
33
+	 */
34
+	public function register()
35
+	{
36
+		return array(\T_FOREACH);
37
+	}
38 38
 
39
-    /**
40
-     * Processes this test, when one of its tokens is encountered.
41
-     *
42
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
-     * @param int                   $stackPtr  The position of the current token in the
44
-     *                                         stack passed in $tokens.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        if ($this->supportsBelow('5.4') === false) {
51
-            return;
52
-        }
39
+	/**
40
+	 * Processes this test, when one of its tokens is encountered.
41
+	 *
42
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
43
+	 * @param int                   $stackPtr  The position of the current token in the
44
+	 *                                         stack passed in $tokens.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		if ($this->supportsBelow('5.4') === false) {
51
+			return;
52
+		}
53 53
 
54
-        $tokens = $phpcsFile->getTokens();
54
+		$tokens = $phpcsFile->getTokens();
55 55
 
56
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
57
-            return;
58
-        }
56
+		if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
57
+			return;
58
+		}
59 59
 
60
-        $opener = $tokens[$stackPtr]['parenthesis_opener'];
61
-        $closer = $tokens[$stackPtr]['parenthesis_closer'];
60
+		$opener = $tokens[$stackPtr]['parenthesis_opener'];
61
+		$closer = $tokens[$stackPtr]['parenthesis_closer'];
62 62
 
63
-        $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
64
-        if ($asToken === false) {
65
-            return;
66
-        }
63
+		$asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
64
+		if ($asToken === false) {
65
+			return;
66
+		}
67 67
 
68
-        $hasList = $phpcsFile->findNext(array(\T_LIST, \T_OPEN_SHORT_ARRAY), ($asToken + 1), $closer);
69
-        if ($hasList === false) {
70
-            return;
71
-        }
68
+		$hasList = $phpcsFile->findNext(array(\T_LIST, \T_OPEN_SHORT_ARRAY), ($asToken + 1), $closer);
69
+		if ($hasList === false) {
70
+			return;
71
+		}
72 72
 
73
-        $phpcsFile->addError(
74
-            'Unpacking nested arrays with list() in a foreach is not supported in PHP 5.4 or earlier.',
75
-            $hasList,
76
-            'Found'
77
-        );
78
-    }
73
+		$phpcsFile->addError(
74
+			'Unpacking nested arrays with list() in a foreach is not supported in PHP 5.4 or earlier.',
75
+			$hasList,
76
+			'Found'
77
+		);
78
+	}
79 79
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      */
34 34
     public function register()
35 35
     {
36
-        return array(\T_FOREACH);
36
+        return array( \T_FOREACH );
37 37
     }
38 38
 
39 39
     /**
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return void
47 47
      */
48
-    public function process(File $phpcsFile, $stackPtr)
48
+    public function process( File $phpcsFile, $stackPtr )
49 49
     {
50
-        if ($this->supportsBelow('5.4') === false) {
50
+        if ( $this->supportsBelow( '5.4' ) === false ) {
51 51
             return;
52 52
         }
53 53
 
54 54
         $tokens = $phpcsFile->getTokens();
55 55
 
56
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
56
+        if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) {
57 57
             return;
58 58
         }
59 59
 
60
-        $opener = $tokens[$stackPtr]['parenthesis_opener'];
61
-        $closer = $tokens[$stackPtr]['parenthesis_closer'];
60
+        $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
61
+        $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ];
62 62
 
63
-        $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
64
-        if ($asToken === false) {
63
+        $asToken = $phpcsFile->findNext( \T_AS, ( $opener + 1 ), $closer );
64
+        if ( $asToken === false ) {
65 65
             return;
66 66
         }
67 67
 
68
-        $hasList = $phpcsFile->findNext(array(\T_LIST, \T_OPEN_SHORT_ARRAY), ($asToken + 1), $closer);
69
-        if ($hasList === false) {
68
+        $hasList = $phpcsFile->findNext( array( \T_LIST, \T_OPEN_SHORT_ARRAY ), ( $asToken + 1 ), $closer );
69
+        if ( $hasList === false ) {
70 70
             return;
71 71
         }
72 72
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,16 +23,14 @@  discard block
 block discarded – undo
23 23
  * @package  PHPCompatibility
24 24
  * @author   Juliette Reinders Folmer <[email protected]>
25 25
  */
26
-class NewListInForeachSniff extends Sniff
27
-{
26
+class NewListInForeachSniff extends Sniff {
28 27
 
29 28
     /**
30 29
      * Returns an array of tokens this test wants to listen for.
31 30
      *
32 31
      * @return array
33 32
      */
34
-    public function register()
35
-    {
33
+    public function register() {
36 34
         return array(\T_FOREACH);
37 35
     }
38 36
 
@@ -45,8 +43,7 @@  discard block
 block discarded – undo
45 43
      *
46 44
      * @return void
47 45
      */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
46
+    public function process(File $phpcsFile, $stackPtr) {
50 47
         if ($this->supportsBelow('5.4') === false) {
51 48
             return;
52 49
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
Sniffs/ControlStructures/NewForeachExpressionReferencingSniff.php 4 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -29,68 +29,68 @@
 block discarded – undo
29 29
 class NewForeachExpressionReferencingSniff extends Sniff
30 30
 {
31 31
 
32
-    /**
33
-     * Returns an array of tokens this test wants to listen for.
34
-     *
35
-     * @return array
36
-     */
37
-    public function register()
38
-    {
39
-        return array(\T_FOREACH);
40
-    }
32
+	/**
33
+	 * Returns an array of tokens this test wants to listen for.
34
+	 *
35
+	 * @return array
36
+	 */
37
+	public function register()
38
+	{
39
+		return array(\T_FOREACH);
40
+	}
41 41
 
42
-    /**
43
-     * Processes this test, when one of its tokens is encountered.
44
-     *
45
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
46
-     * @param int                   $stackPtr  The position of the current token in the
47
-     *                                         stack passed in $tokens.
48
-     *
49
-     * @return void
50
-     */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
53
-        if ($this->supportsBelow('5.4') === false) {
54
-            return;
55
-        }
42
+	/**
43
+	 * Processes this test, when one of its tokens is encountered.
44
+	 *
45
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
46
+	 * @param int                   $stackPtr  The position of the current token in the
47
+	 *                                         stack passed in $tokens.
48
+	 *
49
+	 * @return void
50
+	 */
51
+	public function process(File $phpcsFile, $stackPtr)
52
+	{
53
+		if ($this->supportsBelow('5.4') === false) {
54
+			return;
55
+		}
56 56
 
57
-        $tokens = $phpcsFile->getTokens();
57
+		$tokens = $phpcsFile->getTokens();
58 58
 
59
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
60
-            return;
61
-        }
59
+		if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
60
+			return;
61
+		}
62 62
 
63
-        $opener = $tokens[$stackPtr]['parenthesis_opener'];
64
-        $closer = $tokens[$stackPtr]['parenthesis_closer'];
63
+		$opener = $tokens[$stackPtr]['parenthesis_opener'];
64
+		$closer = $tokens[$stackPtr]['parenthesis_closer'];
65 65
 
66
-        $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
67
-        if ($asToken === false) {
68
-            return;
69
-        }
66
+		$asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
67
+		if ($asToken === false) {
68
+			return;
69
+		}
70 70
 
71
-        /*
71
+		/*
72 72
          * Note: referencing $key is not allowed in any version, so this should only find referenced $values.
73 73
          * If it does find a referenced key, it would be a parse error anyway.
74 74
          */
75
-        $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer);
76
-        if ($hasReference === false) {
77
-            return;
78
-        }
75
+		$hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer);
76
+		if ($hasReference === false) {
77
+			return;
78
+		}
79 79
 
80
-        $nestingLevel = 0;
81
-        if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) {
82
-            $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']);
83
-        }
80
+		$nestingLevel = 0;
81
+		if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) {
82
+			$nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']);
83
+		}
84 84
 
85
-        if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) {
86
-            return;
87
-        }
85
+		if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) {
86
+			return;
87
+		}
88 88
 
89
-        // Non-variable detected before the `as` keyword.
90
-        $phpcsFile->addError(
91
-            'Referencing $value is only possible if the iterated array is a variable in PHP 5.4 or earlier.',
92
-            $hasReference,
93
-            'Found'
94
-        );
95
-    }
89
+		// Non-variable detected before the `as` keyword.
90
+		$phpcsFile->addError(
91
+			'Referencing $value is only possible if the iterated array is a variable in PHP 5.4 or earlier.',
92
+			$hasReference,
93
+			'Found'
94
+		);
95
+	}
96 96
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function register()
38 38
     {
39
-        return array(\T_FOREACH);
39
+        return array( \T_FOREACH );
40 40
     }
41 41
 
42 42
     /**
@@ -48,23 +48,23 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return void
50 50
      */
51
-    public function process(File $phpcsFile, $stackPtr)
51
+    public function process( File $phpcsFile, $stackPtr )
52 52
     {
53
-        if ($this->supportsBelow('5.4') === false) {
53
+        if ( $this->supportsBelow( '5.4' ) === false ) {
54 54
             return;
55 55
         }
56 56
 
57 57
         $tokens = $phpcsFile->getTokens();
58 58
 
59
-        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
59
+        if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ], $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) {
60 60
             return;
61 61
         }
62 62
 
63
-        $opener = $tokens[$stackPtr]['parenthesis_opener'];
64
-        $closer = $tokens[$stackPtr]['parenthesis_closer'];
63
+        $opener = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
64
+        $closer = $tokens[ $stackPtr ][ 'parenthesis_closer' ];
65 65
 
66
-        $asToken = $phpcsFile->findNext(\T_AS, ($opener + 1), $closer);
67
-        if ($asToken === false) {
66
+        $asToken = $phpcsFile->findNext( \T_AS, ( $opener + 1 ), $closer );
67
+        if ( $asToken === false ) {
68 68
             return;
69 69
         }
70 70
 
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
          * Note: referencing $key is not allowed in any version, so this should only find referenced $values.
73 73
          * If it does find a referenced key, it would be a parse error anyway.
74 74
          */
75
-        $hasReference = $phpcsFile->findNext(\T_BITWISE_AND, ($asToken + 1), $closer);
76
-        if ($hasReference === false) {
75
+        $hasReference = $phpcsFile->findNext( \T_BITWISE_AND, ( $asToken + 1 ), $closer );
76
+        if ( $hasReference === false ) {
77 77
             return;
78 78
         }
79 79
 
80 80
         $nestingLevel = 0;
81
-        if ($asToken !== ($opener + 1) && isset($tokens[$opener + 1]['nested_parenthesis'])) {
82
-            $nestingLevel = \count($tokens[$opener + 1]['nested_parenthesis']);
81
+        if ( $asToken !== ( $opener + 1 ) && isset( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] ) ) {
82
+            $nestingLevel = \count( $tokens[ $opener + 1 ][ 'nested_parenthesis' ] );
83 83
         }
84 84
 
85
-        if ($this->isVariable($phpcsFile, ($opener + 1), $asToken, $nestingLevel) === true) {
85
+        if ( $this->isVariable( $phpcsFile, ( $opener + 1 ), $asToken, $nestingLevel ) === true ) {
86 86
             return;
87 87
         }
88 88
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,16 +26,14 @@  discard block
 block discarded – undo
26 26
  * @package  PHPCompatibility
27 27
  * @author   Juliette Reinders Folmer <[email protected]>
28 28
  */
29
-class NewForeachExpressionReferencingSniff extends Sniff
30
-{
29
+class NewForeachExpressionReferencingSniff extends Sniff {
31 30
 
32 31
     /**
33 32
      * Returns an array of tokens this test wants to listen for.
34 33
      *
35 34
      * @return array
36 35
      */
37
-    public function register()
38
-    {
36
+    public function register() {
39 37
         return array(\T_FOREACH);
40 38
     }
41 39
 
@@ -48,8 +46,7 @@  discard block
 block discarded – undo
48 46
      *
49 47
      * @return void
50 48
      */
51
-    public function process(File $phpcsFile, $stackPtr)
52
-    {
49
+    public function process(File $phpcsFile, $stackPtr) {
53 50
         if ($this->supportsBelow('5.4') === false) {
54 51
             return;
55 52
         }
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
     /**
66 66
      * Returns an array of tokens this test wants to listen for.
67 67
      *
68
-     * @return array
68
+     * @return integer[]
69 69
      */
70 70
     public function register()
71 71
     {
Please login to merge, or discard this patch.
Sniffs/FunctionDeclarations/NewReturnTypeDeclarationsSniff.php 3 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -26,148 +26,148 @@
 block discarded – undo
26 26
 class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff
27 27
 {
28 28
 
29
-    /**
30
-     * A list of new types
31
-     *
32
-     * The array lists : version number with false (not present) or true (present).
33
-     * If's sufficient to list the first version where the keyword appears.
34
-     *
35
-     * @var array(string => array(string => int|string|null))
36
-     */
37
-    protected $newTypes = array(
38
-        'int' => array(
39
-            '5.6' => false,
40
-            '7.0' => true,
41
-        ),
42
-        'float' => array(
43
-            '5.6' => false,
44
-            '7.0' => true,
45
-        ),
46
-        'bool' => array(
47
-            '5.6' => false,
48
-            '7.0' => true,
49
-        ),
50
-        'string' => array(
51
-            '5.6' => false,
52
-            '7.0' => true,
53
-        ),
54
-        'array' => array(
55
-            '5.6' => false,
56
-            '7.0' => true,
57
-        ),
58
-        'callable' => array(
59
-            '5.6' => false,
60
-            '7.0' => true,
61
-        ),
62
-        'parent' => array(
63
-            '5.6' => false,
64
-            '7.0' => true,
65
-        ),
66
-        'self' => array(
67
-            '5.6' => false,
68
-            '7.0' => true,
69
-        ),
70
-        'Class name' => array(
71
-            '5.6' => false,
72
-            '7.0' => true,
73
-        ),
74
-
75
-        'iterable' => array(
76
-            '7.0' => false,
77
-            '7.1' => true,
78
-        ),
79
-        'void' => array(
80
-            '7.0' => false,
81
-            '7.1' => true,
82
-        ),
83
-
84
-        'object' => array(
85
-            '7.1' => false,
86
-            '7.2' => true,
87
-        ),
88
-    );
89
-
90
-
91
-    /**
92
-     * Returns an array of tokens this test wants to listen for.
93
-     *
94
-     * @return array
95
-     */
96
-    public function register()
97
-    {
98
-        $tokens = array(
99
-            \T_FUNCTION,
100
-            \T_CLOSURE,
101
-        );
102
-
103
-        if (\defined('T_RETURN_TYPE')) {
104
-            $tokens[] = \T_RETURN_TYPE;
105
-        }
106
-
107
-        return $tokens;
108
-    }
109
-
110
-
111
-    /**
112
-     * Processes this test, when one of its tokens is encountered.
113
-     *
114
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
115
-     * @param int                   $stackPtr  The position of the current token in
116
-     *                                         the stack passed in $tokens.
117
-     *
118
-     * @return void
119
-     */
120
-    public function process(File $phpcsFile, $stackPtr)
121
-    {
122
-        $tokens = $phpcsFile->getTokens();
123
-
124
-        // Deal with older PHPCS version which don't recognize return type hints
125
-        // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
126
-        if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) {
127
-            $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
128
-            if ($returnTypeHint !== false) {
129
-                $stackPtr = $returnTypeHint;
130
-            }
131
-        }
132
-
133
-        if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) {
134
-            $itemInfo = array(
135
-                'name' => $tokens[$stackPtr]['content'],
136
-            );
137
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
138
-        }
139
-        // Handle class name based return types.
140
-        elseif ($tokens[$stackPtr]['code'] === \T_STRING
141
-            || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE)
142
-        ) {
143
-            $itemInfo = array(
144
-                'name'   => 'Class name',
145
-            );
146
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
147
-        }
148
-    }
149
-
150
-
151
-    /**
152
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
153
-     *
154
-     * @param array $itemInfo Base information about the item.
155
-     *
156
-     * @return array Version and other information about the item.
157
-     */
158
-    public function getItemArray(array $itemInfo)
159
-    {
160
-        return $this->newTypes[$itemInfo['name']];
161
-    }
162
-
163
-
164
-    /**
165
-     * Get the error message template for this sniff.
166
-     *
167
-     * @return string
168
-     */
169
-    protected function getErrorMsgTemplate()
170
-    {
171
-        return '%s return type is not present in PHP version %s or earlier';
172
-    }
29
+	/**
30
+	 * A list of new types
31
+	 *
32
+	 * The array lists : version number with false (not present) or true (present).
33
+	 * If's sufficient to list the first version where the keyword appears.
34
+	 *
35
+	 * @var array(string => array(string => int|string|null))
36
+	 */
37
+	protected $newTypes = array(
38
+		'int' => array(
39
+			'5.6' => false,
40
+			'7.0' => true,
41
+		),
42
+		'float' => array(
43
+			'5.6' => false,
44
+			'7.0' => true,
45
+		),
46
+		'bool' => array(
47
+			'5.6' => false,
48
+			'7.0' => true,
49
+		),
50
+		'string' => array(
51
+			'5.6' => false,
52
+			'7.0' => true,
53
+		),
54
+		'array' => array(
55
+			'5.6' => false,
56
+			'7.0' => true,
57
+		),
58
+		'callable' => array(
59
+			'5.6' => false,
60
+			'7.0' => true,
61
+		),
62
+		'parent' => array(
63
+			'5.6' => false,
64
+			'7.0' => true,
65
+		),
66
+		'self' => array(
67
+			'5.6' => false,
68
+			'7.0' => true,
69
+		),
70
+		'Class name' => array(
71
+			'5.6' => false,
72
+			'7.0' => true,
73
+		),
74
+
75
+		'iterable' => array(
76
+			'7.0' => false,
77
+			'7.1' => true,
78
+		),
79
+		'void' => array(
80
+			'7.0' => false,
81
+			'7.1' => true,
82
+		),
83
+
84
+		'object' => array(
85
+			'7.1' => false,
86
+			'7.2' => true,
87
+		),
88
+	);
89
+
90
+
91
+	/**
92
+	 * Returns an array of tokens this test wants to listen for.
93
+	 *
94
+	 * @return array
95
+	 */
96
+	public function register()
97
+	{
98
+		$tokens = array(
99
+			\T_FUNCTION,
100
+			\T_CLOSURE,
101
+		);
102
+
103
+		if (\defined('T_RETURN_TYPE')) {
104
+			$tokens[] = \T_RETURN_TYPE;
105
+		}
106
+
107
+		return $tokens;
108
+	}
109
+
110
+
111
+	/**
112
+	 * Processes this test, when one of its tokens is encountered.
113
+	 *
114
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
115
+	 * @param int                   $stackPtr  The position of the current token in
116
+	 *                                         the stack passed in $tokens.
117
+	 *
118
+	 * @return void
119
+	 */
120
+	public function process(File $phpcsFile, $stackPtr)
121
+	{
122
+		$tokens = $phpcsFile->getTokens();
123
+
124
+		// Deal with older PHPCS version which don't recognize return type hints
125
+		// as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
126
+		if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) {
127
+			$returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
128
+			if ($returnTypeHint !== false) {
129
+				$stackPtr = $returnTypeHint;
130
+			}
131
+		}
132
+
133
+		if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) {
134
+			$itemInfo = array(
135
+				'name' => $tokens[$stackPtr]['content'],
136
+			);
137
+			$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
138
+		}
139
+		// Handle class name based return types.
140
+		elseif ($tokens[$stackPtr]['code'] === \T_STRING
141
+			|| (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE)
142
+		) {
143
+			$itemInfo = array(
144
+				'name'   => 'Class name',
145
+			);
146
+			$this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
147
+		}
148
+	}
149
+
150
+
151
+	/**
152
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
153
+	 *
154
+	 * @param array $itemInfo Base information about the item.
155
+	 *
156
+	 * @return array Version and other information about the item.
157
+	 */
158
+	public function getItemArray(array $itemInfo)
159
+	{
160
+		return $this->newTypes[$itemInfo['name']];
161
+	}
162
+
163
+
164
+	/**
165
+	 * Get the error message template for this sniff.
166
+	 *
167
+	 * @return string
168
+	 */
169
+	protected function getErrorMsgTemplate()
170
+	{
171
+		return '%s return type is not present in PHP version %s or earlier';
172
+	}
173 173
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
             \T_CLOSURE,
101 101
         );
102 102
 
103
-        if (\defined('T_RETURN_TYPE')) {
104
-            $tokens[] = \T_RETURN_TYPE;
103
+        if ( \defined( 'T_RETURN_TYPE' ) ) {
104
+            $tokens[ ] = \T_RETURN_TYPE;
105 105
         }
106 106
 
107 107
         return $tokens;
@@ -117,33 +117,33 @@  discard block
 block discarded – undo
117 117
      *
118 118
      * @return void
119 119
      */
120
-    public function process(File $phpcsFile, $stackPtr)
120
+    public function process( File $phpcsFile, $stackPtr )
121 121
     {
122 122
         $tokens = $phpcsFile->getTokens();
123 123
 
124 124
         // Deal with older PHPCS version which don't recognize return type hints
125 125
         // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed.
126
-        if ($tokens[$stackPtr]['code'] === \T_FUNCTION || $tokens[$stackPtr]['code'] === \T_CLOSURE) {
127
-            $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr);
128
-            if ($returnTypeHint !== false) {
126
+        if ( $tokens[ $stackPtr ][ 'code' ] === \T_FUNCTION || $tokens[ $stackPtr ][ 'code' ] === \T_CLOSURE ) {
127
+            $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr );
128
+            if ( $returnTypeHint !== false ) {
129 129
                 $stackPtr = $returnTypeHint;
130 130
             }
131 131
         }
132 132
 
133
-        if (isset($this->newTypes[$tokens[$stackPtr]['content']]) === true) {
133
+        if ( isset( $this->newTypes[ $tokens[ $stackPtr ][ 'content' ] ] ) === true ) {
134 134
             $itemInfo = array(
135
-                'name' => $tokens[$stackPtr]['content'],
135
+                'name' => $tokens[ $stackPtr ][ 'content' ],
136 136
             );
137
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
137
+            $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo );
138 138
         }
139 139
         // Handle class name based return types.
140
-        elseif ($tokens[$stackPtr]['code'] === \T_STRING
141
-            || (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE)
140
+        elseif ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING
141
+            || ( \defined( 'T_RETURN_TYPE' ) && $tokens[ $stackPtr ][ 'code' ] === \T_RETURN_TYPE )
142 142
         ) {
143 143
             $itemInfo = array(
144 144
                 'name'   => 'Class name',
145 145
             );
146
-            $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
146
+            $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo );
147 147
         }
148 148
     }
149 149
 
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
      *
156 156
      * @return array Version and other information about the item.
157 157
      */
158
-    public function getItemArray(array $itemInfo)
158
+    public function getItemArray( array $itemInfo )
159 159
     {
160
-        return $this->newTypes[$itemInfo['name']];
160
+        return $this->newTypes[ $itemInfo[ 'name' ] ];
161 161
     }
162 162
 
163 163
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
  * @package  PHPCompatibility
24 24
  * @author   Wim Godden <[email protected]>
25 25
  */
26
-class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff
27
-{
26
+class NewReturnTypeDeclarationsSniff extends AbstractNewFeatureSniff {
28 27
 
29 28
     /**
30 29
      * A list of new types
@@ -93,8 +92,7 @@  discard block
 block discarded – undo
93 92
      *
94 93
      * @return array
95 94
      */
96
-    public function register()
97
-    {
95
+    public function register() {
98 96
         $tokens = array(
99 97
             \T_FUNCTION,
100 98
             \T_CLOSURE,
@@ -117,8 +115,7 @@  discard block
 block discarded – undo
117 115
      *
118 116
      * @return void
119 117
      */
120
-    public function process(File $phpcsFile, $stackPtr)
121
-    {
118
+    public function process(File $phpcsFile, $stackPtr) {
122 119
         $tokens = $phpcsFile->getTokens();
123 120
 
124 121
         // Deal with older PHPCS version which don't recognize return type hints
@@ -155,8 +152,7 @@  discard block
 block discarded – undo
155 152
      *
156 153
      * @return array Version and other information about the item.
157 154
      */
158
-    public function getItemArray(array $itemInfo)
159
-    {
155
+    public function getItemArray(array $itemInfo) {
160 156
         return $this->newTypes[$itemInfo['name']];
161 157
     }
162 158
 
@@ -166,8 +162,7 @@  discard block
 block discarded – undo
166 162
      *
167 163
      * @return string
168 164
      */
169
-    protected function getErrorMsgTemplate()
170
-    {
165
+    protected function getErrorMsgTemplate() {
171 166
         return '%s return type is not present in PHP version %s or earlier';
172 167
     }
173 168
 }
Please login to merge, or discard this patch.
Sniffs/FunctionDeclarations/NewParamTypeDeclarationsSniff.php 3 patches
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -23,173 +23,173 @@
 block discarded – undo
23 23
 class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff
24 24
 {
25 25
 
26
-    /**
27
-     * A list of new types.
28
-     *
29
-     * The array lists : version number with false (not present) or true (present).
30
-     * If's sufficient to list the first version where the keyword appears.
31
-     *
32
-     * @var array(string => array(string => int|string|null))
33
-     */
34
-    protected $newTypes = array(
35
-        'array' => array(
36
-            '5.0' => false,
37
-            '5.1' => true,
38
-        ),
39
-        'self' => array(
40
-            '5.1' => false,
41
-            '5.2' => true,
42
-        ),
43
-        'parent' => array(
44
-            '5.1' => false,
45
-            '5.2' => true,
46
-        ),
47
-        'callable' => array(
48
-            '5.3' => false,
49
-            '5.4' => true,
50
-        ),
51
-        'int' => array(
52
-            '5.6' => false,
53
-            '7.0' => true,
54
-        ),
55
-        'float' => array(
56
-            '5.6' => false,
57
-            '7.0' => true,
58
-        ),
59
-        'bool' => array(
60
-            '5.6' => false,
61
-            '7.0' => true,
62
-        ),
63
-        'string' => array(
64
-            '5.6' => false,
65
-            '7.0' => true,
66
-        ),
67
-        'iterable' => array(
68
-            '7.0' => false,
69
-            '7.1' => true,
70
-        ),
71
-        'object' => array(
72
-            '7.1' => false,
73
-            '7.2' => true,
74
-        ),
75
-    );
76
-
77
-
78
-    /**
79
-     * Invalid types
80
-     *
81
-     * The array lists : the invalid type hint => what was probably intended/alternative.
82
-     *
83
-     * @var array(string => string)
84
-     */
85
-    protected $invalidTypes = array(
86
-        'static'  => 'self',
87
-        'boolean' => 'bool',
88
-        'integer' => 'int',
89
-    );
90
-
91
-
92
-    /**
93
-     * Returns an array of tokens this test wants to listen for.
94
-     *
95
-     * @return array
96
-     */
97
-    public function register()
98
-    {
99
-        return array(
100
-            \T_FUNCTION,
101
-            \T_CLOSURE,
102
-        );
103
-    }
104
-
105
-
106
-    /**
107
-     * Processes this test, when one of its tokens is encountered.
108
-     *
109
-     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
110
-     * @param int                   $stackPtr  The position of the current token in
111
-     *                                         the stack passed in $tokens.
112
-     *
113
-     * @return void
114
-     */
115
-    public function process(File $phpcsFile, $stackPtr)
116
-    {
117
-        // Get all parameters from method signature.
118
-        $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
119
-        if (empty($paramNames)) {
120
-            return;
121
-        }
122
-
123
-        $supportsPHP4 = $this->supportsBelow('4.4');
124
-
125
-        foreach ($paramNames as $param) {
126
-            if ($param['type_hint'] === '') {
127
-                continue;
128
-            }
129
-
130
-            // Strip off potential nullable indication.
131
-            $typeHint = ltrim($param['type_hint'], '?');
132
-
133
-            if ($supportsPHP4 === true) {
134
-                $phpcsFile->addError(
135
-                    'Type declarations were not present in PHP 4.4 or earlier.',
136
-                    $param['token'],
137
-                    'TypeHintFound'
138
-                );
139
-
140
-            } elseif (isset($this->newTypes[$typeHint])) {
141
-                $itemInfo = array(
142
-                    'name' => $typeHint,
143
-                );
144
-                $this->handleFeature($phpcsFile, $param['token'], $itemInfo);
145
-
146
-                // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error.
147
-                // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error
148
-                // will be thrown.
149
-                if (($typeHint === 'self' || $typeHint === 'parent')
150
-                    && $this->inClassScope($phpcsFile, $stackPtr, false) === false
151
-                    && $this->supportsAbove('5.2') !== false
152
-                ) {
153
-                    $phpcsFile->addError(
154
-                        "'%s' type cannot be used outside of class scope",
155
-                        $param['token'],
156
-                        ucfirst($typeHint) . 'OutsideClassScopeFound',
157
-                        array($typeHint)
158
-                    );
159
-                }
160
-            } elseif (isset($this->invalidTypes[$typeHint])) {
161
-                $error = "'%s' is not a valid type declaration. Did you mean %s ?";
162
-                $data  = array(
163
-                    $typeHint,
164
-                    $this->invalidTypes[$typeHint],
165
-                );
166
-
167
-                $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data);
168
-            }
169
-        }
170
-    }
171
-
172
-
173
-    /**
174
-     * Get the relevant sub-array for a specific item from a multi-dimensional array.
175
-     *
176
-     * @param array $itemInfo Base information about the item.
177
-     *
178
-     * @return array Version and other information about the item.
179
-     */
180
-    public function getItemArray(array $itemInfo)
181
-    {
182
-        return $this->newTypes[$itemInfo['name']];
183
-    }
184
-
185
-
186
-    /**
187
-     * Get the error message template for this sniff.
188
-     *
189
-     * @return string
190
-     */
191
-    protected function getErrorMsgTemplate()
192
-    {
193
-        return "'%s' type declaration is not present in PHP version %s or earlier";
194
-    }
26
+	/**
27
+	 * A list of new types.
28
+	 *
29
+	 * The array lists : version number with false (not present) or true (present).
30
+	 * If's sufficient to list the first version where the keyword appears.
31
+	 *
32
+	 * @var array(string => array(string => int|string|null))
33
+	 */
34
+	protected $newTypes = array(
35
+		'array' => array(
36
+			'5.0' => false,
37
+			'5.1' => true,
38
+		),
39
+		'self' => array(
40
+			'5.1' => false,
41
+			'5.2' => true,
42
+		),
43
+		'parent' => array(
44
+			'5.1' => false,
45
+			'5.2' => true,
46
+		),
47
+		'callable' => array(
48
+			'5.3' => false,
49
+			'5.4' => true,
50
+		),
51
+		'int' => array(
52
+			'5.6' => false,
53
+			'7.0' => true,
54
+		),
55
+		'float' => array(
56
+			'5.6' => false,
57
+			'7.0' => true,
58
+		),
59
+		'bool' => array(
60
+			'5.6' => false,
61
+			'7.0' => true,
62
+		),
63
+		'string' => array(
64
+			'5.6' => false,
65
+			'7.0' => true,
66
+		),
67
+		'iterable' => array(
68
+			'7.0' => false,
69
+			'7.1' => true,
70
+		),
71
+		'object' => array(
72
+			'7.1' => false,
73
+			'7.2' => true,
74
+		),
75
+	);
76
+
77
+
78
+	/**
79
+	 * Invalid types
80
+	 *
81
+	 * The array lists : the invalid type hint => what was probably intended/alternative.
82
+	 *
83
+	 * @var array(string => string)
84
+	 */
85
+	protected $invalidTypes = array(
86
+		'static'  => 'self',
87
+		'boolean' => 'bool',
88
+		'integer' => 'int',
89
+	);
90
+
91
+
92
+	/**
93
+	 * Returns an array of tokens this test wants to listen for.
94
+	 *
95
+	 * @return array
96
+	 */
97
+	public function register()
98
+	{
99
+		return array(
100
+			\T_FUNCTION,
101
+			\T_CLOSURE,
102
+		);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Processes this test, when one of its tokens is encountered.
108
+	 *
109
+	 * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
110
+	 * @param int                   $stackPtr  The position of the current token in
111
+	 *                                         the stack passed in $tokens.
112
+	 *
113
+	 * @return void
114
+	 */
115
+	public function process(File $phpcsFile, $stackPtr)
116
+	{
117
+		// Get all parameters from method signature.
118
+		$paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
119
+		if (empty($paramNames)) {
120
+			return;
121
+		}
122
+
123
+		$supportsPHP4 = $this->supportsBelow('4.4');
124
+
125
+		foreach ($paramNames as $param) {
126
+			if ($param['type_hint'] === '') {
127
+				continue;
128
+			}
129
+
130
+			// Strip off potential nullable indication.
131
+			$typeHint = ltrim($param['type_hint'], '?');
132
+
133
+			if ($supportsPHP4 === true) {
134
+				$phpcsFile->addError(
135
+					'Type declarations were not present in PHP 4.4 or earlier.',
136
+					$param['token'],
137
+					'TypeHintFound'
138
+				);
139
+
140
+			} elseif (isset($this->newTypes[$typeHint])) {
141
+				$itemInfo = array(
142
+					'name' => $typeHint,
143
+				);
144
+				$this->handleFeature($phpcsFile, $param['token'], $itemInfo);
145
+
146
+				// As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error.
147
+				// Only throw this error for PHP 5.2+ as before that the "type hint not supported" error
148
+				// will be thrown.
149
+				if (($typeHint === 'self' || $typeHint === 'parent')
150
+					&& $this->inClassScope($phpcsFile, $stackPtr, false) === false
151
+					&& $this->supportsAbove('5.2') !== false
152
+				) {
153
+					$phpcsFile->addError(
154
+						"'%s' type cannot be used outside of class scope",
155
+						$param['token'],
156
+						ucfirst($typeHint) . 'OutsideClassScopeFound',
157
+						array($typeHint)
158
+					);
159
+				}
160
+			} elseif (isset($this->invalidTypes[$typeHint])) {
161
+				$error = "'%s' is not a valid type declaration. Did you mean %s ?";
162
+				$data  = array(
163
+					$typeHint,
164
+					$this->invalidTypes[$typeHint],
165
+				);
166
+
167
+				$phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data);
168
+			}
169
+		}
170
+	}
171
+
172
+
173
+	/**
174
+	 * Get the relevant sub-array for a specific item from a multi-dimensional array.
175
+	 *
176
+	 * @param array $itemInfo Base information about the item.
177
+	 *
178
+	 * @return array Version and other information about the item.
179
+	 */
180
+	public function getItemArray(array $itemInfo)
181
+	{
182
+		return $this->newTypes[$itemInfo['name']];
183
+	}
184
+
185
+
186
+	/**
187
+	 * Get the error message template for this sniff.
188
+	 *
189
+	 * @return string
190
+	 */
191
+	protected function getErrorMsgTemplate()
192
+	{
193
+		return "'%s' type declaration is not present in PHP version %s or earlier";
194
+	}
195 195
 }
Please login to merge, or discard this patch.
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -112,59 +112,59 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @return void
114 114
      */
115
-    public function process(File $phpcsFile, $stackPtr)
115
+    public function process( File $phpcsFile, $stackPtr )
116 116
     {
117 117
         // Get all parameters from method signature.
118
-        $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
119
-        if (empty($paramNames)) {
118
+        $paramNames = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr );
119
+        if ( empty( $paramNames ) ) {
120 120
             return;
121 121
         }
122 122
 
123
-        $supportsPHP4 = $this->supportsBelow('4.4');
123
+        $supportsPHP4 = $this->supportsBelow( '4.4' );
124 124
 
125
-        foreach ($paramNames as $param) {
126
-            if ($param['type_hint'] === '') {
125
+        foreach ( $paramNames as $param ) {
126
+            if ( $param[ 'type_hint' ] === '' ) {
127 127
                 continue;
128 128
             }
129 129
 
130 130
             // Strip off potential nullable indication.
131
-            $typeHint = ltrim($param['type_hint'], '?');
131
+            $typeHint = ltrim( $param[ 'type_hint' ], '?' );
132 132
 
133
-            if ($supportsPHP4 === true) {
133
+            if ( $supportsPHP4 === true ) {
134 134
                 $phpcsFile->addError(
135 135
                     'Type declarations were not present in PHP 4.4 or earlier.',
136
-                    $param['token'],
136
+                    $param[ 'token' ],
137 137
                     'TypeHintFound'
138 138
                 );
139 139
 
140
-            } elseif (isset($this->newTypes[$typeHint])) {
140
+            } elseif ( isset( $this->newTypes[ $typeHint ] ) ) {
141 141
                 $itemInfo = array(
142 142
                     'name' => $typeHint,
143 143
                 );
144
-                $this->handleFeature($phpcsFile, $param['token'], $itemInfo);
144
+                $this->handleFeature( $phpcsFile, $param[ 'token' ], $itemInfo );
145 145
 
146 146
                 // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error.
147 147
                 // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error
148 148
                 // will be thrown.
149
-                if (($typeHint === 'self' || $typeHint === 'parent')
150
-                    && $this->inClassScope($phpcsFile, $stackPtr, false) === false
151
-                    && $this->supportsAbove('5.2') !== false
149
+                if ( ( $typeHint === 'self' || $typeHint === 'parent' )
150
+                    && $this->inClassScope( $phpcsFile, $stackPtr, false ) === false
151
+                    && $this->supportsAbove( '5.2' ) !== false
152 152
                 ) {
153 153
                     $phpcsFile->addError(
154 154
                         "'%s' type cannot be used outside of class scope",
155
-                        $param['token'],
156
-                        ucfirst($typeHint) . 'OutsideClassScopeFound',
157
-                        array($typeHint)
155
+                        $param[ 'token' ],
156
+                        ucfirst( $typeHint ) . 'OutsideClassScopeFound',
157
+                        array( $typeHint )
158 158
                     );
159 159
                 }
160
-            } elseif (isset($this->invalidTypes[$typeHint])) {
160
+            } elseif ( isset( $this->invalidTypes[ $typeHint ] ) ) {
161 161
                 $error = "'%s' is not a valid type declaration. Did you mean %s ?";
162 162
                 $data  = array(
163 163
                     $typeHint,
164
-                    $this->invalidTypes[$typeHint],
164
+                    $this->invalidTypes[ $typeHint ],
165 165
                 );
166 166
 
167
-                $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data);
167
+                $phpcsFile->addError( $error, $param[ 'token' ], 'InvalidTypeHintFound', $data );
168 168
             }
169 169
         }
170 170
     }
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
      *
178 178
      * @return array Version and other information about the item.
179 179
      */
180
-    public function getItemArray(array $itemInfo)
180
+    public function getItemArray( array $itemInfo )
181 181
     {
182
-        return $this->newTypes[$itemInfo['name']];
182
+        return $this->newTypes[ $itemInfo[ 'name' ] ];
183 183
     }
184 184
 
185 185
 
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,8 +20,7 @@  discard block
 block discarded – undo
20 20
  * @package  PHPCompatibility
21 21
  * @author   Wim Godden <[email protected]>
22 22
  */
23
-class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff
24
-{
23
+class NewParamTypeDeclarationsSniff extends AbstractNewFeatureSniff {
25 24
 
26 25
     /**
27 26
      * A list of new types.
@@ -94,8 +93,7 @@  discard block
 block discarded – undo
94 93
      *
95 94
      * @return array
96 95
      */
97
-    public function register()
98
-    {
96
+    public function register() {
99 97
         return array(
100 98
             \T_FUNCTION,
101 99
             \T_CLOSURE,
@@ -112,8 +110,7 @@  discard block
 block discarded – undo
112 110
      *
113 111
      * @return void
114 112
      */
115
-    public function process(File $phpcsFile, $stackPtr)
116
-    {
113
+    public function process(File $phpcsFile, $stackPtr) {
117 114
         // Get all parameters from method signature.
118 115
         $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
119 116
         if (empty($paramNames)) {
@@ -177,8 +174,7 @@  discard block
 block discarded – undo
177 174
      *
178 175
      * @return array Version and other information about the item.
179 176
      */
180
-    public function getItemArray(array $itemInfo)
181
-    {
177
+    public function getItemArray(array $itemInfo) {
182 178
         return $this->newTypes[$itemInfo['name']];
183 179
     }
184 180
 
@@ -188,8 +184,7 @@  discard block
 block discarded – undo
188 184
      *
189 185
      * @return string
190 186
      */
191
-    protected function getErrorMsgTemplate()
192
-    {
187
+    protected function getErrorMsgTemplate() {
193 188
         return "'%s' type declaration is not present in PHP version %s or earlier";
194 189
     }
195 190
 }
Please login to merge, or discard this patch.