GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 699b70...879176 )
by Chris
13:23
created
Standards/Squiz/Sniffs/Functions/MultiLineFunctionDeclarationSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@
 block discarded – undo
55 55
      * @param array                $tokens      The stack of tokens that make up
56 56
      *                                          the file.
57 57
      *
58
-     * @return void
58
+     * @return boolean
59 59
      */
60 60
     public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
61 61
     {
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -13,8 +13,8 @@  discard block
 block discarded – undo
13 13
  */
14 14
 
15 15
 if (class_exists('PEAR_Sniffs_Functions_FunctionDeclarationSniff', true) === false) {
16
-    $error = 'Class PEAR_Sniffs_Functions_FunctionDeclarationSniff not found';
17
-    throw new PHP_CodeSniffer_Exception($error);
16
+	 $error = 'Class PEAR_Sniffs_Functions_FunctionDeclarationSniff not found';
17
+	 throw new PHP_CodeSniffer_Exception($error);
18 18
 }
19 19
 
20 20
 /**
@@ -33,188 +33,188 @@  discard block
 block discarded – undo
33 33
 class Squiz_Sniffs_Functions_MultiLineFunctionDeclarationSniff extends PEAR_Sniffs_Functions_FunctionDeclarationSniff
34 34
 {
35 35
 
36
-    /**
37
-     * A list of tokenizers this sniff supports.
38
-     *
39
-     * @var array
40
-     */
41
-    public $supportedTokenizers = array(
42
-                                   'PHP',
43
-                                   'JS',
44
-                                  );
45
-
46
-
47
-    /**
48
-     * Determine if this is a multi-line function declaration.
49
-     *
50
-     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
51
-     * @param int                  $stackPtr    The position of the current token
52
-     *                                          in the stack passed in $tokens.
53
-     * @param int                  $openBracket The position of the opening bracket
54
-     *                                          in the stack passed in $tokens.
55
-     * @param array                $tokens      The stack of tokens that make up
56
-     *                                          the file.
57
-     *
58
-     * @return void
59
-     */
60
-    public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
61
-    {
62
-        $bracketsToCheck = array($stackPtr => $openBracket);
63
-
64
-        // Closures may use the USE keyword and so be multi-line in this way.
65
-        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
66
-            $use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
67
-            if ($use !== false) {
68
-                $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
69
-                if ($open !== false) {
70
-                    $bracketsToCheck[$use] = $open;
71
-                }
72
-            }
73
-        }
74
-
75
-        foreach ($bracketsToCheck as $stackPtr => $openBracket) {
76
-            // If the first argument is on a new line, this is a multi-line
77
-            // function declaration, even if there is only one argument.
78
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
79
-            if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
80
-                return true;
81
-            }
82
-
83
-            $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
84
-
85
-            $end = $phpcsFile->findEndOfStatement($openBracket + 1);
86
-            while ($tokens[$end]['code'] === T_COMMA) {
87
-                // If the next bit of code is not on the same line, this is a
88
-                // multi-line function declaration.
89
-                $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
90
-                if ($next === false) {
91
-                    continue(2);
92
-                }
93
-
94
-                if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
95
-                    return true;
96
-                }
97
-
98
-                $end = $phpcsFile->findEndOfStatement($next);
99
-            }
100
-
101
-            // We've reached the last argument, so see if the next content
102
-            // (should be the close bracket) is also on the same line.
103
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
104
-            if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
105
-                return true;
106
-            }
107
-        }//end foreach
108
-
109
-        return false;
110
-
111
-    }//end isMultiLineDeclaration()
112
-
113
-
114
-    /**
115
-     * Processes multi-line declarations.
116
-     *
117
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
118
-     * @param int                  $stackPtr  The position of the current token
119
-     *                                        in the stack passed in $tokens.
120
-     * @param array                $tokens    The stack of tokens that make up
121
-     *                                        the file.
122
-     *
123
-     * @return void
124
-     */
125
-    public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
126
-    {
127
-        // We do everything the parent sniff does, and a bit more.
128
-        parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
129
-
130
-        $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
131
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
132
-
133
-        if ($tokens[$stackPtr]['code'] !== T_CLOSURE) {
134
-            return;
135
-        }
136
-
137
-        $use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
138
-        if ($use === false) {
139
-            return;
140
-        }
141
-
142
-        $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null);
143
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'use');
144
-
145
-        // Also check spacing.
146
-        if ($tokens[($use - 1)]['code'] === T_WHITESPACE) {
147
-            $gap = strlen($tokens[($use - 1)]['content']);
148
-        } else {
149
-            $gap = 0;
150
-        }
151
-
152
-    }//end processMultiLineDeclaration()
153
-
154
-
155
-    /**
156
-     * Processes the contents of a single set of brackets.
157
-     *
158
-     * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
159
-     * @param int                  $openBracket The position of the open bracket
160
-     *                                          in the stack passed in $tokens.
161
-     * @param array                $tokens      The stack of tokens that make up
162
-     *                                          the file.
163
-     * @param string               $type        The type of the token the brackets
164
-     *                                          belong to (function or use).
165
-     *
166
-     * @return void
167
-     */
168
-    public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function')
169
-    {
170
-        $errorPrefix = '';
171
-        if ($type === 'use') {
172
-            $errorPrefix = 'Use';
173
-        }
174
-
175
-        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
176
-
177
-        // The open bracket should be the last thing on the line.
178
-        if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
179
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
180
-            if ($tokens[$next]['line'] !== ($tokens[$openBracket]['line'] + 1)) {
181
-                $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket';
182
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing');
183
-                if ($fix === true) {
184
-                    $phpcsFile->fixer->addNewline($openBracket);
185
-                }
186
-            }
187
-        }
188
-
189
-        // Each line between the brackets should contain a single parameter.
190
-        $lastComma = null;
191
-        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
192
-            // Skip brackets, like arrays, as they can contain commas.
193
-            if (isset($tokens[$i]['bracket_opener']) === true) {
194
-                $i = $tokens[$i]['bracket_closer'];
195
-                continue;
196
-            }
197
-
198
-            if (isset($tokens[$i]['parenthesis_opener']) === true) {
199
-                $i = $tokens[$i]['parenthesis_closer'];
200
-                continue;
201
-            }
202
-
203
-            if ($tokens[$i]['code'] !== T_COMMA) {
204
-                continue;
205
-            }
206
-
207
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
208
-            if ($tokens[$next]['line'] !== ($tokens[$i]['line'] + 1)) {
209
-                $error = 'Multi-line '.$type.' declarations must define one parameter per line';
210
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
211
-                if ($fix === true) {
212
-                    $phpcsFile->fixer->addNewline($i);
213
-                }
214
-            }
215
-        }//end for
216
-
217
-    }//end processBracket()
36
+	 /**
37
+	  * A list of tokenizers this sniff supports.
38
+	  *
39
+	  * @var array
40
+	  */
41
+	 public $supportedTokenizers = array(
42
+											  'PHP',
43
+											  'JS',
44
+											 );
45
+
46
+
47
+	 /**
48
+	  * Determine if this is a multi-line function declaration.
49
+	  *
50
+	  * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
51
+	  * @param int                  $stackPtr    The position of the current token
52
+	  *                                          in the stack passed in $tokens.
53
+	  * @param int                  $openBracket The position of the opening bracket
54
+	  *                                          in the stack passed in $tokens.
55
+	  * @param array                $tokens      The stack of tokens that make up
56
+	  *                                          the file.
57
+	  *
58
+	  * @return void
59
+	  */
60
+	 public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
61
+	 {
62
+		  $bracketsToCheck = array($stackPtr => $openBracket);
63
+
64
+		  // Closures may use the USE keyword and so be multi-line in this way.
65
+		  if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
66
+				$use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
67
+				if ($use !== false) {
68
+					 $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
69
+					 if ($open !== false) {
70
+						  $bracketsToCheck[$use] = $open;
71
+					 }
72
+				}
73
+		  }
74
+
75
+		  foreach ($bracketsToCheck as $stackPtr => $openBracket) {
76
+				// If the first argument is on a new line, this is a multi-line
77
+				// function declaration, even if there is only one argument.
78
+				$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
79
+				if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
80
+					 return true;
81
+				}
82
+
83
+				$closeBracket = $tokens[$openBracket]['parenthesis_closer'];
84
+
85
+				$end = $phpcsFile->findEndOfStatement($openBracket + 1);
86
+				while ($tokens[$end]['code'] === T_COMMA) {
87
+					 // If the next bit of code is not on the same line, this is a
88
+					 // multi-line function declaration.
89
+					 $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
90
+					 if ($next === false) {
91
+						  continue(2);
92
+					 }
93
+
94
+					 if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
95
+						  return true;
96
+					 }
97
+
98
+					 $end = $phpcsFile->findEndOfStatement($next);
99
+				}
100
+
101
+				// We've reached the last argument, so see if the next content
102
+				// (should be the close bracket) is also on the same line.
103
+				$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
104
+				if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
105
+					 return true;
106
+				}
107
+		  }//end foreach
108
+
109
+		  return false;
110
+
111
+	 }//end isMultiLineDeclaration()
112
+
113
+
114
+	 /**
115
+	  * Processes multi-line declarations.
116
+	  *
117
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
118
+	  * @param int                  $stackPtr  The position of the current token
119
+	  *                                        in the stack passed in $tokens.
120
+	  * @param array                $tokens    The stack of tokens that make up
121
+	  *                                        the file.
122
+	  *
123
+	  * @return void
124
+	  */
125
+	 public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
126
+	 {
127
+		  // We do everything the parent sniff does, and a bit more.
128
+		  parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
129
+
130
+		  $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
131
+		  $this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
132
+
133
+		  if ($tokens[$stackPtr]['code'] !== T_CLOSURE) {
134
+				return;
135
+		  }
136
+
137
+		  $use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
138
+		  if ($use === false) {
139
+				return;
140
+		  }
141
+
142
+		  $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null);
143
+		  $this->processBracket($phpcsFile, $openBracket, $tokens, 'use');
144
+
145
+		  // Also check spacing.
146
+		  if ($tokens[($use - 1)]['code'] === T_WHITESPACE) {
147
+				$gap = strlen($tokens[($use - 1)]['content']);
148
+		  } else {
149
+				$gap = 0;
150
+		  }
151
+
152
+	 }//end processMultiLineDeclaration()
153
+
154
+
155
+	 /**
156
+	  * Processes the contents of a single set of brackets.
157
+	  *
158
+	  * @param PHP_CodeSniffer_File $phpcsFile   The file being scanned.
159
+	  * @param int                  $openBracket The position of the open bracket
160
+	  *                                          in the stack passed in $tokens.
161
+	  * @param array                $tokens      The stack of tokens that make up
162
+	  *                                          the file.
163
+	  * @param string               $type        The type of the token the brackets
164
+	  *                                          belong to (function or use).
165
+	  *
166
+	  * @return void
167
+	  */
168
+	 public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function')
169
+	 {
170
+		  $errorPrefix = '';
171
+		  if ($type === 'use') {
172
+				$errorPrefix = 'Use';
173
+		  }
174
+
175
+		  $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
176
+
177
+		  // The open bracket should be the last thing on the line.
178
+		  if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
179
+				$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
180
+				if ($tokens[$next]['line'] !== ($tokens[$openBracket]['line'] + 1)) {
181
+					 $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket';
182
+					 $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing');
183
+					 if ($fix === true) {
184
+						  $phpcsFile->fixer->addNewline($openBracket);
185
+					 }
186
+				}
187
+		  }
188
+
189
+		  // Each line between the brackets should contain a single parameter.
190
+		  $lastComma = null;
191
+		  for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
192
+				// Skip brackets, like arrays, as they can contain commas.
193
+				if (isset($tokens[$i]['bracket_opener']) === true) {
194
+					 $i = $tokens[$i]['bracket_closer'];
195
+					 continue;
196
+				}
197
+
198
+				if (isset($tokens[$i]['parenthesis_opener']) === true) {
199
+					 $i = $tokens[$i]['parenthesis_closer'];
200
+					 continue;
201
+				}
202
+
203
+				if ($tokens[$i]['code'] !== T_COMMA) {
204
+					 continue;
205
+				}
206
+
207
+				$next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
208
+				if ($tokens[$next]['line'] !== ($tokens[$i]['line'] + 1)) {
209
+					 $error = 'Multi-line '.$type.' declarations must define one parameter per line';
210
+					 $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
211
+					 if ($fix === true) {
212
+						  $phpcsFile->fixer->addNewline($i);
213
+					 }
214
+				}
215
+		  }//end for
216
+
217
+	 }//end processBracket()
218 218
 
219 219
 
220 220
 }//end class
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
  * @link      http://pear.php.net/package/PHP_CodeSniffer
13 13
  */
14 14
 
15
-if (class_exists('PEAR_Sniffs_Functions_FunctionDeclarationSniff', true) === false) {
15
+if ( class_exists( 'PEAR_Sniffs_Functions_FunctionDeclarationSniff', true ) === false ) {
16 16
     $error = 'Class PEAR_Sniffs_Functions_FunctionDeclarationSniff not found';
17
-    throw new PHP_CodeSniffer_Exception($error);
17
+    throw new PHP_CodeSniffer_Exception( $error );
18 18
 }
19 19
 
20 20
 /**
@@ -57,51 +57,51 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return void
59 59
      */
60
-    public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
60
+    public function isMultiLineDeclaration( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens )
61 61
     {
62
-        $bracketsToCheck = array($stackPtr => $openBracket);
62
+        $bracketsToCheck = array( $stackPtr => $openBracket );
63 63
 
64 64
         // Closures may use the USE keyword and so be multi-line in this way.
65
-        if ($tokens[$stackPtr]['code'] === T_CLOSURE) {
66
-            $use = $phpcsFile->findNext(T_USE, ($tokens[$openBracket]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
67
-            if ($use !== false) {
68
-                $open = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1));
69
-                if ($open !== false) {
70
-                    $bracketsToCheck[$use] = $open;
65
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_CLOSURE ) {
66
+            $use = $phpcsFile->findNext( T_USE, ( $tokens[ $openBracket ][ 'parenthesis_closer' ] + 1 ), $tokens[ $stackPtr ][ 'scope_opener' ] );
67
+            if ( $use !== false ) {
68
+                $open = $phpcsFile->findNext( T_OPEN_PARENTHESIS, ( $use + 1 ) );
69
+                if ( $open !== false ) {
70
+                    $bracketsToCheck[ $use ] = $open;
71 71
                 }
72 72
             }
73 73
         }
74 74
 
75
-        foreach ($bracketsToCheck as $stackPtr => $openBracket) {
75
+        foreach ( $bracketsToCheck as $stackPtr => $openBracket ) {
76 76
             // If the first argument is on a new line, this is a multi-line
77 77
             // function declaration, even if there is only one argument.
78
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
79
-            if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
78
+            $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $openBracket + 1 ), null, true );
79
+            if ( $tokens[ $next ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) {
80 80
                 return true;
81 81
             }
82 82
 
83
-            $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
83
+            $closeBracket = $tokens[ $openBracket ][ 'parenthesis_closer' ];
84 84
 
85
-            $end = $phpcsFile->findEndOfStatement($openBracket + 1);
86
-            while ($tokens[$end]['code'] === T_COMMA) {
85
+            $end = $phpcsFile->findEndOfStatement( $openBracket + 1 );
86
+            while ( $tokens[ $end ][ 'code' ] === T_COMMA ) {
87 87
                 // If the next bit of code is not on the same line, this is a
88 88
                 // multi-line function declaration.
89
-                $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
90
-                if ($next === false) {
91
-                    continue(2);
89
+                $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $end + 1 ), $closeBracket, true );
90
+                if ( $next === false ) {
91
+                    continue( 2 );
92 92
                 }
93 93
 
94
-                if ($tokens[$next]['line'] !== $tokens[$end]['line']) {
94
+                if ( $tokens[ $next ][ 'line' ] !== $tokens[ $end ][ 'line' ] ) {
95 95
                     return true;
96 96
                 }
97 97
 
98
-                $end = $phpcsFile->findEndOfStatement($next);
98
+                $end = $phpcsFile->findEndOfStatement( $next );
99 99
             }
100 100
 
101 101
             // We've reached the last argument, so see if the next content
102 102
             // (should be the close bracket) is also on the same line.
103
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($end + 1), $closeBracket, true);
104
-            if ($next !== false && $tokens[$next]['line'] !== $tokens[$end]['line']) {
103
+            $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $end + 1 ), $closeBracket, true );
104
+            if ( $next !== false && $tokens[ $next ][ 'line' ] !== $tokens[ $end ][ 'line' ] ) {
105 105
                 return true;
106 106
             }
107 107
         }//end foreach
@@ -122,29 +122,29 @@  discard block
 block discarded – undo
122 122
      *
123 123
      * @return void
124 124
      */
125
-    public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
125
+    public function processMultiLineDeclaration( PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens )
126 126
     {
127 127
         // We do everything the parent sniff does, and a bit more.
128
-        parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
128
+        parent::processMultiLineDeclaration( $phpcsFile, $stackPtr, $tokens );
129 129
 
130
-        $openBracket = $tokens[$stackPtr]['parenthesis_opener'];
131
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'function');
130
+        $openBracket = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
131
+        $this->processBracket( $phpcsFile, $openBracket, $tokens, 'function' );
132 132
 
133
-        if ($tokens[$stackPtr]['code'] !== T_CLOSURE) {
133
+        if ( $tokens[ $stackPtr ][ 'code' ] !== T_CLOSURE ) {
134 134
             return;
135 135
         }
136 136
 
137
-        $use = $phpcsFile->findNext(T_USE, ($tokens[$stackPtr]['parenthesis_closer'] + 1), $tokens[$stackPtr]['scope_opener']);
138
-        if ($use === false) {
137
+        $use = $phpcsFile->findNext( T_USE, ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] + 1 ), $tokens[ $stackPtr ][ 'scope_opener' ] );
138
+        if ( $use === false ) {
139 139
             return;
140 140
         }
141 141
 
142
-        $openBracket = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($use + 1), null);
143
-        $this->processBracket($phpcsFile, $openBracket, $tokens, 'use');
142
+        $openBracket = $phpcsFile->findNext( T_OPEN_PARENTHESIS, ( $use + 1 ), null );
143
+        $this->processBracket( $phpcsFile, $openBracket, $tokens, 'use' );
144 144
 
145 145
         // Also check spacing.
146
-        if ($tokens[($use - 1)]['code'] === T_WHITESPACE) {
147
-            $gap = strlen($tokens[($use - 1)]['content']);
146
+        if ( $tokens[ ( $use - 1 ) ][ 'code' ] === T_WHITESPACE ) {
147
+            $gap = strlen( $tokens[ ( $use - 1 ) ][ 'content' ] );
148 148
         } else {
149 149
             $gap = 0;
150 150
         }
@@ -165,51 +165,51 @@  discard block
 block discarded – undo
165 165
      *
166 166
      * @return void
167 167
      */
168
-    public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function')
168
+    public function processBracket( PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type = 'function' )
169 169
     {
170 170
         $errorPrefix = '';
171
-        if ($type === 'use') {
171
+        if ( $type === 'use' ) {
172 172
             $errorPrefix = 'Use';
173 173
         }
174 174
 
175
-        $closeBracket = $tokens[$openBracket]['parenthesis_closer'];
175
+        $closeBracket = $tokens[ $openBracket ][ 'parenthesis_closer' ];
176 176
 
177 177
         // The open bracket should be the last thing on the line.
178
-        if ($tokens[$openBracket]['line'] !== $tokens[$closeBracket]['line']) {
179
-            $next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($openBracket + 1), null, true);
180
-            if ($tokens[$next]['line'] !== ($tokens[$openBracket]['line'] + 1)) {
181
-                $error = 'The first parameter of a multi-line '.$type.' declaration must be on the line after the opening bracket';
182
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'FirstParamSpacing');
183
-                if ($fix === true) {
184
-                    $phpcsFile->fixer->addNewline($openBracket);
178
+        if ( $tokens[ $openBracket ][ 'line' ] !== $tokens[ $closeBracket ][ 'line' ] ) {
179
+            $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $openBracket + 1 ), null, true );
180
+            if ( $tokens[ $next ][ 'line' ] !== ( $tokens[ $openBracket ][ 'line' ] + 1 ) ) {
181
+                $error = 'The first parameter of a multi-line ' . $type . ' declaration must be on the line after the opening bracket';
182
+                $fix   = $phpcsFile->addFixableError( $error, $next, $errorPrefix . 'FirstParamSpacing' );
183
+                if ( $fix === true ) {
184
+                    $phpcsFile->fixer->addNewline( $openBracket );
185 185
                 }
186 186
             }
187 187
         }
188 188
 
189 189
         // Each line between the brackets should contain a single parameter.
190 190
         $lastComma = null;
191
-        for ($i = ($openBracket + 1); $i < $closeBracket; $i++) {
191
+        for ( $i = ( $openBracket + 1 ); $i < $closeBracket; $i++ ) {
192 192
             // Skip brackets, like arrays, as they can contain commas.
193
-            if (isset($tokens[$i]['bracket_opener']) === true) {
194
-                $i = $tokens[$i]['bracket_closer'];
193
+            if ( isset( $tokens[ $i ][ 'bracket_opener' ] ) === true ) {
194
+                $i = $tokens[ $i ][ 'bracket_closer' ];
195 195
                 continue;
196 196
             }
197 197
 
198
-            if (isset($tokens[$i]['parenthesis_opener']) === true) {
199
-                $i = $tokens[$i]['parenthesis_closer'];
198
+            if ( isset( $tokens[ $i ][ 'parenthesis_opener' ] ) === true ) {
199
+                $i = $tokens[ $i ][ 'parenthesis_closer' ];
200 200
                 continue;
201 201
             }
202 202
 
203
-            if ($tokens[$i]['code'] !== T_COMMA) {
203
+            if ( $tokens[ $i ][ 'code' ] !== T_COMMA ) {
204 204
                 continue;
205 205
             }
206 206
 
207
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($i + 1), null, true);
208
-            if ($tokens[$next]['line'] !== ($tokens[$i]['line'] + 1)) {
209
-                $error = 'Multi-line '.$type.' declarations must define one parameter per line';
210
-                $fix   = $phpcsFile->addFixableError($error, $next, $errorPrefix.'OneParamPerLine');
211
-                if ($fix === true) {
212
-                    $phpcsFile->fixer->addNewline($i);
207
+            $next = $phpcsFile->findNext( T_WHITESPACE, ( $i + 1 ), null, true );
208
+            if ( $tokens[ $next ][ 'line' ] !== ( $tokens[ $i ][ 'line' ] + 1 ) ) {
209
+                $error = 'Multi-line ' . $type . ' declarations must define one parameter per line';
210
+                $fix   = $phpcsFile->addFixableError( $error, $next, $errorPrefix . 'OneParamPerLine' );
211
+                if ( $fix === true ) {
212
+                    $phpcsFile->fixer->addNewline( $i );
213 213
                 }
214 214
             }
215 215
         }//end for
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,8 +30,7 @@  discard block
 block discarded – undo
30 30
  * @version   Release: @package_version@
31 31
  * @link      http://pear.php.net/package/PHP_CodeSniffer
32 32
  */
33
-class Squiz_Sniffs_Functions_MultiLineFunctionDeclarationSniff extends PEAR_Sniffs_Functions_FunctionDeclarationSniff
34
-{
33
+class Squiz_Sniffs_Functions_MultiLineFunctionDeclarationSniff extends PEAR_Sniffs_Functions_FunctionDeclarationSniff {
35 34
 
36 35
     /**
37 36
      * A list of tokenizers this sniff supports.
@@ -57,8 +56,7 @@  discard block
 block discarded – undo
57 56
      *
58 57
      * @return void
59 58
      */
60
-    public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens)
61
-    {
59
+    public function isMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $openBracket, $tokens) {
62 60
         $bracketsToCheck = array($stackPtr => $openBracket);
63 61
 
64 62
         // Closures may use the USE keyword and so be multi-line in this way.
@@ -122,8 +120,7 @@  discard block
 block discarded – undo
122 120
      *
123 121
      * @return void
124 122
      */
125
-    public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens)
126
-    {
123
+    public function processMultiLineDeclaration(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $tokens) {
127 124
         // We do everything the parent sniff does, and a bit more.
128 125
         parent::processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
129 126
 
@@ -165,8 +162,7 @@  discard block
 block discarded – undo
165 162
      *
166 163
      * @return void
167 164
      */
168
-    public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function')
169
-    {
165
+    public function processBracket(PHP_CodeSniffer_File $phpcsFile, $openBracket, $tokens, $type='function') {
170 166
         $errorPrefix = '';
171 167
         if ($type === 'use') {
172 168
             $errorPrefix = 'Use';
Please login to merge, or discard this patch.
Standards/Squiz/Sniffs/Objects/DisallowObjectStringIndexSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
     /**
38 38
      * Returns an array of tokens this test wants to listen for.
39 39
      *
40
-     * @return array
40
+     * @return string[]
41 41
      */
42 42
     public function register()
43 43
     {
Please login to merge, or discard this patch.
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@
 block discarded – undo
26 26
 class Squiz_Sniffs_Objects_DisallowObjectStringIndexSniff implements PHP_CodeSniffer_Sniff
27 27
 {
28 28
 
29
-    /**
30
-     * A list of tokenizers this sniff supports.
31
-     *
32
-     * @var array
33
-     */
34
-    public $supportedTokenizers = array('JS');
29
+	 /**
30
+	  * A list of tokenizers this sniff supports.
31
+	  *
32
+	  * @var array
33
+	  */
34
+	 public $supportedTokenizers = array('JS');
35 35
 
36 36
 
37
-    /**
38
-     * Returns an array of tokens this test wants to listen for.
39
-     *
40
-     * @return array
41
-     */
42
-    public function register()
43
-    {
44
-        return array(T_OPEN_SQUARE_BRACKET);
37
+	 /**
38
+	  * Returns an array of tokens this test wants to listen for.
39
+	  *
40
+	  * @return array
41
+	  */
42
+	 public function register()
43
+	 {
44
+		  return array(T_OPEN_SQUARE_BRACKET);
45 45
 
46
-    }//end register()
46
+	 }//end register()
47 47
 
48 48
 
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
-     * @param int                  $stackPtr  The position of the current token
54
-     *                                        in the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
60
-        $tokens = $phpcsFile->getTokens();
49
+	 /**
50
+	  * Processes this test, when one of its tokens is encountered.
51
+	  *
52
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
53
+	  * @param int                  $stackPtr  The position of the current token
54
+	  *                                        in the stack passed in $tokens.
55
+	  *
56
+	  * @return void
57
+	  */
58
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
+	 {
60
+		  $tokens = $phpcsFile->getTokens();
61 61
 
62
-        // Check if the next non whitespace token is a string.
63
-        $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
64
-        if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
65
-            return;
66
-        }
62
+		  // Check if the next non whitespace token is a string.
63
+		  $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
64
+		  if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
65
+				return;
66
+		  }
67 67
 
68
-        // Make sure it is the only thing in the square brackets.
69
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
70
-        if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
71
-            return;
72
-        }
68
+		  // Make sure it is the only thing in the square brackets.
69
+		  $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
70
+		  if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
71
+				return;
72
+		  }
73 73
 
74
-        // Allow indexes that have dots in them because we can't write
75
-        // them in dot notation.
76
-        $content = trim($tokens[$index]['content'], '"\' ');
77
-        if (strpos($content, '.') !== false) {
78
-            return;
79
-        }
74
+		  // Allow indexes that have dots in them because we can't write
75
+		  // them in dot notation.
76
+		  $content = trim($tokens[$index]['content'], '"\' ');
77
+		  if (strpos($content, '.') !== false) {
78
+				return;
79
+		  }
80 80
 
81
-        // Also ignore reserved words.
82
-        if ($content === 'super') {
83
-            return;
84
-        }
81
+		  // Also ignore reserved words.
82
+		  if ($content === 'super') {
83
+				return;
84
+		  }
85 85
 
86
-        // Token before the opening square bracket cannot be a var name.
87
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
88
-        if ($tokens[$prev]['code'] === T_STRING) {
89
-            $error = 'Object indexes must be written in dot notation';
90
-            $phpcsFile->addError($error, $prev, 'Found');
91
-        }
86
+		  // Token before the opening square bracket cannot be a var name.
87
+		  $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
88
+		  if ($tokens[$prev]['code'] === T_STRING) {
89
+				$error = 'Object indexes must be written in dot notation';
90
+				$phpcsFile->addError($error, $prev, 'Found');
91
+		  }
92 92
 
93
-    }//end process()
93
+	 }//end process()
94 94
 
95 95
 
96 96
 }//end class
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      *
32 32
      * @var array
33 33
      */
34
-    public $supportedTokenizers = array('JS');
34
+    public $supportedTokenizers = array( 'JS' );
35 35
 
36 36
 
37 37
     /**
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function register()
43 43
     {
44
-        return array(T_OPEN_SQUARE_BRACKET);
44
+        return array( T_OPEN_SQUARE_BRACKET );
45 45
 
46 46
     }//end register()
47 47
 
@@ -55,39 +55,39 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return void
57 57
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
58
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
59 59
     {
60 60
         $tokens = $phpcsFile->getTokens();
61 61
 
62 62
         // Check if the next non whitespace token is a string.
63
-        $index = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
64
-        if ($tokens[$index]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
63
+        $index = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
64
+        if ( $tokens[ $index ][ 'code' ] !== T_CONSTANT_ENCAPSED_STRING ) {
65 65
             return;
66 66
         }
67 67
 
68 68
         // Make sure it is the only thing in the square brackets.
69
-        $next = $phpcsFile->findNext(T_WHITESPACE, ($index + 1), null, true);
70
-        if ($tokens[$next]['code'] !== T_CLOSE_SQUARE_BRACKET) {
69
+        $next = $phpcsFile->findNext( T_WHITESPACE, ( $index + 1 ), null, true );
70
+        if ( $tokens[ $next ][ 'code' ] !== T_CLOSE_SQUARE_BRACKET ) {
71 71
             return;
72 72
         }
73 73
 
74 74
         // Allow indexes that have dots in them because we can't write
75 75
         // them in dot notation.
76
-        $content = trim($tokens[$index]['content'], '"\' ');
77
-        if (strpos($content, '.') !== false) {
76
+        $content = trim( $tokens[ $index ][ 'content' ], '"\' ' );
77
+        if ( strpos( $content, '.' ) !== false ) {
78 78
             return;
79 79
         }
80 80
 
81 81
         // Also ignore reserved words.
82
-        if ($content === 'super') {
82
+        if ( $content === 'super' ) {
83 83
             return;
84 84
         }
85 85
 
86 86
         // Token before the opening square bracket cannot be a var name.
87
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
88
-        if ($tokens[$prev]['code'] === T_STRING) {
87
+        $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
88
+        if ( $tokens[ $prev ][ 'code' ] === T_STRING ) {
89 89
             $error = 'Object indexes must be written in dot notation';
90
-            $phpcsFile->addError($error, $prev, 'Found');
90
+            $phpcsFile->addError( $error, $prev, 'Found' );
91 91
         }
92 92
 
93 93
     }//end process()
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,8 +23,7 @@  discard block
 block discarded – undo
23 23
  * @version   Release: @package_version@
24 24
  * @link      http://pear.php.net/package/PHP_CodeSniffer
25 25
  */
26
-class Squiz_Sniffs_Objects_DisallowObjectStringIndexSniff implements PHP_CodeSniffer_Sniff
27
-{
26
+class Squiz_Sniffs_Objects_DisallowObjectStringIndexSniff implements PHP_CodeSniffer_Sniff {
28 27
 
29 28
     /**
30 29
      * A list of tokenizers this sniff supports.
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
      *
40 39
      * @return array
41 40
      */
42
-    public function register()
43
-    {
41
+    public function register() {
44 42
         return array(T_OPEN_SQUARE_BRACKET);
45 43
 
46 44
     }//end register()
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
      *
56 54
      * @return void
57 55
      */
58
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
59
-    {
56
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
60 57
         $tokens = $phpcsFile->getTokens();
61 58
 
62 59
         // Check if the next non whitespace token is a string.
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
     /**
40 40
      * Registers the token types that this sniff wishes to listen to.
41 41
      *
42
-     * @return array
42
+     * @return string[]
43 43
      */
44 44
     public function register()
45 45
     {
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -28,49 +28,49 @@
 block discarded – undo
28 28
 class Squiz_Sniffs_Objects_ObjectMemberCommaSniff implements PHP_CodeSniffer_Sniff
29 29
 {
30 30
 
31
-    /**
32
-     * A list of tokenizers this sniff supports.
33
-     *
34
-     * @var array
35
-     */
36
-    public $supportedTokenizers = array('JS');
31
+	 /**
32
+	  * A list of tokenizers this sniff supports.
33
+	  *
34
+	  * @var array
35
+	  */
36
+	 public $supportedTokenizers = array('JS');
37 37
 
38 38
 
39
-    /**
40
-     * Registers the token types that this sniff wishes to listen to.
41
-     *
42
-     * @return array
43
-     */
44
-    public function register()
45
-    {
46
-        return array(T_CLOSE_OBJECT);
39
+	 /**
40
+	  * Registers the token types that this sniff wishes to listen to.
41
+	  *
42
+	  * @return array
43
+	  */
44
+	 public function register()
45
+	 {
46
+		  return array(T_CLOSE_OBJECT);
47 47
 
48
-    }//end register()
48
+	 }//end register()
49 49
 
50 50
 
51
-    /**
52
-     * Process the tokens that this sniff is listening for.
53
-     *
54
-     * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
55
-     * @param int                  $stackPtr  The position in the stack where
56
-     *                                        the token was found.
57
-     *
58
-     * @return void
59
-     */
60
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
-    {
62
-        $tokens = $phpcsFile->getTokens();
51
+	 /**
52
+	  * Process the tokens that this sniff is listening for.
53
+	  *
54
+	  * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
55
+	  * @param int                  $stackPtr  The position in the stack where
56
+	  *                                        the token was found.
57
+	  *
58
+	  * @return void
59
+	  */
60
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
+	 {
62
+		  $tokens = $phpcsFile->getTokens();
63 63
 
64
-        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
65
-        if ($tokens[$prev]['code'] === T_COMMA) {
66
-            $error = 'Last member of object must not be followed by a comma';
67
-            $fix   = $phpcsFile->addFixableError($error, $prev, 'Missing');
68
-            if ($fix === true) {
69
-                $phpcsFile->fixer->replaceToken($prev, '');
70
-            }
71
-        }
64
+		  $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
65
+		  if ($tokens[$prev]['code'] === T_COMMA) {
66
+				$error = 'Last member of object must not be followed by a comma';
67
+				$fix   = $phpcsFile->addFixableError($error, $prev, 'Missing');
68
+				if ($fix === true) {
69
+					 $phpcsFile->fixer->replaceToken($prev, '');
70
+				}
71
+		  }
72 72
 
73
-    }//end process()
73
+	 }//end process()
74 74
 
75 75
 
76 76
 }//end class
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
      *
34 34
      * @var array
35 35
      */
36
-    public $supportedTokenizers = array('JS');
36
+    public $supportedTokenizers = array( 'JS' );
37 37
 
38 38
 
39 39
     /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function register()
45 45
     {
46
-        return array(T_CLOSE_OBJECT);
46
+        return array( T_CLOSE_OBJECT );
47 47
 
48 48
     }//end register()
49 49
 
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return void
59 59
      */
60
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
60
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
61 61
     {
62 62
         $tokens = $phpcsFile->getTokens();
63 63
 
64
-        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
65
-        if ($tokens[$prev]['code'] === T_COMMA) {
64
+        $prev = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
65
+        if ( $tokens[ $prev ][ 'code' ] === T_COMMA ) {
66 66
             $error = 'Last member of object must not be followed by a comma';
67
-            $fix   = $phpcsFile->addFixableError($error, $prev, 'Missing');
68
-            if ($fix === true) {
69
-                $phpcsFile->fixer->replaceToken($prev, '');
67
+            $fix   = $phpcsFile->addFixableError( $error, $prev, 'Missing' );
68
+            if ( $fix === true ) {
69
+                $phpcsFile->fixer->replaceToken( $prev, '' );
70 70
             }
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
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
  * @version   Release: @package_version@
26 26
  * @link      http://pear.php.net/package/PHP_CodeSniffer
27 27
  */
28
-class Squiz_Sniffs_Objects_ObjectMemberCommaSniff implements PHP_CodeSniffer_Sniff
29
-{
28
+class Squiz_Sniffs_Objects_ObjectMemberCommaSniff implements PHP_CodeSniffer_Sniff {
30 29
 
31 30
     /**
32 31
      * A list of tokenizers this sniff supports.
@@ -41,8 +40,7 @@  discard block
 block discarded – undo
41 40
      *
42 41
      * @return array
43 42
      */
44
-    public function register()
45
-    {
43
+    public function register() {
46 44
         return array(T_CLOSE_OBJECT);
47 45
 
48 46
     }//end register()
@@ -57,8 +55,7 @@  discard block
 block discarded – undo
57 55
      *
58 56
      * @return void
59 57
      */
60
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
-    {
58
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
62 59
         $tokens = $phpcsFile->getTokens();
63 60
 
64 61
         $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
Please login to merge, or discard this patch.
php_codesniffer/CodeSniffer/Standards/Squiz/Sniffs/PHP/EmbeddedPhpSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
     /**
35 35
      * Returns an array of tokens this test wants to listen for.
36 36
      *
37
-     * @return array
37
+     * @return integer[]
38 38
      */
39 39
     public function register()
40 40
     {
Please login to merge, or discard this patch.
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -31,375 +31,375 @@
 block discarded – undo
31 31
 {
32 32
 
33 33
 
34
-    /**
35
-     * Returns an array of tokens this test wants to listen for.
36
-     *
37
-     * @return array
38
-     */
39
-    public function register()
40
-    {
41
-        return array(T_OPEN_TAG);
42
-
43
-    }//end register()
44
-
45
-
46
-    /**
47
-     * Processes this test, when one of its tokens is encountered.
48
-     *
49
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
-     * @param int                  $stackPtr  The position of the current token in the
51
-     *                                        stack passed in $tokens.
52
-     *
53
-     * @return void
54
-     */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
57
-        $tokens = $phpcsFile->getTokens();
58
-
59
-        // If the close php tag is on the same line as the opening
60
-        // then we have an inline embedded PHP block.
61
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
62
-        if ($closeTag === false || $tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
63
-            $this->_validateMultilineEmbeddedPhp($phpcsFile, $stackPtr);
64
-        } else {
65
-            $this->_validateInlineEmbeddedPhp($phpcsFile, $stackPtr);
66
-        }
67
-
68
-    }//end process()
69
-
70
-
71
-    /**
72
-     * Validates embedded PHP that exists on multiple lines.
73
-     *
74
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
75
-     * @param int                  $stackPtr  The position of the current token in the
76
-     *                                        stack passed in $tokens.
77
-     *
78
-     * @return void
79
-     */
80
-    private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
81
-    {
82
-        $tokens = $phpcsFile->getTokens();
83
-
84
-        $prevTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
85
-        if ($prevTag === false) {
86
-            // This is the first open tag.
87
-            return;
88
-        }
89
-
90
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
-        $closingTag   = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
92
-        if ($closingTag !== false) {
93
-            $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), $phpcsFile->numTokens, true);
94
-            if ($nextContent === false) {
95
-                // Final closing tag. It will be handled elsewhere.
96
-                return;
97
-            }
98
-
99
-            // We have an opening and a closing tag, that lie within other content.
100
-            if ($firstContent === $closingTag) {
101
-                $error = 'Empty embedded PHP tag found';
102
-                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
103
-                if ($fix === true) {
104
-                    $phpcsFile->fixer->beginChangeset();
105
-                    for ($i = $stackPtr; $i <= $closingTag; $i++) {
106
-                        $phpcsFile->fixer->replaceToken($i, '');
107
-                    }
108
-
109
-                    $phpcsFile->fixer->endChangeset();
110
-                }
111
-
112
-                return;
113
-            }
114
-        }//end if
115
-
116
-        if ($tokens[$firstContent]['line'] === $tokens[$stackPtr]['line']) {
117
-            $error = 'Opening PHP tag must be on a line by itself';
118
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
119
-            if ($fix === true) {
120
-                $first   = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
121
-                $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
122
-                $phpcsFile->fixer->beginChangeset();
123
-                $phpcsFile->fixer->addNewline($stackPtr);
124
-                $phpcsFile->fixer->addContent($stackPtr, str_repeat(' ', $padding));
125
-                $phpcsFile->fixer->endChangeset();
126
-            }
127
-        } else {
128
-            // Check the indent of the first line, except if it is a scope closer.
129
-            if (isset($tokens[$firstContent]['scope_closer']) === false
130
-                || $tokens[$firstContent]['scope_closer'] !== $firstContent
131
-            ) {
132
-                // Check for a blank line at the top.
133
-                if ($tokens[$firstContent]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
134
-                    // Find a token on the blank line to throw the error on.
135
-                    $i = $stackPtr;
136
-                    do {
137
-                        $i++;
138
-                    } while ($tokens[$i]['line'] !== ($tokens[$stackPtr]['line'] + 1));
139
-
140
-                    $error = 'Blank line found at start of embedded PHP content';
141
-                    $fix   = $phpcsFile->addFixableError($error, $i, 'SpacingBefore');
142
-                    if ($fix === true) {
143
-                        $phpcsFile->fixer->beginChangeset();
144
-                        for ($i = ($stackPtr + 1); $i < $firstContent; $i++) {
145
-                            if ($tokens[$i]['line'] === $tokens[$firstContent]['line']
146
-                                || $tokens[$i]['line'] === $tokens[$stackPtr]['line']
147
-                            ) {
148
-                                continue;
149
-                            }
150
-
151
-                            $phpcsFile->fixer->replaceToken($i, '');
152
-                        }
153
-
154
-                        $phpcsFile->fixer->endChangeset();
155
-                    }
156
-                }//end if
157
-
158
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
159
-                if ($first === false) {
160
-                    $first  = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
161
-                    $indent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
162
-                } else {
163
-                    $indent = ($tokens[($first + 1)]['column'] - 1);
164
-                }
165
-
166
-                $contentColumn = ($tokens[$firstContent]['column'] - 1);
167
-                if ($contentColumn !== $indent) {
168
-                    $error = 'First line of embedded PHP code must be indented %s spaces; %s found';
169
-                    $data  = array(
170
-                              $indent,
171
-                              $contentColumn,
172
-                             );
173
-                    $fix   = $phpcsFile->addFixableError($error, $firstContent, 'Indent', $data);
174
-                    if ($fix === true) {
175
-                        $padding = str_repeat(' ', $indent);
176
-                        if ($contentColumn === 0) {
177
-                            $phpcsFile->fixer->addContentBefore($firstContent, $padding);
178
-                        } else {
179
-                            $phpcsFile->fixer->replaceToken(($firstContent - 1), $padding);
180
-                        }
181
-                    }
182
-                }
183
-            }//end if
184
-        }//end if
185
-
186
-        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
187
-        if ($tokens[$lastContent]['line'] === $tokens[$stackPtr]['line']
188
-            && trim($tokens[$lastContent]['content']) !== ''
189
-        ) {
190
-            $error = 'Opening PHP tag must be on a line by itself';
191
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeOpen');
192
-            if ($fix === true) {
193
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
194
-                if ($first === false) {
195
-                    $first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
196
-                    $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
197
-                } else {
198
-                    $padding = ($tokens[($first + 1)]['column'] - 1);
199
-                }
200
-
201
-                $phpcsFile->fixer->addContentBefore($stackPtr, $phpcsFile->eolChar.str_repeat(' ', $padding));
202
-            }
203
-        } else {
204
-            // Find the first token on the first non-empty line we find.
205
-            for ($first = ($stackPtr - 1); $first > 0; $first--) {
206
-                if ($tokens[$first]['line'] === $tokens[$stackPtr]['line']) {
207
-                    continue;
208
-                } else if (trim($tokens[$first]['content']) !== '') {
209
-                    $first = $phpcsFile->findFirstOnLine(array(), $first, true);
210
-                    break;
211
-                }
212
-            }
213
-
214
-            $expected = 0;
215
-            if ($tokens[$first]['code'] === T_INLINE_HTML
216
-                && trim($tokens[$first]['content']) !== ''
217
-            ) {
218
-                $expected = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
219
-            } else if ($tokens[$first]['code'] === T_WHITESPACE) {
220
-                $expected = ($tokens[($first + 1)]['column'] - 1);
221
-            }
222
-
223
-            $expected += 4;
224
-            $found     = ($tokens[$stackPtr]['column'] - 1);
225
-            if ($found > $expected) {
226
-                $error = 'Opening PHP tag indent incorrect; expected no more than %s spaces but found %s';
227
-                $data  = array(
228
-                          $expected,
229
-                          $found,
230
-                         );
231
-                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'OpenTagIndent', $data);
232
-                if ($fix === true) {
233
-                    $phpcsFile->fixer->replaceToken(($stackPtr - 1), str_repeat(' ', $expected));
234
-                }
235
-            }
236
-        }//end if
237
-
238
-        if ($closingTag === false) {
239
-            return;
240
-        }
241
-
242
-        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closingTag - 1), ($stackPtr + 1), true);
243
-        $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), null, true);
244
-
245
-        if ($tokens[$lastContent]['line'] === $tokens[$closingTag]['line']) {
246
-            $error = 'Closing PHP tag must be on a line by itself';
247
-            $fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentBeforeEnd');
248
-            if ($fix === true) {
249
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
250
-                $phpcsFile->fixer->beginChangeset();
251
-                $phpcsFile->fixer->addContentBefore($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
252
-                $phpcsFile->fixer->addNewlineBefore($closingTag);
253
-                $phpcsFile->fixer->endChangeset();
254
-            }
255
-        } else if ($tokens[$nextContent]['line'] === $tokens[$closingTag]['line']) {
256
-            $error = 'Closing PHP tag must be on a line by itself';
257
-            $fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentAfterEnd');
258
-            if ($fix === true) {
259
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
260
-                $phpcsFile->fixer->beginChangeset();
261
-                $phpcsFile->fixer->addNewline($closingTag);
262
-                $phpcsFile->fixer->addContent($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
263
-                $phpcsFile->fixer->endChangeset();
264
-            }
265
-        }//end if
266
-
267
-        $next = $phpcsFile->findNext(T_OPEN_TAG, ($closingTag + 1));
268
-        if ($next === false) {
269
-            return;
270
-        }
271
-
272
-        // Check for a blank line at the bottom.
273
-        if ((isset($tokens[$lastContent]['scope_closer']) === false
274
-            || $tokens[$lastContent]['scope_closer'] !== $lastContent)
275
-            && $tokens[$lastContent]['line'] < ($tokens[$closingTag]['line'] - 1)
276
-        ) {
277
-            // Find a token on the blank line to throw the error on.
278
-            $i = $closingTag;
279
-            do {
280
-                $i--;
281
-            } while ($tokens[$i]['line'] !== ($tokens[$closingTag]['line'] - 1));
282
-
283
-            $error = 'Blank line found at end of embedded PHP content';
284
-            $fix   = $phpcsFile->addFixableError($error, $i, 'SpacingAfter');
285
-            if ($fix === true) {
286
-                $phpcsFile->fixer->beginChangeset();
287
-                for ($i = ($lastContent + 1); $i < $closingTag; $i++) {
288
-                    if ($tokens[$i]['line'] === $tokens[$lastContent]['line']
289
-                        || $tokens[$i]['line'] === $tokens[$closingTag]['line']
290
-                    ) {
291
-                        continue;
292
-                    }
293
-
294
-                    $phpcsFile->fixer->replaceToken($i, '');
295
-                }
296
-
297
-                $phpcsFile->fixer->endChangeset();
298
-            }
299
-        }//end if
300
-
301
-    }//end _validateMultilineEmbeddedPhp()
302
-
303
-
304
-    /**
305
-     * Validates embedded PHP that exists on one line.
306
-     *
307
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
308
-     * @param int                  $stackPtr  The position of the current token in the
309
-     *                                        stack passed in $tokens.
310
-     *
311
-     * @return void
312
-     */
313
-    private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
314
-    {
315
-        $tokens = $phpcsFile->getTokens();
316
-
317
-        // We only want one line PHP sections, so return if the closing tag is
318
-        // on the next line.
319
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr, null, false);
320
-        if ($tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
321
-            return;
322
-        }
323
-
324
-        // Check that there is one, and only one space at the start of the statement.
325
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), ($closeTag - 1), true);
326
-
327
-        if ($firstContent === false) {
328
-            $error = 'Empty embedded PHP tag found';
329
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
330
-            if ($fix === true) {
331
-                $phpcsFile->fixer->beginChangeset();
332
-                for ($i = $stackPtr; $i <= $closeTag; $i++) {
333
-                    $phpcsFile->fixer->replaceToken($i, '');
334
-                }
335
-
336
-                $phpcsFile->fixer->endChangeset();
337
-            }
338
-
339
-            return;
340
-        }
341
-
342
-        // The open tag token always contains a single space after it.
343
-        $leadingSpace = 1;
344
-        if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
345
-            $leadingSpace = (strlen($tokens[($stackPtr + 1)]['content']) + 1);
346
-        }
347
-
348
-        if ($leadingSpace !== 1) {
349
-            $error = 'Expected 1 space after opening PHP tag; %s found';
350
-            $data  = array($leadingSpace);
351
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data);
352
-            if ($fix === true) {
353
-                $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
354
-            }
355
-        }
356
-
357
-        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeTag - 1), $stackPtr, true);
358
-        if ((isset($tokens[$prev]['scope_opener']) === false
359
-            || $tokens[$prev]['scope_opener'] !== $prev)
360
-            && (isset($tokens[$prev]['scope_closer']) === false
361
-            || $tokens[$prev]['scope_closer'] !== $prev)
362
-            && $tokens[$prev]['code'] !== T_SEMICOLON
363
-        ) {
364
-            $error = 'Inline PHP statement must end with a semicolon';
365
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSemicolon');
366
-            if ($fix === true) {
367
-                $phpcsFile->fixer->addContent($prev, ';');
368
-            }
369
-        } else if ($tokens[$prev]['code'] === T_SEMICOLON) {
370
-            $statementCount = 1;
371
-            for ($i = ($stackPtr + 1); $i < $prev; $i++) {
372
-                if ($tokens[$i]['code'] === T_SEMICOLON) {
373
-                    $statementCount++;
374
-                }
375
-            }
376
-
377
-            if ($statementCount > 1) {
378
-                $error = 'Inline PHP statement must contain a single statement; %s found';
379
-                $data  = array($statementCount);
380
-                $phpcsFile->addError($error, $stackPtr, 'MultipleStatements', $data);
381
-            }
382
-        }
383
-
384
-        $trailingSpace = 0;
385
-        if ($tokens[($closeTag - 1)]['code'] === T_WHITESPACE) {
386
-            $trailingSpace = strlen($tokens[($closeTag - 1)]['content']);
387
-        }
388
-
389
-        if ($trailingSpace !== 1) {
390
-            $error = 'Expected 1 space before closing PHP tag; %s found';
391
-            $data  = array($trailingSpace);
392
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data);
393
-            if ($fix === true) {
394
-                if ($trailingSpace === 0) {
395
-                    $phpcsFile->fixer->addContentBefore($closeTag, ' ');
396
-                } else {
397
-                    $phpcsFile->fixer->replaceToken(($closeTag - 1), ' ');
398
-                }
399
-            }
400
-        }
401
-
402
-    }//end _validateInlineEmbeddedPhp()
34
+	 /**
35
+	  * Returns an array of tokens this test wants to listen for.
36
+	  *
37
+	  * @return array
38
+	  */
39
+	 public function register()
40
+	 {
41
+		  return array(T_OPEN_TAG);
42
+
43
+	 }//end register()
44
+
45
+
46
+	 /**
47
+	  * Processes this test, when one of its tokens is encountered.
48
+	  *
49
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
+	  * @param int                  $stackPtr  The position of the current token in the
51
+	  *                                        stack passed in $tokens.
52
+	  *
53
+	  * @return void
54
+	  */
55
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
+	 {
57
+		  $tokens = $phpcsFile->getTokens();
58
+
59
+		  // If the close php tag is on the same line as the opening
60
+		  // then we have an inline embedded PHP block.
61
+		  $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
62
+		  if ($closeTag === false || $tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
63
+				$this->_validateMultilineEmbeddedPhp($phpcsFile, $stackPtr);
64
+		  } else {
65
+				$this->_validateInlineEmbeddedPhp($phpcsFile, $stackPtr);
66
+		  }
67
+
68
+	 }//end process()
69
+
70
+
71
+	 /**
72
+	  * Validates embedded PHP that exists on multiple lines.
73
+	  *
74
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
75
+	  * @param int                  $stackPtr  The position of the current token in the
76
+	  *                                        stack passed in $tokens.
77
+	  *
78
+	  * @return void
79
+	  */
80
+	 private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
81
+	 {
82
+		  $tokens = $phpcsFile->getTokens();
83
+
84
+		  $prevTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
85
+		  if ($prevTag === false) {
86
+				// This is the first open tag.
87
+				return;
88
+		  }
89
+
90
+		  $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
+		  $closingTag   = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
92
+		  if ($closingTag !== false) {
93
+				$nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), $phpcsFile->numTokens, true);
94
+				if ($nextContent === false) {
95
+					 // Final closing tag. It will be handled elsewhere.
96
+					 return;
97
+				}
98
+
99
+				// We have an opening and a closing tag, that lie within other content.
100
+				if ($firstContent === $closingTag) {
101
+					 $error = 'Empty embedded PHP tag found';
102
+					 $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
103
+					 if ($fix === true) {
104
+						  $phpcsFile->fixer->beginChangeset();
105
+						  for ($i = $stackPtr; $i <= $closingTag; $i++) {
106
+								$phpcsFile->fixer->replaceToken($i, '');
107
+						  }
108
+
109
+						  $phpcsFile->fixer->endChangeset();
110
+					 }
111
+
112
+					 return;
113
+				}
114
+		  }//end if
115
+
116
+		  if ($tokens[$firstContent]['line'] === $tokens[$stackPtr]['line']) {
117
+				$error = 'Opening PHP tag must be on a line by itself';
118
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
119
+				if ($fix === true) {
120
+					 $first   = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
121
+					 $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
122
+					 $phpcsFile->fixer->beginChangeset();
123
+					 $phpcsFile->fixer->addNewline($stackPtr);
124
+					 $phpcsFile->fixer->addContent($stackPtr, str_repeat(' ', $padding));
125
+					 $phpcsFile->fixer->endChangeset();
126
+				}
127
+		  } else {
128
+				// Check the indent of the first line, except if it is a scope closer.
129
+				if (isset($tokens[$firstContent]['scope_closer']) === false
130
+					 || $tokens[$firstContent]['scope_closer'] !== $firstContent
131
+				) {
132
+					 // Check for a blank line at the top.
133
+					 if ($tokens[$firstContent]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
134
+						  // Find a token on the blank line to throw the error on.
135
+						  $i = $stackPtr;
136
+						  do {
137
+								$i++;
138
+						  } while ($tokens[$i]['line'] !== ($tokens[$stackPtr]['line'] + 1));
139
+
140
+						  $error = 'Blank line found at start of embedded PHP content';
141
+						  $fix   = $phpcsFile->addFixableError($error, $i, 'SpacingBefore');
142
+						  if ($fix === true) {
143
+								$phpcsFile->fixer->beginChangeset();
144
+								for ($i = ($stackPtr + 1); $i < $firstContent; $i++) {
145
+									 if ($tokens[$i]['line'] === $tokens[$firstContent]['line']
146
+										  || $tokens[$i]['line'] === $tokens[$stackPtr]['line']
147
+									 ) {
148
+										  continue;
149
+									 }
150
+
151
+									 $phpcsFile->fixer->replaceToken($i, '');
152
+								}
153
+
154
+								$phpcsFile->fixer->endChangeset();
155
+						  }
156
+					 }//end if
157
+
158
+					 $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
159
+					 if ($first === false) {
160
+						  $first  = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
161
+						  $indent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
162
+					 } else {
163
+						  $indent = ($tokens[($first + 1)]['column'] - 1);
164
+					 }
165
+
166
+					 $contentColumn = ($tokens[$firstContent]['column'] - 1);
167
+					 if ($contentColumn !== $indent) {
168
+						  $error = 'First line of embedded PHP code must be indented %s spaces; %s found';
169
+						  $data  = array(
170
+										$indent,
171
+										$contentColumn,
172
+									  );
173
+						  $fix   = $phpcsFile->addFixableError($error, $firstContent, 'Indent', $data);
174
+						  if ($fix === true) {
175
+								$padding = str_repeat(' ', $indent);
176
+								if ($contentColumn === 0) {
177
+									 $phpcsFile->fixer->addContentBefore($firstContent, $padding);
178
+								} else {
179
+									 $phpcsFile->fixer->replaceToken(($firstContent - 1), $padding);
180
+								}
181
+						  }
182
+					 }
183
+				}//end if
184
+		  }//end if
185
+
186
+		  $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
187
+		  if ($tokens[$lastContent]['line'] === $tokens[$stackPtr]['line']
188
+				&& trim($tokens[$lastContent]['content']) !== ''
189
+		  ) {
190
+				$error = 'Opening PHP tag must be on a line by itself';
191
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeOpen');
192
+				if ($fix === true) {
193
+					 $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
194
+					 if ($first === false) {
195
+						  $first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
196
+						  $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
197
+					 } else {
198
+						  $padding = ($tokens[($first + 1)]['column'] - 1);
199
+					 }
200
+
201
+					 $phpcsFile->fixer->addContentBefore($stackPtr, $phpcsFile->eolChar.str_repeat(' ', $padding));
202
+				}
203
+		  } else {
204
+				// Find the first token on the first non-empty line we find.
205
+				for ($first = ($stackPtr - 1); $first > 0; $first--) {
206
+					 if ($tokens[$first]['line'] === $tokens[$stackPtr]['line']) {
207
+						  continue;
208
+					 } else if (trim($tokens[$first]['content']) !== '') {
209
+						  $first = $phpcsFile->findFirstOnLine(array(), $first, true);
210
+						  break;
211
+					 }
212
+				}
213
+
214
+				$expected = 0;
215
+				if ($tokens[$first]['code'] === T_INLINE_HTML
216
+					 && trim($tokens[$first]['content']) !== ''
217
+				) {
218
+					 $expected = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
219
+				} else if ($tokens[$first]['code'] === T_WHITESPACE) {
220
+					 $expected = ($tokens[($first + 1)]['column'] - 1);
221
+				}
222
+
223
+				$expected += 4;
224
+				$found     = ($tokens[$stackPtr]['column'] - 1);
225
+				if ($found > $expected) {
226
+					 $error = 'Opening PHP tag indent incorrect; expected no more than %s spaces but found %s';
227
+					 $data  = array(
228
+								  $expected,
229
+								  $found,
230
+								 );
231
+					 $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'OpenTagIndent', $data);
232
+					 if ($fix === true) {
233
+						  $phpcsFile->fixer->replaceToken(($stackPtr - 1), str_repeat(' ', $expected));
234
+					 }
235
+				}
236
+		  }//end if
237
+
238
+		  if ($closingTag === false) {
239
+				return;
240
+		  }
241
+
242
+		  $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closingTag - 1), ($stackPtr + 1), true);
243
+		  $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), null, true);
244
+
245
+		  if ($tokens[$lastContent]['line'] === $tokens[$closingTag]['line']) {
246
+				$error = 'Closing PHP tag must be on a line by itself';
247
+				$fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentBeforeEnd');
248
+				if ($fix === true) {
249
+					 $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
250
+					 $phpcsFile->fixer->beginChangeset();
251
+					 $phpcsFile->fixer->addContentBefore($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
252
+					 $phpcsFile->fixer->addNewlineBefore($closingTag);
253
+					 $phpcsFile->fixer->endChangeset();
254
+				}
255
+		  } else if ($tokens[$nextContent]['line'] === $tokens[$closingTag]['line']) {
256
+				$error = 'Closing PHP tag must be on a line by itself';
257
+				$fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentAfterEnd');
258
+				if ($fix === true) {
259
+					 $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
260
+					 $phpcsFile->fixer->beginChangeset();
261
+					 $phpcsFile->fixer->addNewline($closingTag);
262
+					 $phpcsFile->fixer->addContent($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
263
+					 $phpcsFile->fixer->endChangeset();
264
+				}
265
+		  }//end if
266
+
267
+		  $next = $phpcsFile->findNext(T_OPEN_TAG, ($closingTag + 1));
268
+		  if ($next === false) {
269
+				return;
270
+		  }
271
+
272
+		  // Check for a blank line at the bottom.
273
+		  if ((isset($tokens[$lastContent]['scope_closer']) === false
274
+				|| $tokens[$lastContent]['scope_closer'] !== $lastContent)
275
+				&& $tokens[$lastContent]['line'] < ($tokens[$closingTag]['line'] - 1)
276
+		  ) {
277
+				// Find a token on the blank line to throw the error on.
278
+				$i = $closingTag;
279
+				do {
280
+					 $i--;
281
+				} while ($tokens[$i]['line'] !== ($tokens[$closingTag]['line'] - 1));
282
+
283
+				$error = 'Blank line found at end of embedded PHP content';
284
+				$fix   = $phpcsFile->addFixableError($error, $i, 'SpacingAfter');
285
+				if ($fix === true) {
286
+					 $phpcsFile->fixer->beginChangeset();
287
+					 for ($i = ($lastContent + 1); $i < $closingTag; $i++) {
288
+						  if ($tokens[$i]['line'] === $tokens[$lastContent]['line']
289
+								|| $tokens[$i]['line'] === $tokens[$closingTag]['line']
290
+						  ) {
291
+								continue;
292
+						  }
293
+
294
+						  $phpcsFile->fixer->replaceToken($i, '');
295
+					 }
296
+
297
+					 $phpcsFile->fixer->endChangeset();
298
+				}
299
+		  }//end if
300
+
301
+	 }//end _validateMultilineEmbeddedPhp()
302
+
303
+
304
+	 /**
305
+	  * Validates embedded PHP that exists on one line.
306
+	  *
307
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
308
+	  * @param int                  $stackPtr  The position of the current token in the
309
+	  *                                        stack passed in $tokens.
310
+	  *
311
+	  * @return void
312
+	  */
313
+	 private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
314
+	 {
315
+		  $tokens = $phpcsFile->getTokens();
316
+
317
+		  // We only want one line PHP sections, so return if the closing tag is
318
+		  // on the next line.
319
+		  $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr, null, false);
320
+		  if ($tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
321
+				return;
322
+		  }
323
+
324
+		  // Check that there is one, and only one space at the start of the statement.
325
+		  $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), ($closeTag - 1), true);
326
+
327
+		  if ($firstContent === false) {
328
+				$error = 'Empty embedded PHP tag found';
329
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
330
+				if ($fix === true) {
331
+					 $phpcsFile->fixer->beginChangeset();
332
+					 for ($i = $stackPtr; $i <= $closeTag; $i++) {
333
+						  $phpcsFile->fixer->replaceToken($i, '');
334
+					 }
335
+
336
+					 $phpcsFile->fixer->endChangeset();
337
+				}
338
+
339
+				return;
340
+		  }
341
+
342
+		  // The open tag token always contains a single space after it.
343
+		  $leadingSpace = 1;
344
+		  if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
345
+				$leadingSpace = (strlen($tokens[($stackPtr + 1)]['content']) + 1);
346
+		  }
347
+
348
+		  if ($leadingSpace !== 1) {
349
+				$error = 'Expected 1 space after opening PHP tag; %s found';
350
+				$data  = array($leadingSpace);
351
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data);
352
+				if ($fix === true) {
353
+					 $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
354
+				}
355
+		  }
356
+
357
+		  $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeTag - 1), $stackPtr, true);
358
+		  if ((isset($tokens[$prev]['scope_opener']) === false
359
+				|| $tokens[$prev]['scope_opener'] !== $prev)
360
+				&& (isset($tokens[$prev]['scope_closer']) === false
361
+				|| $tokens[$prev]['scope_closer'] !== $prev)
362
+				&& $tokens[$prev]['code'] !== T_SEMICOLON
363
+		  ) {
364
+				$error = 'Inline PHP statement must end with a semicolon';
365
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSemicolon');
366
+				if ($fix === true) {
367
+					 $phpcsFile->fixer->addContent($prev, ';');
368
+				}
369
+		  } else if ($tokens[$prev]['code'] === T_SEMICOLON) {
370
+				$statementCount = 1;
371
+				for ($i = ($stackPtr + 1); $i < $prev; $i++) {
372
+					 if ($tokens[$i]['code'] === T_SEMICOLON) {
373
+						  $statementCount++;
374
+					 }
375
+				}
376
+
377
+				if ($statementCount > 1) {
378
+					 $error = 'Inline PHP statement must contain a single statement; %s found';
379
+					 $data  = array($statementCount);
380
+					 $phpcsFile->addError($error, $stackPtr, 'MultipleStatements', $data);
381
+				}
382
+		  }
383
+
384
+		  $trailingSpace = 0;
385
+		  if ($tokens[($closeTag - 1)]['code'] === T_WHITESPACE) {
386
+				$trailingSpace = strlen($tokens[($closeTag - 1)]['content']);
387
+		  }
388
+
389
+		  if ($trailingSpace !== 1) {
390
+				$error = 'Expected 1 space before closing PHP tag; %s found';
391
+				$data  = array($trailingSpace);
392
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data);
393
+				if ($fix === true) {
394
+					 if ($trailingSpace === 0) {
395
+						  $phpcsFile->fixer->addContentBefore($closeTag, ' ');
396
+					 } else {
397
+						  $phpcsFile->fixer->replaceToken(($closeTag - 1), ' ');
398
+					 }
399
+				}
400
+		  }
401
+
402
+	 }//end _validateInlineEmbeddedPhp()
403 403
 
404 404
 
405 405
 }//end class
Please login to merge, or discard this patch.
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function register()
40 40
     {
41
-        return array(T_OPEN_TAG);
41
+        return array( T_OPEN_TAG );
42 42
 
43 43
     }//end register()
44 44
 
@@ -52,17 +52,17 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return void
54 54
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
55
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
56 56
     {
57 57
         $tokens = $phpcsFile->getTokens();
58 58
 
59 59
         // If the close php tag is on the same line as the opening
60 60
         // then we have an inline embedded PHP block.
61
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
62
-        if ($closeTag === false || $tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
63
-            $this->_validateMultilineEmbeddedPhp($phpcsFile, $stackPtr);
61
+        $closeTag = $phpcsFile->findNext( T_CLOSE_TAG, $stackPtr );
62
+        if ( $closeTag === false || $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $closeTag ][ 'line' ] ) {
63
+            $this->_validateMultilineEmbeddedPhp( $phpcsFile, $stackPtr );
64 64
         } else {
65
-            $this->_validateInlineEmbeddedPhp($phpcsFile, $stackPtr);
65
+            $this->_validateInlineEmbeddedPhp( $phpcsFile, $stackPtr );
66 66
         }
67 67
 
68 68
     }//end process()
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
      *
78 78
      * @return void
79 79
      */
80
-    private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
80
+    private function _validateMultilineEmbeddedPhp( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
81 81
     {
82 82
         $tokens = $phpcsFile->getTokens();
83 83
 
84
-        $prevTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
85
-        if ($prevTag === false) {
84
+        $prevTag = $phpcsFile->findPrevious( T_OPEN_TAG, ( $stackPtr - 1 ) );
85
+        if ( $prevTag === false ) {
86 86
             // This is the first open tag.
87 87
             return;
88 88
         }
89 89
 
90
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
91
-        $closingTag   = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr);
92
-        if ($closingTag !== false) {
93
-            $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), $phpcsFile->numTokens, true);
94
-            if ($nextContent === false) {
90
+        $firstContent = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
91
+        $closingTag   = $phpcsFile->findNext( T_CLOSE_TAG, $stackPtr );
92
+        if ( $closingTag !== false ) {
93
+            $nextContent = $phpcsFile->findNext( T_WHITESPACE, ( $closingTag + 1 ), $phpcsFile->numTokens, true );
94
+            if ( $nextContent === false ) {
95 95
                 // Final closing tag. It will be handled elsewhere.
96 96
                 return;
97 97
             }
98 98
 
99 99
             // We have an opening and a closing tag, that lie within other content.
100
-            if ($firstContent === $closingTag) {
100
+            if ( $firstContent === $closingTag ) {
101 101
                 $error = 'Empty embedded PHP tag found';
102
-                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
103
-                if ($fix === true) {
102
+                $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'Empty' );
103
+                if ( $fix === true ) {
104 104
                     $phpcsFile->fixer->beginChangeset();
105
-                    for ($i = $stackPtr; $i <= $closingTag; $i++) {
106
-                        $phpcsFile->fixer->replaceToken($i, '');
105
+                    for ( $i = $stackPtr; $i <= $closingTag; $i++ ) {
106
+                        $phpcsFile->fixer->replaceToken( $i, '' );
107 107
                     }
108 108
 
109 109
                     $phpcsFile->fixer->endChangeset();
@@ -113,185 +113,185 @@  discard block
 block discarded – undo
113 113
             }
114 114
         }//end if
115 115
 
116
-        if ($tokens[$firstContent]['line'] === $tokens[$stackPtr]['line']) {
116
+        if ( $tokens[ $firstContent ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) {
117 117
             $error = 'Opening PHP tag must be on a line by itself';
118
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentAfterOpen');
119
-            if ($fix === true) {
120
-                $first   = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr, true);
121
-                $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
118
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'ContentAfterOpen' );
119
+            if ( $fix === true ) {
120
+                $first   = $phpcsFile->findFirstOnLine( T_WHITESPACE, $stackPtr, true );
121
+                $padding = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( ltrim( $tokens[ $first ][ 'content' ] ) ) );
122 122
                 $phpcsFile->fixer->beginChangeset();
123
-                $phpcsFile->fixer->addNewline($stackPtr);
124
-                $phpcsFile->fixer->addContent($stackPtr, str_repeat(' ', $padding));
123
+                $phpcsFile->fixer->addNewline( $stackPtr );
124
+                $phpcsFile->fixer->addContent( $stackPtr, str_repeat( ' ', $padding ) );
125 125
                 $phpcsFile->fixer->endChangeset();
126 126
             }
127 127
         } else {
128 128
             // Check the indent of the first line, except if it is a scope closer.
129
-            if (isset($tokens[$firstContent]['scope_closer']) === false
130
-                || $tokens[$firstContent]['scope_closer'] !== $firstContent
129
+            if ( isset( $tokens[ $firstContent ][ 'scope_closer' ] ) === false
130
+                || $tokens[ $firstContent ][ 'scope_closer' ] !== $firstContent
131 131
             ) {
132 132
                 // Check for a blank line at the top.
133
-                if ($tokens[$firstContent]['line'] > ($tokens[$stackPtr]['line'] + 1)) {
133
+                if ( $tokens[ $firstContent ][ 'line' ] > ( $tokens[ $stackPtr ][ 'line' ] + 1 ) ) {
134 134
                     // Find a token on the blank line to throw the error on.
135 135
                     $i = $stackPtr;
136 136
                     do {
137 137
                         $i++;
138
-                    } while ($tokens[$i]['line'] !== ($tokens[$stackPtr]['line'] + 1));
138
+                    } while ( $tokens[ $i ][ 'line' ] !== ( $tokens[ $stackPtr ][ 'line' ] + 1 ) );
139 139
 
140 140
                     $error = 'Blank line found at start of embedded PHP content';
141
-                    $fix   = $phpcsFile->addFixableError($error, $i, 'SpacingBefore');
142
-                    if ($fix === true) {
141
+                    $fix   = $phpcsFile->addFixableError( $error, $i, 'SpacingBefore' );
142
+                    if ( $fix === true ) {
143 143
                         $phpcsFile->fixer->beginChangeset();
144
-                        for ($i = ($stackPtr + 1); $i < $firstContent; $i++) {
145
-                            if ($tokens[$i]['line'] === $tokens[$firstContent]['line']
146
-                                || $tokens[$i]['line'] === $tokens[$stackPtr]['line']
144
+                        for ( $i = ( $stackPtr + 1 ); $i < $firstContent; $i++ ) {
145
+                            if ( $tokens[ $i ][ 'line' ] === $tokens[ $firstContent ][ 'line' ]
146
+                                || $tokens[ $i ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ]
147 147
                             ) {
148 148
                                 continue;
149 149
                             }
150 150
 
151
-                            $phpcsFile->fixer->replaceToken($i, '');
151
+                            $phpcsFile->fixer->replaceToken( $i, '' );
152 152
                         }
153 153
 
154 154
                         $phpcsFile->fixer->endChangeset();
155 155
                     }
156 156
                 }//end if
157 157
 
158
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
159
-                if ($first === false) {
160
-                    $first  = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
161
-                    $indent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
158
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $stackPtr );
159
+                if ( $first === false ) {
160
+                    $first  = $phpcsFile->findFirstOnLine( T_INLINE_HTML, $stackPtr );
161
+                    $indent = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( ltrim( $tokens[ $first ][ 'content' ] ) ) );
162 162
                 } else {
163
-                    $indent = ($tokens[($first + 1)]['column'] - 1);
163
+                    $indent = ( $tokens[ ( $first + 1 ) ][ 'column' ] - 1 );
164 164
                 }
165 165
 
166
-                $contentColumn = ($tokens[$firstContent]['column'] - 1);
167
-                if ($contentColumn !== $indent) {
166
+                $contentColumn = ( $tokens[ $firstContent ][ 'column' ] - 1 );
167
+                if ( $contentColumn !== $indent ) {
168 168
                     $error = 'First line of embedded PHP code must be indented %s spaces; %s found';
169 169
                     $data  = array(
170 170
                               $indent,
171 171
                               $contentColumn,
172 172
                              );
173
-                    $fix   = $phpcsFile->addFixableError($error, $firstContent, 'Indent', $data);
174
-                    if ($fix === true) {
175
-                        $padding = str_repeat(' ', $indent);
176
-                        if ($contentColumn === 0) {
177
-                            $phpcsFile->fixer->addContentBefore($firstContent, $padding);
173
+                    $fix = $phpcsFile->addFixableError( $error, $firstContent, 'Indent', $data );
174
+                    if ( $fix === true ) {
175
+                        $padding = str_repeat( ' ', $indent );
176
+                        if ( $contentColumn === 0 ) {
177
+                            $phpcsFile->fixer->addContentBefore( $firstContent, $padding );
178 178
                         } else {
179
-                            $phpcsFile->fixer->replaceToken(($firstContent - 1), $padding);
179
+                            $phpcsFile->fixer->replaceToken( ( $firstContent - 1 ), $padding );
180 180
                         }
181 181
                     }
182 182
                 }
183 183
             }//end if
184 184
         }//end if
185 185
 
186
-        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
187
-        if ($tokens[$lastContent]['line'] === $tokens[$stackPtr]['line']
188
-            && trim($tokens[$lastContent]['content']) !== ''
186
+        $lastContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
187
+        if ( $tokens[ $lastContent ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ]
188
+            && trim( $tokens[ $lastContent ][ 'content' ] ) !== ''
189 189
         ) {
190 190
             $error = 'Opening PHP tag must be on a line by itself';
191
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeOpen');
192
-            if ($fix === true) {
193
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $stackPtr);
194
-                if ($first === false) {
195
-                    $first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
196
-                    $padding = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
191
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'ContentBeforeOpen' );
192
+            if ( $fix === true ) {
193
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $stackPtr );
194
+                if ( $first === false ) {
195
+                    $first   = $phpcsFile->findFirstOnLine( T_INLINE_HTML, $stackPtr );
196
+                    $padding = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( ltrim( $tokens[ $first ][ 'content' ] ) ) );
197 197
                 } else {
198
-                    $padding = ($tokens[($first + 1)]['column'] - 1);
198
+                    $padding = ( $tokens[ ( $first + 1 ) ][ 'column' ] - 1 );
199 199
                 }
200 200
 
201
-                $phpcsFile->fixer->addContentBefore($stackPtr, $phpcsFile->eolChar.str_repeat(' ', $padding));
201
+                $phpcsFile->fixer->addContentBefore( $stackPtr, $phpcsFile->eolChar . str_repeat( ' ', $padding ) );
202 202
             }
203 203
         } else {
204 204
             // Find the first token on the first non-empty line we find.
205
-            for ($first = ($stackPtr - 1); $first > 0; $first--) {
206
-                if ($tokens[$first]['line'] === $tokens[$stackPtr]['line']) {
205
+            for ( $first = ( $stackPtr - 1 ); $first > 0; $first-- ) {
206
+                if ( $tokens[ $first ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) {
207 207
                     continue;
208
-                } else if (trim($tokens[$first]['content']) !== '') {
209
-                    $first = $phpcsFile->findFirstOnLine(array(), $first, true);
208
+                } else if ( trim( $tokens[ $first ][ 'content' ] ) !== '' ) {
209
+                    $first = $phpcsFile->findFirstOnLine( array(), $first, true );
210 210
                     break;
211 211
                 }
212 212
             }
213 213
 
214 214
             $expected = 0;
215
-            if ($tokens[$first]['code'] === T_INLINE_HTML
216
-                && trim($tokens[$first]['content']) !== ''
215
+            if ( $tokens[ $first ][ 'code' ] === T_INLINE_HTML
216
+                && trim( $tokens[ $first ][ 'content' ] ) !== ''
217 217
             ) {
218
-                $expected = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
219
-            } else if ($tokens[$first]['code'] === T_WHITESPACE) {
220
-                $expected = ($tokens[($first + 1)]['column'] - 1);
218
+                $expected = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( ltrim( $tokens[ $first ][ 'content' ] ) ) );
219
+            } else if ( $tokens[ $first ][ 'code' ] === T_WHITESPACE ) {
220
+                $expected = ( $tokens[ ( $first + 1 ) ][ 'column' ] - 1 );
221 221
             }
222 222
 
223 223
             $expected += 4;
224
-            $found     = ($tokens[$stackPtr]['column'] - 1);
225
-            if ($found > $expected) {
224
+            $found     = ( $tokens[ $stackPtr ][ 'column' ] - 1 );
225
+            if ( $found > $expected ) {
226 226
                 $error = 'Opening PHP tag indent incorrect; expected no more than %s spaces but found %s';
227 227
                 $data  = array(
228 228
                           $expected,
229 229
                           $found,
230 230
                          );
231
-                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'OpenTagIndent', $data);
232
-                if ($fix === true) {
233
-                    $phpcsFile->fixer->replaceToken(($stackPtr - 1), str_repeat(' ', $expected));
231
+                $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'OpenTagIndent', $data );
232
+                if ( $fix === true ) {
233
+                    $phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), str_repeat( ' ', $expected ) );
234 234
                 }
235 235
             }
236 236
         }//end if
237 237
 
238
-        if ($closingTag === false) {
238
+        if ( $closingTag === false ) {
239 239
             return;
240 240
         }
241 241
 
242
-        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closingTag - 1), ($stackPtr + 1), true);
243
-        $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($closingTag + 1), null, true);
242
+        $lastContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $closingTag - 1 ), ( $stackPtr + 1 ), true );
243
+        $nextContent = $phpcsFile->findNext( T_WHITESPACE, ( $closingTag + 1 ), null, true );
244 244
 
245
-        if ($tokens[$lastContent]['line'] === $tokens[$closingTag]['line']) {
245
+        if ( $tokens[ $lastContent ][ 'line' ] === $tokens[ $closingTag ][ 'line' ] ) {
246 246
             $error = 'Closing PHP tag must be on a line by itself';
247
-            $fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentBeforeEnd');
248
-            if ($fix === true) {
249
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
247
+            $fix   = $phpcsFile->addFixableError( $error, $closingTag, 'ContentBeforeEnd' );
248
+            if ( $fix === true ) {
249
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $closingTag, true );
250 250
                 $phpcsFile->fixer->beginChangeset();
251
-                $phpcsFile->fixer->addContentBefore($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
252
-                $phpcsFile->fixer->addNewlineBefore($closingTag);
251
+                $phpcsFile->fixer->addContentBefore( $closingTag, str_repeat( ' ', ( $tokens[ $first ][ 'column' ] - 1 ) ) );
252
+                $phpcsFile->fixer->addNewlineBefore( $closingTag );
253 253
                 $phpcsFile->fixer->endChangeset();
254 254
             }
255
-        } else if ($tokens[$nextContent]['line'] === $tokens[$closingTag]['line']) {
255
+        } else if ( $tokens[ $nextContent ][ 'line' ] === $tokens[ $closingTag ][ 'line' ] ) {
256 256
             $error = 'Closing PHP tag must be on a line by itself';
257
-            $fix   = $phpcsFile->addFixableError($error, $closingTag, 'ContentAfterEnd');
258
-            if ($fix === true) {
259
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $closingTag, true);
257
+            $fix   = $phpcsFile->addFixableError( $error, $closingTag, 'ContentAfterEnd' );
258
+            if ( $fix === true ) {
259
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $closingTag, true );
260 260
                 $phpcsFile->fixer->beginChangeset();
261
-                $phpcsFile->fixer->addNewline($closingTag);
262
-                $phpcsFile->fixer->addContent($closingTag, str_repeat(' ', ($tokens[$first]['column'] - 1)));
261
+                $phpcsFile->fixer->addNewline( $closingTag );
262
+                $phpcsFile->fixer->addContent( $closingTag, str_repeat( ' ', ( $tokens[ $first ][ 'column' ] - 1 ) ) );
263 263
                 $phpcsFile->fixer->endChangeset();
264 264
             }
265 265
         }//end if
266 266
 
267
-        $next = $phpcsFile->findNext(T_OPEN_TAG, ($closingTag + 1));
268
-        if ($next === false) {
267
+        $next = $phpcsFile->findNext( T_OPEN_TAG, ( $closingTag + 1 ) );
268
+        if ( $next === false ) {
269 269
             return;
270 270
         }
271 271
 
272 272
         // Check for a blank line at the bottom.
273
-        if ((isset($tokens[$lastContent]['scope_closer']) === false
274
-            || $tokens[$lastContent]['scope_closer'] !== $lastContent)
275
-            && $tokens[$lastContent]['line'] < ($tokens[$closingTag]['line'] - 1)
273
+        if ( ( isset( $tokens[ $lastContent ][ 'scope_closer' ] ) === false
274
+            || $tokens[ $lastContent ][ 'scope_closer' ] !== $lastContent )
275
+            && $tokens[ $lastContent ][ 'line' ] < ( $tokens[ $closingTag ][ 'line' ] - 1 )
276 276
         ) {
277 277
             // Find a token on the blank line to throw the error on.
278 278
             $i = $closingTag;
279 279
             do {
280 280
                 $i--;
281
-            } while ($tokens[$i]['line'] !== ($tokens[$closingTag]['line'] - 1));
281
+            } while ( $tokens[ $i ][ 'line' ] !== ( $tokens[ $closingTag ][ 'line' ] - 1 ) );
282 282
 
283 283
             $error = 'Blank line found at end of embedded PHP content';
284
-            $fix   = $phpcsFile->addFixableError($error, $i, 'SpacingAfter');
285
-            if ($fix === true) {
284
+            $fix   = $phpcsFile->addFixableError( $error, $i, 'SpacingAfter' );
285
+            if ( $fix === true ) {
286 286
                 $phpcsFile->fixer->beginChangeset();
287
-                for ($i = ($lastContent + 1); $i < $closingTag; $i++) {
288
-                    if ($tokens[$i]['line'] === $tokens[$lastContent]['line']
289
-                        || $tokens[$i]['line'] === $tokens[$closingTag]['line']
287
+                for ( $i = ( $lastContent + 1 ); $i < $closingTag; $i++ ) {
288
+                    if ( $tokens[ $i ][ 'line' ] === $tokens[ $lastContent ][ 'line' ]
289
+                        || $tokens[ $i ][ 'line' ] === $tokens[ $closingTag ][ 'line' ]
290 290
                     ) {
291 291
                         continue;
292 292
                     }
293 293
 
294
-                    $phpcsFile->fixer->replaceToken($i, '');
294
+                    $phpcsFile->fixer->replaceToken( $i, '' );
295 295
                 }
296 296
 
297 297
                 $phpcsFile->fixer->endChangeset();
@@ -310,27 +310,27 @@  discard block
 block discarded – undo
310 310
      *
311 311
      * @return void
312 312
      */
313
-    private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
313
+    private function _validateInlineEmbeddedPhp( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
314 314
     {
315 315
         $tokens = $phpcsFile->getTokens();
316 316
 
317 317
         // We only want one line PHP sections, so return if the closing tag is
318 318
         // on the next line.
319
-        $closeTag = $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr, null, false);
320
-        if ($tokens[$stackPtr]['line'] !== $tokens[$closeTag]['line']) {
319
+        $closeTag = $phpcsFile->findNext( T_CLOSE_TAG, $stackPtr, null, false );
320
+        if ( $tokens[ $stackPtr ][ 'line' ] !== $tokens[ $closeTag ][ 'line' ] ) {
321 321
             return;
322 322
         }
323 323
 
324 324
         // Check that there is one, and only one space at the start of the statement.
325
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), ($closeTag - 1), true);
325
+        $firstContent = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), ( $closeTag - 1 ), true );
326 326
 
327
-        if ($firstContent === false) {
327
+        if ( $firstContent === false ) {
328 328
             $error = 'Empty embedded PHP tag found';
329
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
330
-            if ($fix === true) {
329
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'Empty' );
330
+            if ( $fix === true ) {
331 331
                 $phpcsFile->fixer->beginChangeset();
332
-                for ($i = $stackPtr; $i <= $closeTag; $i++) {
333
-                    $phpcsFile->fixer->replaceToken($i, '');
332
+                for ( $i = $stackPtr; $i <= $closeTag; $i++ ) {
333
+                    $phpcsFile->fixer->replaceToken( $i, '' );
334 334
                 }
335 335
 
336 336
                 $phpcsFile->fixer->endChangeset();
@@ -341,60 +341,60 @@  discard block
 block discarded – undo
341 341
 
342 342
         // The open tag token always contains a single space after it.
343 343
         $leadingSpace = 1;
344
-        if ($tokens[($stackPtr + 1)]['code'] === T_WHITESPACE) {
345
-            $leadingSpace = (strlen($tokens[($stackPtr + 1)]['content']) + 1);
344
+        if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] === T_WHITESPACE ) {
345
+            $leadingSpace = ( strlen( $tokens[ ( $stackPtr + 1 ) ][ 'content' ] ) + 1 );
346 346
         }
347 347
 
348
-        if ($leadingSpace !== 1) {
348
+        if ( $leadingSpace !== 1 ) {
349 349
             $error = 'Expected 1 space after opening PHP tag; %s found';
350
-            $data  = array($leadingSpace);
351
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingAfterOpen', $data);
352
-            if ($fix === true) {
353
-                $phpcsFile->fixer->replaceToken(($stackPtr + 1), '');
350
+            $data  = array( $leadingSpace );
351
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'SpacingAfterOpen', $data );
352
+            if ( $fix === true ) {
353
+                $phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), '' );
354 354
             }
355 355
         }
356 356
 
357
-        $prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($closeTag - 1), $stackPtr, true);
358
-        if ((isset($tokens[$prev]['scope_opener']) === false
359
-            || $tokens[$prev]['scope_opener'] !== $prev)
360
-            && (isset($tokens[$prev]['scope_closer']) === false
361
-            || $tokens[$prev]['scope_closer'] !== $prev)
362
-            && $tokens[$prev]['code'] !== T_SEMICOLON
357
+        $prev = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $closeTag - 1 ), $stackPtr, true );
358
+        if ( ( isset( $tokens[ $prev ][ 'scope_opener' ] ) === false
359
+            || $tokens[ $prev ][ 'scope_opener' ] !== $prev )
360
+            && ( isset( $tokens[ $prev ][ 'scope_closer' ] ) === false
361
+            || $tokens[ $prev ][ 'scope_closer' ] !== $prev )
362
+            && $tokens[ $prev ][ 'code' ] !== T_SEMICOLON
363 363
         ) {
364 364
             $error = 'Inline PHP statement must end with a semicolon';
365
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoSemicolon');
366
-            if ($fix === true) {
367
-                $phpcsFile->fixer->addContent($prev, ';');
365
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'NoSemicolon' );
366
+            if ( $fix === true ) {
367
+                $phpcsFile->fixer->addContent( $prev, ';' );
368 368
             }
369
-        } else if ($tokens[$prev]['code'] === T_SEMICOLON) {
369
+        } else if ( $tokens[ $prev ][ 'code' ] === T_SEMICOLON ) {
370 370
             $statementCount = 1;
371
-            for ($i = ($stackPtr + 1); $i < $prev; $i++) {
372
-                if ($tokens[$i]['code'] === T_SEMICOLON) {
371
+            for ( $i = ( $stackPtr + 1 ); $i < $prev; $i++ ) {
372
+                if ( $tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
373 373
                     $statementCount++;
374 374
                 }
375 375
             }
376 376
 
377
-            if ($statementCount > 1) {
377
+            if ( $statementCount > 1 ) {
378 378
                 $error = 'Inline PHP statement must contain a single statement; %s found';
379
-                $data  = array($statementCount);
380
-                $phpcsFile->addError($error, $stackPtr, 'MultipleStatements', $data);
379
+                $data  = array( $statementCount );
380
+                $phpcsFile->addError( $error, $stackPtr, 'MultipleStatements', $data );
381 381
             }
382 382
         }
383 383
 
384 384
         $trailingSpace = 0;
385
-        if ($tokens[($closeTag - 1)]['code'] === T_WHITESPACE) {
386
-            $trailingSpace = strlen($tokens[($closeTag - 1)]['content']);
385
+        if ( $tokens[ ( $closeTag - 1 ) ][ 'code' ] === T_WHITESPACE ) {
386
+            $trailingSpace = strlen( $tokens[ ( $closeTag - 1 ) ][ 'content' ] );
387 387
         }
388 388
 
389
-        if ($trailingSpace !== 1) {
389
+        if ( $trailingSpace !== 1 ) {
390 390
             $error = 'Expected 1 space before closing PHP tag; %s found';
391
-            $data  = array($trailingSpace);
392
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpacingBeforeClose', $data);
393
-            if ($fix === true) {
394
-                if ($trailingSpace === 0) {
395
-                    $phpcsFile->fixer->addContentBefore($closeTag, ' ');
391
+            $data  = array( $trailingSpace );
392
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'SpacingBeforeClose', $data );
393
+            if ( $fix === true ) {
394
+                if ( $trailingSpace === 0 ) {
395
+                    $phpcsFile->fixer->addContentBefore( $closeTag, ' ' );
396 396
                 } else {
397
-                    $phpcsFile->fixer->replaceToken(($closeTag - 1), ' ');
397
+                    $phpcsFile->fixer->replaceToken( ( $closeTag - 1 ), ' ' );
398 398
                 }
399 399
             }
400 400
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_PHP_EmbeddedPhpSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_PHP_EmbeddedPhpSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
 
34 33
     /**
@@ -36,8 +35,7 @@  discard block
 block discarded – undo
36 35
      *
37 36
      * @return array
38 37
      */
39
-    public function register()
40
-    {
38
+    public function register() {
41 39
         return array(T_OPEN_TAG);
42 40
 
43 41
     }//end register()
@@ -52,8 +50,7 @@  discard block
 block discarded – undo
52 50
      *
53 51
      * @return void
54 52
      */
55
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
-    {
53
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
57 54
         $tokens = $phpcsFile->getTokens();
58 55
 
59 56
         // If the close php tag is on the same line as the opening
@@ -77,8 +74,7 @@  discard block
 block discarded – undo
77 74
      *
78 75
      * @return void
79 76
      */
80
-    private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
81
-    {
77
+    private function _validateMultilineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
82 78
         $tokens = $phpcsFile->getTokens();
83 79
 
84 80
         $prevTag = $phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1));
@@ -310,8 +306,7 @@  discard block
 block discarded – undo
310 306
      *
311 307
      * @return void
312 308
      */
313
-    private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
314
-    {
309
+    private function _validateInlineEmbeddedPhp(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
315 310
         $tokens = $phpcsFile->getTokens();
316 311
 
317 312
         // We only want one line PHP sections, so return if the closing tag is
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/Strings/EchoedStringsSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@
 block discarded – undo
35 35
     /**
36 36
      * Returns an array of tokens this test wants to listen for.
37 37
      *
38
-     * @return array
38
+     * @return integer[]
39 39
      */
40 40
     public function register()
41 41
     {
Please login to merge, or discard this patch.
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -32,72 +32,72 @@
 block discarded – undo
32 32
 {
33 33
 
34 34
 
35
-    /**
36
-     * Returns an array of tokens this test wants to listen for.
37
-     *
38
-     * @return array
39
-     */
40
-    public function register()
41
-    {
42
-        return array(T_ECHO);
43
-
44
-    }//end register()
45
-
46
-
47
-    /**
48
-     * Processes this test, when one of its tokens is encountered.
49
-     *
50
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
-     * @param int                  $stackPtr  The position of the current token in the
52
-     *                                        stack passed in $tokens.
53
-     *
54
-     * @return void
55
-     */
56
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
-    {
58
-        $tokens = $phpcsFile->getTokens();
59
-
60
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
61
-        // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
62
-        if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
63
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
64
-            return;
65
-        }
66
-
67
-        $end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false);
68
-
69
-        // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
70
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), null, true);
71
-        if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
72
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
73
-            return;
74
-        }
75
-
76
-        // If the parenthesis don't match, then we are not concerned.
77
-        if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) {
78
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
79
-            return;
80
-        }
81
-
82
-        $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes');
83
-
84
-        if (($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false)) === false) {
85
-            // There are no arithmetic operators in this.
86
-            $error = 'Echoed strings should not be bracketed';
87
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket');
88
-            if ($fix === true) {
89
-                $phpcsFile->fixer->beginChangeset();
90
-                $phpcsFile->fixer->replaceToken($firstContent, '');
91
-                if ($tokens[($firstContent - 1)]['code'] !== T_WHITESPACE) {
92
-                    $phpcsFile->fixer->addContent(($firstContent - 1), ' ');
93
-                }
94
-
95
-                $phpcsFile->fixer->replaceToken($prev, '');
96
-                $phpcsFile->fixer->endChangeset();
97
-            }
98
-        }
99
-
100
-    }//end process()
35
+	 /**
36
+	  * Returns an array of tokens this test wants to listen for.
37
+	  *
38
+	  * @return array
39
+	  */
40
+	 public function register()
41
+	 {
42
+		  return array(T_ECHO);
43
+
44
+	 }//end register()
45
+
46
+
47
+	 /**
48
+	  * Processes this test, when one of its tokens is encountered.
49
+	  *
50
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
51
+	  * @param int                  $stackPtr  The position of the current token in the
52
+	  *                                        stack passed in $tokens.
53
+	  *
54
+	  * @return void
55
+	  */
56
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
+	 {
58
+		  $tokens = $phpcsFile->getTokens();
59
+
60
+		  $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
61
+		  // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
62
+		  if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
63
+				$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
64
+				return;
65
+		  }
66
+
67
+		  $end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false);
68
+
69
+		  // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
70
+		  $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), null, true);
71
+		  if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
72
+				$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
73
+				return;
74
+		  }
75
+
76
+		  // If the parenthesis don't match, then we are not concerned.
77
+		  if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) {
78
+				$phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
79
+				return;
80
+		  }
81
+
82
+		  $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes');
83
+
84
+		  if (($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false)) === false) {
85
+				// There are no arithmetic operators in this.
86
+				$error = 'Echoed strings should not be bracketed';
87
+				$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket');
88
+				if ($fix === true) {
89
+					 $phpcsFile->fixer->beginChangeset();
90
+					 $phpcsFile->fixer->replaceToken($firstContent, '');
91
+					 if ($tokens[($firstContent - 1)]['code'] !== T_WHITESPACE) {
92
+						  $phpcsFile->fixer->addContent(($firstContent - 1), ' ');
93
+					 }
94
+
95
+					 $phpcsFile->fixer->replaceToken($prev, '');
96
+					 $phpcsFile->fixer->endChangeset();
97
+				}
98
+		  }
99
+
100
+	 }//end process()
101 101
 
102 102
 
103 103
 }//end class
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function register()
41 41
     {
42
-        return array(T_ECHO);
42
+        return array( T_ECHO );
43 43
 
44 44
     }//end register()
45 45
 
@@ -53,46 +53,46 @@  discard block
 block discarded – undo
53 53
      *
54 54
      * @return void
55 55
      */
56
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
57 57
     {
58 58
         $tokens = $phpcsFile->getTokens();
59 59
 
60
-        $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
60
+        $firstContent = $phpcsFile->findNext( T_WHITESPACE, ( $stackPtr + 1 ), null, true );
61 61
         // If the first non-whitespace token is not an opening parenthesis, then we are not concerned.
62
-        if ($tokens[$firstContent]['code'] !== T_OPEN_PARENTHESIS) {
63
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
62
+        if ( $tokens[ $firstContent ][ 'code' ] !== T_OPEN_PARENTHESIS ) {
63
+            $phpcsFile->recordMetric( $stackPtr, 'Brackets around echoed strings', 'no' );
64 64
             return;
65 65
         }
66 66
 
67
-        $end = $phpcsFile->findNext(array(T_SEMICOLON, T_CLOSE_TAG), $stackPtr, null, false);
67
+        $end = $phpcsFile->findNext( array( T_SEMICOLON, T_CLOSE_TAG ), $stackPtr, null, false );
68 68
 
69 69
         // If the token before the semi-colon is not a closing parenthesis, then we are not concerned.
70
-        $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($end - 1), null, true);
71
-        if ($tokens[$prev]['code'] !== T_CLOSE_PARENTHESIS) {
72
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
70
+        $prev = $phpcsFile->findPrevious( T_WHITESPACE, ( $end - 1 ), null, true );
71
+        if ( $tokens[ $prev ][ 'code' ] !== T_CLOSE_PARENTHESIS ) {
72
+            $phpcsFile->recordMetric( $stackPtr, 'Brackets around echoed strings', 'no' );
73 73
             return;
74 74
         }
75 75
 
76 76
         // If the parenthesis don't match, then we are not concerned.
77
-        if ($tokens[$firstContent]['parenthesis_closer'] !== $prev) {
78
-            $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'no');
77
+        if ( $tokens[ $firstContent ][ 'parenthesis_closer' ] !== $prev ) {
78
+            $phpcsFile->recordMetric( $stackPtr, 'Brackets around echoed strings', 'no' );
79 79
             return;
80 80
         }
81 81
 
82
-        $phpcsFile->recordMetric($stackPtr, 'Brackets around echoed strings', 'yes');
82
+        $phpcsFile->recordMetric( $stackPtr, 'Brackets around echoed strings', 'yes' );
83 83
 
84
-        if (($phpcsFile->findNext(PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false)) === false) {
84
+        if ( ( $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$operators, $stackPtr, $end, false ) ) === false ) {
85 85
             // There are no arithmetic operators in this.
86 86
             $error = 'Echoed strings should not be bracketed';
87
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'HasBracket');
88
-            if ($fix === true) {
87
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'HasBracket' );
88
+            if ( $fix === true ) {
89 89
                 $phpcsFile->fixer->beginChangeset();
90
-                $phpcsFile->fixer->replaceToken($firstContent, '');
91
-                if ($tokens[($firstContent - 1)]['code'] !== T_WHITESPACE) {
92
-                    $phpcsFile->fixer->addContent(($firstContent - 1), ' ');
90
+                $phpcsFile->fixer->replaceToken( $firstContent, '' );
91
+                if ( $tokens[ ( $firstContent - 1 ) ][ 'code' ] !== T_WHITESPACE ) {
92
+                    $phpcsFile->fixer->addContent( ( $firstContent - 1 ), ' ' );
93 93
                 }
94 94
 
95
-                $phpcsFile->fixer->replaceToken($prev, '');
95
+                $phpcsFile->fixer->replaceToken( $prev, '' );
96 96
                 $phpcsFile->fixer->endChangeset();
97 97
             }
98 98
         }
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
  * @version   Release: @package_version@
29 29
  * @link      http://pear.php.net/package/PHP_CodeSniffer
30 30
  */
31
-class Squiz_Sniffs_Strings_EchoedStringsSniff implements PHP_CodeSniffer_Sniff
32
-{
31
+class Squiz_Sniffs_Strings_EchoedStringsSniff implements PHP_CodeSniffer_Sniff {
33 32
 
34 33
 
35 34
     /**
@@ -37,8 +36,7 @@  discard block
 block discarded – undo
37 36
      *
38 37
      * @return array
39 38
      */
40
-    public function register()
41
-    {
39
+    public function register() {
42 40
         return array(T_ECHO);
43 41
 
44 42
     }//end register()
@@ -53,8 +51,7 @@  discard block
 block discarded – undo
53 51
      *
54 52
      * @return void
55 53
      */
56
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
57
-    {
54
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
58 55
         $tokens = $phpcsFile->getTokens();
59 56
 
60 57
         $firstContent = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
Please login to merge, or discard this patch.
Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     /**
45 45
      * Returns an array of tokens this test wants to listen for.
46 46
      *
47
-     * @return array
47
+     * @return integer[]
48 48
      */
49 49
     public function register()
50 50
     {
Please login to merge, or discard this patch.
Indentation   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -30,287 +30,287 @@
 block discarded – undo
30 30
 class Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * A list of tokenizers this sniff supports.
35
-     *
36
-     * @var array
37
-     */
38
-    public $supportedTokenizers = array(
39
-                                   'PHP',
40
-                                   'JS',
41
-                                  );
42
-
43
-
44
-    /**
45
-     * Returns an array of tokens this test wants to listen for.
46
-     *
47
-     * @return array
48
-     */
49
-    public function register()
50
-    {
51
-        return array(
52
-                T_IF,
53
-                T_WHILE,
54
-                T_FOREACH,
55
-                T_FOR,
56
-                T_SWITCH,
57
-                T_DO,
58
-                T_ELSE,
59
-                T_ELSEIF,
60
-                T_TRY,
61
-                T_CATCH,
62
-               );
63
-
64
-    }//end register()
65
-
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
72
-     *                                        in the stack passed in $tokens.
73
-     *
74
-     * @return void
75
-     */
76
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
77
-    {
78
-        $tokens = $phpcsFile->getTokens();
79
-
80
-        if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
81
-            && isset($tokens[$stackPtr]['parenthesis_closer']) === true
82
-        ) {
83
-            $parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
84
-            $parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
85
-            if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
86
-                $gap = $tokens[($parenOpener + 1)]['length'];
87
-
88
-                if ($gap === 0) {
89
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 'newline');
90
-                    $gap = 'newline';
91
-                } else {
92
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $gap);
93
-                }
94
-
95
-                $error = 'Expected 0 spaces after opening bracket; %s found';
96
-                $data  = array($gap);
97
-                $fix   = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);
98
-                if ($fix === true) {
99
-                    $phpcsFile->fixer->replaceToken(($parenOpener + 1), '');
100
-                }
101
-            } else {
102
-                $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 0);
103
-            }
104
-
105
-            if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']
106
-                && $tokens[($parenCloser - 1)]['code'] === T_WHITESPACE
107
-            ) {
108
-                $gap   = $tokens[($parenCloser - 1)]['length'];
109
-                $error = 'Expected 0 spaces before closing bracket; %s found';
110
-                $data  = array($gap);
111
-                $fix   = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);
112
-                if ($fix === true) {
113
-                    $phpcsFile->fixer->replaceToken(($parenCloser - 1), '');
114
-                }
115
-
116
-                if ($gap === 0) {
117
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 'newline');
118
-                } else {
119
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $gap);
120
-                }
121
-            } else {
122
-                $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 0);
123
-            }
124
-        }//end if
125
-
126
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
127
-            return;
128
-        }
129
-
130
-        $scopeOpener = $tokens[$stackPtr]['scope_opener'];
131
-        $scopeCloser = $tokens[$stackPtr]['scope_closer'];
132
-
133
-        for ($firstContent = ($scopeOpener + 1); $firstContent < $phpcsFile->numTokens; $firstContent++) {
134
-            if ($tokens[$firstContent]['code'] !== T_WHITESPACE) {
135
-                break;
136
-            }
137
-        }
138
-
139
-        // We ignore spacing for some structures that tend to have their own rules.
140
-        $ignore = array(
141
-                   T_FUNCTION             => true,
142
-                   T_CLASS                => true,
143
-                   T_INTERFACE            => true,
144
-                   T_TRAIT                => true,
145
-                   T_DOC_COMMENT_OPEN_TAG => true,
146
-                  );
147
-
148
-        if (isset($ignore[$tokens[$firstContent]['code']]) === false
149
-            && $tokens[$firstContent]['line'] >= ($tokens[$scopeOpener]['line'] + 2)
150
-        ) {
151
-            $error = 'Blank line found at start of control structure';
152
-            $fix   = $phpcsFile->addFixableError($error, $scopeOpener, 'SpacingAfterOpen');
153
-
154
-            if ($fix === true) {
155
-                $phpcsFile->fixer->beginChangeset();
156
-                $i = ($scopeOpener + 1);
157
-                while ($tokens[$i]['line'] !== $tokens[$firstContent]['line']) {
158
-                    $phpcsFile->fixer->replaceToken($i, '');
159
-                    $i++;
160
-                }
161
-
162
-                $phpcsFile->fixer->addNewline($scopeOpener);
163
-                $phpcsFile->fixer->endChangeset();
164
-            }
165
-        }
166
-
167
-        if ($firstContent !== $scopeCloser) {
168
-            $lastContent = $phpcsFile->findPrevious(
169
-                T_WHITESPACE,
170
-                ($scopeCloser - 1),
171
-                null,
172
-                true
173
-            );
174
-
175
-            $lastNonEmptyContent = $phpcsFile->findPrevious(
176
-                PHP_CodeSniffer_Tokens::$emptyTokens,
177
-                ($scopeCloser - 1),
178
-                null,
179
-                true
180
-            );
181
-
182
-            $checkToken = $lastContent;
183
-            if (isset($tokens[$lastNonEmptyContent]['scope_condition']) === true) {
184
-                $checkToken = $tokens[$lastNonEmptyContent]['scope_condition'];
185
-            }
186
-
187
-            if (isset($ignore[$tokens[$checkToken]['code']]) === false
188
-                && $tokens[$lastContent]['line'] <= ($tokens[$scopeCloser]['line'] - 2)
189
-            ) {
190
-                $errorToken = $scopeCloser;
191
-                for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
192
-                    if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) {
193
-                        $errorToken = $i;
194
-                        break;
195
-                    }
196
-                }
197
-
198
-                $error = 'Blank line found at end of control structure';
199
-                $fix   = $phpcsFile->addFixableError($error, $errorToken, 'SpacingBeforeClose');
200
-
201
-                if ($fix === true) {
202
-                    $phpcsFile->fixer->beginChangeset();
203
-                    $i = ($scopeCloser - 1);
204
-                    for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
205
-                        if ($tokens[$i]['line'] === $tokens[$scopeCloser]['line']) {
206
-                            continue;
207
-                        }
208
-
209
-                        if ($tokens[$i]['line'] === $tokens[$lastContent]['line']) {
210
-                            break;
211
-                        }
212
-
213
-                        $phpcsFile->fixer->replaceToken($i, '');
214
-                    }
215
-
216
-                    $phpcsFile->fixer->endChangeset();
217
-                }
218
-            }//end if
219
-        }//end if
220
-
221
-        $trailingContent = $phpcsFile->findNext(
222
-            T_WHITESPACE,
223
-            ($scopeCloser + 1),
224
-            null,
225
-            true
226
-        );
227
-
228
-        if ($tokens[$trailingContent]['code'] === T_COMMENT) {
229
-            // Special exception for code where the comment about
230
-            // an ELSE or ELSEIF is written between the control structures.
231
-            $nextCode = $phpcsFile->findNext(
232
-                PHP_CodeSniffer_Tokens::$emptyTokens,
233
-                ($scopeCloser + 1),
234
-                null,
235
-                true
236
-            );
237
-
238
-            if ($tokens[$nextCode]['code'] === T_ELSE
239
-                || $tokens[$nextCode]['code'] === T_ELSEIF
240
-            ) {
241
-                $trailingContent = $nextCode;
242
-            }
243
-        }//end if
244
-
245
-        if ($tokens[$trailingContent]['code'] === T_ELSE) {
246
-            if ($tokens[$stackPtr]['code'] === T_IF) {
247
-                // IF with ELSE.
248
-                return;
249
-            }
250
-        }
251
-
252
-        if ($tokens[$trailingContent]['code'] === T_WHILE
253
-            && $tokens[$stackPtr]['code'] === T_DO
254
-        ) {
255
-            // DO with WHILE.
256
-            return;
257
-        }
258
-
259
-        if ($tokens[$trailingContent]['code'] === T_CLOSE_TAG) {
260
-            // At the end of the script or embedded code.
261
-            return;
262
-        }
263
-
264
-        if (isset($tokens[$trailingContent]['scope_condition']) === true
265
-            && $tokens[$trailingContent]['scope_condition'] !== $trailingContent
266
-            && isset($tokens[$trailingContent]['scope_opener']) === true
267
-            && $tokens[$trailingContent]['scope_opener'] !== $trailingContent
268
-        ) {
269
-            // Another control structure's closing brace.
270
-            $owner = $tokens[$trailingContent]['scope_condition'];
271
-            if ($tokens[$owner]['code'] === T_FUNCTION) {
272
-                // The next content is the closing brace of a function
273
-                // so normal function rules apply and we can ignore it.
274
-                return;
275
-            }
276
-
277
-            if ($tokens[$owner]['code'] === T_CLOSURE
278
-                && ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
279
-                || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
280
-                || isset($tokens[$stackPtr]['nested_parenthesis']) === true)
281
-            ) {
282
-                return;
283
-            }
284
-
285
-            if ($tokens[$trailingContent]['line'] !== ($tokens[$scopeCloser]['line'] + 1)) {
286
-                $error = 'Blank line found after control structure';
287
-                $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'LineAfterClose');
288
-
289
-                if ($fix === true) {
290
-                    $phpcsFile->fixer->beginChangeset();
291
-                    $i = ($scopeCloser + 1);
292
-                    while ($tokens[$i]['line'] !== $tokens[$trailingContent]['line']) {
293
-                        $phpcsFile->fixer->replaceToken($i, '');
294
-                        $i++;
295
-                    }
296
-
297
-                    $phpcsFile->fixer->addNewline($scopeCloser);
298
-                    $phpcsFile->fixer->endChangeset();
299
-                }
300
-            }
301
-        } else if ($tokens[$trailingContent]['code'] !== T_ELSE
302
-            && $tokens[$trailingContent]['code'] !== T_ELSEIF
303
-            && $tokens[$trailingContent]['code'] !== T_CATCH
304
-            && $tokens[$trailingContent]['line'] === ($tokens[$scopeCloser]['line'] + 1)
305
-        ) {
306
-            $error = 'No blank line found after control structure';
307
-            $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'NoLineAfterClose');
308
-            if ($fix === true) {
309
-                $phpcsFile->fixer->addNewline($scopeCloser);
310
-            }
311
-        }//end if
312
-
313
-    }//end process()
33
+	 /**
34
+	  * A list of tokenizers this sniff supports.
35
+	  *
36
+	  * @var array
37
+	  */
38
+	 public $supportedTokenizers = array(
39
+											  'PHP',
40
+											  'JS',
41
+											 );
42
+
43
+
44
+	 /**
45
+	  * Returns an array of tokens this test wants to listen for.
46
+	  *
47
+	  * @return array
48
+	  */
49
+	 public function register()
50
+	 {
51
+		  return array(
52
+					 T_IF,
53
+					 T_WHILE,
54
+					 T_FOREACH,
55
+					 T_FOR,
56
+					 T_SWITCH,
57
+					 T_DO,
58
+					 T_ELSE,
59
+					 T_ELSEIF,
60
+					 T_TRY,
61
+					 T_CATCH,
62
+					);
63
+
64
+	 }//end register()
65
+
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
72
+	  *                                        in the stack passed in $tokens.
73
+	  *
74
+	  * @return void
75
+	  */
76
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
77
+	 {
78
+		  $tokens = $phpcsFile->getTokens();
79
+
80
+		  if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
81
+				&& isset($tokens[$stackPtr]['parenthesis_closer']) === true
82
+		  ) {
83
+				$parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
84
+				$parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
85
+				if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
86
+					 $gap = $tokens[($parenOpener + 1)]['length'];
87
+
88
+					 if ($gap === 0) {
89
+						  $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 'newline');
90
+						  $gap = 'newline';
91
+					 } else {
92
+						  $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $gap);
93
+					 }
94
+
95
+					 $error = 'Expected 0 spaces after opening bracket; %s found';
96
+					 $data  = array($gap);
97
+					 $fix   = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);
98
+					 if ($fix === true) {
99
+						  $phpcsFile->fixer->replaceToken(($parenOpener + 1), '');
100
+					 }
101
+				} else {
102
+					 $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 0);
103
+				}
104
+
105
+				if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']
106
+					 && $tokens[($parenCloser - 1)]['code'] === T_WHITESPACE
107
+				) {
108
+					 $gap   = $tokens[($parenCloser - 1)]['length'];
109
+					 $error = 'Expected 0 spaces before closing bracket; %s found';
110
+					 $data  = array($gap);
111
+					 $fix   = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);
112
+					 if ($fix === true) {
113
+						  $phpcsFile->fixer->replaceToken(($parenCloser - 1), '');
114
+					 }
115
+
116
+					 if ($gap === 0) {
117
+						  $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 'newline');
118
+					 } else {
119
+						  $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $gap);
120
+					 }
121
+				} else {
122
+					 $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 0);
123
+				}
124
+		  }//end if
125
+
126
+		  if (isset($tokens[$stackPtr]['scope_closer']) === false) {
127
+				return;
128
+		  }
129
+
130
+		  $scopeOpener = $tokens[$stackPtr]['scope_opener'];
131
+		  $scopeCloser = $tokens[$stackPtr]['scope_closer'];
132
+
133
+		  for ($firstContent = ($scopeOpener + 1); $firstContent < $phpcsFile->numTokens; $firstContent++) {
134
+				if ($tokens[$firstContent]['code'] !== T_WHITESPACE) {
135
+					 break;
136
+				}
137
+		  }
138
+
139
+		  // We ignore spacing for some structures that tend to have their own rules.
140
+		  $ignore = array(
141
+						 T_FUNCTION             => true,
142
+						 T_CLASS                => true,
143
+						 T_INTERFACE            => true,
144
+						 T_TRAIT                => true,
145
+						 T_DOC_COMMENT_OPEN_TAG => true,
146
+						);
147
+
148
+		  if (isset($ignore[$tokens[$firstContent]['code']]) === false
149
+				&& $tokens[$firstContent]['line'] >= ($tokens[$scopeOpener]['line'] + 2)
150
+		  ) {
151
+				$error = 'Blank line found at start of control structure';
152
+				$fix   = $phpcsFile->addFixableError($error, $scopeOpener, 'SpacingAfterOpen');
153
+
154
+				if ($fix === true) {
155
+					 $phpcsFile->fixer->beginChangeset();
156
+					 $i = ($scopeOpener + 1);
157
+					 while ($tokens[$i]['line'] !== $tokens[$firstContent]['line']) {
158
+						  $phpcsFile->fixer->replaceToken($i, '');
159
+						  $i++;
160
+					 }
161
+
162
+					 $phpcsFile->fixer->addNewline($scopeOpener);
163
+					 $phpcsFile->fixer->endChangeset();
164
+				}
165
+		  }
166
+
167
+		  if ($firstContent !== $scopeCloser) {
168
+				$lastContent = $phpcsFile->findPrevious(
169
+					 T_WHITESPACE,
170
+					 ($scopeCloser - 1),
171
+					 null,
172
+					 true
173
+				);
174
+
175
+				$lastNonEmptyContent = $phpcsFile->findPrevious(
176
+					 PHP_CodeSniffer_Tokens::$emptyTokens,
177
+					 ($scopeCloser - 1),
178
+					 null,
179
+					 true
180
+				);
181
+
182
+				$checkToken = $lastContent;
183
+				if (isset($tokens[$lastNonEmptyContent]['scope_condition']) === true) {
184
+					 $checkToken = $tokens[$lastNonEmptyContent]['scope_condition'];
185
+				}
186
+
187
+				if (isset($ignore[$tokens[$checkToken]['code']]) === false
188
+					 && $tokens[$lastContent]['line'] <= ($tokens[$scopeCloser]['line'] - 2)
189
+				) {
190
+					 $errorToken = $scopeCloser;
191
+					 for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
192
+						  if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) {
193
+								$errorToken = $i;
194
+								break;
195
+						  }
196
+					 }
197
+
198
+					 $error = 'Blank line found at end of control structure';
199
+					 $fix   = $phpcsFile->addFixableError($error, $errorToken, 'SpacingBeforeClose');
200
+
201
+					 if ($fix === true) {
202
+						  $phpcsFile->fixer->beginChangeset();
203
+						  $i = ($scopeCloser - 1);
204
+						  for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
205
+								if ($tokens[$i]['line'] === $tokens[$scopeCloser]['line']) {
206
+									 continue;
207
+								}
208
+
209
+								if ($tokens[$i]['line'] === $tokens[$lastContent]['line']) {
210
+									 break;
211
+								}
212
+
213
+								$phpcsFile->fixer->replaceToken($i, '');
214
+						  }
215
+
216
+						  $phpcsFile->fixer->endChangeset();
217
+					 }
218
+				}//end if
219
+		  }//end if
220
+
221
+		  $trailingContent = $phpcsFile->findNext(
222
+				T_WHITESPACE,
223
+				($scopeCloser + 1),
224
+				null,
225
+				true
226
+		  );
227
+
228
+		  if ($tokens[$trailingContent]['code'] === T_COMMENT) {
229
+				// Special exception for code where the comment about
230
+				// an ELSE or ELSEIF is written between the control structures.
231
+				$nextCode = $phpcsFile->findNext(
232
+					 PHP_CodeSniffer_Tokens::$emptyTokens,
233
+					 ($scopeCloser + 1),
234
+					 null,
235
+					 true
236
+				);
237
+
238
+				if ($tokens[$nextCode]['code'] === T_ELSE
239
+					 || $tokens[$nextCode]['code'] === T_ELSEIF
240
+				) {
241
+					 $trailingContent = $nextCode;
242
+				}
243
+		  }//end if
244
+
245
+		  if ($tokens[$trailingContent]['code'] === T_ELSE) {
246
+				if ($tokens[$stackPtr]['code'] === T_IF) {
247
+					 // IF with ELSE.
248
+					 return;
249
+				}
250
+		  }
251
+
252
+		  if ($tokens[$trailingContent]['code'] === T_WHILE
253
+				&& $tokens[$stackPtr]['code'] === T_DO
254
+		  ) {
255
+				// DO with WHILE.
256
+				return;
257
+		  }
258
+
259
+		  if ($tokens[$trailingContent]['code'] === T_CLOSE_TAG) {
260
+				// At the end of the script or embedded code.
261
+				return;
262
+		  }
263
+
264
+		  if (isset($tokens[$trailingContent]['scope_condition']) === true
265
+				&& $tokens[$trailingContent]['scope_condition'] !== $trailingContent
266
+				&& isset($tokens[$trailingContent]['scope_opener']) === true
267
+				&& $tokens[$trailingContent]['scope_opener'] !== $trailingContent
268
+		  ) {
269
+				// Another control structure's closing brace.
270
+				$owner = $tokens[$trailingContent]['scope_condition'];
271
+				if ($tokens[$owner]['code'] === T_FUNCTION) {
272
+					 // The next content is the closing brace of a function
273
+					 // so normal function rules apply and we can ignore it.
274
+					 return;
275
+				}
276
+
277
+				if ($tokens[$owner]['code'] === T_CLOSURE
278
+					 && ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
279
+					 || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
280
+					 || isset($tokens[$stackPtr]['nested_parenthesis']) === true)
281
+				) {
282
+					 return;
283
+				}
284
+
285
+				if ($tokens[$trailingContent]['line'] !== ($tokens[$scopeCloser]['line'] + 1)) {
286
+					 $error = 'Blank line found after control structure';
287
+					 $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'LineAfterClose');
288
+
289
+					 if ($fix === true) {
290
+						  $phpcsFile->fixer->beginChangeset();
291
+						  $i = ($scopeCloser + 1);
292
+						  while ($tokens[$i]['line'] !== $tokens[$trailingContent]['line']) {
293
+								$phpcsFile->fixer->replaceToken($i, '');
294
+								$i++;
295
+						  }
296
+
297
+						  $phpcsFile->fixer->addNewline($scopeCloser);
298
+						  $phpcsFile->fixer->endChangeset();
299
+					 }
300
+				}
301
+		  } else if ($tokens[$trailingContent]['code'] !== T_ELSE
302
+				&& $tokens[$trailingContent]['code'] !== T_ELSEIF
303
+				&& $tokens[$trailingContent]['code'] !== T_CATCH
304
+				&& $tokens[$trailingContent]['line'] === ($tokens[$scopeCloser]['line'] + 1)
305
+		  ) {
306
+				$error = 'No blank line found after control structure';
307
+				$fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'NoLineAfterClose');
308
+				if ($fix === true) {
309
+					 $phpcsFile->fixer->addNewline($scopeCloser);
310
+				}
311
+		  }//end if
312
+
313
+	 }//end process()
314 314
 
315 315
 
316 316
 }//end class
Please login to merge, or discard this patch.
Spacing   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -73,65 +73,65 @@  discard block
 block discarded – undo
73 73
      *
74 74
      * @return void
75 75
      */
76
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
76
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
77 77
     {
78 78
         $tokens = $phpcsFile->getTokens();
79 79
 
80
-        if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
81
-            && isset($tokens[$stackPtr]['parenthesis_closer']) === true
80
+        if ( isset( $tokens[ $stackPtr ][ 'parenthesis_opener' ] ) === true
81
+            && isset( $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true
82 82
         ) {
83
-            $parenOpener = $tokens[$stackPtr]['parenthesis_opener'];
84
-            $parenCloser = $tokens[$stackPtr]['parenthesis_closer'];
85
-            if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
86
-                $gap = $tokens[($parenOpener + 1)]['length'];
83
+            $parenOpener = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
84
+            $parenCloser = $tokens[ $stackPtr ][ 'parenthesis_closer' ];
85
+            if ( $tokens[ ( $parenOpener + 1 ) ][ 'code' ] === T_WHITESPACE ) {
86
+                $gap = $tokens[ ( $parenOpener + 1 ) ][ 'length' ];
87 87
 
88
-                if ($gap === 0) {
89
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 'newline');
88
+                if ( $gap === 0 ) {
89
+                    $phpcsFile->recordMetric( $stackPtr, 'Spaces after control structure open parenthesis', 'newline' );
90 90
                     $gap = 'newline';
91 91
                 } else {
92
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', $gap);
92
+                    $phpcsFile->recordMetric( $stackPtr, 'Spaces after control structure open parenthesis', $gap );
93 93
                 }
94 94
 
95 95
                 $error = 'Expected 0 spaces after opening bracket; %s found';
96
-                $data  = array($gap);
97
-                $fix   = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);
98
-                if ($fix === true) {
99
-                    $phpcsFile->fixer->replaceToken(($parenOpener + 1), '');
96
+                $data  = array( $gap );
97
+                $fix   = $phpcsFile->addFixableError( $error, ( $parenOpener + 1 ), 'SpacingAfterOpenBrace', $data );
98
+                if ( $fix === true ) {
99
+                    $phpcsFile->fixer->replaceToken( ( $parenOpener + 1 ), '' );
100 100
                 }
101 101
             } else {
102
-                $phpcsFile->recordMetric($stackPtr, 'Spaces after control structure open parenthesis', 0);
102
+                $phpcsFile->recordMetric( $stackPtr, 'Spaces after control structure open parenthesis', 0 );
103 103
             }
104 104
 
105
-            if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']
106
-                && $tokens[($parenCloser - 1)]['code'] === T_WHITESPACE
105
+            if ( $tokens[ $parenOpener ][ 'line' ] === $tokens[ $parenCloser ][ 'line' ]
106
+                && $tokens[ ( $parenCloser - 1 ) ][ 'code' ] === T_WHITESPACE
107 107
             ) {
108
-                $gap   = $tokens[($parenCloser - 1)]['length'];
108
+                $gap   = $tokens[ ( $parenCloser - 1 ) ][ 'length' ];
109 109
                 $error = 'Expected 0 spaces before closing bracket; %s found';
110
-                $data  = array($gap);
111
-                $fix   = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);
112
-                if ($fix === true) {
113
-                    $phpcsFile->fixer->replaceToken(($parenCloser - 1), '');
110
+                $data  = array( $gap );
111
+                $fix   = $phpcsFile->addFixableError( $error, ( $parenCloser - 1 ), 'SpaceBeforeCloseBrace', $data );
112
+                if ( $fix === true ) {
113
+                    $phpcsFile->fixer->replaceToken( ( $parenCloser - 1 ), '' );
114 114
                 }
115 115
 
116
-                if ($gap === 0) {
117
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 'newline');
116
+                if ( $gap === 0 ) {
117
+                    $phpcsFile->recordMetric( $stackPtr, 'Spaces before control structure close parenthesis', 'newline' );
118 118
                 } else {
119
-                    $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', $gap);
119
+                    $phpcsFile->recordMetric( $stackPtr, 'Spaces before control structure close parenthesis', $gap );
120 120
                 }
121 121
             } else {
122
-                $phpcsFile->recordMetric($stackPtr, 'Spaces before control structure close parenthesis', 0);
122
+                $phpcsFile->recordMetric( $stackPtr, 'Spaces before control structure close parenthesis', 0 );
123 123
             }
124 124
         }//end if
125 125
 
126
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
126
+        if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
127 127
             return;
128 128
         }
129 129
 
130
-        $scopeOpener = $tokens[$stackPtr]['scope_opener'];
131
-        $scopeCloser = $tokens[$stackPtr]['scope_closer'];
130
+        $scopeOpener = $tokens[ $stackPtr ][ 'scope_opener' ];
131
+        $scopeCloser = $tokens[ $stackPtr ][ 'scope_closer' ];
132 132
 
133
-        for ($firstContent = ($scopeOpener + 1); $firstContent < $phpcsFile->numTokens; $firstContent++) {
134
-            if ($tokens[$firstContent]['code'] !== T_WHITESPACE) {
133
+        for ( $firstContent = ( $scopeOpener + 1 ); $firstContent < $phpcsFile->numTokens; $firstContent++ ) {
134
+            if ( $tokens[ $firstContent ][ 'code' ] !== T_WHITESPACE ) {
135 135
                 break;
136 136
             }
137 137
         }
@@ -145,72 +145,72 @@  discard block
 block discarded – undo
145 145
                    T_DOC_COMMENT_OPEN_TAG => true,
146 146
                   );
147 147
 
148
-        if (isset($ignore[$tokens[$firstContent]['code']]) === false
149
-            && $tokens[$firstContent]['line'] >= ($tokens[$scopeOpener]['line'] + 2)
148
+        if ( isset( $ignore[ $tokens[ $firstContent ][ 'code' ] ] ) === false
149
+            && $tokens[ $firstContent ][ 'line' ] >= ( $tokens[ $scopeOpener ][ 'line' ] + 2 )
150 150
         ) {
151 151
             $error = 'Blank line found at start of control structure';
152
-            $fix   = $phpcsFile->addFixableError($error, $scopeOpener, 'SpacingAfterOpen');
152
+            $fix   = $phpcsFile->addFixableError( $error, $scopeOpener, 'SpacingAfterOpen' );
153 153
 
154
-            if ($fix === true) {
154
+            if ( $fix === true ) {
155 155
                 $phpcsFile->fixer->beginChangeset();
156
-                $i = ($scopeOpener + 1);
157
-                while ($tokens[$i]['line'] !== $tokens[$firstContent]['line']) {
158
-                    $phpcsFile->fixer->replaceToken($i, '');
156
+                $i = ( $scopeOpener + 1 );
157
+                while ( $tokens[ $i ][ 'line' ] !== $tokens[ $firstContent ][ 'line' ] ) {
158
+                    $phpcsFile->fixer->replaceToken( $i, '' );
159 159
                     $i++;
160 160
                 }
161 161
 
162
-                $phpcsFile->fixer->addNewline($scopeOpener);
162
+                $phpcsFile->fixer->addNewline( $scopeOpener );
163 163
                 $phpcsFile->fixer->endChangeset();
164 164
             }
165 165
         }
166 166
 
167
-        if ($firstContent !== $scopeCloser) {
167
+        if ( $firstContent !== $scopeCloser ) {
168 168
             $lastContent = $phpcsFile->findPrevious(
169 169
                 T_WHITESPACE,
170
-                ($scopeCloser - 1),
170
+                ( $scopeCloser - 1 ),
171 171
                 null,
172 172
                 true
173 173
             );
174 174
 
175 175
             $lastNonEmptyContent = $phpcsFile->findPrevious(
176 176
                 PHP_CodeSniffer_Tokens::$emptyTokens,
177
-                ($scopeCloser - 1),
177
+                ( $scopeCloser - 1 ),
178 178
                 null,
179 179
                 true
180 180
             );
181 181
 
182 182
             $checkToken = $lastContent;
183
-            if (isset($tokens[$lastNonEmptyContent]['scope_condition']) === true) {
184
-                $checkToken = $tokens[$lastNonEmptyContent]['scope_condition'];
183
+            if ( isset( $tokens[ $lastNonEmptyContent ][ 'scope_condition' ] ) === true ) {
184
+                $checkToken = $tokens[ $lastNonEmptyContent ][ 'scope_condition' ];
185 185
             }
186 186
 
187
-            if (isset($ignore[$tokens[$checkToken]['code']]) === false
188
-                && $tokens[$lastContent]['line'] <= ($tokens[$scopeCloser]['line'] - 2)
187
+            if ( isset( $ignore[ $tokens[ $checkToken ][ 'code' ] ] ) === false
188
+                && $tokens[ $lastContent ][ 'line' ] <= ( $tokens[ $scopeCloser ][ 'line' ] - 2 )
189 189
             ) {
190 190
                 $errorToken = $scopeCloser;
191
-                for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
192
-                    if ($tokens[$i]['line'] < $tokens[$scopeCloser]['line']) {
191
+                for ( $i = ( $scopeCloser - 1 ); $i > $lastContent; $i-- ) {
192
+                    if ( $tokens[ $i ][ 'line' ] < $tokens[ $scopeCloser ][ 'line' ] ) {
193 193
                         $errorToken = $i;
194 194
                         break;
195 195
                     }
196 196
                 }
197 197
 
198 198
                 $error = 'Blank line found at end of control structure';
199
-                $fix   = $phpcsFile->addFixableError($error, $errorToken, 'SpacingBeforeClose');
199
+                $fix   = $phpcsFile->addFixableError( $error, $errorToken, 'SpacingBeforeClose' );
200 200
 
201
-                if ($fix === true) {
201
+                if ( $fix === true ) {
202 202
                     $phpcsFile->fixer->beginChangeset();
203
-                    $i = ($scopeCloser - 1);
204
-                    for ($i = ($scopeCloser - 1); $i > $lastContent; $i--) {
205
-                        if ($tokens[$i]['line'] === $tokens[$scopeCloser]['line']) {
203
+                    $i = ( $scopeCloser - 1 );
204
+                    for ( $i = ( $scopeCloser - 1 ); $i > $lastContent; $i-- ) {
205
+                        if ( $tokens[ $i ][ 'line' ] === $tokens[ $scopeCloser ][ 'line' ] ) {
206 206
                             continue;
207 207
                         }
208 208
 
209
-                        if ($tokens[$i]['line'] === $tokens[$lastContent]['line']) {
209
+                        if ( $tokens[ $i ][ 'line' ] === $tokens[ $lastContent ][ 'line' ] ) {
210 210
                             break;
211 211
                         }
212 212
 
213
-                        $phpcsFile->fixer->replaceToken($i, '');
213
+                        $phpcsFile->fixer->replaceToken( $i, '' );
214 214
                     }
215 215
 
216 216
                     $phpcsFile->fixer->endChangeset();
@@ -220,93 +220,93 @@  discard block
 block discarded – undo
220 220
 
221 221
         $trailingContent = $phpcsFile->findNext(
222 222
             T_WHITESPACE,
223
-            ($scopeCloser + 1),
223
+            ( $scopeCloser + 1 ),
224 224
             null,
225 225
             true
226 226
         );
227 227
 
228
-        if ($tokens[$trailingContent]['code'] === T_COMMENT) {
228
+        if ( $tokens[ $trailingContent ][ 'code' ] === T_COMMENT ) {
229 229
             // Special exception for code where the comment about
230 230
             // an ELSE or ELSEIF is written between the control structures.
231 231
             $nextCode = $phpcsFile->findNext(
232 232
                 PHP_CodeSniffer_Tokens::$emptyTokens,
233
-                ($scopeCloser + 1),
233
+                ( $scopeCloser + 1 ),
234 234
                 null,
235 235
                 true
236 236
             );
237 237
 
238
-            if ($tokens[$nextCode]['code'] === T_ELSE
239
-                || $tokens[$nextCode]['code'] === T_ELSEIF
238
+            if ( $tokens[ $nextCode ][ 'code' ] === T_ELSE
239
+                || $tokens[ $nextCode ][ 'code' ] === T_ELSEIF
240 240
             ) {
241 241
                 $trailingContent = $nextCode;
242 242
             }
243 243
         }//end if
244 244
 
245
-        if ($tokens[$trailingContent]['code'] === T_ELSE) {
246
-            if ($tokens[$stackPtr]['code'] === T_IF) {
245
+        if ( $tokens[ $trailingContent ][ 'code' ] === T_ELSE ) {
246
+            if ( $tokens[ $stackPtr ][ 'code' ] === T_IF ) {
247 247
                 // IF with ELSE.
248 248
                 return;
249 249
             }
250 250
         }
251 251
 
252
-        if ($tokens[$trailingContent]['code'] === T_WHILE
253
-            && $tokens[$stackPtr]['code'] === T_DO
252
+        if ( $tokens[ $trailingContent ][ 'code' ] === T_WHILE
253
+            && $tokens[ $stackPtr ][ 'code' ] === T_DO
254 254
         ) {
255 255
             // DO with WHILE.
256 256
             return;
257 257
         }
258 258
 
259
-        if ($tokens[$trailingContent]['code'] === T_CLOSE_TAG) {
259
+        if ( $tokens[ $trailingContent ][ 'code' ] === T_CLOSE_TAG ) {
260 260
             // At the end of the script or embedded code.
261 261
             return;
262 262
         }
263 263
 
264
-        if (isset($tokens[$trailingContent]['scope_condition']) === true
265
-            && $tokens[$trailingContent]['scope_condition'] !== $trailingContent
266
-            && isset($tokens[$trailingContent]['scope_opener']) === true
267
-            && $tokens[$trailingContent]['scope_opener'] !== $trailingContent
264
+        if ( isset( $tokens[ $trailingContent ][ 'scope_condition' ] ) === true
265
+            && $tokens[ $trailingContent ][ 'scope_condition' ] !== $trailingContent
266
+            && isset( $tokens[ $trailingContent ][ 'scope_opener' ] ) === true
267
+            && $tokens[ $trailingContent ][ 'scope_opener' ] !== $trailingContent
268 268
         ) {
269 269
             // Another control structure's closing brace.
270
-            $owner = $tokens[$trailingContent]['scope_condition'];
271
-            if ($tokens[$owner]['code'] === T_FUNCTION) {
270
+            $owner = $tokens[ $trailingContent ][ 'scope_condition' ];
271
+            if ( $tokens[ $owner ][ 'code' ] === T_FUNCTION ) {
272 272
                 // The next content is the closing brace of a function
273 273
                 // so normal function rules apply and we can ignore it.
274 274
                 return;
275 275
             }
276 276
 
277
-            if ($tokens[$owner]['code'] === T_CLOSURE
278
-                && ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
279
-                || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
280
-                || isset($tokens[$stackPtr]['nested_parenthesis']) === true)
277
+            if ( $tokens[ $owner ][ 'code' ] === T_CLOSURE
278
+                && ( $phpcsFile->hasCondition( $stackPtr, T_FUNCTION ) === true
279
+                || $phpcsFile->hasCondition( $stackPtr, T_CLOSURE ) === true
280
+                || isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true )
281 281
             ) {
282 282
                 return;
283 283
             }
284 284
 
285
-            if ($tokens[$trailingContent]['line'] !== ($tokens[$scopeCloser]['line'] + 1)) {
285
+            if ( $tokens[ $trailingContent ][ 'line' ] !== ( $tokens[ $scopeCloser ][ 'line' ] + 1 ) ) {
286 286
                 $error = 'Blank line found after control structure';
287
-                $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'LineAfterClose');
287
+                $fix   = $phpcsFile->addFixableError( $error, $scopeCloser, 'LineAfterClose' );
288 288
 
289
-                if ($fix === true) {
289
+                if ( $fix === true ) {
290 290
                     $phpcsFile->fixer->beginChangeset();
291
-                    $i = ($scopeCloser + 1);
292
-                    while ($tokens[$i]['line'] !== $tokens[$trailingContent]['line']) {
293
-                        $phpcsFile->fixer->replaceToken($i, '');
291
+                    $i = ( $scopeCloser + 1 );
292
+                    while ( $tokens[ $i ][ 'line' ] !== $tokens[ $trailingContent ][ 'line' ] ) {
293
+                        $phpcsFile->fixer->replaceToken( $i, '' );
294 294
                         $i++;
295 295
                     }
296 296
 
297
-                    $phpcsFile->fixer->addNewline($scopeCloser);
297
+                    $phpcsFile->fixer->addNewline( $scopeCloser );
298 298
                     $phpcsFile->fixer->endChangeset();
299 299
                 }
300 300
             }
301
-        } else if ($tokens[$trailingContent]['code'] !== T_ELSE
302
-            && $tokens[$trailingContent]['code'] !== T_ELSEIF
303
-            && $tokens[$trailingContent]['code'] !== T_CATCH
304
-            && $tokens[$trailingContent]['line'] === ($tokens[$scopeCloser]['line'] + 1)
301
+        } else if ( $tokens[ $trailingContent ][ 'code' ] !== T_ELSE
302
+            && $tokens[ $trailingContent ][ 'code' ] !== T_ELSEIF
303
+            && $tokens[ $trailingContent ][ 'code' ] !== T_CATCH
304
+            && $tokens[ $trailingContent ][ 'line' ] === ( $tokens[ $scopeCloser ][ 'line' ] + 1 )
305 305
         ) {
306 306
             $error = 'No blank line found after control structure';
307
-            $fix   = $phpcsFile->addFixableError($error, $scopeCloser, 'NoLineAfterClose');
308
-            if ($fix === true) {
309
-                $phpcsFile->fixer->addNewline($scopeCloser);
307
+            $fix   = $phpcsFile->addFixableError( $error, $scopeCloser, 'NoLineAfterClose' );
308
+            if ( $fix === true ) {
309
+                $phpcsFile->fixer->addNewline( $scopeCloser );
310 310
             }
311 311
         }//end if
312 312
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_WhiteSpace_ControlStructureSpacingSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
     /**
34 33
      * A list of tokenizers this sniff supports.
@@ -46,8 +45,7 @@  discard block
 block discarded – undo
46 45
      *
47 46
      * @return array
48 47
      */
49
-    public function register()
50
-    {
48
+    public function register() {
51 49
         return array(
52 50
                 T_IF,
53 51
                 T_WHILE,
@@ -73,8 +71,7 @@  discard block
 block discarded – undo
73 71
      *
74 72
      * @return void
75 73
      */
76
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
77
-    {
74
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
78 75
         $tokens = $phpcsFile->getTokens();
79 76
 
80 77
         if (isset($tokens[$stackPtr]['parenthesis_opener']) === true
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/FunctionSpacingSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
     /**
42 42
      * Returns an array of tokens this test wants to listen for.
43 43
      *
44
-     * @return array
44
+     * @return integer[]
45 45
      */
46 46
     public function register()
47 47
     {
Please login to merge, or discard this patch.
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -30,210 +30,210 @@
 block discarded – undo
30 30
 class Squiz_Sniffs_WhiteSpace_FunctionSpacingSniff implements PHP_CodeSniffer_Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * The number of blank lines between functions.
35
-     *
36
-     * @var int
37
-     */
38
-    public $spacing = 2;
39
-
40
-
41
-    /**
42
-     * Returns an array of tokens this test wants to listen for.
43
-     *
44
-     * @return array
45
-     */
46
-    public function register()
47
-    {
48
-        return array(T_FUNCTION);
49
-
50
-    }//end register()
51
-
52
-
53
-    /**
54
-     * Processes this sniff when one of its tokens is encountered.
55
-     *
56
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
57
-     * @param int                  $stackPtr  The position of the current token
58
-     *                                        in the stack passed in $tokens.
59
-     *
60
-     * @return void
61
-     */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
-    {
64
-        $tokens        = $phpcsFile->getTokens();
65
-        $this->spacing = (int) $this->spacing;
66
-
67
-        /*
33
+	 /**
34
+	  * The number of blank lines between functions.
35
+	  *
36
+	  * @var int
37
+	  */
38
+	 public $spacing = 2;
39
+
40
+
41
+	 /**
42
+	  * Returns an array of tokens this test wants to listen for.
43
+	  *
44
+	  * @return array
45
+	  */
46
+	 public function register()
47
+	 {
48
+		  return array(T_FUNCTION);
49
+
50
+	 }//end register()
51
+
52
+
53
+	 /**
54
+	  * Processes this sniff when one of its tokens is encountered.
55
+	  *
56
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
57
+	  * @param int                  $stackPtr  The position of the current token
58
+	  *                                        in the stack passed in $tokens.
59
+	  *
60
+	  * @return void
61
+	  */
62
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
+	 {
64
+		  $tokens        = $phpcsFile->getTokens();
65
+		  $this->spacing = (int) $this->spacing;
66
+
67
+		  /*
68 68
             Check the number of blank lines
69 69
             after the function.
70 70
         */
71 71
 
72
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
73
-            // Must be an interface method, so the closer is the semicolon.
74
-            $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
75
-        } else {
76
-            $closer = $tokens[$stackPtr]['scope_closer'];
77
-        }
78
-
79
-        // Allow for comments on the same line as the closer.
80
-        for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) {
81
-            if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
82
-                break;
83
-            }
84
-        }
85
-
86
-        $foundLines = 0;
87
-        if ($nextLineToken === ($phpcsFile->numTokens - 1)) {
88
-            // We are at the end of the file.
89
-            // Don't check spacing after the function because this
90
-            // should be done by an EOF sniff.
91
-            $foundLines = $this->spacing;
92
-        } else {
93
-            $nextContent = $phpcsFile->findNext(T_WHITESPACE, $nextLineToken, null, true);
94
-            if ($nextContent === false) {
95
-                // We are at the end of the file.
96
-                // Don't check spacing after the function because this
97
-                // should be done by an EOF sniff.
98
-                $foundLines = $this->spacing;
99
-            } else {
100
-                $foundLines += ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']);
101
-            }
102
-        }
103
-
104
-        if ($foundLines !== $this->spacing) {
105
-            $error = 'Expected %s blank line';
106
-            if ($this->spacing !== 1) {
107
-                $error .= 's';
108
-            }
109
-
110
-            $error .= ' after function; %s found';
111
-            $data   = array(
112
-                       $this->spacing,
113
-                       $foundLines,
114
-                      );
115
-
116
-            $fix = $phpcsFile->addFixableError($error, $closer, 'After', $data);
117
-            if ($fix === true) {
118
-                $phpcsFile->fixer->beginChangeset();
119
-                for ($i = $nextLineToken; $i <= $nextContent; $i++) {
120
-                    if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) {
121
-                        $phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $this->spacing));
122
-                        break;
123
-                    }
124
-
125
-                    $phpcsFile->fixer->replaceToken($i, '');
126
-                }
127
-
128
-                $phpcsFile->fixer->endChangeset();
129
-            }//end if
130
-        }//end if
131
-
132
-        /*
72
+		  if (isset($tokens[$stackPtr]['scope_closer']) === false) {
73
+				// Must be an interface method, so the closer is the semicolon.
74
+				$closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
75
+		  } else {
76
+				$closer = $tokens[$stackPtr]['scope_closer'];
77
+		  }
78
+
79
+		  // Allow for comments on the same line as the closer.
80
+		  for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) {
81
+				if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
82
+					 break;
83
+				}
84
+		  }
85
+
86
+		  $foundLines = 0;
87
+		  if ($nextLineToken === ($phpcsFile->numTokens - 1)) {
88
+				// We are at the end of the file.
89
+				// Don't check spacing after the function because this
90
+				// should be done by an EOF sniff.
91
+				$foundLines = $this->spacing;
92
+		  } else {
93
+				$nextContent = $phpcsFile->findNext(T_WHITESPACE, $nextLineToken, null, true);
94
+				if ($nextContent === false) {
95
+					 // We are at the end of the file.
96
+					 // Don't check spacing after the function because this
97
+					 // should be done by an EOF sniff.
98
+					 $foundLines = $this->spacing;
99
+				} else {
100
+					 $foundLines += ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']);
101
+				}
102
+		  }
103
+
104
+		  if ($foundLines !== $this->spacing) {
105
+				$error = 'Expected %s blank line';
106
+				if ($this->spacing !== 1) {
107
+					 $error .= 's';
108
+				}
109
+
110
+				$error .= ' after function; %s found';
111
+				$data   = array(
112
+							  $this->spacing,
113
+							  $foundLines,
114
+							 );
115
+
116
+				$fix = $phpcsFile->addFixableError($error, $closer, 'After', $data);
117
+				if ($fix === true) {
118
+					 $phpcsFile->fixer->beginChangeset();
119
+					 for ($i = $nextLineToken; $i <= $nextContent; $i++) {
120
+						  if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) {
121
+								$phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $this->spacing));
122
+								break;
123
+						  }
124
+
125
+						  $phpcsFile->fixer->replaceToken($i, '');
126
+					 }
127
+
128
+					 $phpcsFile->fixer->endChangeset();
129
+				}//end if
130
+		  }//end if
131
+
132
+		  /*
133 133
             Check the number of blank lines
134 134
             before the function.
135 135
         */
136 136
 
137
-        $prevLineToken = null;
138
-        for ($i = $stackPtr; $i > 0; $i--) {
139
-            if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
140
-                continue;
141
-            } else {
142
-                $prevLineToken = $i;
143
-                break;
144
-            }
145
-        }
146
-
147
-        if (is_null($prevLineToken) === true) {
148
-            // Never found the previous line, which means
149
-            // there are 0 blank lines before the function.
150
-            $foundLines  = 0;
151
-            $prevContent = 0;
152
-        } else {
153
-            $currentLine = $tokens[$stackPtr]['line'];
154
-
155
-            $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $prevLineToken, null, true);
156
-            if ($tokens[$prevContent]['code'] === T_DOC_COMMENT_CLOSE_TAG
157
-                && $tokens[$prevContent]['line'] === ($currentLine - 1)
158
-            ) {
159
-                // Account for function comments.
160
-                $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true);
161
-            }
162
-
163
-            // Before we throw an error, check that we are not throwing an error
164
-            // for another function. We don't want to error for no blank lines after
165
-            // the previous function and no blank lines before this one as well.
166
-            $prevLine   = ($tokens[$prevContent]['line'] - 1);
167
-            $i          = ($stackPtr - 1);
168
-            $foundLines = 0;
169
-            while ($currentLine !== $prevLine && $currentLine > 1 && $i > 0) {
170
-                if (isset($tokens[$i]['scope_condition']) === true) {
171
-                    $scopeCondition = $tokens[$i]['scope_condition'];
172
-                    if ($tokens[$scopeCondition]['code'] === T_FUNCTION) {
173
-                        // Found a previous function.
174
-                        return;
175
-                    }
176
-                } else if ($tokens[$i]['code'] === T_FUNCTION) {
177
-                    // Found another interface function.
178
-                    return;
179
-                }
180
-
181
-                $currentLine = $tokens[$i]['line'];
182
-                if ($currentLine === $prevLine) {
183
-                    break;
184
-                }
185
-
186
-                if ($tokens[($i - 1)]['line'] < $currentLine && $tokens[($i + 1)]['line'] > $currentLine) {
187
-                    // This token is on a line by itself. If it is whitespace, the line is empty.
188
-                    if ($tokens[$i]['code'] === T_WHITESPACE) {
189
-                        $foundLines++;
190
-                    }
191
-                }
192
-
193
-                $i--;
194
-            }//end while
195
-        }//end if
196
-
197
-        if ($foundLines !== $this->spacing) {
198
-            $error = 'Expected %s blank line';
199
-            if ($this->spacing !== 1) {
200
-                $error .= 's';
201
-            }
202
-
203
-            $error .= ' before function; %s found';
204
-            $data   = array(
205
-                       $this->spacing,
206
-                       $foundLines,
207
-                      );
208
-
209
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before', $data);
210
-            if ($fix === true) {
211
-                if ($prevContent === 0) {
212
-                    $nextSpace = 0;
213
-                } else {
214
-                    $nextSpace = $phpcsFile->findNext(T_WHITESPACE, ($prevContent + 1), $stackPtr);
215
-                    if ($nextSpace === false) {
216
-                        $nextSpace = ($stackPtr - 1);
217
-                    }
218
-                }
219
-
220
-                if ($foundLines < $this->spacing) {
221
-                    $padding = str_repeat($phpcsFile->eolChar, ($this->spacing - $foundLines));
222
-                    $phpcsFile->fixer->addContent($nextSpace, $padding);
223
-                } else {
224
-                    $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true);
225
-                    $phpcsFile->fixer->beginChangeset();
226
-                    for ($i = $nextSpace; $i < ($nextContent - 1); $i++) {
227
-                        $phpcsFile->fixer->replaceToken($i, '');
228
-                    }
229
-
230
-                    $phpcsFile->fixer->replaceToken($i, str_repeat($phpcsFile->eolChar, $this->spacing));
231
-                    $phpcsFile->fixer->endChangeset();
232
-                }
233
-            }//end if
234
-        }//end if
235
-
236
-    }//end process()
137
+		  $prevLineToken = null;
138
+		  for ($i = $stackPtr; $i > 0; $i--) {
139
+				if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
140
+					 continue;
141
+				} else {
142
+					 $prevLineToken = $i;
143
+					 break;
144
+				}
145
+		  }
146
+
147
+		  if (is_null($prevLineToken) === true) {
148
+				// Never found the previous line, which means
149
+				// there are 0 blank lines before the function.
150
+				$foundLines  = 0;
151
+				$prevContent = 0;
152
+		  } else {
153
+				$currentLine = $tokens[$stackPtr]['line'];
154
+
155
+				$prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $prevLineToken, null, true);
156
+				if ($tokens[$prevContent]['code'] === T_DOC_COMMENT_CLOSE_TAG
157
+					 && $tokens[$prevContent]['line'] === ($currentLine - 1)
158
+				) {
159
+					 // Account for function comments.
160
+					 $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true);
161
+				}
162
+
163
+				// Before we throw an error, check that we are not throwing an error
164
+				// for another function. We don't want to error for no blank lines after
165
+				// the previous function and no blank lines before this one as well.
166
+				$prevLine   = ($tokens[$prevContent]['line'] - 1);
167
+				$i          = ($stackPtr - 1);
168
+				$foundLines = 0;
169
+				while ($currentLine !== $prevLine && $currentLine > 1 && $i > 0) {
170
+					 if (isset($tokens[$i]['scope_condition']) === true) {
171
+						  $scopeCondition = $tokens[$i]['scope_condition'];
172
+						  if ($tokens[$scopeCondition]['code'] === T_FUNCTION) {
173
+								// Found a previous function.
174
+								return;
175
+						  }
176
+					 } else if ($tokens[$i]['code'] === T_FUNCTION) {
177
+						  // Found another interface function.
178
+						  return;
179
+					 }
180
+
181
+					 $currentLine = $tokens[$i]['line'];
182
+					 if ($currentLine === $prevLine) {
183
+						  break;
184
+					 }
185
+
186
+					 if ($tokens[($i - 1)]['line'] < $currentLine && $tokens[($i + 1)]['line'] > $currentLine) {
187
+						  // This token is on a line by itself. If it is whitespace, the line is empty.
188
+						  if ($tokens[$i]['code'] === T_WHITESPACE) {
189
+								$foundLines++;
190
+						  }
191
+					 }
192
+
193
+					 $i--;
194
+				}//end while
195
+		  }//end if
196
+
197
+		  if ($foundLines !== $this->spacing) {
198
+				$error = 'Expected %s blank line';
199
+				if ($this->spacing !== 1) {
200
+					 $error .= 's';
201
+				}
202
+
203
+				$error .= ' before function; %s found';
204
+				$data   = array(
205
+							  $this->spacing,
206
+							  $foundLines,
207
+							 );
208
+
209
+				$fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before', $data);
210
+				if ($fix === true) {
211
+					 if ($prevContent === 0) {
212
+						  $nextSpace = 0;
213
+					 } else {
214
+						  $nextSpace = $phpcsFile->findNext(T_WHITESPACE, ($prevContent + 1), $stackPtr);
215
+						  if ($nextSpace === false) {
216
+								$nextSpace = ($stackPtr - 1);
217
+						  }
218
+					 }
219
+
220
+					 if ($foundLines < $this->spacing) {
221
+						  $padding = str_repeat($phpcsFile->eolChar, ($this->spacing - $foundLines));
222
+						  $phpcsFile->fixer->addContent($nextSpace, $padding);
223
+					 } else {
224
+						  $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true);
225
+						  $phpcsFile->fixer->beginChangeset();
226
+						  for ($i = $nextSpace; $i < ($nextContent - 1); $i++) {
227
+								$phpcsFile->fixer->replaceToken($i, '');
228
+						  }
229
+
230
+						  $phpcsFile->fixer->replaceToken($i, str_repeat($phpcsFile->eolChar, $this->spacing));
231
+						  $phpcsFile->fixer->endChangeset();
232
+					 }
233
+				}//end if
234
+		  }//end if
235
+
236
+	 }//end process()
237 237
 
238 238
 
239 239
 }//end class
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
      */
46 46
     public function register()
47 47
     {
48
-        return array(T_FUNCTION);
48
+        return array( T_FUNCTION );
49 49
 
50 50
     }//end register()
51 51
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @return void
61 61
      */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
62
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
63 63
     {
64 64
         $tokens        = $phpcsFile->getTokens();
65 65
         $this->spacing = (int) $this->spacing;
@@ -69,41 +69,41 @@  discard block
 block discarded – undo
69 69
             after the function.
70 70
         */
71 71
 
72
-        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
72
+        if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
73 73
             // Must be an interface method, so the closer is the semicolon.
74
-            $closer = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
74
+            $closer = $phpcsFile->findNext( T_SEMICOLON, $stackPtr );
75 75
         } else {
76
-            $closer = $tokens[$stackPtr]['scope_closer'];
76
+            $closer = $tokens[ $stackPtr ][ 'scope_closer' ];
77 77
         }
78 78
 
79 79
         // Allow for comments on the same line as the closer.
80
-        for ($nextLineToken = ($closer + 1); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++) {
81
-            if ($tokens[$nextLineToken]['line'] !== $tokens[$closer]['line']) {
80
+        for ( $nextLineToken = ( $closer + 1 ); $nextLineToken < $phpcsFile->numTokens; $nextLineToken++ ) {
81
+            if ( $tokens[ $nextLineToken ][ 'line' ] !== $tokens[ $closer ][ 'line' ] ) {
82 82
                 break;
83 83
             }
84 84
         }
85 85
 
86 86
         $foundLines = 0;
87
-        if ($nextLineToken === ($phpcsFile->numTokens - 1)) {
87
+        if ( $nextLineToken === ( $phpcsFile->numTokens - 1 ) ) {
88 88
             // We are at the end of the file.
89 89
             // Don't check spacing after the function because this
90 90
             // should be done by an EOF sniff.
91 91
             $foundLines = $this->spacing;
92 92
         } else {
93
-            $nextContent = $phpcsFile->findNext(T_WHITESPACE, $nextLineToken, null, true);
94
-            if ($nextContent === false) {
93
+            $nextContent = $phpcsFile->findNext( T_WHITESPACE, $nextLineToken, null, true );
94
+            if ( $nextContent === false ) {
95 95
                 // We are at the end of the file.
96 96
                 // Don't check spacing after the function because this
97 97
                 // should be done by an EOF sniff.
98 98
                 $foundLines = $this->spacing;
99 99
             } else {
100
-                $foundLines += ($tokens[$nextContent]['line'] - $tokens[$nextLineToken]['line']);
100
+                $foundLines += ( $tokens[ $nextContent ][ 'line' ] - $tokens[ $nextLineToken ][ 'line' ] );
101 101
             }
102 102
         }
103 103
 
104
-        if ($foundLines !== $this->spacing) {
104
+        if ( $foundLines !== $this->spacing ) {
105 105
             $error = 'Expected %s blank line';
106
-            if ($this->spacing !== 1) {
106
+            if ( $this->spacing !== 1 ) {
107 107
                 $error .= 's';
108 108
             }
109 109
 
@@ -113,16 +113,16 @@  discard block
 block discarded – undo
113 113
                        $foundLines,
114 114
                       );
115 115
 
116
-            $fix = $phpcsFile->addFixableError($error, $closer, 'After', $data);
117
-            if ($fix === true) {
116
+            $fix = $phpcsFile->addFixableError( $error, $closer, 'After', $data );
117
+            if ( $fix === true ) {
118 118
                 $phpcsFile->fixer->beginChangeset();
119
-                for ($i = $nextLineToken; $i <= $nextContent; $i++) {
120
-                    if ($tokens[$i]['line'] === $tokens[$nextContent]['line']) {
121
-                        $phpcsFile->fixer->addContentBefore($i, str_repeat($phpcsFile->eolChar, $this->spacing));
119
+                for ( $i = $nextLineToken; $i <= $nextContent; $i++ ) {
120
+                    if ( $tokens[ $i ][ 'line' ] === $tokens[ $nextContent ][ 'line' ] ) {
121
+                        $phpcsFile->fixer->addContentBefore( $i, str_repeat( $phpcsFile->eolChar, $this->spacing ) );
122 122
                         break;
123 123
                     }
124 124
 
125
-                    $phpcsFile->fixer->replaceToken($i, '');
125
+                    $phpcsFile->fixer->replaceToken( $i, '' );
126 126
                 }
127 127
 
128 128
                 $phpcsFile->fixer->endChangeset();
@@ -135,8 +135,8 @@  discard block
 block discarded – undo
135 135
         */
136 136
 
137 137
         $prevLineToken = null;
138
-        for ($i = $stackPtr; $i > 0; $i--) {
139
-            if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) === false) {
138
+        for ( $i = $stackPtr; $i > 0; $i-- ) {
139
+            if ( strpos( $tokens[ $i ][ 'content' ], $phpcsFile->eolChar ) === false ) {
140 140
                 continue;
141 141
             } else {
142 142
                 $prevLineToken = $i;
@@ -144,48 +144,48 @@  discard block
 block discarded – undo
144 144
             }
145 145
         }
146 146
 
147
-        if (is_null($prevLineToken) === true) {
147
+        if ( is_null( $prevLineToken ) === true ) {
148 148
             // Never found the previous line, which means
149 149
             // there are 0 blank lines before the function.
150 150
             $foundLines  = 0;
151 151
             $prevContent = 0;
152 152
         } else {
153
-            $currentLine = $tokens[$stackPtr]['line'];
153
+            $currentLine = $tokens[ $stackPtr ][ 'line' ];
154 154
 
155
-            $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, $prevLineToken, null, true);
156
-            if ($tokens[$prevContent]['code'] === T_DOC_COMMENT_CLOSE_TAG
157
-                && $tokens[$prevContent]['line'] === ($currentLine - 1)
155
+            $prevContent = $phpcsFile->findPrevious( T_WHITESPACE, $prevLineToken, null, true );
156
+            if ( $tokens[ $prevContent ][ 'code' ] === T_DOC_COMMENT_CLOSE_TAG
157
+                && $tokens[ $prevContent ][ 'line' ] === ( $currentLine - 1 )
158 158
             ) {
159 159
                 // Account for function comments.
160
-                $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($tokens[$prevContent]['comment_opener'] - 1), null, true);
160
+                $prevContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $tokens[ $prevContent ][ 'comment_opener' ] - 1 ), null, true );
161 161
             }
162 162
 
163 163
             // Before we throw an error, check that we are not throwing an error
164 164
             // for another function. We don't want to error for no blank lines after
165 165
             // the previous function and no blank lines before this one as well.
166
-            $prevLine   = ($tokens[$prevContent]['line'] - 1);
167
-            $i          = ($stackPtr - 1);
166
+            $prevLine   = ( $tokens[ $prevContent ][ 'line' ] - 1 );
167
+            $i          = ( $stackPtr - 1 );
168 168
             $foundLines = 0;
169
-            while ($currentLine !== $prevLine && $currentLine > 1 && $i > 0) {
170
-                if (isset($tokens[$i]['scope_condition']) === true) {
171
-                    $scopeCondition = $tokens[$i]['scope_condition'];
172
-                    if ($tokens[$scopeCondition]['code'] === T_FUNCTION) {
169
+            while ( $currentLine !== $prevLine && $currentLine > 1 && $i > 0 ) {
170
+                if ( isset( $tokens[ $i ][ 'scope_condition' ] ) === true ) {
171
+                    $scopeCondition = $tokens[ $i ][ 'scope_condition' ];
172
+                    if ( $tokens[ $scopeCondition ][ 'code' ] === T_FUNCTION ) {
173 173
                         // Found a previous function.
174 174
                         return;
175 175
                     }
176
-                } else if ($tokens[$i]['code'] === T_FUNCTION) {
176
+                } else if ( $tokens[ $i ][ 'code' ] === T_FUNCTION ) {
177 177
                     // Found another interface function.
178 178
                     return;
179 179
                 }
180 180
 
181
-                $currentLine = $tokens[$i]['line'];
182
-                if ($currentLine === $prevLine) {
181
+                $currentLine = $tokens[ $i ][ 'line' ];
182
+                if ( $currentLine === $prevLine ) {
183 183
                     break;
184 184
                 }
185 185
 
186
-                if ($tokens[($i - 1)]['line'] < $currentLine && $tokens[($i + 1)]['line'] > $currentLine) {
186
+                if ( $tokens[ ( $i - 1 ) ][ 'line' ] < $currentLine && $tokens[ ( $i + 1 ) ][ 'line' ] > $currentLine ) {
187 187
                     // This token is on a line by itself. If it is whitespace, the line is empty.
188
-                    if ($tokens[$i]['code'] === T_WHITESPACE) {
188
+                    if ( $tokens[ $i ][ 'code' ] === T_WHITESPACE ) {
189 189
                         $foundLines++;
190 190
                     }
191 191
                 }
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
             }//end while
195 195
         }//end if
196 196
 
197
-        if ($foundLines !== $this->spacing) {
197
+        if ( $foundLines !== $this->spacing ) {
198 198
             $error = 'Expected %s blank line';
199
-            if ($this->spacing !== 1) {
199
+            if ( $this->spacing !== 1 ) {
200 200
                 $error .= 's';
201 201
             }
202 202
 
@@ -206,28 +206,28 @@  discard block
 block discarded – undo
206 206
                        $foundLines,
207 207
                       );
208 208
 
209
-            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Before', $data);
210
-            if ($fix === true) {
211
-                if ($prevContent === 0) {
209
+            $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Before', $data );
210
+            if ( $fix === true ) {
211
+                if ( $prevContent === 0 ) {
212 212
                     $nextSpace = 0;
213 213
                 } else {
214
-                    $nextSpace = $phpcsFile->findNext(T_WHITESPACE, ($prevContent + 1), $stackPtr);
215
-                    if ($nextSpace === false) {
216
-                        $nextSpace = ($stackPtr - 1);
214
+                    $nextSpace = $phpcsFile->findNext( T_WHITESPACE, ( $prevContent + 1 ), $stackPtr );
215
+                    if ( $nextSpace === false ) {
216
+                        $nextSpace = ( $stackPtr - 1 );
217 217
                     }
218 218
                 }
219 219
 
220
-                if ($foundLines < $this->spacing) {
221
-                    $padding = str_repeat($phpcsFile->eolChar, ($this->spacing - $foundLines));
222
-                    $phpcsFile->fixer->addContent($nextSpace, $padding);
220
+                if ( $foundLines < $this->spacing ) {
221
+                    $padding = str_repeat( $phpcsFile->eolChar, ( $this->spacing - $foundLines ) );
222
+                    $phpcsFile->fixer->addContent( $nextSpace, $padding );
223 223
                 } else {
224
-                    $nextContent = $phpcsFile->findNext(T_WHITESPACE, ($nextSpace + 1), null, true);
224
+                    $nextContent = $phpcsFile->findNext( T_WHITESPACE, ( $nextSpace + 1 ), null, true );
225 225
                     $phpcsFile->fixer->beginChangeset();
226
-                    for ($i = $nextSpace; $i < ($nextContent - 1); $i++) {
227
-                        $phpcsFile->fixer->replaceToken($i, '');
226
+                    for ( $i = $nextSpace; $i < ( $nextContent - 1 ); $i++ ) {
227
+                        $phpcsFile->fixer->replaceToken( $i, '' );
228 228
                     }
229 229
 
230
-                    $phpcsFile->fixer->replaceToken($i, str_repeat($phpcsFile->eolChar, $this->spacing));
230
+                    $phpcsFile->fixer->replaceToken( $i, str_repeat( $phpcsFile->eolChar, $this->spacing ) );
231 231
                     $phpcsFile->fixer->endChangeset();
232 232
                 }
233 233
             }//end if
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_WhiteSpace_FunctionSpacingSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_WhiteSpace_FunctionSpacingSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
     /**
34 33
      * The number of blank lines between functions.
@@ -43,8 +42,7 @@  discard block
 block discarded – undo
43 42
      *
44 43
      * @return array
45 44
      */
46
-    public function register()
47
-    {
45
+    public function register() {
48 46
         return array(T_FUNCTION);
49 47
 
50 48
     }//end register()
@@ -59,8 +57,7 @@  discard block
 block discarded – undo
59 57
      *
60 58
      * @return void
61 59
      */
62
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
63
-    {
60
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
64 61
         $tokens        = $phpcsFile->getTokens();
65 62
         $this->spacing = (int) $this->spacing;
66 63
 
Please login to merge, or discard this patch.
CodeSniffer/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@
 block discarded – undo
44 44
     /**
45 45
      * Returns an array of tokens this test wants to listen for.
46 46
      *
47
-     * @return array
47
+     * @return string[]
48 48
      */
49 49
     public function register()
50 50
     {
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -30,72 +30,72 @@
 block discarded – undo
30 30
 class Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff
31 31
 {
32 32
 
33
-    /**
34
-     * A list of tokenizers this sniff supports.
35
-     *
36
-     * @var array
37
-     */
38
-    public $supportedTokenizers = array(
39
-                                   'PHP',
40
-                                   'JS',
41
-                                  );
33
+	 /**
34
+	  * A list of tokenizers this sniff supports.
35
+	  *
36
+	  * @var array
37
+	  */
38
+	 public $supportedTokenizers = array(
39
+											  'PHP',
40
+											  'JS',
41
+											 );
42 42
 
43 43
 
44
-    /**
45
-     * Returns an array of tokens this test wants to listen for.
46
-     *
47
-     * @return array
48
-     */
49
-    public function register()
50
-    {
51
-        return array(T_SEMICOLON);
44
+	 /**
45
+	  * Returns an array of tokens this test wants to listen for.
46
+	  *
47
+	  * @return array
48
+	  */
49
+	 public function register()
50
+	 {
51
+		  return array(T_SEMICOLON);
52 52
 
53
-    }//end register()
53
+	 }//end register()
54 54
 
55 55
 
56
-    /**
57
-     * Processes this test, when one of its tokens is encountered.
58
-     *
59
-     * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
-     * @param int                  $stackPtr  The position of the current token
61
-     *                                        in the stack passed in $tokens.
62
-     *
63
-     * @return void
64
-     */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
-    {
67
-        $tokens = $phpcsFile->getTokens();
56
+	 /**
57
+	  * Processes this test, when one of its tokens is encountered.
58
+	  *
59
+	  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
60
+	  * @param int                  $stackPtr  The position of the current token
61
+	  *                                        in the stack passed in $tokens.
62
+	  *
63
+	  * @return void
64
+	  */
65
+	 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
+	 {
67
+		  $tokens = $phpcsFile->getTokens();
68 68
 
69
-        $prevType = $tokens[($stackPtr - 1)]['code'];
70
-        if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$prevType]) === false) {
71
-            return;
72
-        }
69
+		  $prevType = $tokens[($stackPtr - 1)]['code'];
70
+		  if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$prevType]) === false) {
71
+				return;
72
+		  }
73 73
 
74
-        $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true);
75
-        if ($tokens[$nonSpace]['code'] === T_SEMICOLON) {
76
-            // Empty statement.
77
-            return;
78
-        }
74
+		  $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true);
75
+		  if ($tokens[$nonSpace]['code'] === T_SEMICOLON) {
76
+				// Empty statement.
77
+				return;
78
+		  }
79 79
 
80
-        $expected = $tokens[$nonSpace]['content'].';';
81
-        $found    = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).';';
82
-        $error    = 'Space found before semicolon; expected "%s" but found "%s"';
83
-        $data     = array(
84
-                     $expected,
85
-                     $found,
86
-                    );
80
+		  $expected = $tokens[$nonSpace]['content'].';';
81
+		  $found    = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).';';
82
+		  $error    = 'Space found before semicolon; expected "%s" but found "%s"';
83
+		  $data     = array(
84
+							$expected,
85
+							$found,
86
+						  );
87 87
 
88
-        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
89
-        if ($fix === true) {
90
-            $phpcsFile->fixer->beginChangeset();
91
-            for ($i = ($stackPtr - 1); $i > $nonSpace; $i--) {
92
-                $phpcsFile->fixer->replaceToken($i, '');
93
-            }
88
+		  $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
89
+		  if ($fix === true) {
90
+				$phpcsFile->fixer->beginChangeset();
91
+				for ($i = ($stackPtr - 1); $i > $nonSpace; $i--) {
92
+					 $phpcsFile->fixer->replaceToken($i, '');
93
+				}
94 94
 
95
-            $phpcsFile->fixer->endChangeset();
96
-        }
95
+				$phpcsFile->fixer->endChangeset();
96
+		  }
97 97
 
98
-    }//end process()
98
+	 }//end process()
99 99
 
100 100
 
101 101
 }//end class
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      */
49 49
     public function register()
50 50
     {
51
-        return array(T_SEMICOLON);
51
+        return array( T_SEMICOLON );
52 52
 
53 53
     }//end register()
54 54
 
@@ -62,34 +62,34 @@  discard block
 block discarded – undo
62 62
      *
63 63
      * @return void
64 64
      */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
65
+    public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
66 66
     {
67 67
         $tokens = $phpcsFile->getTokens();
68 68
 
69
-        $prevType = $tokens[($stackPtr - 1)]['code'];
70
-        if (isset(PHP_CodeSniffer_Tokens::$emptyTokens[$prevType]) === false) {
69
+        $prevType = $tokens[ ( $stackPtr - 1 ) ][ 'code' ];
70
+        if ( isset( PHP_CodeSniffer_Tokens::$emptyTokens[ $prevType ] ) === false ) {
71 71
             return;
72 72
         }
73 73
 
74
-        $nonSpace = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 2), null, true);
75
-        if ($tokens[$nonSpace]['code'] === T_SEMICOLON) {
74
+        $nonSpace = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr - 2 ), null, true );
75
+        if ( $tokens[ $nonSpace ][ 'code' ] === T_SEMICOLON ) {
76 76
             // Empty statement.
77 77
             return;
78 78
         }
79 79
 
80
-        $expected = $tokens[$nonSpace]['content'].';';
81
-        $found    = $phpcsFile->getTokensAsString($nonSpace, ($stackPtr - $nonSpace)).';';
80
+        $expected = $tokens[ $nonSpace ][ 'content' ] . ';';
81
+        $found    = $phpcsFile->getTokensAsString( $nonSpace, ( $stackPtr - $nonSpace ) ) . ';';
82 82
         $error    = 'Space found before semicolon; expected "%s" but found "%s"';
83 83
         $data     = array(
84 84
                      $expected,
85 85
                      $found,
86 86
                     );
87 87
 
88
-        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Incorrect', $data);
89
-        if ($fix === true) {
88
+        $fix = $phpcsFile->addFixableError( $error, $stackPtr, 'Incorrect', $data );
89
+        if ( $fix === true ) {
90 90
             $phpcsFile->fixer->beginChangeset();
91
-            for ($i = ($stackPtr - 1); $i > $nonSpace; $i--) {
92
-                $phpcsFile->fixer->replaceToken($i, '');
91
+            for ( $i = ( $stackPtr - 1 ); $i > $nonSpace; $i-- ) {
92
+                $phpcsFile->fixer->replaceToken( $i, '' );
93 93
             }
94 94
 
95 95
             $phpcsFile->fixer->endChangeset();
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,8 +27,7 @@  discard block
 block discarded – undo
27 27
  * @version   Release: @package_version@
28 28
  * @link      http://pear.php.net/package/PHP_CodeSniffer
29 29
  */
30
-class Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff
31
-{
30
+class Squiz_Sniffs_WhiteSpace_SemicolonSpacingSniff implements PHP_CodeSniffer_Sniff {
32 31
 
33 32
     /**
34 33
      * A list of tokenizers this sniff supports.
@@ -46,8 +45,7 @@  discard block
 block discarded – undo
46 45
      *
47 46
      * @return array
48 47
      */
49
-    public function register()
50
-    {
48
+    public function register() {
51 49
         return array(T_SEMICOLON);
52 50
 
53 51
     }//end register()
@@ -62,8 +60,7 @@  discard block
 block discarded – undo
62 60
      *
63 61
      * @return void
64 62
      */
65
-    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
66
-    {
63
+    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
67 64
         $tokens = $phpcsFile->getTokens();
68 65
 
69 66
         $prevType = $tokens[($stackPtr - 1)]['code'];
Please login to merge, or discard this patch.
wpcs/WordPress/Sniffs/Arrays/ArrayKeySpacingRestrictionsSniff.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 	/**
23 23
 	 * Returns an array of tokens this test wants to listen for.
24 24
 	 *
25
-	 * @return array
25
+	 * @return string[]
26 26
 	 */
27 27
 	public function register() {
28 28
 		return array(
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		$tokens = $phpcsFile->getTokens();
45 45
 
46 46
 		$token = $tokens[ $stackPtr ];
47
-		if ( ! isset( $token['bracket_closer'] ) ) {
47
+		if ( ! isset( $token[ 'bracket_closer' ] ) ) {
48 48
 			$phpcsFile->addWarning( 'Missing bracket closer.', $stackPtr, 'MissingBracketCloser' );
49 49
 			return;
50 50
 		}
@@ -52,12 +52,12 @@  discard block
 block discarded – undo
52 52
 		$need_spaces = $phpcsFile->findNext(
53 53
 			array( T_CONSTANT_ENCAPSED_STRING, T_LNUMBER, T_WHITESPACE, T_MINUS ),
54 54
 			( $stackPtr + 1 ),
55
-			$token['bracket_closer'],
55
+			$token[ 'bracket_closer' ],
56 56
 			true
57 57
 		);
58 58
 
59
-		$spaced1 = ( T_WHITESPACE === $tokens[ ( $stackPtr + 1 ) ]['code'] );
60
-		$spaced2 = ( T_WHITESPACE === $tokens[ ( $token['bracket_closer'] - 1 ) ]['code'] );
59
+		$spaced1 = ( T_WHITESPACE === $tokens[ ( $stackPtr + 1 ) ][ 'code' ] );
60
+		$spaced2 = ( T_WHITESPACE === $tokens[ ( $token[ 'bracket_closer' ] - 1 ) ][ 'code' ] );
61 61
 
62 62
 		// It should have spaces only if it only has strings or numbers as the key.
63 63
 		if ( $need_spaces && ! ( $spaced1 && $spaced2 ) ) {
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 					$phpcsFile->fixer->addContentBefore( ( $stackPtr + 1 ), ' ' );
69 69
 				}
70 70
 				if ( ! $spaced2 ) {
71
-					$phpcsFile->fixer->addContentBefore( $token['bracket_closer'], ' ' );
71
+					$phpcsFile->fixer->addContentBefore( $token[ 'bracket_closer' ], ' ' );
72 72
 				}
73 73
 			}
74 74
 		} elseif ( ! $need_spaces && ( $spaced1 || $spaced2 ) ) {
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 					$phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), '' );
80 80
 				}
81 81
 				if ( $spaced2 ) {
82
-					$phpcsFile->fixer->replaceToken( ( $token['bracket_closer'] - 1 ), '' );
82
+					$phpcsFile->fixer->replaceToken( ( $token[ 'bracket_closer' ] - 1 ), '' );
83 83
 				}
84 84
 			}
85 85
 		}
Please login to merge, or discard this patch.