Completed
Branch fix-caching-loader-test (60c3ed)
by
unknown
13:01 queued 04:28
created
src/Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@
 block discarded – undo
140 140
      *
141 141
      * @return void
142 142
      */
143
-    public function processBracket($phpcsFile, $openBracket, $tokens, $type='function')
143
+    public function processBracket($phpcsFile, $openBracket, $tokens, $type = 'function')
144 144
     {
145 145
         $errorPrefix = '';
146 146
         if ($type === 'use') {
Please login to merge, or discard this patch.
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -15,244 +15,244 @@
 block discarded – undo
15 15
 class MultiLineFunctionDeclarationSniff extends PEARFunctionDeclarationSniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = [
24
-        'PHP',
25
-        'JS',
26
-    ];
27
-
28
-
29
-    /**
30
-     * Determine if this is a multi-line function declaration.
31
-     *
32
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
33
-     * @param int                         $stackPtr    The position of the current token
34
-     *                                                 in the stack passed in $tokens.
35
-     * @param int                         $openBracket The position of the opening bracket
36
-     *                                                 in the stack passed in $tokens.
37
-     * @param array                       $tokens      The stack of tokens that make up
38
-     *                                                 the file.
39
-     *
40
-     * @return void
41
-     */
42
-    public function isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens)
43
-    {
44
-        $bracketsToCheck = [$stackPtr => $openBracket];
45
-
46
-        // Closures may use the USE keyword and so be multi-line in this way.
47
-        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
48
-            $use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
49
-            if ($use !== false) {
50
-                $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
51
-                if ($open !== false) {
52
-                    $bracketsToCheck[$use] = $open;
53
-                }
54
-            }
55
-        }
56
-
57
-        foreach ($bracketsToCheck as $stackPtr => $openBracket) {
58
-            // If the first argument is on a new line, this is a multi-line
59
-            // function declaration, even if there is only one argument.
60
-            $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true);
61
-            if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
62
-                return true;
63
-            }
64
-
65
-            $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
66
-
67
-            $end = $phpcsFile->findEndOfStatement($openBracket + 1);
68
-            while ($tokens[$end]['code'] === T_COMMA) {
69
-                // If the next bit of code is not on the same line, this is a
70
-                // multi-line function declaration.
71
-                $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
72
-                if ($next === false) {
73
-                    continue(2);
74
-                }
75
-
76
-                if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
77
-                    return true;
78
-                }
79
-
80
-                $end = $phpcsFile->findEndOfStatement($next);
81
-            }
82
-
83
-            // We've reached the last argument, so see if the next content
84
-            // (should be the close bracket) is also on the same line.
85
-            $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
86
-            if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
87
-                return true;
88
-            }
89
-        }//end foreach
90
-
91
-        return false;
92
-
93
-    }//end isMultiLineDeclaration()
94
-
95
-
96
-    /**
97
-     * Processes single-line declarations.
98
-     *
99
-     * Just uses the Generic BSD-Allman brace sniff.
100
-     *
101
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
102
-     * @param int                         $stackPtr  The position of the current token
103
-     *                                               in the stack passed in $tokens.
104
-     * @param array                       $tokens    The stack of tokens that make up
105
-     *                                               the file.
106
-     *
107
-     * @return void
108
-     */
109
-    public function processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens)
110
-    {
111
-        // We do everything the parent sniff does, and a bit more because we
112
-        // define multi-line declarations a bit differently.
113
-        parent::processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
114
-
115
-        $openingBracket = $tokens[$stackPtr]['parenthesis_opener'];
116
-        $closingBracket = $tokens[$stackPtr]['parenthesis_closer'];
117
-
118
-        $prevNonWhiteSpace = $phpcsFile->findPrevious(T_WHITESPACE, ($closingBracket - 1), $openingBracket, true);
119
-        if ($tokens[$prevNonWhiteSpace]['line'] !== $tokens[$closingBracket]['line']) {
120
-            $error = 'There must not be a newline before the closing parenthesis of a single-line function declaration';
121
-
122
-            if (isset(Tokens::$emptyTokens[$tokens[$prevNonWhiteSpace]['code']]) === true) {
123
-                $phpcsFile->addError($error, $closingBracket, 'CloseBracketNewLine');
124
-            } else {
125
-                $fix = $phpcsFile->addFixableError($error, $closingBracket, 'CloseBracketNewLine');
126
-                if ($fix === true) {
127
-                    $phpcsFile->fixer->beginChangeset();
128
-                    for ($i = ($closingBracket - 1); $i > $openingBracket; $i--) {
129
-                        if ($tokens[$i]['code'] !== T_WHITESPACE) {
130
-                            break;
131
-                        }
132
-
133
-                        $phpcsFile->fixer->replaceToken($i, '');
134
-                    }
135
-
136
-                    $phpcsFile->fixer->endChangeset();
137
-                }
138
-            }
139
-        }//end if
140
-
141
-    }//end processSingleLineDeclaration()
142
-
143
-
144
-    /**
145
-     * Processes multi-line declarations.
146
-     *
147
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
148
-     * @param int                         $stackPtr  The position of the current token
149
-     *                                               in the stack passed in $tokens.
150
-     * @param array                       $tokens    The stack of tokens that make up
151
-     *                                               the file.
152
-     *
153
-     * @return void
154
-     */
155
-    public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens)
156
-    {
157
-        // We do everything the parent sniff does, and a bit more.
158
-        parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
159
-
160
-        $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
161
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
162
-
163
-        if ($tokens[$stackPtr]['code'] !== T_CLOSURE) {
164
-            return;
165
-        }
166
-
167
-        $use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
168
-        if ($use === false) {
169
-            return;
170
-        }
171
-
172
-        $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null);
173
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'use');
174
-
175
-    }//end processMultiLineDeclaration()
176
-
177
-
178
-    /**
179
-     * Processes the contents of a single set of brackets.
180
-     *
181
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
182
-     * @param int                         $openBracket The position of the open bracket
183
-     *                                                 in the stack passed in $tokens.
184
-     * @param array                       $tokens      The stack of tokens that make up
185
-     *                                                 the file.
186
-     * @param string                      $type        The type of the token the brackets
187
-     *                                                 belong to (function or use).
188
-     *
189
-     * @return void
190
-     */
191
-    public function processBracket($phpcsFile, $openBracket, $tokens, $type='function')
192
-    {
193
-        $errorPrefix = '';
194
-        if ($type === 'use') {
195
-            $errorPrefix = 'Use';
196
-        }
197
-
198
-        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
199
-
200
-        // The open bracket should be the last thing on the line.
201
-        if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
202
-            $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true);
203
-            if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
204
-                $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket';
205
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing');
206
-                if ($fix === true) {
207
-                    if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
208
-                        $phpcsFile->fixer->addNewline($openBracket);
209
-                    } else {
210
-                        $phpcsFile->fixer->beginChangeset();
211
-                        for ($x = $openBracket; $x < $next; $x++) {
212
-                            if ($tokens[$x]['line'] === $tokens[$openBracket]['line']) {
213
-                                continue;
214
-                            }
215
-
216
-                            if ($tokens[$x]['line'] === $tokens[$next]['line']) {
217
-                                break;
218
-                            }
219
-                        }
220
-
221
-                        $phpcsFile->fixer->endChangeset();
222
-                    }
223
-                }
224
-            }//end if
225
-        }//end if
226
-
227
-        // Each line between the brackets should contain a single parameter.
228
-        $lastComma = null;
229
-        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
230
-            // Skip brackets, like arrays, as they can contain commas.
231
-            if (isset($tokens[$i]['bracket_opener']) === true) {
232
-                $i = $tokens[$i]['bracket_closer'];
233
-                continue;
234
-            }
235
-
236
-            if (isset($tokens[$i]['parenthesis_opener']) === true) {
237
-                $i = $tokens[$i]['parenthesis_closer'];
238
-                continue;
239
-            }
240
-
241
-            if ($tokens[$i]['code'] !== T_COMMA) {
242
-                continue;
243
-            }
244
-
245
-            $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
246
-            if ($tokens[$next]['line'] === $tokens[$i]['line']) {
247
-                $error = 'Multi-line '.$type.' declarations must define one parameter per line';
248
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
249
-                if ($fix === true) {
250
-                    $phpcsFile->fixer->addNewline($i);
251
-                }
252
-            }
253
-        }//end for
254
-
255
-    }//end processBracket()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = [
24
+		'PHP',
25
+		'JS',
26
+	];
27
+
28
+
29
+	/**
30
+	 * Determine if this is a multi-line function declaration.
31
+	 *
32
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
33
+	 * @param int                         $stackPtr    The position of the current token
34
+	 *                                                 in the stack passed in $tokens.
35
+	 * @param int                         $openBracket The position of the opening bracket
36
+	 *                                                 in the stack passed in $tokens.
37
+	 * @param array                       $tokens      The stack of tokens that make up
38
+	 *                                                 the file.
39
+	 *
40
+	 * @return void
41
+	 */
42
+	public function isMultiLineDeclaration($phpcsFile, $stackPtr, $openBracket, $tokens)
43
+	{
44
+		$bracketsToCheck = [$stackPtr => $openBracket];
45
+
46
+		// Closures may use the USE keyword and so be multi-line in this way.
47
+		if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
48
+			$use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
49
+			if ($use !== false) {
50
+				$open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
51
+				if ($open !== false) {
52
+					$bracketsToCheck[$use] = $open;
53
+				}
54
+			}
55
+		}
56
+
57
+		foreach ($bracketsToCheck as $stackPtr => $openBracket) {
58
+			// If the first argument is on a new line, this is a multi-line
59
+			// function declaration, even if there is only one argument.
60
+			$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true);
61
+			if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
62
+				return true;
63
+			}
64
+
65
+			$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
66
+
67
+			$end = $phpcsFile->findEndOfStatement($openBracket + 1);
68
+			while ($tokens[$end]['code'] === T_COMMA) {
69
+				// If the next bit of code is not on the same line, this is a
70
+				// multi-line function declaration.
71
+				$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
72
+				if ($next === false) {
73
+					continue(2);
74
+				}
75
+
76
+				if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
77
+					return true;
78
+				}
79
+
80
+				$end = $phpcsFile->findEndOfStatement($next);
81
+			}
82
+
83
+			// We've reached the last argument, so see if the next content
84
+			// (should be the close bracket) is also on the same line.
85
+			$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
86
+			if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
87
+				return true;
88
+			}
89
+		}//end foreach
90
+
91
+		return false;
92
+
93
+	}//end isMultiLineDeclaration()
94
+
95
+
96
+	/**
97
+	 * Processes single-line declarations.
98
+	 *
99
+	 * Just uses the Generic BSD-Allman brace sniff.
100
+	 *
101
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
102
+	 * @param int                         $stackPtr  The position of the current token
103
+	 *                                               in the stack passed in $tokens.
104
+	 * @param array                       $tokens    The stack of tokens that make up
105
+	 *                                               the file.
106
+	 *
107
+	 * @return void
108
+	 */
109
+	public function processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens)
110
+	{
111
+		// We do everything the parent sniff does, and a bit more because we
112
+		// define multi-line declarations a bit differently.
113
+		parent::processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
114
+
115
+		$openingBracket = $tokens[$stackPtr]['parenthesis_opener'];
116
+		$closingBracket = $tokens[$stackPtr]['parenthesis_closer'];
117
+
118
+		$prevNonWhiteSpace = $phpcsFile->findPrevious(T_WHITESPACE, ($closingBracket - 1), $openingBracket, true);
119
+		if ($tokens[$prevNonWhiteSpace]['line'] !== $tokens[$closingBracket]['line']) {
120
+			$error = 'There must not be a newline before the closing parenthesis of a single-line function declaration';
121
+
122
+			if (isset(Tokens::$emptyTokens[$tokens[$prevNonWhiteSpace]['code']]) === true) {
123
+				$phpcsFile->addError($error, $closingBracket, 'CloseBracketNewLine');
124
+			} else {
125
+				$fix = $phpcsFile->addFixableError($error, $closingBracket, 'CloseBracketNewLine');
126
+				if ($fix === true) {
127
+					$phpcsFile->fixer->beginChangeset();
128
+					for ($i = ($closingBracket - 1); $i > $openingBracket; $i--) {
129
+						if ($tokens[$i]['code'] !== T_WHITESPACE) {
130
+							break;
131
+						}
132
+
133
+						$phpcsFile->fixer->replaceToken($i, '');
134
+					}
135
+
136
+					$phpcsFile->fixer->endChangeset();
137
+				}
138
+			}
139
+		}//end if
140
+
141
+	}//end processSingleLineDeclaration()
142
+
143
+
144
+	/**
145
+	 * Processes multi-line declarations.
146
+	 *
147
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
148
+	 * @param int                         $stackPtr  The position of the current token
149
+	 *                                               in the stack passed in $tokens.
150
+	 * @param array                       $tokens    The stack of tokens that make up
151
+	 *                                               the file.
152
+	 *
153
+	 * @return void
154
+	 */
155
+	public function processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens)
156
+	{
157
+		// We do everything the parent sniff does, and a bit more.
158
+		parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
159
+
160
+		$openBracket = $tokens[$stackPtr]['parenthesis_opener'];
161
+		$this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
162
+
163
+		if ($tokens[$stackPtr]['code'] !== T_CLOSURE) {
164
+			return;
165
+		}
166
+
167
+		$use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
168
+		if ($use === false) {
169
+			return;
170
+		}
171
+
172
+		$openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null);
173
+		$this->processBracket($phpcsFile, $openBracket, $tokens, 'use');
174
+
175
+	}//end processMultiLineDeclaration()
176
+
177
+
178
+	/**
179
+	 * Processes the contents of a single set of brackets.
180
+	 *
181
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile   The file being scanned.
182
+	 * @param int                         $openBracket The position of the open bracket
183
+	 *                                                 in the stack passed in $tokens.
184
+	 * @param array                       $tokens      The stack of tokens that make up
185
+	 *                                                 the file.
186
+	 * @param string                      $type        The type of the token the brackets
187
+	 *                                                 belong to (function or use).
188
+	 *
189
+	 * @return void
190
+	 */
191
+	public function processBracket($phpcsFile, $openBracket, $tokens, $type='function')
192
+	{
193
+		$errorPrefix = '';
194
+		if ($type === 'use') {
195
+			$errorPrefix = 'Use';
196
+		}
197
+
198
+		$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
199
+
200
+		// The open bracket should be the last thing on the line.
201
+		if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
202
+			$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($openBracket + 1), null, true);
203
+			if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
204
+				$error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket';
205
+				$fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing');
206
+				if ($fix === true) {
207
+					if ($tokens[$next]['line'] === $tokens[$openBracket]['line']) {
208
+						$phpcsFile->fixer->addNewline($openBracket);
209
+					} else {
210
+						$phpcsFile->fixer->beginChangeset();
211
+						for ($x = $openBracket; $x < $next; $x++) {
212
+							if ($tokens[$x]['line'] === $tokens[$openBracket]['line']) {
213
+								continue;
214
+							}
215
+
216
+							if ($tokens[$x]['line'] === $tokens[$next]['line']) {
217
+								break;
218
+							}
219
+						}
220
+
221
+						$phpcsFile->fixer->endChangeset();
222
+					}
223
+				}
224
+			}//end if
225
+		}//end if
226
+
227
+		// Each line between the brackets should contain a single parameter.
228
+		$lastComma = null;
229
+		for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
230
+			// Skip brackets, like arrays, as they can contain commas.
231
+			if (isset($tokens[$i]['bracket_opener']) === true) {
232
+				$i = $tokens[$i]['bracket_closer'];
233
+				continue;
234
+			}
235
+
236
+			if (isset($tokens[$i]['parenthesis_opener']) === true) {
237
+				$i = $tokens[$i]['parenthesis_closer'];
238
+				continue;
239
+			}
240
+
241
+			if ($tokens[$i]['code'] !== T_COMMA) {
242
+				continue;
243
+			}
244
+
245
+			$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
246
+			if ($tokens[$next]['line'] === $tokens[$i]['line']) {
247
+				$error = 'Multi-line '.$type.' declarations must define one parameter per line';
248
+				$fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
249
+				if ($fix === true) {
250
+					$phpcsFile->fixer->addNewline($i);
251
+				}
252
+			}
253
+		}//end for
254
+
255
+	}//end processBracket()
256 256
 
257 257
 
258 258
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/Functions/GlobalFunctionSniff.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -16,46 +16,46 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * Returns an array of tokens this test wants to listen for.
21
-     *
22
-     * @return array
23
-     */
24
-    public function register()
25
-    {
26
-        return [T_FUNCTION];
27
-
28
-    }//end register()
29
-
30
-
31
-    /**
32
-     * Processes this test, when one of its tokens is encountered.
33
-     *
34
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
35
-     * @param int                         $stackPtr  The position of the current token in the
36
-     *                                               stack passed in $tokens.
37
-     *
38
-     * @return void
39
-     */
40
-    public function process(File $phpcsFile, $stackPtr)
41
-    {
42
-        $tokens = $phpcsFile->getTokens();
43
-
44
-        if (empty($tokens[$stackPtr]['conditions']) === true) {
45
-            $functionName = $phpcsFile->getDeclarationName($stackPtr);
46
-            if ($functionName === null) {
47
-                return;
48
-            }
49
-
50
-            // Special exception for __autoload as it needs to be global.
51
-            if ($functionName !== '__autoload') {
52
-                $error = 'Consider putting global function "%s" in a static class';
53
-                $data  = [$functionName];
54
-                $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
55
-            }
56
-        }
57
-
58
-    }//end process()
19
+	/**
20
+	 * Returns an array of tokens this test wants to listen for.
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function register()
25
+	{
26
+		return [T_FUNCTION];
27
+
28
+	}//end register()
29
+
30
+
31
+	/**
32
+	 * Processes this test, when one of its tokens is encountered.
33
+	 *
34
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
35
+	 * @param int                         $stackPtr  The position of the current token in the
36
+	 *                                               stack passed in $tokens.
37
+	 *
38
+	 * @return void
39
+	 */
40
+	public function process(File $phpcsFile, $stackPtr)
41
+	{
42
+		$tokens = $phpcsFile->getTokens();
43
+
44
+		if (empty($tokens[$stackPtr]['conditions']) === true) {
45
+			$functionName = $phpcsFile->getDeclarationName($stackPtr);
46
+			if ($functionName === null) {
47
+				return;
48
+			}
49
+
50
+			// Special exception for __autoload as it needs to be global.
51
+			if ($functionName !== '__autoload') {
52
+				$error = 'Consider putting global function "%s" in a static class';
53
+				$data  = [$functionName];
54
+				$phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
55
+			}
56
+		}
57
+
58
+	}//end process()
59 59
 
60 60
 
61 61
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -15,71 +15,71 @@
 block discarded – undo
15 15
 class DisallowObjectStringIndexSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['JS'];
24
-
25
-
26
-    /**
27
-     * Returns an array of tokens this test wants to listen for.
28
-     *
29
-     * @return array
30
-     */
31
-    public function register()
32
-    {
33
-        return [T_OPEN_SQUARE_BRACKET];
34
-
35
-    }//end register()
36
-
37
-
38
-    /**
39
-     * Processes this test, when one of its tokens is encountered.
40
-     *
41
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
42
-     * @param int                         $stackPtr  The position of the current token
43
-     *                                               in the stack passed in $tokens.
44
-     *
45
-     * @return void
46
-     */
47
-    public function process(File $phpcsFile, $stackPtr)
48
-    {
49
-        $tokens = $phpcsFile->getTokens();
50
-
51
-        // Check if the next non whitespace token is a string.
52
-        $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
53
-        if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
54
-            return;
55
-        }
56
-
57
-        // Make sure it is the only thing in the square brackets.
58
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
59
-        if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
60
-            return;
61
-        }
62
-
63
-        // Allow indexes that have dots in them because we can't write
64
-        // them in dot notation.
65
-        $content = trim($tokens[$index]['content'], '"\' ');
66
-        if (strpos($content, '.') !== false) {
67
-            return;
68
-        }
69
-
70
-        // Also ignore reserved words.
71
-        if ($content === 'super') {
72
-            return;
73
-        }
74
-
75
-        // Token before the opening square bracket cannot be a var name.
76
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
77
-        if ($tokens[$prev]['code'] === T_STRING) {
78
-            $error = 'Object indexes must be written in dot notation';
79
-            $phpcsFile->addError($error, $prev, 'Found');
80
-        }
81
-
82
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['JS'];
24
+
25
+
26
+	/**
27
+	 * Returns an array of tokens this test wants to listen for.
28
+	 *
29
+	 * @return array
30
+	 */
31
+	public function register()
32
+	{
33
+		return [T_OPEN_SQUARE_BRACKET];
34
+
35
+	}//end register()
36
+
37
+
38
+	/**
39
+	 * Processes this test, when one of its tokens is encountered.
40
+	 *
41
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
42
+	 * @param int                         $stackPtr  The position of the current token
43
+	 *                                               in the stack passed in $tokens.
44
+	 *
45
+	 * @return void
46
+	 */
47
+	public function process(File $phpcsFile, $stackPtr)
48
+	{
49
+		$tokens = $phpcsFile->getTokens();
50
+
51
+		// Check if the next non whitespace token is a string.
52
+		$index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
53
+		if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
54
+			return;
55
+		}
56
+
57
+		// Make sure it is the only thing in the square brackets.
58
+		$next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
59
+		if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
60
+			return;
61
+		}
62
+
63
+		// Allow indexes that have dots in them because we can't write
64
+		// them in dot notation.
65
+		$content = trim($tokens[$index]['content'], '"\' ');
66
+		if (strpos($content, '.') !== false) {
67
+			return;
68
+		}
69
+
70
+		// Also ignore reserved words.
71
+		if ($content === 'super') {
72
+			return;
73
+		}
74
+
75
+		// Token before the opening square bracket cannot be a var name.
76
+		$prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
77
+		if ($tokens[$prev]['code'] === T_STRING) {
78
+			$error = 'Object indexes must be written in dot notation';
79
+			$phpcsFile->addError($error, $prev, 'Found');
80
+		}
81
+
82
+	}//end process()
83 83
 
84 84
 
85 85
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Squiz/Sniffs/CSS/ForbiddenStylesSniff.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@
 block discarded – undo
136 136
      *
137 137
      * @return void
138 138
      */
139
-    protected function addError($phpcsFile, $stackPtr, $style, $pattern=null)
139
+    protected function addError($phpcsFile, $stackPtr, $style, $pattern = null)
140 140
     {
141 141
         $data  = [$style];
142 142
         $error = 'The use of style %s is ';
Please login to merge, or discard this patch.
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -15,163 +15,163 @@
 block discarded – undo
15 15
 class ForbiddenStylesSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['CSS'];
24
-
25
-    /**
26
-     * A list of forbidden styles with their alternatives.
27
-     *
28
-     * The value is NULL if no alternative exists. i.e., the
29
-     * style should just not be used.
30
-     *
31
-     * @var array<string, string|null>
32
-     */
33
-    protected $forbiddenStyles = [
34
-        '-moz-border-radius'             => 'border-radius',
35
-        '-webkit-border-radius'          => 'border-radius',
36
-        '-moz-border-radius-topleft'     => 'border-top-left-radius',
37
-        '-moz-border-radius-topright'    => 'border-top-right-radius',
38
-        '-moz-border-radius-bottomright' => 'border-bottom-right-radius',
39
-        '-moz-border-radius-bottomleft'  => 'border-bottom-left-radius',
40
-        '-moz-box-shadow'                => 'box-shadow',
41
-        '-webkit-box-shadow'             => 'box-shadow',
42
-    ];
43
-
44
-    /**
45
-     * A cache of forbidden style names, for faster lookups.
46
-     *
47
-     * @var string[]
48
-     */
49
-    protected $forbiddenStyleNames = [];
50
-
51
-    /**
52
-     * If true, forbidden styles will be considered regular expressions.
53
-     *
54
-     * @var boolean
55
-     */
56
-    protected $patternMatch = false;
57
-
58
-    /**
59
-     * If true, an error will be thrown; otherwise a warning.
60
-     *
61
-     * @var boolean
62
-     */
63
-    public $error = true;
64
-
65
-
66
-    /**
67
-     * Returns an array of tokens this test wants to listen for.
68
-     *
69
-     * @return array
70
-     */
71
-    public function register()
72
-    {
73
-        $this->forbiddenStyleNames = array_keys($this->forbiddenStyles);
74
-
75
-        if ($this->patternMatch === true) {
76
-            foreach ($this->forbiddenStyleNames as $i => $name) {
77
-                $this->forbiddenStyleNames[$i] = '/'.$name.'/i';
78
-            }
79
-        }
80
-
81
-        return [T_STYLE];
82
-
83
-    }//end register()
84
-
85
-
86
-    /**
87
-     * Processes this test, when one of its tokens is encountered.
88
-     *
89
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
90
-     * @param int                         $stackPtr  The position of the current token in
91
-     *                                               the stack passed in $tokens.
92
-     *
93
-     * @return void
94
-     */
95
-    public function process(File $phpcsFile, $stackPtr)
96
-    {
97
-        $tokens  = $phpcsFile->getTokens();
98
-        $style   = strtolower($tokens[$stackPtr]['content']);
99
-        $pattern = null;
100
-
101
-        if ($this->patternMatch === true) {
102
-            $count   = 0;
103
-            $pattern = preg_replace(
104
-                $this->forbiddenStyleNames,
105
-                $this->forbiddenStyleNames,
106
-                $style,
107
-                1,
108
-                $count
109
-            );
110
-
111
-            if ($count === 0) {
112
-                return;
113
-            }
114
-
115
-            // Remove the pattern delimiters and modifier.
116
-            $pattern = substr($pattern, 1, -2);
117
-        } else {
118
-            if (in_array($style, $this->forbiddenStyleNames, true) === false) {
119
-                return;
120
-            }
121
-        }//end if
122
-
123
-        $this->addError($phpcsFile, $stackPtr, $style, $pattern);
124
-
125
-    }//end process()
126
-
127
-
128
-    /**
129
-     * Generates the error or warning for this sniff.
130
-     *
131
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
132
-     * @param int                         $stackPtr  The position of the forbidden style
133
-     *                                               in the token array.
134
-     * @param string                      $style     The name of the forbidden style.
135
-     * @param string                      $pattern   The pattern used for the match.
136
-     *
137
-     * @return void
138
-     */
139
-    protected function addError($phpcsFile, $stackPtr, $style, $pattern=null)
140
-    {
141
-        $data  = [$style];
142
-        $error = 'The use of style %s is ';
143
-        if ($this->error === true) {
144
-            $type   = 'Found';
145
-            $error .= 'forbidden';
146
-        } else {
147
-            $type   = 'Discouraged';
148
-            $error .= 'discouraged';
149
-        }
150
-
151
-        if ($pattern === null) {
152
-            $pattern = $style;
153
-        }
154
-
155
-        if ($this->forbiddenStyles[$pattern] !== null) {
156
-            $data[] = $this->forbiddenStyles[$pattern];
157
-            if ($this->error === true) {
158
-                $fix = $phpcsFile->addFixableError($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
159
-            } else {
160
-                $fix = $phpcsFile->addFixableWarning($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
161
-            }
162
-
163
-            if ($fix === true) {
164
-                $phpcsFile->fixer->replaceToken($stackPtr, $this->forbiddenStyles[$pattern]);
165
-            }
166
-        } else {
167
-            if ($this->error === true) {
168
-                $phpcsFile->addError($error, $stackPtr, $type, $data);
169
-            } else {
170
-                $phpcsFile->addWarning($error, $stackPtr, $type, $data);
171
-            }
172
-        }
173
-
174
-    }//end addError()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['CSS'];
24
+
25
+	/**
26
+	 * A list of forbidden styles with their alternatives.
27
+	 *
28
+	 * The value is NULL if no alternative exists. i.e., the
29
+	 * style should just not be used.
30
+	 *
31
+	 * @var array<string, string|null>
32
+	 */
33
+	protected $forbiddenStyles = [
34
+		'-moz-border-radius'             => 'border-radius',
35
+		'-webkit-border-radius'          => 'border-radius',
36
+		'-moz-border-radius-topleft'     => 'border-top-left-radius',
37
+		'-moz-border-radius-topright'    => 'border-top-right-radius',
38
+		'-moz-border-radius-bottomright' => 'border-bottom-right-radius',
39
+		'-moz-border-radius-bottomleft'  => 'border-bottom-left-radius',
40
+		'-moz-box-shadow'                => 'box-shadow',
41
+		'-webkit-box-shadow'             => 'box-shadow',
42
+	];
43
+
44
+	/**
45
+	 * A cache of forbidden style names, for faster lookups.
46
+	 *
47
+	 * @var string[]
48
+	 */
49
+	protected $forbiddenStyleNames = [];
50
+
51
+	/**
52
+	 * If true, forbidden styles will be considered regular expressions.
53
+	 *
54
+	 * @var boolean
55
+	 */
56
+	protected $patternMatch = false;
57
+
58
+	/**
59
+	 * If true, an error will be thrown; otherwise a warning.
60
+	 *
61
+	 * @var boolean
62
+	 */
63
+	public $error = true;
64
+
65
+
66
+	/**
67
+	 * Returns an array of tokens this test wants to listen for.
68
+	 *
69
+	 * @return array
70
+	 */
71
+	public function register()
72
+	{
73
+		$this->forbiddenStyleNames = array_keys($this->forbiddenStyles);
74
+
75
+		if ($this->patternMatch === true) {
76
+			foreach ($this->forbiddenStyleNames as $i => $name) {
77
+				$this->forbiddenStyleNames[$i] = '/'.$name.'/i';
78
+			}
79
+		}
80
+
81
+		return [T_STYLE];
82
+
83
+	}//end register()
84
+
85
+
86
+	/**
87
+	 * Processes this test, when one of its tokens is encountered.
88
+	 *
89
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
90
+	 * @param int                         $stackPtr  The position of the current token in
91
+	 *                                               the stack passed in $tokens.
92
+	 *
93
+	 * @return void
94
+	 */
95
+	public function process(File $phpcsFile, $stackPtr)
96
+	{
97
+		$tokens  = $phpcsFile->getTokens();
98
+		$style   = strtolower($tokens[$stackPtr]['content']);
99
+		$pattern = null;
100
+
101
+		if ($this->patternMatch === true) {
102
+			$count   = 0;
103
+			$pattern = preg_replace(
104
+				$this->forbiddenStyleNames,
105
+				$this->forbiddenStyleNames,
106
+				$style,
107
+				1,
108
+				$count
109
+			);
110
+
111
+			if ($count === 0) {
112
+				return;
113
+			}
114
+
115
+			// Remove the pattern delimiters and modifier.
116
+			$pattern = substr($pattern, 1, -2);
117
+		} else {
118
+			if (in_array($style, $this->forbiddenStyleNames, true) === false) {
119
+				return;
120
+			}
121
+		}//end if
122
+
123
+		$this->addError($phpcsFile, $stackPtr, $style, $pattern);
124
+
125
+	}//end process()
126
+
127
+
128
+	/**
129
+	 * Generates the error or warning for this sniff.
130
+	 *
131
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
132
+	 * @param int                         $stackPtr  The position of the forbidden style
133
+	 *                                               in the token array.
134
+	 * @param string                      $style     The name of the forbidden style.
135
+	 * @param string                      $pattern   The pattern used for the match.
136
+	 *
137
+	 * @return void
138
+	 */
139
+	protected function addError($phpcsFile, $stackPtr, $style, $pattern=null)
140
+	{
141
+		$data  = [$style];
142
+		$error = 'The use of style %s is ';
143
+		if ($this->error === true) {
144
+			$type   = 'Found';
145
+			$error .= 'forbidden';
146
+		} else {
147
+			$type   = 'Discouraged';
148
+			$error .= 'discouraged';
149
+		}
150
+
151
+		if ($pattern === null) {
152
+			$pattern = $style;
153
+		}
154
+
155
+		if ($this->forbiddenStyles[$pattern] !== null) {
156
+			$data[] = $this->forbiddenStyles[$pattern];
157
+			if ($this->error === true) {
158
+				$fix = $phpcsFile->addFixableError($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
159
+			} else {
160
+				$fix = $phpcsFile->addFixableWarning($error.'; use %s instead', $stackPtr, $type.'WithAlternative', $data);
161
+			}
162
+
163
+			if ($fix === true) {
164
+				$phpcsFile->fixer->replaceToken($stackPtr, $this->forbiddenStyles[$pattern]);
165
+			}
166
+		} else {
167
+			if ($this->error === true) {
168
+				$phpcsFile->addError($error, $stackPtr, $type, $data);
169
+			} else {
170
+				$phpcsFile->addWarning($error, $stackPtr, $type, $data);
171
+			}
172
+		}
173
+
174
+	}//end addError()
175 175
 
176 176
 
177 177
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/CSS/ClassDefinitionNameSpacingSniff.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
 
58 58
         // Find the first blank line before this opening brace, unless we get
59 59
         // to another style definition, comment or the start of the file.
60
-        $endTokens  = [
60
+        $endTokens = [
61 61
             T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
62 62
             T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
63 63
             T_OPEN_TAG            => T_OPEN_TAG,
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -16,96 +16,96 @@
 block discarded – undo
16 16
 class ClassDefinitionNameSpacingSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = ['CSS'];
25
-
26
-
27
-    /**
28
-     * Returns the token types that this sniff is interested in.
29
-     *
30
-     * @return int[]
31
-     */
32
-    public function register()
33
-    {
34
-        return [T_OPEN_CURLY_BRACKET];
35
-
36
-    }//end register()
37
-
38
-
39
-    /**
40
-     * Processes the tokens that this sniff is interested in.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
-     * @param int                         $stackPtr  The position in the stack where
44
-     *                                               the token was found.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
51
-
52
-        if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
53
-            // Syntax error or live coding, bow out.
54
-            return;
55
-        }
56
-
57
-        // Do not check nested style definitions as, for example, in @media style rules.
58
-        $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
59
-        if ($nested !== false) {
60
-            return;
61
-        }
62
-
63
-        // Find the first blank line before this opening brace, unless we get
64
-        // to another style definition, comment or the start of the file.
65
-        $endTokens  = [
66
-            T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
67
-            T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
68
-            T_OPEN_TAG            => T_OPEN_TAG,
69
-        ];
70
-        $endTokens += Tokens::$commentTokens;
71
-
72
-        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
73
-
74
-        $foundContent = false;
75
-        $currentLine  = $tokens[$prev]['line'];
76
-        for ($i = ($stackPtr - 1); $i >= 0; $i--) {
77
-            if (isset($endTokens[$tokens[$i]['code']]) === true) {
78
-                break;
79
-            }
80
-
81
-            if ($tokens[$i]['line'] === $currentLine) {
82
-                if ($tokens[$i]['code'] !== T_WHITESPACE) {
83
-                    $foundContent = true;
84
-                }
85
-
86
-                continue;
87
-            }
88
-
89
-            // We changed lines.
90
-            if ($foundContent === false) {
91
-                // Before we throw an error, make sure we are not looking
92
-                // at a gap before the style definition.
93
-                $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
94
-                if ($prev !== false
95
-                    && isset($endTokens[$tokens[$prev]['code']]) === false
96
-                ) {
97
-                    $error = 'Blank lines are not allowed between class names';
98
-                    $phpcsFile->addError($error, ($i + 1), 'BlankLinesFound');
99
-                }
100
-
101
-                break;
102
-            }
103
-
104
-            $foundContent = false;
105
-            $currentLine  = $tokens[$i]['line'];
106
-        }//end for
107
-
108
-    }//end process()
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = ['CSS'];
25
+
26
+
27
+	/**
28
+	 * Returns the token types that this sniff is interested in.
29
+	 *
30
+	 * @return int[]
31
+	 */
32
+	public function register()
33
+	{
34
+		return [T_OPEN_CURLY_BRACKET];
35
+
36
+	}//end register()
37
+
38
+
39
+	/**
40
+	 * Processes the tokens that this sniff is interested in.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
+	 * @param int                         $stackPtr  The position in the stack where
44
+	 *                                               the token was found.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51
+
52
+		if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
53
+			// Syntax error or live coding, bow out.
54
+			return;
55
+		}
56
+
57
+		// Do not check nested style definitions as, for example, in @media style rules.
58
+		$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
59
+		if ($nested !== false) {
60
+			return;
61
+		}
62
+
63
+		// Find the first blank line before this opening brace, unless we get
64
+		// to another style definition, comment or the start of the file.
65
+		$endTokens  = [
66
+			T_OPEN_CURLY_BRACKET  => T_OPEN_CURLY_BRACKET,
67
+			T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
68
+			T_OPEN_TAG            => T_OPEN_TAG,
69
+		];
70
+		$endTokens += Tokens::$commentTokens;
71
+
72
+		$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
73
+
74
+		$foundContent = false;
75
+		$currentLine  = $tokens[$prev]['line'];
76
+		for ($i = ($stackPtr - 1); $i >= 0; $i--) {
77
+			if (isset($endTokens[$tokens[$i]['code']]) === true) {
78
+				break;
79
+			}
80
+
81
+			if ($tokens[$i]['line'] === $currentLine) {
82
+				if ($tokens[$i]['code'] !== T_WHITESPACE) {
83
+					$foundContent = true;
84
+				}
85
+
86
+				continue;
87
+			}
88
+
89
+			// We changed lines.
90
+			if ($foundContent === false) {
91
+				// Before we throw an error, make sure we are not looking
92
+				// at a gap before the style definition.
93
+				$prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true);
94
+				if ($prev !== false
95
+					&& isset($endTokens[$tokens[$prev]['code']]) === false
96
+				) {
97
+					$error = 'Blank lines are not allowed between class names';
98
+					$phpcsFile->addError($error, ($i + 1), 'BlankLinesFound');
99
+				}
100
+
101
+				break;
102
+			}
103
+
104
+			$foundContent = false;
105
+			$currentLine  = $tokens[$i]['line'];
106
+		}//end for
107
+
108
+	}//end process()
109 109
 
110 110
 
111 111
 }//end class
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/Squiz/Sniffs/CSS/ColonSpacingSniff.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -16,92 +16,92 @@
 block discarded – undo
16 16
 class ColonSpacingSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = ['CSS'];
25
-
26
-
27
-    /**
28
-     * Returns the token types that this sniff is interested in.
29
-     *
30
-     * @return int[]
31
-     */
32
-    public function register()
33
-    {
34
-        return [T_COLON];
35
-
36
-    }//end register()
37
-
38
-
39
-    /**
40
-     * Processes the tokens that this sniff is interested in.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
-     * @param int                         $stackPtr  The position in the stack where
44
-     *                                               the token was found.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
51
-
52
-        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
53
-        if ($tokens[$prev]['code'] !== T_STYLE) {
54
-            // The colon is not part of a style definition.
55
-            return;
56
-        }
57
-
58
-        if ($tokens[$prev]['content'] === 'progid') {
59
-            // Special case for IE filters.
60
-            return;
61
-        }
62
-
63
-        if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) {
64
-            $error = 'There must be no space before a colon in a style definition';
65
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
66
-            if ($fix === true) {
67
-                $phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
68
-            }
69
-        }
70
-
71
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
72
-        if ($tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['code'] === T_STYLE) {
73
-            // Empty style definition, ignore it.
74
-            return;
75
-        }
76
-
77
-        if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
78
-            $error = 'Expected 1 space after colon in style definition; 0 found';
79
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoneAfter');
80
-            if ($fix === true) {
81
-                $phpcsFile->fixer->addContent($stackPtr, ' ');
82
-            }
83
-        } else {
84
-            $content = $tokens[($stackPtr + 1)]['content'];
85
-            if (strpos($content, $phpcsFile->eolChar) === false) {
86
-                $length = strlen($content);
87
-                if ($length !== 1) {
88
-                    $error = 'Expected 1 space after colon in style definition; %s found';
89
-                    $data  = [$length];
90
-                    $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'After', $data);
91
-                    if ($fix === true) {
92
-                        $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
93
-                    }
94
-                }
95
-            } else {
96
-                $error = 'Expected 1 space after colon in style definition; newline found';
97
-                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'AfterNewline');
98
-                if ($fix === true) {
99
-                    $phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
100
-                }
101
-            }
102
-        }//end if
103
-
104
-    }//end process()
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = ['CSS'];
25
+
26
+
27
+	/**
28
+	 * Returns the token types that this sniff is interested in.
29
+	 *
30
+	 * @return int[]
31
+	 */
32
+	public function register()
33
+	{
34
+		return [T_COLON];
35
+
36
+	}//end register()
37
+
38
+
39
+	/**
40
+	 * Processes the tokens that this sniff is interested in.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
+	 * @param int                         $stackPtr  The position in the stack where
44
+	 *                                               the token was found.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51
+
52
+		$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
53
+		if ($tokens[$prev]['code'] !== T_STYLE) {
54
+			// The colon is not part of a style definition.
55
+			return;
56
+		}
57
+
58
+		if ($tokens[$prev]['content'] === 'progid') {
59
+			// Special case for IE filters.
60
+			return;
61
+		}
62
+
63
+		if ($tokens[($stackPtr - 1)]['code'] === T_WHITESPACE) {
64
+			$error = 'There must be no space before a colon in a style definition';
65
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Before');
66
+			if ($fix === true) {
67
+				$phpcsFile->fixer->replaceToken(($stackPtr - 1), '');
68
+			}
69
+		}
70
+
71
+		$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
72
+		if ($tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['code'] === T_STYLE) {
73
+			// Empty style definition, ignore it.
74
+			return;
75
+		}
76
+
77
+		if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
78
+			$error = 'Expected 1 space after colon in style definition; 0 found';
79
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoneAfter');
80
+			if ($fix === true) {
81
+				$phpcsFile->fixer->addContent($stackPtr, ' ');
82
+			}
83
+		} else {
84
+			$content = $tokens[($stackPtr + 1)]['content'];
85
+			if (strpos($content, $phpcsFile->eolChar) === false) {
86
+				$length = strlen($content);
87
+				if ($length !== 1) {
88
+					$error = 'Expected 1 space after colon in style definition; %s found';
89
+					$data  = [$length];
90
+					$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'After', $data);
91
+					if ($fix === true) {
92
+						$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
93
+					}
94
+				}
95
+			} else {
96
+				$error = 'Expected 1 space after colon in style definition; newline found';
97
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'AfterNewline');
98
+				if ($fix === true) {
99
+					$phpcsFile->fixer->replaceToken(($stackPtr + 1), ' ');
100
+				}
101
+			}
102
+		}//end if
103
+
104
+	}//end process()
105 105
 
106 106
 
107 107
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/CSS/EmptyStyleDefinitionSniff.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -16,49 +16,49 @@
 block discarded – undo
16 16
 class EmptyStyleDefinitionSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = ['CSS'];
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = ['CSS'];
25 25
 
26 26
 
27
-    /**
28
-     * Returns the token types that this sniff is interested in.
29
-     *
30
-     * @return int[]
31
-     */
32
-    public function register()
33
-    {
34
-        return [T_STYLE];
27
+	/**
28
+	 * Returns the token types that this sniff is interested in.
29
+	 *
30
+	 * @return int[]
31
+	 */
32
+	public function register()
33
+	{
34
+		return [T_STYLE];
35 35
 
36
-    }//end register()
36
+	}//end register()
37 37
 
38 38
 
39
-    /**
40
-     * Processes the tokens that this sniff is interested in.
41
-     *
42
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
-     * @param int                         $stackPtr  The position in the stack where
44
-     *                                               the token was found.
45
-     *
46
-     * @return void
47
-     */
48
-    public function process(File $phpcsFile, $stackPtr)
49
-    {
50
-        $tokens = $phpcsFile->getTokens();
39
+	/**
40
+	 * Processes the tokens that this sniff is interested in.
41
+	 *
42
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
43
+	 * @param int                         $stackPtr  The position in the stack where
44
+	 *                                               the token was found.
45
+	 *
46
+	 * @return void
47
+	 */
48
+	public function process(File $phpcsFile, $stackPtr)
49
+	{
50
+		$tokens = $phpcsFile->getTokens();
51 51
 
52
-        $ignore   = Tokens::$emptyTokens;
53
-        $ignore[] = T_COLON;
52
+		$ignore   = Tokens::$emptyTokens;
53
+		$ignore[] = T_COLON;
54 54
 
55
-        $next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
56
-        if ($next === false || $tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
57
-            $error = 'Style definition is empty';
58
-            $phpcsFile->addError($error, $stackPtr, 'Found');
59
-        }
55
+		$next = $phpcsFile->findNext($ignore, ($stackPtr + 1), null, true);
56
+		if ($next === false || $tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
57
+			$error = 'Style definition is empty';
58
+			$phpcsFile->addError($error, $stackPtr, 'Found');
59
+		}
60 60
 
61
-    }//end process()
61
+	}//end process()
62 62
 
63 63
 
64 64
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/CSS/LowercaseStyleDefinitionSniff.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -15,83 +15,83 @@
 block discarded – undo
15 15
 class LowercaseStyleDefinitionSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['CSS'];
24
-
25
-
26
-    /**
27
-     * Returns the token types that this sniff is interested in.
28
-     *
29
-     * @return int[]
30
-     */
31
-    public function register()
32
-    {
33
-        return [T_OPEN_CURLY_BRACKET];
34
-
35
-    }//end register()
36
-
37
-
38
-    /**
39
-     * Processes the tokens that this sniff is interested in.
40
-     *
41
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
42
-     * @param int                         $stackPtr  The position in the stack where
43
-     *                                               the token was found.
44
-     *
45
-     * @return void
46
-     */
47
-    public function process(File $phpcsFile, $stackPtr)
48
-    {
49
-        $tokens  = $phpcsFile->getTokens();
50
-        $start   = ($stackPtr + 1);
51
-        $end     = ($tokens[$stackPtr]['bracket_closer'] - 1);
52
-        $inStyle = null;
53
-
54
-        for ($i = $start; $i <= $end; $i++) {
55
-            // Skip nested definitions as they are checked individually.
56
-            if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
57
-                $i = $tokens[$i]['bracket_closer'];
58
-                continue;
59
-            }
60
-
61
-            if ($tokens[$i]['code'] === T_STYLE) {
62
-                $inStyle = $tokens[$i]['content'];
63
-            }
64
-
65
-            if ($tokens[$i]['code'] === T_SEMICOLON) {
66
-                $inStyle = null;
67
-            }
68
-
69
-            if ($inStyle === 'progid') {
70
-                // Special case for IE filters.
71
-                continue;
72
-            }
73
-
74
-            if ($tokens[$i]['code'] === T_STYLE
75
-                || ($inStyle !== null
76
-                && $tokens[$i]['code'] === T_STRING)
77
-            ) {
78
-                $expected = strtolower($tokens[$i]['content']);
79
-                if ($expected !== $tokens[$i]['content']) {
80
-                    $error = 'Style definitions must be lowercase; expected %s but found %s';
81
-                    $data  = [
82
-                        $expected,
83
-                        $tokens[$i]['content'],
84
-                    ];
85
-
86
-                    $fix = $phpcsFile->addFixableError($error, $i, 'FoundUpper', $data);
87
-                    if ($fix === true) {
88
-                        $phpcsFile->fixer->replaceToken($i, $expected);
89
-                    }
90
-                }
91
-            }
92
-        }//end for
93
-
94
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['CSS'];
24
+
25
+
26
+	/**
27
+	 * Returns the token types that this sniff is interested in.
28
+	 *
29
+	 * @return int[]
30
+	 */
31
+	public function register()
32
+	{
33
+		return [T_OPEN_CURLY_BRACKET];
34
+
35
+	}//end register()
36
+
37
+
38
+	/**
39
+	 * Processes the tokens that this sniff is interested in.
40
+	 *
41
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
42
+	 * @param int                         $stackPtr  The position in the stack where
43
+	 *                                               the token was found.
44
+	 *
45
+	 * @return void
46
+	 */
47
+	public function process(File $phpcsFile, $stackPtr)
48
+	{
49
+		$tokens  = $phpcsFile->getTokens();
50
+		$start   = ($stackPtr + 1);
51
+		$end     = ($tokens[$stackPtr]['bracket_closer'] - 1);
52
+		$inStyle = null;
53
+
54
+		for ($i = $start; $i <= $end; $i++) {
55
+			// Skip nested definitions as they are checked individually.
56
+			if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
57
+				$i = $tokens[$i]['bracket_closer'];
58
+				continue;
59
+			}
60
+
61
+			if ($tokens[$i]['code'] === T_STYLE) {
62
+				$inStyle = $tokens[$i]['content'];
63
+			}
64
+
65
+			if ($tokens[$i]['code'] === T_SEMICOLON) {
66
+				$inStyle = null;
67
+			}
68
+
69
+			if ($inStyle === 'progid') {
70
+				// Special case for IE filters.
71
+				continue;
72
+			}
73
+
74
+			if ($tokens[$i]['code'] === T_STYLE
75
+				|| ($inStyle !== null
76
+				&& $tokens[$i]['code'] === T_STRING)
77
+			) {
78
+				$expected = strtolower($tokens[$i]['content']);
79
+				if ($expected !== $tokens[$i]['content']) {
80
+					$error = 'Style definitions must be lowercase; expected %s but found %s';
81
+					$data  = [
82
+						$expected,
83
+						$tokens[$i]['content'],
84
+					];
85
+
86
+					$fix = $phpcsFile->addFixableError($error, $i, 'FoundUpper', $data);
87
+					if ($fix === true) {
88
+						$phpcsFile->fixer->replaceToken($i, $expected);
89
+					}
90
+				}
91
+			}
92
+		}//end for
93
+
94
+	}//end process()
95 95
 
96 96
 
97 97
 }//end class
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/CSS/DuplicateStyleDefinitionSniff.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
             } else {
76 76
                 $styleNames[$name] = $next;
77 77
             }
78
-        } while ($next !== false);
78
+        }while ($next !== false);
79 79
 
80 80
     }//end process()
81 81
 
Please login to merge, or discard this patch.
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -15,74 +15,74 @@
 block discarded – undo
15 15
 class DuplicateStyleDefinitionSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = ['CSS'];
24
-
25
-
26
-    /**
27
-     * Returns the token types that this sniff is interested in.
28
-     *
29
-     * @return int[]
30
-     */
31
-    public function register()
32
-    {
33
-        return [T_OPEN_CURLY_BRACKET];
34
-
35
-    }//end register()
36
-
37
-
38
-    /**
39
-     * Processes the tokens that this sniff is interested in.
40
-     *
41
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
42
-     * @param int                         $stackPtr  The position in the stack where
43
-     *                                               the token was found.
44
-     *
45
-     * @return void
46
-     */
47
-    public function process(File $phpcsFile, $stackPtr)
48
-    {
49
-        $tokens = $phpcsFile->getTokens();
50
-
51
-        if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
52
-            // Syntax error or live coding, bow out.
53
-            return;
54
-        }
55
-
56
-        // Find the content of each style definition name.
57
-        $styleNames = [];
58
-
59
-        $next = $stackPtr;
60
-        $end  = $tokens[$stackPtr]['bracket_closer'];
61
-
62
-        do {
63
-            $next = $phpcsFile->findNext([T_STYLE, T_OPEN_CURLY_BRACKET], ($next + 1), $end);
64
-            if ($next === false) {
65
-                // Class definition is empty.
66
-                break;
67
-            }
68
-
69
-            if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) {
70
-                $next = $tokens[$next]['bracket_closer'];
71
-                continue;
72
-            }
73
-
74
-            $name = $tokens[$next]['content'];
75
-            if (isset($styleNames[$name]) === true) {
76
-                $first = $styleNames[$name];
77
-                $error = 'Duplicate style definition found; first defined on line %s';
78
-                $data  = [$tokens[$first]['line']];
79
-                $phpcsFile->addError($error, $next, 'Found', $data);
80
-            } else {
81
-                $styleNames[$name] = $next;
82
-            }
83
-        } while ($next !== false);
84
-
85
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = ['CSS'];
24
+
25
+
26
+	/**
27
+	 * Returns the token types that this sniff is interested in.
28
+	 *
29
+	 * @return int[]
30
+	 */
31
+	public function register()
32
+	{
33
+		return [T_OPEN_CURLY_BRACKET];
34
+
35
+	}//end register()
36
+
37
+
38
+	/**
39
+	 * Processes the tokens that this sniff is interested in.
40
+	 *
41
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
42
+	 * @param int                         $stackPtr  The position in the stack where
43
+	 *                                               the token was found.
44
+	 *
45
+	 * @return void
46
+	 */
47
+	public function process(File $phpcsFile, $stackPtr)
48
+	{
49
+		$tokens = $phpcsFile->getTokens();
50
+
51
+		if (isset($tokens[$stackPtr]['bracket_closer']) === false) {
52
+			// Syntax error or live coding, bow out.
53
+			return;
54
+		}
55
+
56
+		// Find the content of each style definition name.
57
+		$styleNames = [];
58
+
59
+		$next = $stackPtr;
60
+		$end  = $tokens[$stackPtr]['bracket_closer'];
61
+
62
+		do {
63
+			$next = $phpcsFile->findNext([T_STYLE, T_OPEN_CURLY_BRACKET], ($next + 1), $end);
64
+			if ($next === false) {
65
+				// Class definition is empty.
66
+				break;
67
+			}
68
+
69
+			if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) {
70
+				$next = $tokens[$next]['bracket_closer'];
71
+				continue;
72
+			}
73
+
74
+			$name = $tokens[$next]['content'];
75
+			if (isset($styleNames[$name]) === true) {
76
+				$first = $styleNames[$name];
77
+				$error = 'Duplicate style definition found; first defined on line %s';
78
+				$data  = [$tokens[$first]['line']];
79
+				$phpcsFile->addError($error, $next, 'Found', $data);
80
+			} else {
81
+				$styleNames[$name] = $next;
82
+			}
83
+		} while ($next !== false);
84
+
85
+	}//end process()
86 86
 
87 87
 
88 88
 }//end class
Please login to merge, or discard this patch.