Completed
Pull Request — develop (#1492)
by Zack
15:57
created
src/Standards/PEAR/Tests/Commenting/FunctionCommentUnitTest.inc 4 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -9,10 +9,10 @@  discard block
 block discarded – undo
9 9
      *
10 10
      * @param int $stackPtr   The position in @ @unknown the stack of the token
11 11
      *                        that opened the scope
12
-     * @param int $detph    How many scope levels down we are.
12
+     * @param int $depth    How many scope levels down we are.
13 13
      * @param int    $index    The index
14 14
      * @return
15
-     * @throws
15
+     integer @throws
16 16
      */
17 17
     private function _functionCall($stackPtr, $depth=1, $index)
18 18
     {
@@ -121,7 +121,6 @@  discard block
 block discarded – undo
121 121
      *
122 122
      * @return
123 123
      * @param   int   $threeSpaces
124
-     * @param int     $superfluous
125 124
      * @param missing
126 125
      * @param
127 126
      */
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -2,148 +2,148 @@  discard block
 block discarded – undo
2 2
 class PHP_CodeSniffer_File
3 3
 {
4 4
 
5
-    /**
6
-     * A simple function comment.
7
-     *
8
-     * long desc here
9
-     *
10
-     * @param int $stackPtr   The position in @ @unknown the stack of the token
11
-     *                        that opened the scope
12
-     * @param int $detph    How many scope levels down we are.
13
-     * @param int    $index    The index
14
-     * @return
15
-     * @throws
16
-     */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
18
-    {
19
-        return $stackPtr;
20
-
21
-    }//end _functionCall()
22
-
23
-    //
24
-    // Sample function comment
25
-    //
26
-    //
27
-    //
28
-    public function invalidCommentStyle()
29
-    {
30
-
31
-    }//end invalidCommentStyle()
32
-
33
-
34
-    /**
35
-     *
36
-     *
37
-     * A simple function comment
38
-     *
39
-     *
40
-     * Long description with extra blank line before and after
41
-     *
42
-     *
43
-     * @return void
44
-     */
45
-    public function extraDescriptionNewlines()
46
-    {
47
-
48
-    }//end extraDescriptionNewlines()
49
-
50
-
51
-    /**
52
-     * A simple function comment
53
-     * @return void
54
-     */
55
-    public function missingNewlinesBeforeTags()
56
-    {
57
-
58
-    }//end missingNewlinesBeforeTags()
59
-
60
-
61
-    /**
62
-     * Access tag should not be treated as a long description
63
-     *
64
-     * @access public
65
-     * @return void
66
-     */
67
-    public function accessTag()
68
-    {
69
-
70
-    }//end accessTag()
71
-
72
-    /**
73
-     * Constructor
74
-     *
75
-     * No return tag
76
-     */
77
-    function PHP_CodeSniffer_File()
78
-    {
79
-        return;
80
-    }
81
-
82
-
83
-    /**
84
-     * Destructor
85
-     *
86
-     * No return tag too
87
-     */
88
-    function _PHP_CodeSniffer_File()
89
-    {
90
-        return;
91
-    }
92
-
93
-
94
-    /**
95
-     * Destructor PHP5
96
-     */
97
-    function __destruct()
98
-    {
99
-        return;
100
-    }
101
-
102
-
103
-    function missingComment()
104
-    {
105
-        return;
106
-    }
107
-
108
-
109
-    /**
110
-     * no return tag
111
-     *
112
-     */
113
-    public function noReturn($one)
114
-    {
115
-
116
-    }//end noReturn()
117
-
118
-
119
-    /**
120
-     * Param not immediate
121
-     *
122
-     * @return
123
-     * @param   int   $threeSpaces
124
-     * @param int     $superfluous
125
-     * @param missing
126
-     * @param
127
-     */
128
-    public function missingDescription($threeSpaces)
129
-    {
130
-
131
-    }//end missingDescription()
132
-
133
-
134
-    /**
135
-     * Param not immediate
136
-     *
137
-     * @param int      $one   comment
138
-     * @param int      $two   comment
139
-     * @param string   $three comment
140
-     *
141
-     * @return void
142
-     */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
144
-    {
145
-
146
-    }//end oneSpaceAfterLongestVar()
5
+	/**
6
+	 * A simple function comment.
7
+	 *
8
+	 * long desc here
9
+	 *
10
+	 * @param int $stackPtr   The position in @ @unknown the stack of the token
11
+	 *                        that opened the scope
12
+	 * @param int $detph    How many scope levels down we are.
13
+	 * @param int    $index    The index
14
+	 * @return
15
+	 * @throws
16
+	 */
17
+	private function _functionCall($stackPtr, $depth=1, $index)
18
+	{
19
+		return $stackPtr;
20
+
21
+	}//end _functionCall()
22
+
23
+	//
24
+	// Sample function comment
25
+	//
26
+	//
27
+	//
28
+	public function invalidCommentStyle()
29
+	{
30
+
31
+	}//end invalidCommentStyle()
32
+
33
+
34
+	/**
35
+	 *
36
+	 *
37
+	 * A simple function comment
38
+	 *
39
+	 *
40
+	 * Long description with extra blank line before and after
41
+	 *
42
+	 *
43
+	 * @return void
44
+	 */
45
+	public function extraDescriptionNewlines()
46
+	{
47
+
48
+	}//end extraDescriptionNewlines()
49
+
50
+
51
+	/**
52
+	 * A simple function comment
53
+	 * @return void
54
+	 */
55
+	public function missingNewlinesBeforeTags()
56
+	{
57
+
58
+	}//end missingNewlinesBeforeTags()
59
+
60
+
61
+	/**
62
+	 * Access tag should not be treated as a long description
63
+	 *
64
+	 * @access public
65
+	 * @return void
66
+	 */
67
+	public function accessTag()
68
+	{
69
+
70
+	}//end accessTag()
71
+
72
+	/**
73
+	 * Constructor
74
+	 *
75
+	 * No return tag
76
+	 */
77
+	function PHP_CodeSniffer_File()
78
+	{
79
+		return;
80
+	}
81
+
82
+
83
+	/**
84
+	 * Destructor
85
+	 *
86
+	 * No return tag too
87
+	 */
88
+	function _PHP_CodeSniffer_File()
89
+	{
90
+		return;
91
+	}
92
+
93
+
94
+	/**
95
+	 * Destructor PHP5
96
+	 */
97
+	function __destruct()
98
+	{
99
+		return;
100
+	}
101
+
102
+
103
+	function missingComment()
104
+	{
105
+		return;
106
+	}
107
+
108
+
109
+	/**
110
+	 * no return tag
111
+	 *
112
+	 */
113
+	public function noReturn($one)
114
+	{
115
+
116
+	}//end noReturn()
117
+
118
+
119
+	/**
120
+	 * Param not immediate
121
+	 *
122
+	 * @return
123
+	 * @param   int   $threeSpaces
124
+	 * @param int     $superfluous
125
+	 * @param missing
126
+	 * @param
127
+	 */
128
+	public function missingDescription($threeSpaces)
129
+	{
130
+
131
+	}//end missingDescription()
132
+
133
+
134
+	/**
135
+	 * Param not immediate
136
+	 *
137
+	 * @param int      $one   comment
138
+	 * @param int      $two   comment
139
+	 * @param string   $three comment
140
+	 *
141
+	 * @return void
142
+	 */
143
+	public function oneSpaceAfterLongestVar($one, $two, $three)
144
+	{
145
+
146
+	}//end oneSpaceAfterLongestVar()
147 147
 
148 148
 
149 149
 }//end class
@@ -159,19 +159,19 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function functionOutsideClass(&$str, &$foo)
161 161
 {
162
-    return;
162
+	return;
163 163
 }//end functionOutsideClass()
164 164
 
165 165
 function missingCommentOutsideClass()
166 166
 {
167
-    return;
167
+	return;
168 168
 }//end missingCommentOutsideClass()
169 169
 
170 170
 
171 171
 ?><?php
172 172
 function tagBeforeComment()
173 173
 {
174
-    return;
174
+	return;
175 175
 }//end tagBeforeComment()
176 176
 
177 177
 
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
 function myFunction() {}
245 245
 
246 246
 abstract class MyClass {
247
-    /**
248
-     * An abstract function.
249
-     *
250
-     * @return string[]
251
-     */
252
-    abstract protected function myFunction();
247
+	/**
248
+	 * An abstract function.
249
+	 *
250
+	 * @return string[]
251
+	 */
252
+	abstract protected function myFunction();
253 253
 }
254 254
 
255 255
 /**
@@ -271,18 +271,18 @@  discard block
 block discarded – undo
271 271
  *
272 272
  */
273 273
 function _() {
274
-    return $foo;
274
+	return $foo;
275 275
 }
276 276
 
277 277
 class Baz {
278
-    /**
279
-     * The PHP5 constructor
280
-     *
281
-     * No return tag
282
-     */
283
-    public function __construct() {
284
-
285
-    }
278
+	/**
279
+	 * The PHP5 constructor
280
+	 *
281
+	 * No return tag
282
+	 */
283
+	public function __construct() {
284
+
285
+	}
286 286
 }
287 287
 
288 288
 /**
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
  * @return void
296 296
  */
297 297
 function completeStep($status, array $array = [Class1::class, 'test'], $note = '') {
298
-    echo 'foo';
298
+	echo 'foo';
299 299
 }
300 300
 
301 301
 /**
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
      * @return
15 15
      * @throws
16 16
      */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
17
+    private function _functionCall( $stackPtr, $depth = 1, $index )
18 18
     {
19 19
         return $stackPtr;
20 20
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      * no return tag
111 111
      *
112 112
      */
113
-    public function noReturn($one)
113
+    public function noReturn( $one )
114 114
     {
115 115
 
116 116
     }//end noReturn()
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
      * @param missing
126 126
      * @param
127 127
      */
128
-    public function missingDescription($threeSpaces)
128
+    public function missingDescription( $threeSpaces )
129 129
     {
130 130
 
131 131
     }//end missingDescription()
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      *
141 141
      * @return void
142 142
      */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
143
+    public function oneSpaceAfterLongestVar( $one, $two, $three )
144 144
     {
145 145
 
146 146
     }//end oneSpaceAfterLongestVar()
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
  *
158 158
  * @return void
159 159
  */
160
-function functionOutsideClass(&$str, &$foo)
160
+function functionOutsideClass( &$str, &$foo )
161 161
 {
162 162
     return;
163 163
 }//end functionOutsideClass()
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
  * @return void
196 196
  * @fine  Unknown tag
197 197
  */
198
-function missingTwoParamComment($one, $two, $three)
198
+function missingTwoParamComment( $one, $two, $three )
199 199
 {
200 200
 
201 201
 }//end missingTwoParamComment()
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  * @access public
218 218
  * @return bool
219 219
  */
220
-function myFunction($arg1) {}
220
+function myFunction( $arg1 ) {}
221 221
 
222 222
 
223 223
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 echo $blah;
233 233
 
234
-function myFunction($arg1) {}
234
+function myFunction( $arg1 ) {}
235 235
 
236 236
 /**
237 237
  * Test function.
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
  *
262 262
  * @return void
263 263
  */
264
-function foo(&$tokens, $tokenizer, $eolChar)
264
+function foo( &$tokens, $tokenizer, $eolChar )
265 265
 {
266 266
 
267 267
 }//end foo()
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
  *
295 295
  * @return void
296 296
  */
297
-function completeStep($status, array $array = [Class1::class, 'test'], $note = '') {
297
+function completeStep( $status, array $array = [ Class1::class, 'test' ], $note = '' ) {
298 298
     echo 'foo';
299 299
 }
300 300
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
  *
307 307
  * @return void
308 308
  */
309
-function myFunction(string $name1, string ...$name2) {
309
+function myFunction( string $name1, string ...$name2 ) {
310 310
 }
311 311
 
312 312
 
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  *
319 319
  * @return void
320 320
  */
321
-function myFunction(string $name1, string ...$name2) {
321
+function myFunction( string $name1, string ...$name2 ) {
322 322
 }
323 323
 
324 324
 /**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
  *   Return value
334 334
  *
335 335
  */
336
-function foo($bar) {
336
+function foo( $bar ) {
337 337
 }
338 338
 
339 339
 /**
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
  * @return void
349 349
  * @see    register()
350 350
  */
351
-function process(File $phpcsFile, $stackPtr)
351
+function process( File $phpcsFile, $stackPtr )
352 352
 {
353 353
 
354 354
 }//end process()
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
  * @return void
367 367
  * @see    register()
368 368
  */
369
-function process(File $phpcsFile, $stackPtr)
369
+function process( File $phpcsFile, $stackPtr )
370 370
 {
371 371
 
372 372
 }//end process()
Please login to merge, or discard this patch.
Braces   +22 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,6 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-class PHP_CodeSniffer_File
3
-{
2
+class PHP_CodeSniffer_File {
4 3
 
5 4
     /**
6 5
      * A simple function comment.
@@ -14,8 +13,7 @@  discard block
 block discarded – undo
14 13
      * @return
15 14
      * @throws
16 15
      */
17
-    private function _functionCall($stackPtr, $depth=1, $index)
18
-    {
16
+    private function _functionCall($stackPtr, $depth=1, $index) {
19 17
         return $stackPtr;
20 18
 
21 19
     }//end _functionCall()
@@ -25,8 +23,7 @@  discard block
 block discarded – undo
25 23
     //
26 24
     //
27 25
     //
28
-    public function invalidCommentStyle()
29
-    {
26
+    public function invalidCommentStyle() {
30 27
 
31 28
     }//end invalidCommentStyle()
32 29
 
@@ -42,8 +39,7 @@  discard block
 block discarded – undo
42 39
      *
43 40
      * @return void
44 41
      */
45
-    public function extraDescriptionNewlines()
46
-    {
42
+    public function extraDescriptionNewlines() {
47 43
 
48 44
     }//end extraDescriptionNewlines()
49 45
 
@@ -52,8 +48,7 @@  discard block
 block discarded – undo
52 48
      * A simple function comment
53 49
      * @return void
54 50
      */
55
-    public function missingNewlinesBeforeTags()
56
-    {
51
+    public function missingNewlinesBeforeTags() {
57 52
 
58 53
     }//end missingNewlinesBeforeTags()
59 54
 
@@ -64,8 +59,7 @@  discard block
 block discarded – undo
64 59
      * @access public
65 60
      * @return void
66 61
      */
67
-    public function accessTag()
68
-    {
62
+    public function accessTag() {
69 63
 
70 64
     }//end accessTag()
71 65
 
@@ -74,8 +68,7 @@  discard block
 block discarded – undo
74 68
      *
75 69
      * No return tag
76 70
      */
77
-    function PHP_CodeSniffer_File()
78
-    {
71
+    function PHP_CodeSniffer_File() {
79 72
         return;
80 73
     }
81 74
 
@@ -85,8 +78,7 @@  discard block
 block discarded – undo
85 78
      *
86 79
      * No return tag too
87 80
      */
88
-    function _PHP_CodeSniffer_File()
89
-    {
81
+    function _PHP_CodeSniffer_File() {
90 82
         return;
91 83
     }
92 84
 
@@ -94,14 +86,12 @@  discard block
 block discarded – undo
94 86
     /**
95 87
      * Destructor PHP5
96 88
      */
97
-    function __destruct()
98
-    {
89
+    function __destruct() {
99 90
         return;
100 91
     }
101 92
 
102 93
 
103
-    function missingComment()
104
-    {
94
+    function missingComment() {
105 95
         return;
106 96
     }
107 97
 
@@ -110,8 +100,7 @@  discard block
 block discarded – undo
110 100
      * no return tag
111 101
      *
112 102
      */
113
-    public function noReturn($one)
114
-    {
103
+    public function noReturn($one) {
115 104
 
116 105
     }//end noReturn()
117 106
 
@@ -125,8 +114,7 @@  discard block
 block discarded – undo
125 114
      * @param missing
126 115
      * @param
127 116
      */
128
-    public function missingDescription($threeSpaces)
129
-    {
117
+    public function missingDescription($threeSpaces) {
130 118
 
131 119
     }//end missingDescription()
132 120
 
@@ -140,8 +128,7 @@  discard block
 block discarded – undo
140 128
      *
141 129
      * @return void
142 130
      */
143
-    public function oneSpaceAfterLongestVar($one, $two, $three)
144
-    {
131
+    public function oneSpaceAfterLongestVar($one, $two, $three) {
145 132
 
146 133
     }//end oneSpaceAfterLongestVar()
147 134
 
@@ -157,20 +144,17 @@  discard block
 block discarded – undo
157 144
  *
158 145
  * @return void
159 146
  */
160
-function functionOutsideClass(&$str, &$foo)
161
-{
147
+function functionOutsideClass(&$str, &$foo) {
162 148
     return;
163 149
 }//end functionOutsideClass()
164 150
 
165
-function missingCommentOutsideClass()
166
-{
151
+function missingCommentOutsideClass() {
167 152
     return;
168 153
 }//end missingCommentOutsideClass()
169 154
 
170 155
 
171 156
 ?><?php
172
-function tagBeforeComment()
173
-{
157
+function tagBeforeComment() {
174 158
     return;
175 159
 }//end tagBeforeComment()
176 160
 
@@ -181,8 +165,7 @@  discard block
 block discarded – undo
181 165
  *
182 166
  *
183 167
  */
184
-function noReturnOutsideClass()
185
-{
168
+function noReturnOutsideClass() {
186 169
 
187 170
 }//end noReturnOutsideClass()
188 171
 
@@ -195,8 +178,7 @@  discard block
 block discarded – undo
195 178
  * @return void
196 179
  * @fine  Unknown tag
197 180
  */
198
-function missingTwoParamComment($one, $two, $three)
199
-{
181
+function missingTwoParamComment($one, $two, $three) {
200 182
 
201 183
 }//end missingTwoParamComment()
202 184
 
@@ -204,8 +186,7 @@  discard block
 block discarded – undo
204 186
 /**
205 187
  *
206 188
  */
207
-function emptyFunctionDocComment()
208
-{
189
+function emptyFunctionDocComment() {
209 190
 }//end emptyFunctionDocComment()
210 191
 
211 192
 
@@ -261,8 +242,7 @@  discard block
 block discarded – undo
261 242
  *
262 243
  * @return void
263 244
  */
264
-function foo(&$tokens, $tokenizer, $eolChar)
265
-{
245
+function foo(&$tokens, $tokenizer, $eolChar) {
266 246
 
267 247
 }//end foo()
268 248
 
@@ -348,8 +328,7 @@  discard block
 block discarded – undo
348 328
  * @return void
349 329
  * @see    register()
350 330
  */
351
-function process(File $phpcsFile, $stackPtr)
352
-{
331
+function process(File $phpcsFile, $stackPtr) {
353 332
 
354 333
 }//end process()
355 334
 
@@ -366,7 +345,6 @@  discard block
 block discarded – undo
366 345
  * @return void
367 346
  * @see    register()
368 347
  */
369
-function process(File $phpcsFile, $stackPtr)
370
-{
348
+function process(File $phpcsFile, $stackPtr) {
371 349
 
372 350
 }//end process()
Please login to merge, or discard this patch.
php_codesniffer/src/Standards/PSR1/Sniffs/Files/SideEffectsSniff.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * Returns an array of tokens this test wants to listen for.
22 22
      *
23
-     * @return array
23
+     * @return integer[]
24 24
      */
25 25
     public function register()
26 26
     {
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      * @param int                         $stackPtr  The position of the current token in
37 37
      *                                               the token stack.
38 38
      *
39
-     * @return void
39
+     * @return integer
40 40
      */
41 41
     public function process(File $phpcsFile, $stackPtr)
42 42
     {
Please login to merge, or discard this patch.
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -17,265 +17,265 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Returns an array of tokens this test wants to listen for.
22
-     *
23
-     * @return array
24
-     */
25
-    public function register()
26
-    {
27
-        return [T_OPEN_TAG];
28
-
29
-    }//end register()
30
-
31
-
32
-    /**
33
-     * Processes this sniff, when one of its tokens is encountered.
34
-     *
35
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
-     * @param int                         $stackPtr  The position of the current token in
37
-     *                                               the token stack.
38
-     *
39
-     * @return void
40
-     */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
43
-        $tokens = $phpcsFile->getTokens();
44
-        $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45
-
46
-        if ($result['symbol'] !== null && $result['effect'] !== null) {
47
-            $error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48
-            $data  = [
49
-                $tokens[$result['symbol']]['line'],
50
-                $tokens[$result['effect']]['line'],
51
-            ];
52
-            $phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
54
-        } else {
55
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
56
-        }
57
-
58
-        // Ignore the rest of the file.
59
-        return ($phpcsFile->numTokens + 1);
60
-
61
-    }//end process()
62
-
63
-
64
-    /**
65
-     * Searches for symbol declarations and side effects.
66
-     *
67
-     * Returns the positions of both the first symbol declared and the first
68
-     * side effect in the file. A NULL value for either indicates nothing was
69
-     * found.
70
-     *
71
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
72
-     * @param int                         $start     The token to start searching from.
73
-     * @param int                         $end       The token to search to.
74
-     * @param array                       $tokens    The stack of tokens that make up
75
-     *                                               the file.
76
-     *
77
-     * @return array
78
-     */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
-    {
81
-        $symbols = [
82
-            T_CLASS     => T_CLASS,
83
-            T_INTERFACE => T_INTERFACE,
84
-            T_TRAIT     => T_TRAIT,
85
-            T_FUNCTION  => T_FUNCTION,
86
-        ];
87
-
88
-        $conditions = [
89
-            T_IF     => T_IF,
90
-            T_ELSE   => T_ELSE,
91
-            T_ELSEIF => T_ELSEIF,
92
-        ];
93
-
94
-        $checkAnnotations = $phpcsFile->config->annotations;
95
-
96
-        $firstSymbol = null;
97
-        $firstEffect = null;
98
-        for ($i = $start; $i <= $end; $i++) {
99
-            // Respect phpcs:disable comments.
100
-            if ($checkAnnotations === true
101
-                && $tokens[$i]['code'] === T_PHPCS_DISABLE
102
-                && (empty($tokens[$i]['sniffCodes']) === true
103
-                || isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
106
-            ) {
107
-                do {
108
-                    $i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
-                } while ($i !== false
110
-                    && empty($tokens[$i]['sniffCodes']) === false
111
-                    && isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
-
115
-                if ($i === false) {
116
-                    // The entire rest of the file is disabled,
117
-                    // so return what we have so far.
118
-                    break;
119
-                }
120
-
121
-                continue;
122
-            }
123
-
124
-            // Ignore whitespace and comments.
125
-            if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
126
-                continue;
127
-            }
128
-
129
-            // Ignore PHP tags.
130
-            if ($tokens[$i]['code'] === T_OPEN_TAG
131
-                || $tokens[$i]['code'] === T_CLOSE_TAG
132
-            ) {
133
-                continue;
134
-            }
135
-
136
-            // Ignore shebang.
137
-            if (substr($tokens[$i]['content'], 0, 2) === '#!') {
138
-                continue;
139
-            }
140
-
141
-            // Ignore logical operators.
142
-            if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
143
-                continue;
144
-            }
145
-
146
-            // Ignore entire namespace, declare, const and use statements.
147
-            if ($tokens[$i]['code'] === T_NAMESPACE
148
-                || $tokens[$i]['code'] === T_USE
149
-                || $tokens[$i]['code'] === T_DECLARE
150
-                || $tokens[$i]['code'] === T_CONST
151
-            ) {
152
-                if (isset($tokens[$i]['scope_opener']) === true) {
153
-                    $i = $tokens[$i]['scope_closer'];
154
-                } else {
155
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
-                    if ($semicolon !== false) {
157
-                        $i = $semicolon;
158
-                    }
159
-                }
160
-
161
-                continue;
162
-            }
163
-
164
-            // Ignore function/class prefixes.
165
-            if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
166
-                continue;
167
-            }
168
-
169
-            // Ignore anon classes.
170
-            if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
-                $i = $tokens[$i]['scope_closer'];
172
-                continue;
173
-            }
174
-
175
-            // Detect and skip over symbols.
176
-            if (isset($symbols[$tokens[$i]['code']]) === true
177
-                && isset($tokens[$i]['scope_closer']) === true
178
-            ) {
179
-                if ($firstSymbol === null) {
180
-                    $firstSymbol = $i;
181
-                }
182
-
183
-                $i = $tokens[$i]['scope_closer'];
184
-                continue;
185
-            } else if ($tokens[$i]['code'] === T_STRING
186
-                && strtolower($tokens[$i]['content']) === 'define'
187
-            ) {
188
-                $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
-                if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
-                    && $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
-                    && $tokens[$prev]['code'] !== T_FUNCTION
192
-                ) {
193
-                    if ($firstSymbol === null) {
194
-                        $firstSymbol = $i;
195
-                    }
196
-
197
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
-                    if ($semicolon !== false) {
199
-                        $i = $semicolon;
200
-                    }
201
-
202
-                    continue;
203
-                }
204
-            }//end if
205
-
206
-            // Special case for defined() as it can be used to see
207
-            // if a constant (a symbol) should be defined or not and
208
-            // doesn't need to use a full conditional block.
209
-            if ($tokens[$i]['code'] === T_STRING
210
-                && strtolower($tokens[$i]['content']) === 'defined'
211
-            ) {
212
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
-                if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
-                    && isset($tokens[$openBracket]['parenthesis_closer']) === true
215
-                ) {
216
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
-                    if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
-                        && $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
-                        && $tokens[$prev]['code'] !== T_FUNCTION
220
-                    ) {
221
-                        $i = $tokens[$openBracket]['parenthesis_closer'];
222
-                        continue;
223
-                    }
224
-                }
225
-            }//end if
226
-
227
-            // Conditional statements are allowed in symbol files as long as the
228
-            // contents is only a symbol definition. So don't count these as effects
229
-            // in this case.
230
-            if (isset($conditions[$tokens[$i]['code']]) === true) {
231
-                if (isset($tokens[$i]['scope_opener']) === false) {
232
-                    // Probably an "else if", so just ignore.
233
-                    continue;
234
-                }
235
-
236
-                $result = $this->searchForConflict(
237
-                    $phpcsFile,
238
-                    ($tokens[$i]['scope_opener'] + 1),
239
-                    ($tokens[$i]['scope_closer'] - 1),
240
-                    $tokens
241
-                );
242
-
243
-                if ($result['symbol'] !== null) {
244
-                    if ($firstSymbol === null) {
245
-                        $firstSymbol = $result['symbol'];
246
-                    }
247
-
248
-                    if ($result['effect'] !== null) {
249
-                        // Found a conflict.
250
-                        $firstEffect = $result['effect'];
251
-                        break;
252
-                    }
253
-                }
254
-
255
-                if ($firstEffect === null) {
256
-                    $firstEffect = $result['effect'];
257
-                }
258
-
259
-                $i = $tokens[$i]['scope_closer'];
260
-                continue;
261
-            }//end if
262
-
263
-            if ($firstEffect === null) {
264
-                $firstEffect = $i;
265
-            }
266
-
267
-            if ($firstSymbol !== null) {
268
-                // We have a conflict we have to report, so no point continuing.
269
-                break;
270
-            }
271
-        }//end for
272
-
273
-        return [
274
-            'symbol' => $firstSymbol,
275
-            'effect' => $firstEffect,
276
-        ];
277
-
278
-    }//end searchForConflict()
20
+	/**
21
+	 * Returns an array of tokens this test wants to listen for.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function register()
26
+	{
27
+		return [T_OPEN_TAG];
28
+
29
+	}//end register()
30
+
31
+
32
+	/**
33
+	 * Processes this sniff, when one of its tokens is encountered.
34
+	 *
35
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
36
+	 * @param int                         $stackPtr  The position of the current token in
37
+	 *                                               the token stack.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	public function process(File $phpcsFile, $stackPtr)
42
+	{
43
+		$tokens = $phpcsFile->getTokens();
44
+		$result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45
+
46
+		if ($result['symbol'] !== null && $result['effect'] !== null) {
47
+			$error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48
+			$data  = [
49
+				$tokens[$result['symbol']]['line'],
50
+				$tokens[$result['effect']]['line'],
51
+			];
52
+			$phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
+			$phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
54
+		} else {
55
+			$phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
56
+		}
57
+
58
+		// Ignore the rest of the file.
59
+		return ($phpcsFile->numTokens + 1);
60
+
61
+	}//end process()
62
+
63
+
64
+	/**
65
+	 * Searches for symbol declarations and side effects.
66
+	 *
67
+	 * Returns the positions of both the first symbol declared and the first
68
+	 * side effect in the file. A NULL value for either indicates nothing was
69
+	 * found.
70
+	 *
71
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
72
+	 * @param int                         $start     The token to start searching from.
73
+	 * @param int                         $end       The token to search to.
74
+	 * @param array                       $tokens    The stack of tokens that make up
75
+	 *                                               the file.
76
+	 *
77
+	 * @return array
78
+	 */
79
+	private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
+	{
81
+		$symbols = [
82
+			T_CLASS     => T_CLASS,
83
+			T_INTERFACE => T_INTERFACE,
84
+			T_TRAIT     => T_TRAIT,
85
+			T_FUNCTION  => T_FUNCTION,
86
+		];
87
+
88
+		$conditions = [
89
+			T_IF     => T_IF,
90
+			T_ELSE   => T_ELSE,
91
+			T_ELSEIF => T_ELSEIF,
92
+		];
93
+
94
+		$checkAnnotations = $phpcsFile->config->annotations;
95
+
96
+		$firstSymbol = null;
97
+		$firstEffect = null;
98
+		for ($i = $start; $i <= $end; $i++) {
99
+			// Respect phpcs:disable comments.
100
+			if ($checkAnnotations === true
101
+				&& $tokens[$i]['code'] === T_PHPCS_DISABLE
102
+				&& (empty($tokens[$i]['sniffCodes']) === true
103
+				|| isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
+				|| isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
+				|| isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
106
+			) {
107
+				do {
108
+					$i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
+				} while ($i !== false
110
+					&& empty($tokens[$i]['sniffCodes']) === false
111
+					&& isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
+					&& isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
+					&& isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
+
115
+				if ($i === false) {
116
+					// The entire rest of the file is disabled,
117
+					// so return what we have so far.
118
+					break;
119
+				}
120
+
121
+				continue;
122
+			}
123
+
124
+			// Ignore whitespace and comments.
125
+			if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
126
+				continue;
127
+			}
128
+
129
+			// Ignore PHP tags.
130
+			if ($tokens[$i]['code'] === T_OPEN_TAG
131
+				|| $tokens[$i]['code'] === T_CLOSE_TAG
132
+			) {
133
+				continue;
134
+			}
135
+
136
+			// Ignore shebang.
137
+			if (substr($tokens[$i]['content'], 0, 2) === '#!') {
138
+				continue;
139
+			}
140
+
141
+			// Ignore logical operators.
142
+			if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
143
+				continue;
144
+			}
145
+
146
+			// Ignore entire namespace, declare, const and use statements.
147
+			if ($tokens[$i]['code'] === T_NAMESPACE
148
+				|| $tokens[$i]['code'] === T_USE
149
+				|| $tokens[$i]['code'] === T_DECLARE
150
+				|| $tokens[$i]['code'] === T_CONST
151
+			) {
152
+				if (isset($tokens[$i]['scope_opener']) === true) {
153
+					$i = $tokens[$i]['scope_closer'];
154
+				} else {
155
+					$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
+					if ($semicolon !== false) {
157
+						$i = $semicolon;
158
+					}
159
+				}
160
+
161
+				continue;
162
+			}
163
+
164
+			// Ignore function/class prefixes.
165
+			if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
166
+				continue;
167
+			}
168
+
169
+			// Ignore anon classes.
170
+			if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
+				$i = $tokens[$i]['scope_closer'];
172
+				continue;
173
+			}
174
+
175
+			// Detect and skip over symbols.
176
+			if (isset($symbols[$tokens[$i]['code']]) === true
177
+				&& isset($tokens[$i]['scope_closer']) === true
178
+			) {
179
+				if ($firstSymbol === null) {
180
+					$firstSymbol = $i;
181
+				}
182
+
183
+				$i = $tokens[$i]['scope_closer'];
184
+				continue;
185
+			} else if ($tokens[$i]['code'] === T_STRING
186
+				&& strtolower($tokens[$i]['content']) === 'define'
187
+			) {
188
+				$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
+				if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
+					&& $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
+					&& $tokens[$prev]['code'] !== T_FUNCTION
192
+				) {
193
+					if ($firstSymbol === null) {
194
+						$firstSymbol = $i;
195
+					}
196
+
197
+					$semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
+					if ($semicolon !== false) {
199
+						$i = $semicolon;
200
+					}
201
+
202
+					continue;
203
+				}
204
+			}//end if
205
+
206
+			// Special case for defined() as it can be used to see
207
+			// if a constant (a symbol) should be defined or not and
208
+			// doesn't need to use a full conditional block.
209
+			if ($tokens[$i]['code'] === T_STRING
210
+				&& strtolower($tokens[$i]['content']) === 'defined'
211
+			) {
212
+				$openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
+				if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
+					&& isset($tokens[$openBracket]['parenthesis_closer']) === true
215
+				) {
216
+					$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
+					if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
+						&& $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
+						&& $tokens[$prev]['code'] !== T_FUNCTION
220
+					) {
221
+						$i = $tokens[$openBracket]['parenthesis_closer'];
222
+						continue;
223
+					}
224
+				}
225
+			}//end if
226
+
227
+			// Conditional statements are allowed in symbol files as long as the
228
+			// contents is only a symbol definition. So don't count these as effects
229
+			// in this case.
230
+			if (isset($conditions[$tokens[$i]['code']]) === true) {
231
+				if (isset($tokens[$i]['scope_opener']) === false) {
232
+					// Probably an "else if", so just ignore.
233
+					continue;
234
+				}
235
+
236
+				$result = $this->searchForConflict(
237
+					$phpcsFile,
238
+					($tokens[$i]['scope_opener'] + 1),
239
+					($tokens[$i]['scope_closer'] - 1),
240
+					$tokens
241
+				);
242
+
243
+				if ($result['symbol'] !== null) {
244
+					if ($firstSymbol === null) {
245
+						$firstSymbol = $result['symbol'];
246
+					}
247
+
248
+					if ($result['effect'] !== null) {
249
+						// Found a conflict.
250
+						$firstEffect = $result['effect'];
251
+						break;
252
+					}
253
+				}
254
+
255
+				if ($firstEffect === null) {
256
+					$firstEffect = $result['effect'];
257
+				}
258
+
259
+				$i = $tokens[$i]['scope_closer'];
260
+				continue;
261
+			}//end if
262
+
263
+			if ($firstEffect === null) {
264
+				$firstEffect = $i;
265
+			}
266
+
267
+			if ($firstSymbol !== null) {
268
+				// We have a conflict we have to report, so no point continuing.
269
+				break;
270
+			}
271
+		}//end for
272
+
273
+		return [
274
+			'symbol' => $firstSymbol,
275
+			'effect' => $firstEffect,
276
+		];
277
+
278
+	}//end searchForConflict()
279 279
 
280 280
 
281 281
 }//end class
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function register()
26 26
     {
27
-        return [T_OPEN_TAG];
27
+        return [ T_OPEN_TAG ];
28 28
 
29 29
     }//end register()
30 30
 
@@ -38,25 +38,25 @@  discard block
 block discarded – undo
38 38
      *
39 39
      * @return void
40 40
      */
41
-    public function process(File $phpcsFile, $stackPtr)
41
+    public function process( File $phpcsFile, $stackPtr )
42 42
     {
43 43
         $tokens = $phpcsFile->getTokens();
44
-        $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
44
+        $result = $this->searchForConflict( $phpcsFile, 0, ( $phpcsFile->numTokens - 1 ), $tokens );
45 45
 
46
-        if ($result['symbol'] !== null && $result['effect'] !== null) {
46
+        if ( $result[ 'symbol' ] !== null && $result[ 'effect' ] !== null ) {
47 47
             $error = 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line %s and the first side effect is on line %s.';
48 48
             $data  = [
49
-                $tokens[$result['symbol']]['line'],
50
-                $tokens[$result['effect']]['line'],
49
+                $tokens[ $result[ 'symbol' ] ][ 'line' ],
50
+                $tokens[ $result[ 'effect' ] ][ 'line' ],
51 51
             ];
52
-            $phpcsFile->addWarning($error, 0, 'FoundWithSymbols', $data);
53
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'yes');
52
+            $phpcsFile->addWarning( $error, 0, 'FoundWithSymbols', $data );
53
+            $phpcsFile->recordMetric( $stackPtr, 'Declarations and side effects mixed', 'yes' );
54 54
         } else {
55
-            $phpcsFile->recordMetric($stackPtr, 'Declarations and side effects mixed', 'no');
55
+            $phpcsFile->recordMetric( $stackPtr, 'Declarations and side effects mixed', 'no' );
56 56
         }
57 57
 
58 58
         // Ignore the rest of the file.
59
-        return ($phpcsFile->numTokens + 1);
59
+        return ( $phpcsFile->numTokens + 1 );
60 60
 
61 61
     }//end process()
62 62
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      *
77 77
      * @return array
78 78
      */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
79
+    private function searchForConflict( $phpcsFile, $start, $end, $tokens )
80 80
     {
81 81
         $symbols = [
82 82
             T_CLASS     => T_CLASS,
@@ -95,24 +95,24 @@  discard block
 block discarded – undo
95 95
 
96 96
         $firstSymbol = null;
97 97
         $firstEffect = null;
98
-        for ($i = $start; $i <= $end; $i++) {
98
+        for ( $i = $start; $i <= $end; $i++ ) {
99 99
             // Respect phpcs:disable comments.
100
-            if ($checkAnnotations === true
101
-                && $tokens[$i]['code'] === T_PHPCS_DISABLE
102
-                && (empty($tokens[$i]['sniffCodes']) === true
103
-                || isset($tokens[$i]['sniffCodes']['PSR1']) === true
104
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files']) === true
105
-                || isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === true)
100
+            if ( $checkAnnotations === true
101
+                && $tokens[ $i ][ 'code' ] === T_PHPCS_DISABLE
102
+                && ( empty( $tokens[ $i ][ 'sniffCodes' ] ) === true
103
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1' ] ) === true
104
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files' ] ) === true
105
+                || isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files.SideEffects' ] ) === true )
106 106
             ) {
107 107
                 do {
108
-                    $i = $phpcsFile->findNext(T_PHPCS_ENABLE, ($i + 1));
109
-                } while ($i !== false
110
-                    && empty($tokens[$i]['sniffCodes']) === false
111
-                    && isset($tokens[$i]['sniffCodes']['PSR1']) === false
112
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files']) === false
113
-                    && isset($tokens[$i]['sniffCodes']['PSR1.Files.SideEffects']) === false);
114
-
115
-                if ($i === false) {
108
+                    $i = $phpcsFile->findNext( T_PHPCS_ENABLE, ( $i + 1 ) );
109
+                } while ( $i !== false
110
+                    && empty( $tokens[ $i ][ 'sniffCodes' ] ) === false
111
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1' ] ) === false
112
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files' ] ) === false
113
+                    && isset( $tokens[ $i ][ 'sniffCodes' ][ 'PSR1.Files.SideEffects' ] ) === false );
114
+
115
+                if ( $i === false ) {
116 116
                     // The entire rest of the file is disabled,
117 117
                     // so return what we have so far.
118 118
                     break;
@@ -122,38 +122,38 @@  discard block
 block discarded – undo
122 122
             }
123 123
 
124 124
             // Ignore whitespace and comments.
125
-            if (isset(Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
125
+            if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) {
126 126
                 continue;
127 127
             }
128 128
 
129 129
             // Ignore PHP tags.
130
-            if ($tokens[$i]['code'] === T_OPEN_TAG
131
-                || $tokens[$i]['code'] === T_CLOSE_TAG
130
+            if ( $tokens[ $i ][ 'code' ] === T_OPEN_TAG
131
+                || $tokens[ $i ][ 'code' ] === T_CLOSE_TAG
132 132
             ) {
133 133
                 continue;
134 134
             }
135 135
 
136 136
             // Ignore shebang.
137
-            if (substr($tokens[$i]['content'], 0, 2) === '#!') {
137
+            if ( substr( $tokens[ $i ][ 'content' ], 0, 2 ) === '#!' ) {
138 138
                 continue;
139 139
             }
140 140
 
141 141
             // Ignore logical operators.
142
-            if (isset(Tokens::$booleanOperators[$tokens[$i]['code']]) === true) {
142
+            if ( isset( Tokens::$booleanOperators[ $tokens[ $i ][ 'code' ] ] ) === true ) {
143 143
                 continue;
144 144
             }
145 145
 
146 146
             // Ignore entire namespace, declare, const and use statements.
147
-            if ($tokens[$i]['code'] === T_NAMESPACE
148
-                || $tokens[$i]['code'] === T_USE
149
-                || $tokens[$i]['code'] === T_DECLARE
150
-                || $tokens[$i]['code'] === T_CONST
147
+            if ( $tokens[ $i ][ 'code' ] === T_NAMESPACE
148
+                || $tokens[ $i ][ 'code' ] === T_USE
149
+                || $tokens[ $i ][ 'code' ] === T_DECLARE
150
+                || $tokens[ $i ][ 'code' ] === T_CONST
151 151
             ) {
152
-                if (isset($tokens[$i]['scope_opener']) === true) {
153
-                    $i = $tokens[$i]['scope_closer'];
152
+                if ( isset( $tokens[ $i ][ 'scope_opener' ] ) === true ) {
153
+                    $i = $tokens[ $i ][ 'scope_closer' ];
154 154
                 } else {
155
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
156
-                    if ($semicolon !== false) {
155
+                    $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $i + 1 ) );
156
+                    if ( $semicolon !== false ) {
157 157
                         $i = $semicolon;
158 158
                     }
159 159
                 }
@@ -162,40 +162,40 @@  discard block
 block discarded – undo
162 162
             }
163 163
 
164 164
             // Ignore function/class prefixes.
165
-            if (isset(Tokens::$methodPrefixes[$tokens[$i]['code']]) === true) {
165
+            if ( isset( Tokens::$methodPrefixes[ $tokens[ $i ][ 'code' ] ] ) === true ) {
166 166
                 continue;
167 167
             }
168 168
 
169 169
             // Ignore anon classes.
170
-            if ($tokens[$i]['code'] === T_ANON_CLASS) {
171
-                $i = $tokens[$i]['scope_closer'];
170
+            if ( $tokens[ $i ][ 'code' ] === T_ANON_CLASS ) {
171
+                $i = $tokens[ $i ][ 'scope_closer' ];
172 172
                 continue;
173 173
             }
174 174
 
175 175
             // Detect and skip over symbols.
176
-            if (isset($symbols[$tokens[$i]['code']]) === true
177
-                && isset($tokens[$i]['scope_closer']) === true
176
+            if ( isset( $symbols[ $tokens[ $i ][ 'code' ] ] ) === true
177
+                && isset( $tokens[ $i ][ 'scope_closer' ] ) === true
178 178
             ) {
179
-                if ($firstSymbol === null) {
179
+                if ( $firstSymbol === null ) {
180 180
                     $firstSymbol = $i;
181 181
                 }
182 182
 
183
-                $i = $tokens[$i]['scope_closer'];
183
+                $i = $tokens[ $i ][ 'scope_closer' ];
184 184
                 continue;
185
-            } else if ($tokens[$i]['code'] === T_STRING
186
-                && strtolower($tokens[$i]['content']) === 'define'
185
+            } else if ( $tokens[ $i ][ 'code' ] === T_STRING
186
+                && strtolower( $tokens[ $i ][ 'content' ] ) === 'define'
187 187
             ) {
188
-                $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
189
-                if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
190
-                    && $tokens[$prev]['code'] !== T_DOUBLE_COLON
191
-                    && $tokens[$prev]['code'] !== T_FUNCTION
188
+                $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true );
189
+                if ( $tokens[ $prev ][ 'code' ] !== T_OBJECT_OPERATOR
190
+                    && $tokens[ $prev ][ 'code' ] !== T_DOUBLE_COLON
191
+                    && $tokens[ $prev ][ 'code' ] !== T_FUNCTION
192 192
                 ) {
193
-                    if ($firstSymbol === null) {
193
+                    if ( $firstSymbol === null ) {
194 194
                         $firstSymbol = $i;
195 195
                     }
196 196
 
197
-                    $semicolon = $phpcsFile->findNext(T_SEMICOLON, ($i + 1));
198
-                    if ($semicolon !== false) {
197
+                    $semicolon = $phpcsFile->findNext( T_SEMICOLON, ( $i + 1 ) );
198
+                    if ( $semicolon !== false ) {
199 199
                         $i = $semicolon;
200 200
                     }
201 201
 
@@ -206,19 +206,19 @@  discard block
 block discarded – undo
206 206
             // Special case for defined() as it can be used to see
207 207
             // if a constant (a symbol) should be defined or not and
208 208
             // doesn't need to use a full conditional block.
209
-            if ($tokens[$i]['code'] === T_STRING
210
-                && strtolower($tokens[$i]['content']) === 'defined'
209
+            if ( $tokens[ $i ][ 'code' ] === T_STRING
210
+                && strtolower( $tokens[ $i ][ 'content' ] ) === 'defined'
211 211
             ) {
212
-                $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
213
-                if ($tokens[$openBracket]['code'] === T_OPEN_PARENTHESIS
214
-                    && isset($tokens[$openBracket]['parenthesis_closer']) === true
212
+                $openBracket = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true );
213
+                if ( $tokens[ $openBracket ][ 'code' ] === T_OPEN_PARENTHESIS
214
+                    && isset( $tokens[ $openBracket ][ 'parenthesis_closer' ] ) === true
215 215
                 ) {
216
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($i - 1), null, true);
217
-                    if ($tokens[$prev]['code'] !== T_OBJECT_OPERATOR
218
-                        && $tokens[$prev]['code'] !== T_DOUBLE_COLON
219
-                        && $tokens[$prev]['code'] !== T_FUNCTION
216
+                    $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $i - 1 ), null, true );
217
+                    if ( $tokens[ $prev ][ 'code' ] !== T_OBJECT_OPERATOR
218
+                        && $tokens[ $prev ][ 'code' ] !== T_DOUBLE_COLON
219
+                        && $tokens[ $prev ][ 'code' ] !== T_FUNCTION
220 220
                     ) {
221
-                        $i = $tokens[$openBracket]['parenthesis_closer'];
221
+                        $i = $tokens[ $openBracket ][ 'parenthesis_closer' ];
222 222
                         continue;
223 223
                     }
224 224
                 }
@@ -227,44 +227,44 @@  discard block
 block discarded – undo
227 227
             // Conditional statements are allowed in symbol files as long as the
228 228
             // contents is only a symbol definition. So don't count these as effects
229 229
             // in this case.
230
-            if (isset($conditions[$tokens[$i]['code']]) === true) {
231
-                if (isset($tokens[$i]['scope_opener']) === false) {
230
+            if ( isset( $conditions[ $tokens[ $i ][ 'code' ] ] ) === true ) {
231
+                if ( isset( $tokens[ $i ][ 'scope_opener' ] ) === false ) {
232 232
                     // Probably an "else if", so just ignore.
233 233
                     continue;
234 234
                 }
235 235
 
236 236
                 $result = $this->searchForConflict(
237 237
                     $phpcsFile,
238
-                    ($tokens[$i]['scope_opener'] + 1),
239
-                    ($tokens[$i]['scope_closer'] - 1),
238
+                    ( $tokens[ $i ][ 'scope_opener' ] + 1 ),
239
+                    ( $tokens[ $i ][ 'scope_closer' ] - 1 ),
240 240
                     $tokens
241 241
                 );
242 242
 
243
-                if ($result['symbol'] !== null) {
244
-                    if ($firstSymbol === null) {
245
-                        $firstSymbol = $result['symbol'];
243
+                if ( $result[ 'symbol' ] !== null ) {
244
+                    if ( $firstSymbol === null ) {
245
+                        $firstSymbol = $result[ 'symbol' ];
246 246
                     }
247 247
 
248
-                    if ($result['effect'] !== null) {
248
+                    if ( $result[ 'effect' ] !== null ) {
249 249
                         // Found a conflict.
250
-                        $firstEffect = $result['effect'];
250
+                        $firstEffect = $result[ 'effect' ];
251 251
                         break;
252 252
                     }
253 253
                 }
254 254
 
255
-                if ($firstEffect === null) {
256
-                    $firstEffect = $result['effect'];
255
+                if ( $firstEffect === null ) {
256
+                    $firstEffect = $result[ 'effect' ];
257 257
                 }
258 258
 
259
-                $i = $tokens[$i]['scope_closer'];
259
+                $i = $tokens[ $i ][ 'scope_closer' ];
260 260
                 continue;
261 261
             }//end if
262 262
 
263
-            if ($firstEffect === null) {
263
+            if ( $firstEffect === null ) {
264 264
                 $firstEffect = $i;
265 265
             }
266 266
 
267
-            if ($firstSymbol !== null) {
267
+            if ( $firstSymbol !== null ) {
268 268
                 // We have a conflict we have to report, so no point continuing.
269 269
                 break;
270 270
             }
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 
16
-class SideEffectsSniff implements Sniff
17
-{
16
+class SideEffectsSniff implements Sniff {
18 17
 
19 18
 
20 19
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return array
24 23
      */
25
-    public function register()
26
-    {
24
+    public function register() {
27 25
         return [T_OPEN_TAG];
28 26
 
29 27
     }//end register()
@@ -38,8 +36,7 @@  discard block
 block discarded – undo
38 36
      *
39 37
      * @return void
40 38
      */
41
-    public function process(File $phpcsFile, $stackPtr)
42
-    {
39
+    public function process(File $phpcsFile, $stackPtr) {
43 40
         $tokens = $phpcsFile->getTokens();
44 41
         $result = $this->searchForConflict($phpcsFile, 0, ($phpcsFile->numTokens - 1), $tokens);
45 42
 
@@ -76,8 +73,7 @@  discard block
 block discarded – undo
76 73
      *
77 74
      * @return array
78 75
      */
79
-    private function searchForConflict($phpcsFile, $start, $end, $tokens)
80
-    {
76
+    private function searchForConflict($phpcsFile, $start, $end, $tokens) {
81 77
         $symbols = [
82 78
             T_CLASS     => T_CLASS,
83 79
             T_INTERFACE => T_INTERFACE,
Please login to merge, or discard this patch.
src/Standards/Squiz/Sniffs/Commenting/InlineCommentSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
      * @param int                         $stackPtr  The position of the current token in the
50 50
      *                                               stack passed in $tokens.
51 51
      *
52
-     * @return void
52
+     * @return null|integer
53 53
      */
54 54
     public function process(File $phpcsFile, $stackPtr)
55 55
     {
Please login to merge, or discard this patch.
Indentation   +322 added lines, -322 removed lines patch added patch discarded remove patch
@@ -16,328 +16,328 @@
 block discarded – undo
16 16
 class InlineCommentSniff implements Sniff
17 17
 {
18 18
 
19
-    /**
20
-     * A list of tokenizers this sniff supports.
21
-     *
22
-     * @var array
23
-     */
24
-    public $supportedTokenizers = [
25
-        'PHP',
26
-        'JS',
27
-    ];
28
-
29
-
30
-    /**
31
-     * Returns an array of tokens this test wants to listen for.
32
-     *
33
-     * @return array
34
-     */
35
-    public function register()
36
-    {
37
-        return [
38
-            T_COMMENT,
39
-            T_DOC_COMMENT_OPEN_TAG,
40
-        ];
41
-
42
-    }//end register()
43
-
44
-
45
-    /**
46
-     * Processes this test, when one of its tokens is encountered.
47
-     *
48
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
-     * @param int                         $stackPtr  The position of the current token in the
50
-     *                                               stack passed in $tokens.
51
-     *
52
-     * @return void
53
-     */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
56
-        $tokens = $phpcsFile->getTokens();
57
-
58
-        // If this is a function/class/interface doc block comment, skip it.
59
-        // We are only interested in inline doc block comments, which are
60
-        // not allowed.
61
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
62
-            $nextToken = $phpcsFile->findNext(
63
-                Tokens::$emptyTokens,
64
-                ($stackPtr + 1),
65
-                null,
66
-                true
67
-            );
68
-
69
-            $ignore = [
70
-                T_CLASS,
71
-                T_INTERFACE,
72
-                T_TRAIT,
73
-                T_FUNCTION,
74
-                T_CLOSURE,
75
-                T_PUBLIC,
76
-                T_PRIVATE,
77
-                T_PROTECTED,
78
-                T_FINAL,
79
-                T_STATIC,
80
-                T_ABSTRACT,
81
-                T_CONST,
82
-                T_PROPERTY,
83
-                T_INCLUDE,
84
-                T_INCLUDE_ONCE,
85
-                T_REQUIRE,
86
-                T_REQUIRE_ONCE,
87
-            ];
88
-
89
-            if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
90
-                return;
91
-            }
92
-
93
-            if ($phpcsFile->tokenizerType === 'JS') {
94
-                // We allow block comments if a function or object
95
-                // is being assigned to a variable.
96
-                $ignore    = Tokens::$emptyTokens;
97
-                $ignore[]  = T_EQUAL;
98
-                $ignore[]  = T_STRING;
99
-                $ignore[]  = T_OBJECT_OPERATOR;
100
-                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
-                if ($tokens[$nextToken]['code'] === T_FUNCTION
102
-                    || $tokens[$nextToken]['code'] === T_CLOSURE
103
-                    || $tokens[$nextToken]['code'] === T_OBJECT
104
-                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
105
-                ) {
106
-                    return;
107
-                }
108
-            }
109
-
110
-            $prevToken = $phpcsFile->findPrevious(
111
-                Tokens::$emptyTokens,
112
-                ($stackPtr - 1),
113
-                null,
114
-                true
115
-            );
116
-
117
-            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
118
-                return;
119
-            }
120
-
121
-            if ($tokens[$stackPtr]['content'] === '/**') {
122
-                $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
-                $phpcsFile->addError($error, $stackPtr, 'DocBlock');
124
-            }
125
-        }//end if
126
-
127
-        if ($tokens[$stackPtr]['content']{0} === '#') {
128
-            $error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
-            if ($fix === true) {
131
-                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
-                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
133
-            }
134
-        }
135
-
136
-        // We don't want end of block comments. Check if the last token before the
137
-        // comment is a closing curly brace.
138
-        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
-        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
-            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
141
-                return;
142
-            }
143
-
144
-            // Special case for JS files.
145
-            if ($tokens[$previousContent]['code'] === T_COMMA
146
-                || $tokens[$previousContent]['code'] === T_SEMICOLON
147
-            ) {
148
-                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
-                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
150
-                    return;
151
-                }
152
-            }
153
-        }
154
-
155
-        // Only want inline comments.
156
-        if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
157
-            return;
158
-        }
159
-
160
-        $commentTokens = [$stackPtr];
161
-
162
-        $nextComment = $stackPtr;
163
-        $lastComment = $stackPtr;
164
-        while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
-            if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
166
-                break;
167
-            }
168
-
169
-            // Only want inline comments.
170
-            if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
171
-                break;
172
-            }
173
-
174
-            // There is a comment on the very next line. If there is
175
-            // no code between the comments, they are part of the same
176
-            // comment block.
177
-            $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
-            if ($prevNonWhitespace !== $lastComment) {
179
-                break;
180
-            }
181
-
182
-            $commentTokens[] = $nextComment;
183
-            $lastComment     = $nextComment;
184
-        }//end while
185
-
186
-        $commentText = '';
187
-        foreach ($commentTokens as $lastCommentToken) {
188
-            $comment = rtrim($tokens[$lastCommentToken]['content']);
189
-
190
-            if (trim(substr($comment, 2)) === '') {
191
-                continue;
192
-            }
193
-
194
-            $spaceCount = 0;
195
-            $tabFound   = false;
196
-
197
-            $commentLength = strlen($comment);
198
-            for ($i = 2; $i < $commentLength; $i++) {
199
-                if ($comment[$i] === "\t") {
200
-                    $tabFound = true;
201
-                    break;
202
-                }
203
-
204
-                if ($comment[$i] !== ' ') {
205
-                    break;
206
-                }
207
-
208
-                $spaceCount++;
209
-            }
210
-
211
-            $fix = false;
212
-            if ($tabFound === true) {
213
-                $error = 'Tab found before comment text; expected "// %s" but found "%s"';
214
-                $data  = [
215
-                    ltrim(substr($comment, 2)),
216
-                    $comment,
217
-                ];
218
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
-            } else if ($spaceCount === 0) {
220
-                $error = 'No space found before comment text; expected "// %s" but found "%s"';
221
-                $data  = [
222
-                    substr($comment, 2),
223
-                    $comment,
224
-                ];
225
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
-            } else if ($spaceCount > 1) {
227
-                $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228
-                $data  = [
229
-                    $spaceCount,
230
-                    substr($comment, (2 + $spaceCount)),
231
-                    $comment,
232
-                ];
233
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
234
-            }//end if
235
-
236
-            if ($fix === true) {
237
-                $newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
-                $phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
239
-            }
240
-
241
-            $commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
242
-        }//end foreach
243
-
244
-        if ($commentText === '') {
245
-            $error = 'Blank comments are not allowed';
246
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
-            if ($fix === true) {
248
-                $phpcsFile->fixer->replaceToken($stackPtr, '');
249
-            }
250
-
251
-            return ($lastCommentToken + 1);
252
-        }
253
-
254
-        if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
255
-            $error = 'Inline comments must start with a capital letter';
256
-            $phpcsFile->addError($error, $stackPtr, 'NotCapital');
257
-        }
258
-
259
-        // Only check the end of comment character if the start of the comment
260
-        // is a letter, indicating that the comment is just standard text.
261
-        if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
-            $commentCloser   = $commentText[(strlen($commentText) - 1)];
263
-            $acceptedClosers = [
264
-                'full-stops'        => '.',
265
-                'exclamation marks' => '!',
266
-                'or question marks' => '?',
267
-            ];
268
-
269
-            if (in_array($commentCloser, $acceptedClosers, true) === false) {
270
-                $error = 'Inline comments must end in %s';
271
-                $ender = '';
272
-                foreach ($acceptedClosers as $closerName => $symbol) {
273
-                    $ender .= ' '.$closerName.',';
274
-                }
275
-
276
-                $ender = trim($ender, ' ,');
277
-                $data  = [$ender];
278
-                $phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
279
-            }
280
-        }
281
-
282
-        // Finally, the line below the last comment cannot be empty if this inline
283
-        // comment is on a line by itself.
284
-        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
-            if ($next === false) {
287
-                // Ignore if the comment is the last non-whitespace token in a file.
288
-                return ($lastCommentToken + 1);
289
-            }
290
-
291
-            if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
292
-                // If this inline comment is followed by a docblock,
293
-                // ignore spacing as docblock/function etc spacing rules
294
-                // are likely to conflict with our rules.
295
-                return ($lastCommentToken + 1);
296
-            }
297
-
298
-            $errorCode = 'SpacingAfter';
299
-
300
-            if (isset($tokens[$stackPtr]['conditions']) === true) {
301
-                $conditions   = $tokens[$stackPtr]['conditions'];
302
-                $type         = end($conditions);
303
-                $conditionPtr = key($conditions);
304
-
305
-                if (($type === T_FUNCTION || $type === T_CLOSURE)
306
-                    && $tokens[$conditionPtr]['scope_closer'] === $next
307
-                ) {
308
-                    $errorCode = 'SpacingAfterAtFunctionEnd';
309
-                }
310
-            }
311
-
312
-            for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
-                if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
-                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
-                        return ($lastCommentToken + 1);
316
-                    }
317
-                } else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
318
-                    break;
319
-                }
320
-            }
321
-
322
-            $error = 'There must be no blank line following an inline comment';
323
-            $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
-            if ($fix === true) {
325
-                $phpcsFile->fixer->beginChangeset();
326
-                for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
-                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
328
-                        break;
329
-                    }
330
-
331
-                    $phpcsFile->fixer->replaceToken($i, '');
332
-                }
333
-
334
-                $phpcsFile->fixer->endChangeset();
335
-            }
336
-        }//end if
337
-
338
-        return ($lastCommentToken + 1);
339
-
340
-    }//end process()
19
+	/**
20
+	 * A list of tokenizers this sniff supports.
21
+	 *
22
+	 * @var array
23
+	 */
24
+	public $supportedTokenizers = [
25
+		'PHP',
26
+		'JS',
27
+	];
28
+
29
+
30
+	/**
31
+	 * Returns an array of tokens this test wants to listen for.
32
+	 *
33
+	 * @return array
34
+	 */
35
+	public function register()
36
+	{
37
+		return [
38
+			T_COMMENT,
39
+			T_DOC_COMMENT_OPEN_TAG,
40
+		];
41
+
42
+	}//end register()
43
+
44
+
45
+	/**
46
+	 * Processes this test, when one of its tokens is encountered.
47
+	 *
48
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
49
+	 * @param int                         $stackPtr  The position of the current token in the
50
+	 *                                               stack passed in $tokens.
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function process(File $phpcsFile, $stackPtr)
55
+	{
56
+		$tokens = $phpcsFile->getTokens();
57
+
58
+		// If this is a function/class/interface doc block comment, skip it.
59
+		// We are only interested in inline doc block comments, which are
60
+		// not allowed.
61
+		if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
62
+			$nextToken = $phpcsFile->findNext(
63
+				Tokens::$emptyTokens,
64
+				($stackPtr + 1),
65
+				null,
66
+				true
67
+			);
68
+
69
+			$ignore = [
70
+				T_CLASS,
71
+				T_INTERFACE,
72
+				T_TRAIT,
73
+				T_FUNCTION,
74
+				T_CLOSURE,
75
+				T_PUBLIC,
76
+				T_PRIVATE,
77
+				T_PROTECTED,
78
+				T_FINAL,
79
+				T_STATIC,
80
+				T_ABSTRACT,
81
+				T_CONST,
82
+				T_PROPERTY,
83
+				T_INCLUDE,
84
+				T_INCLUDE_ONCE,
85
+				T_REQUIRE,
86
+				T_REQUIRE_ONCE,
87
+			];
88
+
89
+			if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
90
+				return;
91
+			}
92
+
93
+			if ($phpcsFile->tokenizerType === 'JS') {
94
+				// We allow block comments if a function or object
95
+				// is being assigned to a variable.
96
+				$ignore    = Tokens::$emptyTokens;
97
+				$ignore[]  = T_EQUAL;
98
+				$ignore[]  = T_STRING;
99
+				$ignore[]  = T_OBJECT_OPERATOR;
100
+				$nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
+				if ($tokens[$nextToken]['code'] === T_FUNCTION
102
+					|| $tokens[$nextToken]['code'] === T_CLOSURE
103
+					|| $tokens[$nextToken]['code'] === T_OBJECT
104
+					|| $tokens[$nextToken]['code'] === T_PROTOTYPE
105
+				) {
106
+					return;
107
+				}
108
+			}
109
+
110
+			$prevToken = $phpcsFile->findPrevious(
111
+				Tokens::$emptyTokens,
112
+				($stackPtr - 1),
113
+				null,
114
+				true
115
+			);
116
+
117
+			if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
118
+				return;
119
+			}
120
+
121
+			if ($tokens[$stackPtr]['content'] === '/**') {
122
+				$error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
+				$phpcsFile->addError($error, $stackPtr, 'DocBlock');
124
+			}
125
+		}//end if
126
+
127
+		if ($tokens[$stackPtr]['content']{0} === '#') {
128
+			$error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
+			if ($fix === true) {
131
+				$comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
+				$phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
133
+			}
134
+		}
135
+
136
+		// We don't want end of block comments. Check if the last token before the
137
+		// comment is a closing curly brace.
138
+		$previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
+		if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
+			if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
141
+				return;
142
+			}
143
+
144
+			// Special case for JS files.
145
+			if ($tokens[$previousContent]['code'] === T_COMMA
146
+				|| $tokens[$previousContent]['code'] === T_SEMICOLON
147
+			) {
148
+				$lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
+				if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
150
+					return;
151
+				}
152
+			}
153
+		}
154
+
155
+		// Only want inline comments.
156
+		if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
157
+			return;
158
+		}
159
+
160
+		$commentTokens = [$stackPtr];
161
+
162
+		$nextComment = $stackPtr;
163
+		$lastComment = $stackPtr;
164
+		while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
+			if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
166
+				break;
167
+			}
168
+
169
+			// Only want inline comments.
170
+			if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
171
+				break;
172
+			}
173
+
174
+			// There is a comment on the very next line. If there is
175
+			// no code between the comments, they are part of the same
176
+			// comment block.
177
+			$prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
+			if ($prevNonWhitespace !== $lastComment) {
179
+				break;
180
+			}
181
+
182
+			$commentTokens[] = $nextComment;
183
+			$lastComment     = $nextComment;
184
+		}//end while
185
+
186
+		$commentText = '';
187
+		foreach ($commentTokens as $lastCommentToken) {
188
+			$comment = rtrim($tokens[$lastCommentToken]['content']);
189
+
190
+			if (trim(substr($comment, 2)) === '') {
191
+				continue;
192
+			}
193
+
194
+			$spaceCount = 0;
195
+			$tabFound   = false;
196
+
197
+			$commentLength = strlen($comment);
198
+			for ($i = 2; $i < $commentLength; $i++) {
199
+				if ($comment[$i] === "\t") {
200
+					$tabFound = true;
201
+					break;
202
+				}
203
+
204
+				if ($comment[$i] !== ' ') {
205
+					break;
206
+				}
207
+
208
+				$spaceCount++;
209
+			}
210
+
211
+			$fix = false;
212
+			if ($tabFound === true) {
213
+				$error = 'Tab found before comment text; expected "// %s" but found "%s"';
214
+				$data  = [
215
+					ltrim(substr($comment, 2)),
216
+					$comment,
217
+				];
218
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
+			} else if ($spaceCount === 0) {
220
+				$error = 'No space found before comment text; expected "// %s" but found "%s"';
221
+				$data  = [
222
+					substr($comment, 2),
223
+					$comment,
224
+				];
225
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
+			} else if ($spaceCount > 1) {
227
+				$error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228
+				$data  = [
229
+					$spaceCount,
230
+					substr($comment, (2 + $spaceCount)),
231
+					$comment,
232
+				];
233
+				$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
234
+			}//end if
235
+
236
+			if ($fix === true) {
237
+				$newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
+				$phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
239
+			}
240
+
241
+			$commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
242
+		}//end foreach
243
+
244
+		if ($commentText === '') {
245
+			$error = 'Blank comments are not allowed';
246
+			$fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
+			if ($fix === true) {
248
+				$phpcsFile->fixer->replaceToken($stackPtr, '');
249
+			}
250
+
251
+			return ($lastCommentToken + 1);
252
+		}
253
+
254
+		if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
255
+			$error = 'Inline comments must start with a capital letter';
256
+			$phpcsFile->addError($error, $stackPtr, 'NotCapital');
257
+		}
258
+
259
+		// Only check the end of comment character if the start of the comment
260
+		// is a letter, indicating that the comment is just standard text.
261
+		if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
+			$commentCloser   = $commentText[(strlen($commentText) - 1)];
263
+			$acceptedClosers = [
264
+				'full-stops'        => '.',
265
+				'exclamation marks' => '!',
266
+				'or question marks' => '?',
267
+			];
268
+
269
+			if (in_array($commentCloser, $acceptedClosers, true) === false) {
270
+				$error = 'Inline comments must end in %s';
271
+				$ender = '';
272
+				foreach ($acceptedClosers as $closerName => $symbol) {
273
+					$ender .= ' '.$closerName.',';
274
+				}
275
+
276
+				$ender = trim($ender, ' ,');
277
+				$data  = [$ender];
278
+				$phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
279
+			}
280
+		}
281
+
282
+		// Finally, the line below the last comment cannot be empty if this inline
283
+		// comment is on a line by itself.
284
+		if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
+			$next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
+			if ($next === false) {
287
+				// Ignore if the comment is the last non-whitespace token in a file.
288
+				return ($lastCommentToken + 1);
289
+			}
290
+
291
+			if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
292
+				// If this inline comment is followed by a docblock,
293
+				// ignore spacing as docblock/function etc spacing rules
294
+				// are likely to conflict with our rules.
295
+				return ($lastCommentToken + 1);
296
+			}
297
+
298
+			$errorCode = 'SpacingAfter';
299
+
300
+			if (isset($tokens[$stackPtr]['conditions']) === true) {
301
+				$conditions   = $tokens[$stackPtr]['conditions'];
302
+				$type         = end($conditions);
303
+				$conditionPtr = key($conditions);
304
+
305
+				if (($type === T_FUNCTION || $type === T_CLOSURE)
306
+					&& $tokens[$conditionPtr]['scope_closer'] === $next
307
+				) {
308
+					$errorCode = 'SpacingAfterAtFunctionEnd';
309
+				}
310
+			}
311
+
312
+			for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
+				if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
+					if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
+						return ($lastCommentToken + 1);
316
+					}
317
+				} else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
318
+					break;
319
+				}
320
+			}
321
+
322
+			$error = 'There must be no blank line following an inline comment';
323
+			$fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
+			if ($fix === true) {
325
+				$phpcsFile->fixer->beginChangeset();
326
+				for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
+					if ($tokens[$i]['line'] === $tokens[$next]['line']) {
328
+						break;
329
+					}
330
+
331
+					$phpcsFile->fixer->replaceToken($i, '');
332
+				}
333
+
334
+				$phpcsFile->fixer->endChangeset();
335
+			}
336
+		}//end if
337
+
338
+		return ($lastCommentToken + 1);
339
+
340
+	}//end process()
341 341
 
342 342
 
343 343
 }//end class
Please login to merge, or discard this patch.
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -51,17 +51,17 @@  discard block
 block discarded – undo
51 51
      *
52 52
      * @return void
53 53
      */
54
-    public function process(File $phpcsFile, $stackPtr)
54
+    public function process( File $phpcsFile, $stackPtr )
55 55
     {
56 56
         $tokens = $phpcsFile->getTokens();
57 57
 
58 58
         // If this is a function/class/interface doc block comment, skip it.
59 59
         // We are only interested in inline doc block comments, which are
60 60
         // not allowed.
61
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
61
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
62 62
             $nextToken = $phpcsFile->findNext(
63 63
                 Tokens::$emptyTokens,
64
-                ($stackPtr + 1),
64
+                ( $stackPtr + 1 ),
65 65
                 null,
66 66
                 true
67 67
             );
@@ -86,22 +86,22 @@  discard block
 block discarded – undo
86 86
                 T_REQUIRE_ONCE,
87 87
             ];
88 88
 
89
-            if (in_array($tokens[$nextToken]['code'], $ignore, true) === true) {
89
+            if ( in_array( $tokens[ $nextToken ][ 'code' ], $ignore, true ) === true ) {
90 90
                 return;
91 91
             }
92 92
 
93
-            if ($phpcsFile->tokenizerType === 'JS') {
93
+            if ( $phpcsFile->tokenizerType === 'JS' ) {
94 94
                 // We allow block comments if a function or object
95 95
                 // is being assigned to a variable.
96 96
                 $ignore    = Tokens::$emptyTokens;
97
-                $ignore[]  = T_EQUAL;
98
-                $ignore[]  = T_STRING;
99
-                $ignore[]  = T_OBJECT_OPERATOR;
100
-                $nextToken = $phpcsFile->findNext($ignore, ($nextToken + 1), null, true);
101
-                if ($tokens[$nextToken]['code'] === T_FUNCTION
102
-                    || $tokens[$nextToken]['code'] === T_CLOSURE
103
-                    || $tokens[$nextToken]['code'] === T_OBJECT
104
-                    || $tokens[$nextToken]['code'] === T_PROTOTYPE
97
+                $ignore[ ]  = T_EQUAL;
98
+                $ignore[ ]  = T_STRING;
99
+                $ignore[ ]  = T_OBJECT_OPERATOR;
100
+                $nextToken = $phpcsFile->findNext( $ignore, ( $nextToken + 1 ), null, true );
101
+                if ( $tokens[ $nextToken ][ 'code' ] === T_FUNCTION
102
+                    || $tokens[ $nextToken ][ 'code' ] === T_CLOSURE
103
+                    || $tokens[ $nextToken ][ 'code' ] === T_OBJECT
104
+                    || $tokens[ $nextToken ][ 'code' ] === T_PROTOTYPE
105 105
                 ) {
106 106
                     return;
107 107
                 }
@@ -109,99 +109,99 @@  discard block
 block discarded – undo
109 109
 
110 110
             $prevToken = $phpcsFile->findPrevious(
111 111
                 Tokens::$emptyTokens,
112
-                ($stackPtr - 1),
112
+                ( $stackPtr - 1 ),
113 113
                 null,
114 114
                 true
115 115
             );
116 116
 
117
-            if ($tokens[$prevToken]['code'] === T_OPEN_TAG) {
117
+            if ( $tokens[ $prevToken ][ 'code' ] === T_OPEN_TAG ) {
118 118
                 return;
119 119
             }
120 120
 
121
-            if ($tokens[$stackPtr]['content'] === '/**') {
121
+            if ( $tokens[ $stackPtr ][ 'content' ] === '/**' ) {
122 122
                 $error = 'Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead';
123
-                $phpcsFile->addError($error, $stackPtr, 'DocBlock');
123
+                $phpcsFile->addError( $error, $stackPtr, 'DocBlock' );
124 124
             }
125 125
         }//end if
126 126
 
127
-        if ($tokens[$stackPtr]['content']{0} === '#') {
127
+        if ( $tokens[ $stackPtr ][ 'content' ]{0} === '#' ) {
128 128
             $error = 'Perl-style comments are not allowed; use "// Comment" instead';
129
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'WrongStyle');
130
-            if ($fix === true) {
131
-                $comment = ltrim($tokens[$stackPtr]['content'], "# \t");
132
-                $phpcsFile->fixer->replaceToken($stackPtr, "// $comment");
129
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'WrongStyle' );
130
+            if ( $fix === true ) {
131
+                $comment = ltrim( $tokens[ $stackPtr ][ 'content' ], "# \t" );
132
+                $phpcsFile->fixer->replaceToken( $stackPtr, "// $comment" );
133 133
             }
134 134
         }
135 135
 
136 136
         // We don't want end of block comments. Check if the last token before the
137 137
         // comment is a closing curly brace.
138
-        $previousContent = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
139
-        if ($tokens[$previousContent]['line'] === $tokens[$stackPtr]['line']) {
140
-            if ($tokens[$previousContent]['code'] === T_CLOSE_CURLY_BRACKET) {
138
+        $previousContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $stackPtr - 1 ), null, true );
139
+        if ( $tokens[ $previousContent ][ 'line' ] === $tokens[ $stackPtr ][ 'line' ] ) {
140
+            if ( $tokens[ $previousContent ][ 'code' ] === T_CLOSE_CURLY_BRACKET ) {
141 141
                 return;
142 142
             }
143 143
 
144 144
             // Special case for JS files.
145
-            if ($tokens[$previousContent]['code'] === T_COMMA
146
-                || $tokens[$previousContent]['code'] === T_SEMICOLON
145
+            if ( $tokens[ $previousContent ][ 'code' ] === T_COMMA
146
+                || $tokens[ $previousContent ][ 'code' ] === T_SEMICOLON
147 147
             ) {
148
-                $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($previousContent - 1), null, true);
149
-                if ($tokens[$lastContent]['code'] === T_CLOSE_CURLY_BRACKET) {
148
+                $lastContent = $phpcsFile->findPrevious( T_WHITESPACE, ( $previousContent - 1 ), null, true );
149
+                if ( $tokens[ $lastContent ][ 'code' ] === T_CLOSE_CURLY_BRACKET ) {
150 150
                     return;
151 151
                 }
152 152
             }
153 153
         }
154 154
 
155 155
         // Only want inline comments.
156
-        if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
156
+        if ( substr( $tokens[ $stackPtr ][ 'content' ], 0, 2 ) !== '//' ) {
157 157
             return;
158 158
         }
159 159
 
160
-        $commentTokens = [$stackPtr];
160
+        $commentTokens = [ $stackPtr ];
161 161
 
162 162
         $nextComment = $stackPtr;
163 163
         $lastComment = $stackPtr;
164
-        while (($nextComment = $phpcsFile->findNext(T_COMMENT, ($nextComment + 1), null, false)) !== false) {
165
-            if ($tokens[$nextComment]['line'] !== ($tokens[$lastComment]['line'] + 1)) {
164
+        while ( ( $nextComment = $phpcsFile->findNext( T_COMMENT, ( $nextComment + 1 ), null, false ) ) !== false ) {
165
+            if ( $tokens[ $nextComment ][ 'line' ] !== ( $tokens[ $lastComment ][ 'line' ] + 1 ) ) {
166 166
                 break;
167 167
             }
168 168
 
169 169
             // Only want inline comments.
170
-            if (substr($tokens[$nextComment]['content'], 0, 2) !== '//') {
170
+            if ( substr( $tokens[ $nextComment ][ 'content' ], 0, 2 ) !== '//' ) {
171 171
                 break;
172 172
             }
173 173
 
174 174
             // There is a comment on the very next line. If there is
175 175
             // no code between the comments, they are part of the same
176 176
             // comment block.
177
-            $prevNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, ($nextComment - 1), $lastComment, true);
178
-            if ($prevNonWhitespace !== $lastComment) {
177
+            $prevNonWhitespace = $phpcsFile->findPrevious( T_WHITESPACE, ( $nextComment - 1 ), $lastComment, true );
178
+            if ( $prevNonWhitespace !== $lastComment ) {
179 179
                 break;
180 180
             }
181 181
 
182
-            $commentTokens[] = $nextComment;
182
+            $commentTokens[ ] = $nextComment;
183 183
             $lastComment     = $nextComment;
184 184
         }//end while
185 185
 
186 186
         $commentText = '';
187
-        foreach ($commentTokens as $lastCommentToken) {
188
-            $comment = rtrim($tokens[$lastCommentToken]['content']);
187
+        foreach ( $commentTokens as $lastCommentToken ) {
188
+            $comment = rtrim( $tokens[ $lastCommentToken ][ 'content' ] );
189 189
 
190
-            if (trim(substr($comment, 2)) === '') {
190
+            if ( trim( substr( $comment, 2 ) ) === '' ) {
191 191
                 continue;
192 192
             }
193 193
 
194 194
             $spaceCount = 0;
195 195
             $tabFound   = false;
196 196
 
197
-            $commentLength = strlen($comment);
198
-            for ($i = 2; $i < $commentLength; $i++) {
199
-                if ($comment[$i] === "\t") {
197
+            $commentLength = strlen( $comment );
198
+            for ( $i = 2; $i < $commentLength; $i++ ) {
199
+                if ( $comment[ $i ] === "\t" ) {
200 200
                     $tabFound = true;
201 201
                     break;
202 202
                 }
203 203
 
204
-                if ($comment[$i] !== ' ') {
204
+                if ( $comment[ $i ] !== ' ' ) {
205 205
                     break;
206 206
                 }
207 207
 
@@ -209,133 +209,133 @@  discard block
 block discarded – undo
209 209
             }
210 210
 
211 211
             $fix = false;
212
-            if ($tabFound === true) {
212
+            if ( $tabFound === true ) {
213 213
                 $error = 'Tab found before comment text; expected "// %s" but found "%s"';
214 214
                 $data  = [
215
-                    ltrim(substr($comment, 2)),
215
+                    ltrim( substr( $comment, 2 ) ),
216 216
                     $comment,
217 217
                 ];
218
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'TabBefore', $data);
219
-            } else if ($spaceCount === 0) {
218
+                $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, 'TabBefore', $data );
219
+            } else if ( $spaceCount === 0 ) {
220 220
                 $error = 'No space found before comment text; expected "// %s" but found "%s"';
221 221
                 $data  = [
222
-                    substr($comment, 2),
222
+                    substr( $comment, 2 ),
223 223
                     $comment,
224 224
                 ];
225
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'NoSpaceBefore', $data);
226
-            } else if ($spaceCount > 1) {
225
+                $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, 'NoSpaceBefore', $data );
226
+            } else if ( $spaceCount > 1 ) {
227 227
                 $error = 'Expected 1 space before comment text but found %s; use block comment if you need indentation';
228 228
                 $data  = [
229 229
                     $spaceCount,
230
-                    substr($comment, (2 + $spaceCount)),
230
+                    substr( $comment, ( 2 + $spaceCount ) ),
231 231
                     $comment,
232 232
                 ];
233
-                $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, 'SpacingBefore', $data);
233
+                $fix = $phpcsFile->addFixableError( $error, $lastCommentToken, 'SpacingBefore', $data );
234 234
             }//end if
235 235
 
236
-            if ($fix === true) {
237
-                $newComment = '// '.ltrim($tokens[$lastCommentToken]['content'], "/\t ");
238
-                $phpcsFile->fixer->replaceToken($lastCommentToken, $newComment);
236
+            if ( $fix === true ) {
237
+                $newComment = '// ' . ltrim( $tokens[ $lastCommentToken ][ 'content' ], "/\t " );
238
+                $phpcsFile->fixer->replaceToken( $lastCommentToken, $newComment );
239 239
             }
240 240
 
241
-            $commentText .= trim(substr($tokens[$lastCommentToken]['content'], 2));
241
+            $commentText .= trim( substr( $tokens[ $lastCommentToken ][ 'content' ], 2 ) );
242 242
         }//end foreach
243 243
 
244
-        if ($commentText === '') {
244
+        if ( $commentText === '' ) {
245 245
             $error = 'Blank comments are not allowed';
246
-            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'Empty');
247
-            if ($fix === true) {
248
-                $phpcsFile->fixer->replaceToken($stackPtr, '');
246
+            $fix   = $phpcsFile->addFixableError( $error, $stackPtr, 'Empty' );
247
+            if ( $fix === true ) {
248
+                $phpcsFile->fixer->replaceToken( $stackPtr, '' );
249 249
             }
250 250
 
251
-            return ($lastCommentToken + 1);
251
+            return ( $lastCommentToken + 1 );
252 252
         }
253 253
 
254
-        if (preg_match('/^\p{Ll}/u', $commentText) === 1) {
254
+        if ( preg_match( '/^\p{Ll}/u', $commentText ) === 1 ) {
255 255
             $error = 'Inline comments must start with a capital letter';
256
-            $phpcsFile->addError($error, $stackPtr, 'NotCapital');
256
+            $phpcsFile->addError( $error, $stackPtr, 'NotCapital' );
257 257
         }
258 258
 
259 259
         // Only check the end of comment character if the start of the comment
260 260
         // is a letter, indicating that the comment is just standard text.
261
-        if (preg_match('/^\p{L}/u', $commentText) === 1) {
262
-            $commentCloser   = $commentText[(strlen($commentText) - 1)];
261
+        if ( preg_match( '/^\p{L}/u', $commentText ) === 1 ) {
262
+            $commentCloser   = $commentText[ ( strlen( $commentText ) - 1 ) ];
263 263
             $acceptedClosers = [
264 264
                 'full-stops'        => '.',
265 265
                 'exclamation marks' => '!',
266 266
                 'or question marks' => '?',
267 267
             ];
268 268
 
269
-            if (in_array($commentCloser, $acceptedClosers, true) === false) {
269
+            if ( in_array( $commentCloser, $acceptedClosers, true ) === false ) {
270 270
                 $error = 'Inline comments must end in %s';
271 271
                 $ender = '';
272
-                foreach ($acceptedClosers as $closerName => $symbol) {
273
-                    $ender .= ' '.$closerName.',';
272
+                foreach ( $acceptedClosers as $closerName => $symbol ) {
273
+                    $ender .= ' ' . $closerName . ',';
274 274
                 }
275 275
 
276
-                $ender = trim($ender, ' ,');
277
-                $data  = [$ender];
278
-                $phpcsFile->addError($error, $lastCommentToken, 'InvalidEndChar', $data);
276
+                $ender = trim( $ender, ' ,' );
277
+                $data  = [ $ender ];
278
+                $phpcsFile->addError( $error, $lastCommentToken, 'InvalidEndChar', $data );
279 279
             }
280 280
         }
281 281
 
282 282
         // Finally, the line below the last comment cannot be empty if this inline
283 283
         // comment is on a line by itself.
284
-        if ($tokens[$previousContent]['line'] < $tokens[$stackPtr]['line']) {
285
-            $next = $phpcsFile->findNext(T_WHITESPACE, ($lastCommentToken + 1), null, true);
286
-            if ($next === false) {
284
+        if ( $tokens[ $previousContent ][ 'line' ] < $tokens[ $stackPtr ][ 'line' ] ) {
285
+            $next = $phpcsFile->findNext( T_WHITESPACE, ( $lastCommentToken + 1 ), null, true );
286
+            if ( $next === false ) {
287 287
                 // Ignore if the comment is the last non-whitespace token in a file.
288
-                return ($lastCommentToken + 1);
288
+                return ( $lastCommentToken + 1 );
289 289
             }
290 290
 
291
-            if ($tokens[$next]['code'] === T_DOC_COMMENT_OPEN_TAG) {
291
+            if ( $tokens[ $next ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
292 292
                 // If this inline comment is followed by a docblock,
293 293
                 // ignore spacing as docblock/function etc spacing rules
294 294
                 // are likely to conflict with our rules.
295
-                return ($lastCommentToken + 1);
295
+                return ( $lastCommentToken + 1 );
296 296
             }
297 297
 
298 298
             $errorCode = 'SpacingAfter';
299 299
 
300
-            if (isset($tokens[$stackPtr]['conditions']) === true) {
301
-                $conditions   = $tokens[$stackPtr]['conditions'];
302
-                $type         = end($conditions);
303
-                $conditionPtr = key($conditions);
300
+            if ( isset( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) {
301
+                $conditions   = $tokens[ $stackPtr ][ 'conditions' ];
302
+                $type         = end( $conditions );
303
+                $conditionPtr = key( $conditions );
304 304
 
305
-                if (($type === T_FUNCTION || $type === T_CLOSURE)
306
-                    && $tokens[$conditionPtr]['scope_closer'] === $next
305
+                if ( ( $type === T_FUNCTION || $type === T_CLOSURE )
306
+                    && $tokens[ $conditionPtr ][ 'scope_closer' ] === $next
307 307
                 ) {
308 308
                     $errorCode = 'SpacingAfterAtFunctionEnd';
309 309
                 }
310 310
             }
311 311
 
312
-            for ($i = ($lastCommentToken + 1); $i < $phpcsFile->numTokens; $i++) {
313
-                if ($tokens[$i]['line'] === ($tokens[$lastCommentToken]['line'] + 1)) {
314
-                    if ($tokens[$i]['code'] !== T_WHITESPACE) {
315
-                        return ($lastCommentToken + 1);
312
+            for ( $i = ( $lastCommentToken + 1 ); $i < $phpcsFile->numTokens; $i++ ) {
313
+                if ( $tokens[ $i ][ 'line' ] === ( $tokens[ $lastCommentToken ][ 'line' ] + 1 ) ) {
314
+                    if ( $tokens[ $i ][ 'code' ] !== T_WHITESPACE ) {
315
+                        return ( $lastCommentToken + 1 );
316 316
                     }
317
-                } else if ($tokens[$i]['line'] > ($tokens[$lastCommentToken]['line'] + 1)) {
317
+                } else if ( $tokens[ $i ][ 'line' ] > ( $tokens[ $lastCommentToken ][ 'line' ] + 1 ) ) {
318 318
                     break;
319 319
                 }
320 320
             }
321 321
 
322 322
             $error = 'There must be no blank line following an inline comment';
323
-            $fix   = $phpcsFile->addFixableError($error, $lastCommentToken, $errorCode);
324
-            if ($fix === true) {
323
+            $fix   = $phpcsFile->addFixableError( $error, $lastCommentToken, $errorCode );
324
+            if ( $fix === true ) {
325 325
                 $phpcsFile->fixer->beginChangeset();
326
-                for ($i = ($lastCommentToken + 1); $i < $next; $i++) {
327
-                    if ($tokens[$i]['line'] === $tokens[$next]['line']) {
326
+                for ( $i = ( $lastCommentToken + 1 ); $i < $next; $i++ ) {
327
+                    if ( $tokens[ $i ][ 'line' ] === $tokens[ $next ][ 'line' ] ) {
328 328
                         break;
329 329
                     }
330 330
 
331
-                    $phpcsFile->fixer->replaceToken($i, '');
331
+                    $phpcsFile->fixer->replaceToken( $i, '' );
332 332
                 }
333 333
 
334 334
                 $phpcsFile->fixer->endChangeset();
335 335
             }
336 336
         }//end if
337 337
 
338
-        return ($lastCommentToken + 1);
338
+        return ( $lastCommentToken + 1 );
339 339
 
340 340
     }//end process()
341 341
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 
16
-class InlineCommentSniff implements Sniff
17
-{
16
+class InlineCommentSniff implements Sniff {
18 17
 
19 18
     /**
20 19
      * A list of tokenizers this sniff supports.
@@ -32,8 +31,7 @@  discard block
 block discarded – undo
32 31
      *
33 32
      * @return array
34 33
      */
35
-    public function register()
36
-    {
34
+    public function register() {
37 35
         return [
38 36
             T_COMMENT,
39 37
             T_DOC_COMMENT_OPEN_TAG,
@@ -51,8 +49,7 @@  discard block
 block discarded – undo
51 49
      *
52 50
      * @return void
53 51
      */
54
-    public function process(File $phpcsFile, $stackPtr)
55
-    {
52
+    public function process(File $phpcsFile, $stackPtr) {
56 53
         $tokens = $phpcsFile->getTokens();
57 54
 
58 55
         // If this is a function/class/interface doc block comment, skip it.
Please login to merge, or discard this patch.
src/Standards/Squiz/Tests/Commenting/DocCommentAlignmentUnitTest.inc 3 patches
Doc Comments   -3 removed lines patch added patch discarded remove patch
@@ -61,9 +61,6 @@
 block discarded – undo
61 61
  *   - three
62 62
  *
63 63
  * @param array  &$tokens   The array of tokens to process.
64
- * @param object $tokenizer The tokenizer being used to
65
- *                          process this file.
66
- * @param string $eolChar   The EOL character to use for splitting strings.
67 64
  *
68 65
  * @return void
69 66
  */
Please login to merge, or discard this patch.
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -5,40 +5,40 @@  discard block
 block discarded – undo
5 5
  */
6 6
 class MyClass
7 7
 {
8
-    /**
9
-     * Some info about the function here.
10
-     *
11
-     *@return void
12
-     */
13
-    function myFunction() {}
8
+	/**
9
+	 * Some info about the function here.
10
+	 *
11
+	 *@return void
12
+	 */
13
+	function myFunction() {}
14 14
 }
15 15
 
16 16
 /**
17
-  *  Some info about the class here
18
-  *
19
-  */
17
+ *  Some info about the class here
18
+ *
19
+ */
20 20
 class MyClass
21 21
 {
22
-    /**
23
-      *Some info about the function here.
24
-      *
25
-      *  @return void
26
-      */
27
-    function myFunction() {}
22
+	/**
23
+	 *Some info about the function here.
24
+	 *
25
+	 *  @return void
26
+	 */
27
+	function myFunction() {}
28 28
 }
29 29
 
30 30
 /**
31 31
  * Some info about the class here
32
-  *
32
+ *
33 33
 */
34 34
 class MyClass
35 35
 {
36
-    /**
37
-     * Some info about the function here.
38
-      *
39
-    * @return void
40
-     */
41
-    function myFunction() {}
36
+	/**
37
+	 * Some info about the function here.
38
+	 *
39
+	 * @return void
40
+	 */
41
+	function myFunction() {}
42 42
 }
43 43
 
44 44
 /** @var Database $mockedDatabase */
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 
47 47
 function myFunction()
48 48
 {
49
-    echo 'hi';
50
-    /**
49
+	echo 'hi';
50
+	/**
51 51
         Comment here.
52
-        */
52
+	 */
53 53
 }
54 54
 
55 55
 /**
@@ -71,10 +71,10 @@  discard block
 block discarded – undo
71 71
 
72 72
 class MyClass2
73 73
 {
74
-    /**
75
-       * Some info about the variable here.
76
-     */
77
-    var $x;
74
+	/**
75
+	 * Some info about the variable here.
76
+	 */
77
+	var $x;
78 78
 }
79 79
 
80 80
 /** ************************************************************************
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -3,8 +3,7 @@  discard block
 block discarded – undo
3 3
 * Some info about the class here
4 4
  *
5 5
  */
6
-class MyClass
7
-{
6
+class MyClass {
8 7
     /**
9 8
      * Some info about the function here.
10 9
      *
@@ -17,8 +16,7 @@  discard block
 block discarded – undo
17 16
   *  Some info about the class here
18 17
   *
19 18
   */
20
-class MyClass
21
-{
19
+class MyClass {
22 20
     /**
23 21
       *Some info about the function here.
24 22
       *
@@ -31,8 +29,7 @@  discard block
 block discarded – undo
31 29
  * Some info about the class here
32 30
   *
33 31
 */
34
-class MyClass
35
-{
32
+class MyClass {
36 33
     /**
37 34
      * Some info about the function here.
38 35
       *
@@ -44,8 +41,7 @@  discard block
 block discarded – undo
44 41
 /** @var Database $mockedDatabase */
45 42
 /** @var Container $mockedContainer */
46 43
 
47
-function myFunction()
48
-{
44
+function myFunction() {
49 45
     echo 'hi';
50 46
     /**
51 47
         Comment here.
@@ -69,8 +65,7 @@  discard block
 block discarded – undo
69 65
  */
70 66
 function myFunction() {}
71 67
 
72
-class MyClass2
73
-{
68
+class MyClass2 {
74 69
     /**
75 70
        * Some info about the variable here.
76 71
      */
Please login to merge, or discard this patch.
src/Standards/Squiz/Tests/ControlStructures/InlineIfDeclarationUnitTest.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
      *
21 21
      * @param string $testFile The name of the file being tested.
22 22
      *
23
-     * @return array
23
+     * @return string[]
24 24
      */
25 25
     public function getCliValues($testFile)
26 26
     {
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -15,61 +15,61 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Get a list of CLI values to set before the file is tested.
20
-     *
21
-     * @param string $testFile The name of the file being tested.
22
-     *
23
-     * @return array
24
-     */
25
-    public function getCliValues($testFile)
26
-    {
27
-        return ['--encoding=utf-8'];
18
+	/**
19
+	 * Get a list of CLI values to set before the file is tested.
20
+	 *
21
+	 * @param string $testFile The name of the file being tested.
22
+	 *
23
+	 * @return array
24
+	 */
25
+	public function getCliValues($testFile)
26
+	{
27
+		return ['--encoding=utf-8'];
28 28
 
29
-    }//end getCliValues()
29
+	}//end getCliValues()
30 30
 
31 31
 
32
-    /**
33
-     * Returns the lines where errors should occur.
34
-     *
35
-     * The key of the array should represent the line number and the value
36
-     * should represent the number of errors that should occur on that line.
37
-     *
38
-     * @return array<int, int>
39
-     */
40
-    public function getErrorList()
41
-    {
42
-        return [
43
-            4  => 1,
44
-            5  => 1,
45
-            6  => 1,
46
-            7  => 1,
47
-            8  => 1,
48
-            9  => 1,
49
-            10 => 1,
50
-            13 => 1,
51
-            20 => 1,
52
-            24 => 4,
53
-            44 => 1,
54
-            47 => 1,
55
-        ];
32
+	/**
33
+	 * Returns the lines where errors should occur.
34
+	 *
35
+	 * The key of the array should represent the line number and the value
36
+	 * should represent the number of errors that should occur on that line.
37
+	 *
38
+	 * @return array<int, int>
39
+	 */
40
+	public function getErrorList()
41
+	{
42
+		return [
43
+			4  => 1,
44
+			5  => 1,
45
+			6  => 1,
46
+			7  => 1,
47
+			8  => 1,
48
+			9  => 1,
49
+			10 => 1,
50
+			13 => 1,
51
+			20 => 1,
52
+			24 => 4,
53
+			44 => 1,
54
+			47 => 1,
55
+		];
56 56
 
57
-    }//end getErrorList()
57
+	}//end getErrorList()
58 58
 
59 59
 
60
-    /**
61
-     * Returns the lines where warnings should occur.
62
-     *
63
-     * The key of the array should represent the line number and the value
64
-     * should represent the number of warnings that should occur on that line.
65
-     *
66
-     * @return array<int, int>
67
-     */
68
-    public function getWarningList()
69
-    {
70
-        return [];
60
+	/**
61
+	 * Returns the lines where warnings should occur.
62
+	 *
63
+	 * The key of the array should represent the line number and the value
64
+	 * should represent the number of warnings that should occur on that line.
65
+	 *
66
+	 * @return array<int, int>
67
+	 */
68
+	public function getWarningList()
69
+	{
70
+		return [];
71 71
 
72
-    }//end getWarningList()
72
+	}//end getWarningList()
73 73
 
74 74
 
75 75
 }//end class
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,9 +22,9 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @return array
24 24
      */
25
-    public function getCliValues($testFile)
25
+    public function getCliValues( $testFile )
26 26
     {
27
-        return ['--encoding=utf-8'];
27
+        return [ '--encoding=utf-8' ];
28 28
 
29 29
     }//end getCliValues()
30 30
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     public function getWarningList()
69 69
     {
70
-        return [];
70
+        return [ ];
71 71
 
72 72
     }//end getWarningList()
73 73
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
13 13
 
14
-class InlineIfDeclarationUnitTest extends AbstractSniffUnitTest
15
-{
14
+class InlineIfDeclarationUnitTest extends AbstractSniffUnitTest {
16 15
 
17 16
 
18 17
     /**
@@ -22,8 +21,7 @@  discard block
 block discarded – undo
22 21
      *
23 22
      * @return array
24 23
      */
25
-    public function getCliValues($testFile)
26
-    {
24
+    public function getCliValues($testFile) {
27 25
         return ['--encoding=utf-8'];
28 26
 
29 27
     }//end getCliValues()
@@ -37,8 +35,7 @@  discard block
 block discarded – undo
37 35
      *
38 36
      * @return array<int, int>
39 37
      */
40
-    public function getErrorList()
41
-    {
38
+    public function getErrorList() {
42 39
         return [
43 40
             4  => 1,
44 41
             5  => 1,
@@ -65,8 +62,7 @@  discard block
 block discarded – undo
65 62
      *
66 63
      * @return array<int, int>
67 64
      */
68
-    public function getWarningList()
69
-    {
65
+    public function getWarningList() {
70 66
         return [];
71 67
 
72 68
     }//end getWarningList()
Please login to merge, or discard this patch.
squizlabs/php_codesniffer/src/Standards/Squiz/Tests/PHP/HeredocUnitTest.inc 6 patches
Doc Comments   -6 removed lines patch added patch discarded remove patch
@@ -19,9 +19,3 @@
 block discarded – undo
19 19
         $arr = array(
20 20
             'a' => 'a'
21 21
 <<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
Please login to merge, or discard this patch.
Indentation   +3 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,13 +15,7 @@
 block discarded – undo
15 15
 // This is not a merge conflict - it is a valid test case.
16 16
 // Please do not remove.
17 17
 function test()
18
-    {
19
-        $arr = array(
20
-            'a' => 'a'
18
+	{
19
+		$arr = array(
20
+			'a' => 'a'
21 21
 <<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
Please login to merge, or discard this patch.
Switch Indentation   -6 removed lines patch added patch discarded remove patch
@@ -19,9 +19,3 @@
 block discarded – undo
19 19
         $arr = array(
20 20
             'a' => 'a'
21 21
 <<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -7 removed lines patch added patch discarded remove patch
@@ -18,10 +18,4 @@
 block discarded – undo
18 18
     {
19 19
         $arr = array(
20 20
             'a' => 'a'
21
-<<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
21
+<< << <<< HEAD
Please login to merge, or discard this patch.
Braces   +1 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,14 +14,7 @@
 block discarded – undo
14 14
 // The following function has a simulated git conflict for testing.
15 15
 // This is not a merge conflict - it is a valid test case.
16 16
 // Please do not remove.
17
-function test()
18
-    {
17
+function test() {
19 18
         $arr = array(
20 19
             'a' => 'a'
21 20
 <<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -8 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@  discard block
 block discarded – undo
3 3
 Example of string
4 4
 spanning multiple lines
5 5
 using heredoc syntax.
6
-EOD;
6
+eod;
7 7
 
8 8
 echo <<<'EOT'
9 9
 My name is "$name". I am printing some $foo->foo.
10 10
 Now, I am printing some {$foo->bar[1]}.
11 11
 This should not print a capital 'A': \x41
12
-EOT;
12
+eot;
13 13
 
14 14
 // The following function has a simulated git conflict for testing.
15 15
 // This is not a merge conflict - it is a valid test case.
@@ -19,9 +19,3 @@  discard block
 block discarded – undo
19 19
         $arr = array(
20 20
             'a' => 'a'
21 21
 <<<<<<< HEAD
22
-            'b' => 'b'
23
-=======
24
-            'c' => 'c'
25
->>>>>>> master
26
-        );
27
-    }
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Tokenizers/Tokenizer.php 5 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -78,6 +78,7 @@
 block discarded – undo
78 78
      * @param string                         $content The content to tokenize,
79 79
      * @param \PHP_CodeSniffer\Config | null $config  The config data for the run.
80 80
      * @param string                         $eolChar The EOL char used in the content.
81
+     * @param null|\PHP_CodeSniffer\Config $config
81 82
      *
82 83
      * @return void
83 84
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
Please login to merge, or discard this patch.
Indentation   +1620 added lines, -1620 removed lines patch added patch discarded remove patch
@@ -15,1632 +15,1632 @@
 block discarded – undo
15 15
 abstract class Tokenizer
16 16
 {
17 17
 
18
-    /**
19
-     * The config data for the run.
20
-     *
21
-     * @var \PHP_CodeSniffer\Config
22
-     */
23
-    protected $config = null;
24
-
25
-    /**
26
-     * The EOL char used in the content.
27
-     *
28
-     * @var string
29
-     */
30
-    protected $eolChar = [];
31
-
32
-    /**
33
-     * A token-based representation of the content.
34
-     *
35
-     * @var array
36
-     */
37
-    protected $tokens = [];
38
-
39
-    /**
40
-     * The number of tokens in the tokens array.
41
-     *
42
-     * @var integer
43
-     */
44
-    protected $numTokens = 0;
45
-
46
-    /**
47
-     * A list of tokens that are allowed to open a scope.
48
-     *
49
-     * @var array
50
-     */
51
-    public $scopeOpeners = [];
52
-
53
-    /**
54
-     * A list of tokens that end the scope.
55
-     *
56
-     * @var array
57
-     */
58
-    public $endScopeTokens = [];
59
-
60
-    /**
61
-     * Known lengths of tokens.
62
-     *
63
-     * @var array<int, int>
64
-     */
65
-    public $knownLengths = [];
66
-
67
-    /**
68
-     * A list of lines being ignored due to error suppression comments.
69
-     *
70
-     * @var array
71
-     */
72
-    public $ignoredLines = [];
73
-
74
-
75
-    /**
76
-     * Initialise and run the tokenizer.
77
-     *
78
-     * @param string                         $content The content to tokenize,
79
-     * @param \PHP_CodeSniffer\Config | null $config  The config data for the run.
80
-     * @param string                         $eolChar The EOL char used in the content.
81
-     *
82
-     * @return void
83
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
84
-     */
85
-    public function __construct($content, $config, $eolChar='\n')
86
-    {
87
-        $this->eolChar = $eolChar;
88
-
89
-        $this->config = $config;
90
-        $this->tokens = $this->tokenize($content);
91
-
92
-        if ($config === null) {
93
-            return;
94
-        }
95
-
96
-        $this->createPositionMap();
97
-        $this->createTokenMap();
98
-        $this->createParenthesisNestingMap();
99
-        $this->createScopeMap();
100
-        $this->createLevelMap();
101
-
102
-        // Allow the tokenizer to do additional processing if required.
103
-        $this->processAdditional();
104
-
105
-    }//end __construct()
106
-
107
-
108
-    /**
109
-     * Checks the content to see if it looks minified.
110
-     *
111
-     * @param string $content The content to tokenize.
112
-     * @param string $eolChar The EOL char used in the content.
113
-     *
114
-     * @return boolean
115
-     */
116
-    protected function isMinifiedContent($content, $eolChar='\n')
117
-    {
118
-        // Minified files often have a very large number of characters per line
119
-        // and cause issues when tokenizing.
120
-        $numChars = strlen($content);
121
-        $numLines = (substr_count($content, $eolChar) + 1);
122
-        $average  = ($numChars / $numLines);
123
-        if ($average > 100) {
124
-            return true;
125
-        }
126
-
127
-        return false;
128
-
129
-    }//end isMinifiedContent()
130
-
131
-
132
-    /**
133
-     * Gets the array of tokens.
134
-     *
135
-     * @return array
136
-     */
137
-    public function getTokens()
138
-    {
139
-        return $this->tokens;
140
-
141
-    }//end getTokens()
142
-
143
-
144
-    /**
145
-     * Creates an array of tokens when given some content.
146
-     *
147
-     * @param string $string The string to tokenize.
148
-     *
149
-     * @return array
150
-     */
151
-    abstract protected function tokenize($string);
152
-
153
-
154
-    /**
155
-     * Performs additional processing after main tokenizing.
156
-     *
157
-     * @return void
158
-     */
159
-    abstract protected function processAdditional();
160
-
161
-
162
-    /**
163
-     * Sets token position information.
164
-     *
165
-     * Can also convert tabs into spaces. Each tab can represent between
166
-     * 1 and $width spaces, so this cannot be a straight string replace.
167
-     *
168
-     * @return void
169
-     */
170
-    private function createPositionMap()
171
-    {
172
-        $currColumn = 1;
173
-        $lineNumber = 1;
174
-        $eolLen     = strlen($this->eolChar);
175
-        $ignoring   = null;
176
-        $inTests    = defined('PHP_CODESNIFFER_IN_TESTS');
177
-
178
-        $checkEncoding = false;
179
-        if (function_exists('iconv_strlen') === true) {
180
-            $checkEncoding = true;
181
-        }
182
-
183
-        $checkAnnotations = $this->config->annotations;
184
-        $encoding         = $this->config->encoding;
185
-        $tabWidth         = $this->config->tabWidth;
186
-
187
-        $tokensWithTabs = [
188
-            T_WHITESPACE               => true,
189
-            T_COMMENT                  => true,
190
-            T_DOC_COMMENT              => true,
191
-            T_DOC_COMMENT_WHITESPACE   => true,
192
-            T_DOC_COMMENT_STRING       => true,
193
-            T_CONSTANT_ENCAPSED_STRING => true,
194
-            T_DOUBLE_QUOTED_STRING     => true,
195
-            T_HEREDOC                  => true,
196
-            T_NOWDOC                   => true,
197
-            T_INLINE_HTML              => true,
198
-        ];
199
-
200
-        $this->numTokens = count($this->tokens);
201
-        for ($i = 0; $i < $this->numTokens; $i++) {
202
-            $this->tokens[$i]['line']   = $lineNumber;
203
-            $this->tokens[$i]['column'] = $currColumn;
204
-
205
-            if (isset($this->knownLengths[$this->tokens[$i]['code']]) === true) {
206
-                // There are no tabs in the tokens we know the length of.
207
-                $length      = $this->knownLengths[$this->tokens[$i]['code']];
208
-                $currColumn += $length;
209
-            } else if ($tabWidth === 0
210
-                || isset($tokensWithTabs[$this->tokens[$i]['code']]) === false
211
-                || strpos($this->tokens[$i]['content'], "\t") === false
212
-            ) {
213
-                // There are no tabs in this content, or we aren't replacing them.
214
-                if ($checkEncoding === true) {
215
-                    // Not using the default encoding, so take a bit more care.
216
-                    $oldLevel = error_reporting();
217
-                    error_reporting(0);
218
-                    $length = iconv_strlen($this->tokens[$i]['content'], $encoding);
219
-                    error_reporting($oldLevel);
220
-
221
-                    if ($length === false) {
222
-                        // String contained invalid characters, so revert to default.
223
-                        $length = strlen($this->tokens[$i]['content']);
224
-                    }
225
-                } else {
226
-                    $length = strlen($this->tokens[$i]['content']);
227
-                }
228
-
229
-                $currColumn += $length;
230
-            } else {
231
-                $this->replaceTabsInToken($this->tokens[$i]);
232
-                $length      = $this->tokens[$i]['length'];
233
-                $currColumn += $length;
234
-            }//end if
235
-
236
-            $this->tokens[$i]['length'] = $length;
237
-
238
-            if (isset($this->knownLengths[$this->tokens[$i]['code']]) === false
239
-                && strpos($this->tokens[$i]['content'], $this->eolChar) !== false
240
-            ) {
241
-                $lineNumber++;
242
-                $currColumn = 1;
243
-
244
-                // Newline chars are not counted in the token length.
245
-                $this->tokens[$i]['length'] -= $eolLen;
246
-            }
247
-
248
-            if ($this->tokens[$i]['code'] === T_COMMENT
249
-                || $this->tokens[$i]['code'] === T_DOC_COMMENT_STRING
250
-                || $this->tokens[$i]['code'] === T_DOC_COMMENT_TAG
251
-                || ($inTests === true && $this->tokens[$i]['code'] === T_INLINE_HTML)
252
-            ) {
253
-                $commentText      = ltrim($this->tokens[$i]['content'], " \t/*");
254
-                $commentText      = rtrim($commentText, " */\t\r\n");
255
-                $commentTextLower = strtolower($commentText);
256
-                if (strpos($commentText, '@codingStandards') !== false) {
257
-                    // If this comment is the only thing on the line, it tells us
258
-                    // to ignore the following line. If the line contains other content
259
-                    // then we are just ignoring this one single line.
260
-                    $ownLine = false;
261
-                    if ($i > 0) {
262
-                        for ($prev = ($i - 1); $prev >= 0; $prev--) {
263
-                            if ($this->tokens[$prev]['code'] === T_WHITESPACE) {
264
-                                continue;
265
-                            }
266
-
267
-                            break;
268
-                        }
269
-
270
-                        if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
271
-                            $ownLine = true;
272
-                        }
273
-                    }
274
-
275
-                    if ($ignoring === null
276
-                        && strpos($commentText, '@codingStandardsIgnoreStart') !== false
277
-                    ) {
278
-                        $ignoring = ['.all' => true];
279
-                        if ($ownLine === true) {
280
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
281
-                        }
282
-                    } else if ($ignoring !== null
283
-                        && strpos($commentText, '@codingStandardsIgnoreEnd') !== false
284
-                    ) {
285
-                        if ($ownLine === true) {
286
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
287
-                        } else {
288
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
289
-                        }
290
-
291
-                        $ignoring = null;
292
-                    } else if ($ignoring === null
293
-                        && strpos($commentText, '@codingStandardsIgnoreLine') !== false
294
-                    ) {
295
-                        $ignoring = ['.all' => true];
296
-                        if ($ownLine === true) {
297
-                            $this->ignoredLines[$this->tokens[$i]['line']]       = $ignoring;
298
-                            $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoring;
299
-                        } else {
300
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
301
-                        }
302
-
303
-                        $ignoring = null;
304
-                    }//end if
305
-                } else if (substr($commentTextLower, 0, 6) === 'phpcs:'
306
-                    || substr($commentTextLower, 0, 7) === '@phpcs:'
307
-                ) {
308
-                    // If the @phpcs: syntax is being used, strip the @ to make
309
-                    // comparisons easier.
310
-                    if ($commentText[0] === '@') {
311
-                        $commentText      = substr($commentText, 1);
312
-                        $commentTextLower = strtolower($commentText);
313
-                    }
314
-
315
-                    // If there is a comment on the end, strip it off.
316
-                    $commentStart = strpos($commentTextLower, ' --');
317
-                    if ($commentStart !== false) {
318
-                        $commentText      = substr($commentText, 0, $commentStart);
319
-                        $commentTextLower = strtolower($commentText);
320
-                    }
321
-
322
-                    // If this comment is the only thing on the line, it tells us
323
-                    // to ignore the following line. If the line contains other content
324
-                    // then we are just ignoring this one single line.
325
-                    $lineHasOtherContent = false;
326
-                    $lineHasOtherTokens  = false;
327
-                    if ($i > 0) {
328
-                        for ($prev = ($i - 1); $prev > 0; $prev--) {
329
-                            if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
330
-                                // Changed lines.
331
-                                break;
332
-                            }
333
-
334
-                            if ($this->tokens[$prev]['code'] === T_WHITESPACE
335
-                                || ($this->tokens[$prev]['code'] === T_INLINE_HTML
336
-                                && trim($this->tokens[$prev]['content']) === '')
337
-                            ) {
338
-                                continue;
339
-                            }
340
-
341
-                            $lineHasOtherTokens = true;
342
-
343
-                            if ($this->tokens[$prev]['code'] === T_OPEN_TAG) {
344
-                                continue;
345
-                            }
346
-
347
-                            $lineHasOtherContent = true;
348
-                            break;
349
-                        }//end for
350
-
351
-                        $changedLines = false;
352
-                        for ($next = $i; $next < $this->numTokens; $next++) {
353
-                            if ($changedLines === true) {
354
-                                // Changed lines.
355
-                                break;
356
-                            }
357
-
358
-                            if (isset($this->knownLengths[$this->tokens[$next]['code']]) === false
359
-                                && strpos($this->tokens[$next]['content'], $this->eolChar) !== false
360
-                            ) {
361
-                                // Last token on the current line.
362
-                                $changedLines = true;
363
-                            }
364
-
365
-                            if ($next === $i) {
366
-                                continue;
367
-                            }
368
-
369
-                            if ($this->tokens[$next]['code'] === T_WHITESPACE
370
-                                || ($this->tokens[$next]['code'] === T_INLINE_HTML
371
-                                && trim($this->tokens[$next]['content']) === '')
372
-                            ) {
373
-                                continue;
374
-                            }
375
-
376
-                            $lineHasOtherTokens = true;
377
-
378
-                            if ($this->tokens[$next]['code'] === T_CLOSE_TAG) {
379
-                                continue;
380
-                            }
381
-
382
-                            $lineHasOtherContent = true;
383
-                            break;
384
-                        }//end for
385
-                    }//end if
386
-
387
-                    if (substr($commentTextLower, 0, 9) === 'phpcs:set') {
388
-                        // Ignore standards for complete lines that change sniff settings.
389
-                        if ($lineHasOtherTokens === false) {
390
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
391
-                        }
392
-
393
-                        // Need to maintain case here, to get the correct sniff code.
394
-                        $parts = explode(' ', substr($commentText, 10));
395
-                        if (count($parts) >= 2) {
396
-                            $sniffParts = explode('.', $parts[0]);
397
-                            if (count($sniffParts) >= 3) {
398
-                                $this->tokens[$i]['sniffCode']          = array_shift($parts);
399
-                                $this->tokens[$i]['sniffProperty']      = array_shift($parts);
400
-                                $this->tokens[$i]['sniffPropertyValue'] = rtrim(implode(' ', $parts), " */\r\n");
401
-                            }
402
-                        }
403
-
404
-                        $this->tokens[$i]['code'] = T_PHPCS_SET;
405
-                        $this->tokens[$i]['type'] = 'T_PHPCS_SET';
406
-                    } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile') {
407
-                        // The whole file will be ignored, but at least set the correct token.
408
-                        $this->tokens[$i]['code'] = T_PHPCS_IGNORE_FILE;
409
-                        $this->tokens[$i]['type'] = 'T_PHPCS_IGNORE_FILE';
410
-                    } else if (substr($commentTextLower, 0, 13) === 'phpcs:disable') {
411
-                        if ($lineHasOtherContent === false) {
412
-                            // Completely ignore the comment line.
413
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
414
-                        }
415
-
416
-                        if ($ignoring === null) {
417
-                            $ignoring = [];
418
-                        }
419
-
420
-                        $disabledSniffs = [];
421
-
422
-                        $additionalText = substr($commentText, 14);
423
-                        if ($additionalText === false) {
424
-                            $ignoring = ['.all' => true];
425
-                        } else {
426
-                            $parts = explode(',', substr($commentText, 13));
427
-                            foreach ($parts as $sniffCode) {
428
-                                $sniffCode = trim($sniffCode);
429
-                                $disabledSniffs[$sniffCode] = true;
430
-                                $ignoring[$sniffCode]       = true;
431
-
432
-                                // This newly disabled sniff might be disabling an existing
433
-                                // enabled exception that we are tracking.
434
-                                if (isset($ignoring['.except']) === true) {
435
-                                    foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
436
-                                        if ($ignoredSniffCode === $sniffCode
437
-                                            || strpos($ignoredSniffCode, $sniffCode.'.') === 0
438
-                                        ) {
439
-                                            unset($ignoring['.except'][$ignoredSniffCode]);
440
-                                        }
441
-                                    }
442
-
443
-                                    if (empty($ignoring['.except']) === true) {
444
-                                        unset($ignoring['.except']);
445
-                                    }
446
-                                }
447
-                            }//end foreach
448
-                        }//end if
449
-
450
-                        $this->tokens[$i]['code']       = T_PHPCS_DISABLE;
451
-                        $this->tokens[$i]['type']       = 'T_PHPCS_DISABLE';
452
-                        $this->tokens[$i]['sniffCodes'] = $disabledSniffs;
453
-                    } else if (substr($commentTextLower, 0, 12) === 'phpcs:enable') {
454
-                        if ($ignoring !== null) {
455
-                            $enabledSniffs = [];
456
-
457
-                            $additionalText = substr($commentText, 13);
458
-                            if ($additionalText === false) {
459
-                                $ignoring = null;
460
-                            } else {
461
-                                $parts = explode(',', substr($commentText, 13));
462
-                                foreach ($parts as $sniffCode) {
463
-                                    $sniffCode = trim($sniffCode);
464
-                                    $enabledSniffs[$sniffCode] = true;
465
-
466
-                                    // This new enabled sniff might remove previously disabled
467
-                                    // sniffs if it is actually a standard or category of sniffs.
468
-                                    foreach (array_keys($ignoring) as $ignoredSniffCode) {
469
-                                        if ($ignoredSniffCode === $sniffCode
470
-                                            || strpos($ignoredSniffCode, $sniffCode.'.') === 0
471
-                                        ) {
472
-                                            unset($ignoring[$ignoredSniffCode]);
473
-                                        }
474
-                                    }
475
-
476
-                                    // This new enabled sniff might be able to clear up
477
-                                    // previously enabled sniffs if it is actually a standard or
478
-                                    // category of sniffs.
479
-                                    if (isset($ignoring['.except']) === true) {
480
-                                        foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
481
-                                            if ($ignoredSniffCode === $sniffCode
482
-                                                || strpos($ignoredSniffCode, $sniffCode.'.') === 0
483
-                                            ) {
484
-                                                unset($ignoring['.except'][$ignoredSniffCode]);
485
-                                            }
486
-                                        }
487
-                                    }
488
-                                }//end foreach
489
-
490
-                                if (empty($ignoring) === true) {
491
-                                    $ignoring = null;
492
-                                } else {
493
-                                    if (isset($ignoring['.except']) === true) {
494
-                                        $ignoring['.except'] += $enabledSniffs;
495
-                                    } else {
496
-                                        $ignoring['.except'] = $enabledSniffs;
497
-                                    }
498
-                                }
499
-                            }//end if
500
-
501
-                            if ($lineHasOtherContent === false) {
502
-                                // Completely ignore the comment line.
503
-                                $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
504
-                            } else {
505
-                                // The comment is on the same line as the code it is ignoring,
506
-                                // so respect the new ignore rules.
507
-                                $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
508
-                            }
509
-
510
-                            $this->tokens[$i]['sniffCodes'] = $enabledSniffs;
511
-                        }//end if
512
-
513
-                        $this->tokens[$i]['code'] = T_PHPCS_ENABLE;
514
-                        $this->tokens[$i]['type'] = 'T_PHPCS_ENABLE';
515
-                    } else if (substr($commentTextLower, 0, 12) === 'phpcs:ignore') {
516
-                        $ignoreRules = [];
517
-
518
-                        $additionalText = substr($commentText, 13);
519
-                        if ($additionalText === false) {
520
-                            $ignoreRules = ['.all' => true];
521
-                        } else {
522
-                            $parts = explode(',', substr($commentText, 13));
523
-                            foreach ($parts as $sniffCode) {
524
-                                $ignoreRules[trim($sniffCode)] = true;
525
-                            }
526
-                        }
527
-
528
-                        $this->tokens[$i]['code']       = T_PHPCS_IGNORE;
529
-                        $this->tokens[$i]['type']       = 'T_PHPCS_IGNORE';
530
-                        $this->tokens[$i]['sniffCodes'] = $ignoreRules;
531
-
532
-                        if ($ignoring !== null) {
533
-                            $ignoreRules += $ignoring;
534
-                        }
535
-
536
-                        if ($lineHasOtherContent === false) {
537
-                            // Completely ignore the comment line, and set the following
538
-                            // line to include the ignore rules we've set.
539
-                            $this->ignoredLines[$this->tokens[$i]['line']]       = ['.all' => true];
540
-                            $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoreRules;
541
-                        } else {
542
-                            // The comment is on the same line as the code it is ignoring,
543
-                            // so respect the ignore rules it set.
544
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoreRules;
545
-                        }
546
-                    }//end if
547
-                }//end if
548
-            }//end if
549
-
550
-            if ($ignoring !== null && isset($this->ignoredLines[$this->tokens[$i]['line']]) === false) {
551
-                $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
552
-            }
553
-        }//end for
554
-
555
-        // If annotations are being ignored, we clear out all the ignore rules
556
-        // but leave the annotations tokenized as normal.
557
-        if ($checkAnnotations === false) {
558
-            $this->ignoredLines = [];
559
-        }
560
-
561
-    }//end createPositionMap()
562
-
563
-
564
-    /**
565
-     * Replaces tabs in original token content with spaces.
566
-     *
567
-     * Each tab can represent between 1 and $config->tabWidth spaces,
568
-     * so this cannot be a straight string replace. The original content
569
-     * is placed into an orig_content index and the new token length is also
570
-     * set in the length index.
571
-     *
572
-     * @param array  $token    The token to replace tabs inside.
573
-     * @param string $prefix   The character to use to represent the start of a tab.
574
-     * @param string $padding  The character to use to represent the end of a tab.
575
-     * @param int    $tabWidth The number of spaces each tab represents.
576
-     *
577
-     * @return void
578
-     */
579
-    public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null)
580
-    {
581
-        $checkEncoding = false;
582
-        if (function_exists('iconv_strlen') === true) {
583
-            $checkEncoding = true;
584
-        }
585
-
586
-        $currColumn = $token['column'];
587
-        if ($tabWidth === null) {
588
-            $tabWidth = $this->config->tabWidth;
589
-            if ($tabWidth === 0) {
590
-                $tabWidth = 1;
591
-            }
592
-        }
593
-
594
-        if (rtrim($token['content'], "\t") === '') {
595
-            // String only contains tabs, so we can shortcut the process.
596
-            $numTabs = strlen($token['content']);
597
-
598
-            $firstTabSize = ($tabWidth - (($currColumn - 1) % $tabWidth));
599
-            $length       = ($firstTabSize + ($tabWidth * ($numTabs - 1)));
600
-            $newContent   = $prefix.str_repeat($padding, ($length - 1));
601
-        } else {
602
-            // We need to determine the length of each tab.
603
-            $tabs = explode("\t", $token['content']);
604
-
605
-            $numTabs    = (count($tabs) - 1);
606
-            $tabNum     = 0;
607
-            $newContent = '';
608
-            $length     = 0;
609
-
610
-            foreach ($tabs as $content) {
611
-                if ($content !== '') {
612
-                    $newContent .= $content;
613
-                    if ($checkEncoding === true) {
614
-                        // Not using the default encoding, so take a bit more care.
615
-                        $oldLevel = error_reporting();
616
-                        error_reporting(0);
617
-                        $contentLength = iconv_strlen($content, $this->config->encoding);
618
-                        error_reporting($oldLevel);
619
-                        if ($contentLength === false) {
620
-                            // String contained invalid characters, so revert to default.
621
-                            $contentLength = strlen($content);
622
-                        }
623
-                    } else {
624
-                        $contentLength = strlen($content);
625
-                    }
626
-
627
-                    $currColumn += $contentLength;
628
-                    $length     += $contentLength;
629
-                }
630
-
631
-                // The last piece of content does not have a tab after it.
632
-                if ($tabNum === $numTabs) {
633
-                    break;
634
-                }
635
-
636
-                // Process the tab that comes after the content.
637
-                $lastCurrColumn = $currColumn;
638
-                $tabNum++;
639
-
640
-                // Move the pointer to the next tab stop.
641
-                if (($currColumn % $tabWidth) === 0) {
642
-                    // This is the first tab, and we are already at a
643
-                    // tab stop, so this tab counts as a single space.
644
-                    $currColumn++;
645
-                } else {
646
-                    $currColumn++;
647
-                    while (($currColumn % $tabWidth) !== 0) {
648
-                        $currColumn++;
649
-                    }
650
-
651
-                    $currColumn++;
652
-                }
653
-
654
-                $length     += ($currColumn - $lastCurrColumn);
655
-                $newContent .= $prefix.str_repeat($padding, ($currColumn - $lastCurrColumn - 1));
656
-            }//end foreach
657
-        }//end if
658
-
659
-        $token['orig_content'] = $token['content'];
660
-        $token['content']      = $newContent;
661
-        $token['length']       = $length;
662
-
663
-    }//end replaceTabsInToken()
664
-
665
-
666
-    /**
667
-     * Creates a map of brackets positions.
668
-     *
669
-     * @return void
670
-     */
671
-    private function createTokenMap()
672
-    {
673
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
674
-            echo "\t*** START TOKEN MAP ***".PHP_EOL;
675
-        }
676
-
677
-        $squareOpeners   = [];
678
-        $curlyOpeners    = [];
679
-        $this->numTokens = count($this->tokens);
680
-
681
-        $openers   = [];
682
-        $openOwner = null;
683
-
684
-        for ($i = 0; $i < $this->numTokens; $i++) {
685
-            /*
18
+	/**
19
+	 * The config data for the run.
20
+	 *
21
+	 * @var \PHP_CodeSniffer\Config
22
+	 */
23
+	protected $config = null;
24
+
25
+	/**
26
+	 * The EOL char used in the content.
27
+	 *
28
+	 * @var string
29
+	 */
30
+	protected $eolChar = [];
31
+
32
+	/**
33
+	 * A token-based representation of the content.
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $tokens = [];
38
+
39
+	/**
40
+	 * The number of tokens in the tokens array.
41
+	 *
42
+	 * @var integer
43
+	 */
44
+	protected $numTokens = 0;
45
+
46
+	/**
47
+	 * A list of tokens that are allowed to open a scope.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	public $scopeOpeners = [];
52
+
53
+	/**
54
+	 * A list of tokens that end the scope.
55
+	 *
56
+	 * @var array
57
+	 */
58
+	public $endScopeTokens = [];
59
+
60
+	/**
61
+	 * Known lengths of tokens.
62
+	 *
63
+	 * @var array<int, int>
64
+	 */
65
+	public $knownLengths = [];
66
+
67
+	/**
68
+	 * A list of lines being ignored due to error suppression comments.
69
+	 *
70
+	 * @var array
71
+	 */
72
+	public $ignoredLines = [];
73
+
74
+
75
+	/**
76
+	 * Initialise and run the tokenizer.
77
+	 *
78
+	 * @param string                         $content The content to tokenize,
79
+	 * @param \PHP_CodeSniffer\Config | null $config  The config data for the run.
80
+	 * @param string                         $eolChar The EOL char used in the content.
81
+	 *
82
+	 * @return void
83
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
84
+	 */
85
+	public function __construct($content, $config, $eolChar='\n')
86
+	{
87
+		$this->eolChar = $eolChar;
88
+
89
+		$this->config = $config;
90
+		$this->tokens = $this->tokenize($content);
91
+
92
+		if ($config === null) {
93
+			return;
94
+		}
95
+
96
+		$this->createPositionMap();
97
+		$this->createTokenMap();
98
+		$this->createParenthesisNestingMap();
99
+		$this->createScopeMap();
100
+		$this->createLevelMap();
101
+
102
+		// Allow the tokenizer to do additional processing if required.
103
+		$this->processAdditional();
104
+
105
+	}//end __construct()
106
+
107
+
108
+	/**
109
+	 * Checks the content to see if it looks minified.
110
+	 *
111
+	 * @param string $content The content to tokenize.
112
+	 * @param string $eolChar The EOL char used in the content.
113
+	 *
114
+	 * @return boolean
115
+	 */
116
+	protected function isMinifiedContent($content, $eolChar='\n')
117
+	{
118
+		// Minified files often have a very large number of characters per line
119
+		// and cause issues when tokenizing.
120
+		$numChars = strlen($content);
121
+		$numLines = (substr_count($content, $eolChar) + 1);
122
+		$average  = ($numChars / $numLines);
123
+		if ($average > 100) {
124
+			return true;
125
+		}
126
+
127
+		return false;
128
+
129
+	}//end isMinifiedContent()
130
+
131
+
132
+	/**
133
+	 * Gets the array of tokens.
134
+	 *
135
+	 * @return array
136
+	 */
137
+	public function getTokens()
138
+	{
139
+		return $this->tokens;
140
+
141
+	}//end getTokens()
142
+
143
+
144
+	/**
145
+	 * Creates an array of tokens when given some content.
146
+	 *
147
+	 * @param string $string The string to tokenize.
148
+	 *
149
+	 * @return array
150
+	 */
151
+	abstract protected function tokenize($string);
152
+
153
+
154
+	/**
155
+	 * Performs additional processing after main tokenizing.
156
+	 *
157
+	 * @return void
158
+	 */
159
+	abstract protected function processAdditional();
160
+
161
+
162
+	/**
163
+	 * Sets token position information.
164
+	 *
165
+	 * Can also convert tabs into spaces. Each tab can represent between
166
+	 * 1 and $width spaces, so this cannot be a straight string replace.
167
+	 *
168
+	 * @return void
169
+	 */
170
+	private function createPositionMap()
171
+	{
172
+		$currColumn = 1;
173
+		$lineNumber = 1;
174
+		$eolLen     = strlen($this->eolChar);
175
+		$ignoring   = null;
176
+		$inTests    = defined('PHP_CODESNIFFER_IN_TESTS');
177
+
178
+		$checkEncoding = false;
179
+		if (function_exists('iconv_strlen') === true) {
180
+			$checkEncoding = true;
181
+		}
182
+
183
+		$checkAnnotations = $this->config->annotations;
184
+		$encoding         = $this->config->encoding;
185
+		$tabWidth         = $this->config->tabWidth;
186
+
187
+		$tokensWithTabs = [
188
+			T_WHITESPACE               => true,
189
+			T_COMMENT                  => true,
190
+			T_DOC_COMMENT              => true,
191
+			T_DOC_COMMENT_WHITESPACE   => true,
192
+			T_DOC_COMMENT_STRING       => true,
193
+			T_CONSTANT_ENCAPSED_STRING => true,
194
+			T_DOUBLE_QUOTED_STRING     => true,
195
+			T_HEREDOC                  => true,
196
+			T_NOWDOC                   => true,
197
+			T_INLINE_HTML              => true,
198
+		];
199
+
200
+		$this->numTokens = count($this->tokens);
201
+		for ($i = 0; $i < $this->numTokens; $i++) {
202
+			$this->tokens[$i]['line']   = $lineNumber;
203
+			$this->tokens[$i]['column'] = $currColumn;
204
+
205
+			if (isset($this->knownLengths[$this->tokens[$i]['code']]) === true) {
206
+				// There are no tabs in the tokens we know the length of.
207
+				$length      = $this->knownLengths[$this->tokens[$i]['code']];
208
+				$currColumn += $length;
209
+			} else if ($tabWidth === 0
210
+				|| isset($tokensWithTabs[$this->tokens[$i]['code']]) === false
211
+				|| strpos($this->tokens[$i]['content'], "\t") === false
212
+			) {
213
+				// There are no tabs in this content, or we aren't replacing them.
214
+				if ($checkEncoding === true) {
215
+					// Not using the default encoding, so take a bit more care.
216
+					$oldLevel = error_reporting();
217
+					error_reporting(0);
218
+					$length = iconv_strlen($this->tokens[$i]['content'], $encoding);
219
+					error_reporting($oldLevel);
220
+
221
+					if ($length === false) {
222
+						// String contained invalid characters, so revert to default.
223
+						$length = strlen($this->tokens[$i]['content']);
224
+					}
225
+				} else {
226
+					$length = strlen($this->tokens[$i]['content']);
227
+				}
228
+
229
+				$currColumn += $length;
230
+			} else {
231
+				$this->replaceTabsInToken($this->tokens[$i]);
232
+				$length      = $this->tokens[$i]['length'];
233
+				$currColumn += $length;
234
+			}//end if
235
+
236
+			$this->tokens[$i]['length'] = $length;
237
+
238
+			if (isset($this->knownLengths[$this->tokens[$i]['code']]) === false
239
+				&& strpos($this->tokens[$i]['content'], $this->eolChar) !== false
240
+			) {
241
+				$lineNumber++;
242
+				$currColumn = 1;
243
+
244
+				// Newline chars are not counted in the token length.
245
+				$this->tokens[$i]['length'] -= $eolLen;
246
+			}
247
+
248
+			if ($this->tokens[$i]['code'] === T_COMMENT
249
+				|| $this->tokens[$i]['code'] === T_DOC_COMMENT_STRING
250
+				|| $this->tokens[$i]['code'] === T_DOC_COMMENT_TAG
251
+				|| ($inTests === true && $this->tokens[$i]['code'] === T_INLINE_HTML)
252
+			) {
253
+				$commentText      = ltrim($this->tokens[$i]['content'], " \t/*");
254
+				$commentText      = rtrim($commentText, " */\t\r\n");
255
+				$commentTextLower = strtolower($commentText);
256
+				if (strpos($commentText, '@codingStandards') !== false) {
257
+					// If this comment is the only thing on the line, it tells us
258
+					// to ignore the following line. If the line contains other content
259
+					// then we are just ignoring this one single line.
260
+					$ownLine = false;
261
+					if ($i > 0) {
262
+						for ($prev = ($i - 1); $prev >= 0; $prev--) {
263
+							if ($this->tokens[$prev]['code'] === T_WHITESPACE) {
264
+								continue;
265
+							}
266
+
267
+							break;
268
+						}
269
+
270
+						if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
271
+							$ownLine = true;
272
+						}
273
+					}
274
+
275
+					if ($ignoring === null
276
+						&& strpos($commentText, '@codingStandardsIgnoreStart') !== false
277
+					) {
278
+						$ignoring = ['.all' => true];
279
+						if ($ownLine === true) {
280
+							$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
281
+						}
282
+					} else if ($ignoring !== null
283
+						&& strpos($commentText, '@codingStandardsIgnoreEnd') !== false
284
+					) {
285
+						if ($ownLine === true) {
286
+							$this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
287
+						} else {
288
+							$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
289
+						}
290
+
291
+						$ignoring = null;
292
+					} else if ($ignoring === null
293
+						&& strpos($commentText, '@codingStandardsIgnoreLine') !== false
294
+					) {
295
+						$ignoring = ['.all' => true];
296
+						if ($ownLine === true) {
297
+							$this->ignoredLines[$this->tokens[$i]['line']]       = $ignoring;
298
+							$this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoring;
299
+						} else {
300
+							$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
301
+						}
302
+
303
+						$ignoring = null;
304
+					}//end if
305
+				} else if (substr($commentTextLower, 0, 6) === 'phpcs:'
306
+					|| substr($commentTextLower, 0, 7) === '@phpcs:'
307
+				) {
308
+					// If the @phpcs: syntax is being used, strip the @ to make
309
+					// comparisons easier.
310
+					if ($commentText[0] === '@') {
311
+						$commentText      = substr($commentText, 1);
312
+						$commentTextLower = strtolower($commentText);
313
+					}
314
+
315
+					// If there is a comment on the end, strip it off.
316
+					$commentStart = strpos($commentTextLower, ' --');
317
+					if ($commentStart !== false) {
318
+						$commentText      = substr($commentText, 0, $commentStart);
319
+						$commentTextLower = strtolower($commentText);
320
+					}
321
+
322
+					// If this comment is the only thing on the line, it tells us
323
+					// to ignore the following line. If the line contains other content
324
+					// then we are just ignoring this one single line.
325
+					$lineHasOtherContent = false;
326
+					$lineHasOtherTokens  = false;
327
+					if ($i > 0) {
328
+						for ($prev = ($i - 1); $prev > 0; $prev--) {
329
+							if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
330
+								// Changed lines.
331
+								break;
332
+							}
333
+
334
+							if ($this->tokens[$prev]['code'] === T_WHITESPACE
335
+								|| ($this->tokens[$prev]['code'] === T_INLINE_HTML
336
+								&& trim($this->tokens[$prev]['content']) === '')
337
+							) {
338
+								continue;
339
+							}
340
+
341
+							$lineHasOtherTokens = true;
342
+
343
+							if ($this->tokens[$prev]['code'] === T_OPEN_TAG) {
344
+								continue;
345
+							}
346
+
347
+							$lineHasOtherContent = true;
348
+							break;
349
+						}//end for
350
+
351
+						$changedLines = false;
352
+						for ($next = $i; $next < $this->numTokens; $next++) {
353
+							if ($changedLines === true) {
354
+								// Changed lines.
355
+								break;
356
+							}
357
+
358
+							if (isset($this->knownLengths[$this->tokens[$next]['code']]) === false
359
+								&& strpos($this->tokens[$next]['content'], $this->eolChar) !== false
360
+							) {
361
+								// Last token on the current line.
362
+								$changedLines = true;
363
+							}
364
+
365
+							if ($next === $i) {
366
+								continue;
367
+							}
368
+
369
+							if ($this->tokens[$next]['code'] === T_WHITESPACE
370
+								|| ($this->tokens[$next]['code'] === T_INLINE_HTML
371
+								&& trim($this->tokens[$next]['content']) === '')
372
+							) {
373
+								continue;
374
+							}
375
+
376
+							$lineHasOtherTokens = true;
377
+
378
+							if ($this->tokens[$next]['code'] === T_CLOSE_TAG) {
379
+								continue;
380
+							}
381
+
382
+							$lineHasOtherContent = true;
383
+							break;
384
+						}//end for
385
+					}//end if
386
+
387
+					if (substr($commentTextLower, 0, 9) === 'phpcs:set') {
388
+						// Ignore standards for complete lines that change sniff settings.
389
+						if ($lineHasOtherTokens === false) {
390
+							$this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
391
+						}
392
+
393
+						// Need to maintain case here, to get the correct sniff code.
394
+						$parts = explode(' ', substr($commentText, 10));
395
+						if (count($parts) >= 2) {
396
+							$sniffParts = explode('.', $parts[0]);
397
+							if (count($sniffParts) >= 3) {
398
+								$this->tokens[$i]['sniffCode']          = array_shift($parts);
399
+								$this->tokens[$i]['sniffProperty']      = array_shift($parts);
400
+								$this->tokens[$i]['sniffPropertyValue'] = rtrim(implode(' ', $parts), " */\r\n");
401
+							}
402
+						}
403
+
404
+						$this->tokens[$i]['code'] = T_PHPCS_SET;
405
+						$this->tokens[$i]['type'] = 'T_PHPCS_SET';
406
+					} else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile') {
407
+						// The whole file will be ignored, but at least set the correct token.
408
+						$this->tokens[$i]['code'] = T_PHPCS_IGNORE_FILE;
409
+						$this->tokens[$i]['type'] = 'T_PHPCS_IGNORE_FILE';
410
+					} else if (substr($commentTextLower, 0, 13) === 'phpcs:disable') {
411
+						if ($lineHasOtherContent === false) {
412
+							// Completely ignore the comment line.
413
+							$this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
414
+						}
415
+
416
+						if ($ignoring === null) {
417
+							$ignoring = [];
418
+						}
419
+
420
+						$disabledSniffs = [];
421
+
422
+						$additionalText = substr($commentText, 14);
423
+						if ($additionalText === false) {
424
+							$ignoring = ['.all' => true];
425
+						} else {
426
+							$parts = explode(',', substr($commentText, 13));
427
+							foreach ($parts as $sniffCode) {
428
+								$sniffCode = trim($sniffCode);
429
+								$disabledSniffs[$sniffCode] = true;
430
+								$ignoring[$sniffCode]       = true;
431
+
432
+								// This newly disabled sniff might be disabling an existing
433
+								// enabled exception that we are tracking.
434
+								if (isset($ignoring['.except']) === true) {
435
+									foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
436
+										if ($ignoredSniffCode === $sniffCode
437
+											|| strpos($ignoredSniffCode, $sniffCode.'.') === 0
438
+										) {
439
+											unset($ignoring['.except'][$ignoredSniffCode]);
440
+										}
441
+									}
442
+
443
+									if (empty($ignoring['.except']) === true) {
444
+										unset($ignoring['.except']);
445
+									}
446
+								}
447
+							}//end foreach
448
+						}//end if
449
+
450
+						$this->tokens[$i]['code']       = T_PHPCS_DISABLE;
451
+						$this->tokens[$i]['type']       = 'T_PHPCS_DISABLE';
452
+						$this->tokens[$i]['sniffCodes'] = $disabledSniffs;
453
+					} else if (substr($commentTextLower, 0, 12) === 'phpcs:enable') {
454
+						if ($ignoring !== null) {
455
+							$enabledSniffs = [];
456
+
457
+							$additionalText = substr($commentText, 13);
458
+							if ($additionalText === false) {
459
+								$ignoring = null;
460
+							} else {
461
+								$parts = explode(',', substr($commentText, 13));
462
+								foreach ($parts as $sniffCode) {
463
+									$sniffCode = trim($sniffCode);
464
+									$enabledSniffs[$sniffCode] = true;
465
+
466
+									// This new enabled sniff might remove previously disabled
467
+									// sniffs if it is actually a standard or category of sniffs.
468
+									foreach (array_keys($ignoring) as $ignoredSniffCode) {
469
+										if ($ignoredSniffCode === $sniffCode
470
+											|| strpos($ignoredSniffCode, $sniffCode.'.') === 0
471
+										) {
472
+											unset($ignoring[$ignoredSniffCode]);
473
+										}
474
+									}
475
+
476
+									// This new enabled sniff might be able to clear up
477
+									// previously enabled sniffs if it is actually a standard or
478
+									// category of sniffs.
479
+									if (isset($ignoring['.except']) === true) {
480
+										foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
481
+											if ($ignoredSniffCode === $sniffCode
482
+												|| strpos($ignoredSniffCode, $sniffCode.'.') === 0
483
+											) {
484
+												unset($ignoring['.except'][$ignoredSniffCode]);
485
+											}
486
+										}
487
+									}
488
+								}//end foreach
489
+
490
+								if (empty($ignoring) === true) {
491
+									$ignoring = null;
492
+								} else {
493
+									if (isset($ignoring['.except']) === true) {
494
+										$ignoring['.except'] += $enabledSniffs;
495
+									} else {
496
+										$ignoring['.except'] = $enabledSniffs;
497
+									}
498
+								}
499
+							}//end if
500
+
501
+							if ($lineHasOtherContent === false) {
502
+								// Completely ignore the comment line.
503
+								$this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
504
+							} else {
505
+								// The comment is on the same line as the code it is ignoring,
506
+								// so respect the new ignore rules.
507
+								$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
508
+							}
509
+
510
+							$this->tokens[$i]['sniffCodes'] = $enabledSniffs;
511
+						}//end if
512
+
513
+						$this->tokens[$i]['code'] = T_PHPCS_ENABLE;
514
+						$this->tokens[$i]['type'] = 'T_PHPCS_ENABLE';
515
+					} else if (substr($commentTextLower, 0, 12) === 'phpcs:ignore') {
516
+						$ignoreRules = [];
517
+
518
+						$additionalText = substr($commentText, 13);
519
+						if ($additionalText === false) {
520
+							$ignoreRules = ['.all' => true];
521
+						} else {
522
+							$parts = explode(',', substr($commentText, 13));
523
+							foreach ($parts as $sniffCode) {
524
+								$ignoreRules[trim($sniffCode)] = true;
525
+							}
526
+						}
527
+
528
+						$this->tokens[$i]['code']       = T_PHPCS_IGNORE;
529
+						$this->tokens[$i]['type']       = 'T_PHPCS_IGNORE';
530
+						$this->tokens[$i]['sniffCodes'] = $ignoreRules;
531
+
532
+						if ($ignoring !== null) {
533
+							$ignoreRules += $ignoring;
534
+						}
535
+
536
+						if ($lineHasOtherContent === false) {
537
+							// Completely ignore the comment line, and set the following
538
+							// line to include the ignore rules we've set.
539
+							$this->ignoredLines[$this->tokens[$i]['line']]       = ['.all' => true];
540
+							$this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoreRules;
541
+						} else {
542
+							// The comment is on the same line as the code it is ignoring,
543
+							// so respect the ignore rules it set.
544
+							$this->ignoredLines[$this->tokens[$i]['line']] = $ignoreRules;
545
+						}
546
+					}//end if
547
+				}//end if
548
+			}//end if
549
+
550
+			if ($ignoring !== null && isset($this->ignoredLines[$this->tokens[$i]['line']]) === false) {
551
+				$this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
552
+			}
553
+		}//end for
554
+
555
+		// If annotations are being ignored, we clear out all the ignore rules
556
+		// but leave the annotations tokenized as normal.
557
+		if ($checkAnnotations === false) {
558
+			$this->ignoredLines = [];
559
+		}
560
+
561
+	}//end createPositionMap()
562
+
563
+
564
+	/**
565
+	 * Replaces tabs in original token content with spaces.
566
+	 *
567
+	 * Each tab can represent between 1 and $config->tabWidth spaces,
568
+	 * so this cannot be a straight string replace. The original content
569
+	 * is placed into an orig_content index and the new token length is also
570
+	 * set in the length index.
571
+	 *
572
+	 * @param array  $token    The token to replace tabs inside.
573
+	 * @param string $prefix   The character to use to represent the start of a tab.
574
+	 * @param string $padding  The character to use to represent the end of a tab.
575
+	 * @param int    $tabWidth The number of spaces each tab represents.
576
+	 *
577
+	 * @return void
578
+	 */
579
+	public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null)
580
+	{
581
+		$checkEncoding = false;
582
+		if (function_exists('iconv_strlen') === true) {
583
+			$checkEncoding = true;
584
+		}
585
+
586
+		$currColumn = $token['column'];
587
+		if ($tabWidth === null) {
588
+			$tabWidth = $this->config->tabWidth;
589
+			if ($tabWidth === 0) {
590
+				$tabWidth = 1;
591
+			}
592
+		}
593
+
594
+		if (rtrim($token['content'], "\t") === '') {
595
+			// String only contains tabs, so we can shortcut the process.
596
+			$numTabs = strlen($token['content']);
597
+
598
+			$firstTabSize = ($tabWidth - (($currColumn - 1) % $tabWidth));
599
+			$length       = ($firstTabSize + ($tabWidth * ($numTabs - 1)));
600
+			$newContent   = $prefix.str_repeat($padding, ($length - 1));
601
+		} else {
602
+			// We need to determine the length of each tab.
603
+			$tabs = explode("\t", $token['content']);
604
+
605
+			$numTabs    = (count($tabs) - 1);
606
+			$tabNum     = 0;
607
+			$newContent = '';
608
+			$length     = 0;
609
+
610
+			foreach ($tabs as $content) {
611
+				if ($content !== '') {
612
+					$newContent .= $content;
613
+					if ($checkEncoding === true) {
614
+						// Not using the default encoding, so take a bit more care.
615
+						$oldLevel = error_reporting();
616
+						error_reporting(0);
617
+						$contentLength = iconv_strlen($content, $this->config->encoding);
618
+						error_reporting($oldLevel);
619
+						if ($contentLength === false) {
620
+							// String contained invalid characters, so revert to default.
621
+							$contentLength = strlen($content);
622
+						}
623
+					} else {
624
+						$contentLength = strlen($content);
625
+					}
626
+
627
+					$currColumn += $contentLength;
628
+					$length     += $contentLength;
629
+				}
630
+
631
+				// The last piece of content does not have a tab after it.
632
+				if ($tabNum === $numTabs) {
633
+					break;
634
+				}
635
+
636
+				// Process the tab that comes after the content.
637
+				$lastCurrColumn = $currColumn;
638
+				$tabNum++;
639
+
640
+				// Move the pointer to the next tab stop.
641
+				if (($currColumn % $tabWidth) === 0) {
642
+					// This is the first tab, and we are already at a
643
+					// tab stop, so this tab counts as a single space.
644
+					$currColumn++;
645
+				} else {
646
+					$currColumn++;
647
+					while (($currColumn % $tabWidth) !== 0) {
648
+						$currColumn++;
649
+					}
650
+
651
+					$currColumn++;
652
+				}
653
+
654
+				$length     += ($currColumn - $lastCurrColumn);
655
+				$newContent .= $prefix.str_repeat($padding, ($currColumn - $lastCurrColumn - 1));
656
+			}//end foreach
657
+		}//end if
658
+
659
+		$token['orig_content'] = $token['content'];
660
+		$token['content']      = $newContent;
661
+		$token['length']       = $length;
662
+
663
+	}//end replaceTabsInToken()
664
+
665
+
666
+	/**
667
+	 * Creates a map of brackets positions.
668
+	 *
669
+	 * @return void
670
+	 */
671
+	private function createTokenMap()
672
+	{
673
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
674
+			echo "\t*** START TOKEN MAP ***".PHP_EOL;
675
+		}
676
+
677
+		$squareOpeners   = [];
678
+		$curlyOpeners    = [];
679
+		$this->numTokens = count($this->tokens);
680
+
681
+		$openers   = [];
682
+		$openOwner = null;
683
+
684
+		for ($i = 0; $i < $this->numTokens; $i++) {
685
+			/*
686 686
                 Parenthesis mapping.
687 687
             */
688 688
 
689
-            if (isset(Util\Tokens::$parenthesisOpeners[$this->tokens[$i]['code']]) === true) {
690
-                $this->tokens[$i]['parenthesis_opener'] = null;
691
-                $this->tokens[$i]['parenthesis_closer'] = null;
692
-                $this->tokens[$i]['parenthesis_owner']  = $i;
693
-                $openOwner = $i;
694
-            } else if ($this->tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
695
-                $openers[] = $i;
696
-                $this->tokens[$i]['parenthesis_opener'] = $i;
697
-                if ($openOwner !== null) {
698
-                    $this->tokens[$openOwner]['parenthesis_opener'] = $i;
699
-                    $this->tokens[$i]['parenthesis_owner']          = $openOwner;
700
-                    $openOwner = null;
701
-                }
702
-            } else if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
703
-                // Did we set an owner for this set of parenthesis?
704
-                $numOpeners = count($openers);
705
-                if ($numOpeners !== 0) {
706
-                    $opener = array_pop($openers);
707
-                    if (isset($this->tokens[$opener]['parenthesis_owner']) === true) {
708
-                        $owner = $this->tokens[$opener]['parenthesis_owner'];
709
-
710
-                        $this->tokens[$owner]['parenthesis_closer'] = $i;
711
-                        $this->tokens[$i]['parenthesis_owner']      = $owner;
712
-                    }
713
-
714
-                    $this->tokens[$i]['parenthesis_opener']      = $opener;
715
-                    $this->tokens[$i]['parenthesis_closer']      = $i;
716
-                    $this->tokens[$opener]['parenthesis_closer'] = $i;
717
-                }
718
-            }//end if
719
-
720
-            /*
689
+			if (isset(Util\Tokens::$parenthesisOpeners[$this->tokens[$i]['code']]) === true) {
690
+				$this->tokens[$i]['parenthesis_opener'] = null;
691
+				$this->tokens[$i]['parenthesis_closer'] = null;
692
+				$this->tokens[$i]['parenthesis_owner']  = $i;
693
+				$openOwner = $i;
694
+			} else if ($this->tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
695
+				$openers[] = $i;
696
+				$this->tokens[$i]['parenthesis_opener'] = $i;
697
+				if ($openOwner !== null) {
698
+					$this->tokens[$openOwner]['parenthesis_opener'] = $i;
699
+					$this->tokens[$i]['parenthesis_owner']          = $openOwner;
700
+					$openOwner = null;
701
+				}
702
+			} else if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
703
+				// Did we set an owner for this set of parenthesis?
704
+				$numOpeners = count($openers);
705
+				if ($numOpeners !== 0) {
706
+					$opener = array_pop($openers);
707
+					if (isset($this->tokens[$opener]['parenthesis_owner']) === true) {
708
+						$owner = $this->tokens[$opener]['parenthesis_owner'];
709
+
710
+						$this->tokens[$owner]['parenthesis_closer'] = $i;
711
+						$this->tokens[$i]['parenthesis_owner']      = $owner;
712
+					}
713
+
714
+					$this->tokens[$i]['parenthesis_opener']      = $opener;
715
+					$this->tokens[$i]['parenthesis_closer']      = $i;
716
+					$this->tokens[$opener]['parenthesis_closer'] = $i;
717
+				}
718
+			}//end if
719
+
720
+			/*
721 721
                 Bracket mapping.
722 722
             */
723 723
 
724
-            switch ($this->tokens[$i]['code']) {
725
-            case T_OPEN_SQUARE_BRACKET:
726
-                $squareOpeners[] = $i;
727
-
728
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
729
-                    echo str_repeat("\t", count($squareOpeners));
730
-                    echo str_repeat("\t", count($curlyOpeners));
731
-                    echo "=> Found square bracket opener at $i".PHP_EOL;
732
-                }
733
-                break;
734
-            case T_OPEN_CURLY_BRACKET:
735
-                if (isset($this->tokens[$i]['scope_closer']) === false) {
736
-                    $curlyOpeners[] = $i;
737
-
738
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
739
-                        echo str_repeat("\t", count($squareOpeners));
740
-                        echo str_repeat("\t", count($curlyOpeners));
741
-                        echo "=> Found curly bracket opener at $i".PHP_EOL;
742
-                    }
743
-                }
744
-                break;
745
-            case T_CLOSE_SQUARE_BRACKET:
746
-                if (empty($squareOpeners) === false) {
747
-                    $opener = array_pop($squareOpeners);
748
-                    $this->tokens[$i]['bracket_opener']      = $opener;
749
-                    $this->tokens[$i]['bracket_closer']      = $i;
750
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
751
-                    $this->tokens[$opener]['bracket_closer'] = $i;
752
-
753
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
754
-                        echo str_repeat("\t", count($squareOpeners));
755
-                        echo str_repeat("\t", count($curlyOpeners));
756
-                        echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
757
-                    }
758
-                }
759
-                break;
760
-            case T_CLOSE_CURLY_BRACKET:
761
-                if (empty($curlyOpeners) === false
762
-                    && isset($this->tokens[$i]['scope_opener']) === false
763
-                ) {
764
-                    $opener = array_pop($curlyOpeners);
765
-                    $this->tokens[$i]['bracket_opener']      = $opener;
766
-                    $this->tokens[$i]['bracket_closer']      = $i;
767
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
768
-                    $this->tokens[$opener]['bracket_closer'] = $i;
769
-
770
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
771
-                        echo str_repeat("\t", count($squareOpeners));
772
-                        echo str_repeat("\t", count($curlyOpeners));
773
-                        echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
774
-                    }
775
-                }
776
-                break;
777
-            default:
778
-                continue 2;
779
-            }//end switch
780
-        }//end for
781
-
782
-        // Cleanup for any openers that we didn't find closers for.
783
-        // This typically means there was a syntax error breaking things.
784
-        foreach ($openers as $opener) {
785
-            unset($this->tokens[$opener]['parenthesis_opener']);
786
-            unset($this->tokens[$opener]['parenthesis_owner']);
787
-        }
788
-
789
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
790
-            echo "\t*** END TOKEN MAP ***".PHP_EOL;
791
-        }
792
-
793
-    }//end createTokenMap()
794
-
795
-
796
-    /**
797
-     * Creates a map for the parenthesis tokens that surround other tokens.
798
-     *
799
-     * @return void
800
-     */
801
-    private function createParenthesisNestingMap()
802
-    {
803
-        $map = [];
804
-        for ($i = 0; $i < $this->numTokens; $i++) {
805
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true
806
-                && $i === $this->tokens[$i]['parenthesis_opener']
807
-            ) {
808
-                if (empty($map) === false) {
809
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
810
-                }
811
-
812
-                if (isset($this->tokens[$i]['parenthesis_closer']) === true) {
813
-                    $map[$this->tokens[$i]['parenthesis_opener']]
814
-                        = $this->tokens[$i]['parenthesis_closer'];
815
-                }
816
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
817
-                && $i === $this->tokens[$i]['parenthesis_closer']
818
-            ) {
819
-                array_pop($map);
820
-                if (empty($map) === false) {
821
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
822
-                }
823
-            } else {
824
-                if (empty($map) === false) {
825
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
826
-                }
827
-            }//end if
828
-        }//end for
829
-
830
-    }//end createParenthesisNestingMap()
831
-
832
-
833
-    /**
834
-     * Creates a scope map of tokens that open scopes.
835
-     *
836
-     * @return void
837
-     * @see    recurseScopeMap()
838
-     */
839
-    private function createScopeMap()
840
-    {
841
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
842
-            echo "\t*** START SCOPE MAP ***".PHP_EOL;
843
-        }
844
-
845
-        for ($i = 0; $i < $this->numTokens; $i++) {
846
-            // Check to see if the current token starts a new scope.
847
-            if (isset($this->scopeOpeners[$this->tokens[$i]['code']]) === true) {
848
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
849
-                    $type    = $this->tokens[$i]['type'];
850
-                    $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
851
-                    echo "\tStart scope map at $i:$type => $content".PHP_EOL;
852
-                }
853
-
854
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
855
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
856
-                        echo "\t* already processed, skipping *".PHP_EOL;
857
-                    }
858
-
859
-                    continue;
860
-                }
861
-
862
-                $i = $this->recurseScopeMap($i);
863
-            }//end if
864
-        }//end for
865
-
866
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
867
-            echo "\t*** END SCOPE MAP ***".PHP_EOL;
868
-        }
869
-
870
-    }//end createScopeMap()
871
-
872
-
873
-    /**
874
-     * Recurses though the scope openers to build a scope map.
875
-     *
876
-     * @param int $stackPtr The position in the stack of the token that
877
-     *                      opened the scope (eg. an IF token or FOR token).
878
-     * @param int $depth    How many scope levels down we are.
879
-     * @param int $ignore   How many curly braces we are ignoring.
880
-     *
881
-     * @return int The position in the stack that closed the scope.
882
-     */
883
-    private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
884
-    {
885
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
-            echo str_repeat("\t", $depth);
887
-            echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL;
888
-        }
889
-
890
-        $opener    = null;
891
-        $currType  = $this->tokens[$stackPtr]['code'];
892
-        $startLine = $this->tokens[$stackPtr]['line'];
893
-
894
-        // We will need this to restore the value if we end up
895
-        // returning a token ID that causes our calling function to go back
896
-        // over already ignored braces.
897
-        $originalIgnore = $ignore;
898
-
899
-        // If the start token for this scope opener is the same as
900
-        // the scope token, we have already found our opener.
901
-        if (isset($this->scopeOpeners[$currType]['start'][$currType]) === true) {
902
-            $opener = $stackPtr;
903
-        }
904
-
905
-        for ($i = ($stackPtr + 1); $i < $this->numTokens; $i++) {
906
-            $tokenType = $this->tokens[$i]['code'];
907
-
908
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
909
-                $type    = $this->tokens[$i]['type'];
910
-                $line    = $this->tokens[$i]['line'];
911
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
912
-
913
-                echo str_repeat("\t", $depth);
914
-                echo "Process token $i on line $line [";
915
-                if ($opener !== null) {
916
-                    echo "opener:$opener;";
917
-                }
918
-
919
-                if ($ignore > 0) {
920
-                    echo "ignore=$ignore;";
921
-                }
922
-
923
-                echo "]: $type => $content".PHP_EOL;
924
-            }//end if
925
-
926
-            // Very special case for IF statements in PHP that can be defined without
927
-            // scope tokens. E.g., if (1) 1; 1 ? (1 ? 1 : 1) : 1;
928
-            // If an IF statement below this one has an opener but no
929
-            // keyword, the opener will be incorrectly assigned to this IF statement.
930
-            // The same case also applies to USE statements, which don't have to have
931
-            // openers, so a following USE statement can cause an incorrect brace match.
932
-            if (($currType === T_IF || $currType === T_ELSE || $currType === T_USE)
933
-                && $opener === null
934
-                && ($this->tokens[$i]['code'] === T_SEMICOLON
935
-                || $this->tokens[$i]['code'] === T_CLOSE_TAG)
936
-            ) {
937
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
938
-                    $type = $this->tokens[$stackPtr]['type'];
939
-                    echo str_repeat("\t", $depth);
940
-                    if ($this->tokens[$i]['code'] === T_SEMICOLON) {
941
-                        $closerType = 'semicolon';
942
-                    } else {
943
-                        $closerType = 'close tag';
944
-                    }
945
-
946
-                    echo "=> Found $closerType before scope opener for $stackPtr:$type, bailing".PHP_EOL;
947
-                }
948
-
949
-                return $i;
950
-            }
951
-
952
-            // Special case for PHP control structures that have no braces.
953
-            // If we find a curly brace closer before we find the opener,
954
-            // we're not going to find an opener. That closer probably belongs to
955
-            // a control structure higher up.
956
-            if ($opener === null
957
-                && $ignore === 0
958
-                && $tokenType === T_CLOSE_CURLY_BRACKET
959
-                && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
960
-            ) {
961
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
962
-                    $type = $this->tokens[$stackPtr]['type'];
963
-                    echo str_repeat("\t", $depth);
964
-                    echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing".PHP_EOL;
965
-                }
966
-
967
-                return ($i - 1);
968
-            }
969
-
970
-            if ($opener !== null
971
-                && (isset($this->tokens[$i]['scope_opener']) === false
972
-                || $this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true)
973
-                && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
974
-            ) {
975
-                if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) {
976
-                    // The last opening bracket must have been for a string
977
-                    // offset or alike, so let's ignore it.
978
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
979
-                        echo str_repeat("\t", $depth);
980
-                        echo '* finished ignoring curly brace *'.PHP_EOL;
981
-                    }
982
-
983
-                    $ignore--;
984
-                    continue;
985
-                } else if ($this->tokens[$opener]['code'] === T_OPEN_CURLY_BRACKET
986
-                    && $tokenType !== T_CLOSE_CURLY_BRACKET
987
-                ) {
988
-                    // The opener is a curly bracket so the closer must be a curly bracket as well.
989
-                    // We ignore this closer to handle cases such as T_ELSE or T_ELSEIF being considered
990
-                    // a closer of T_IF when it should not.
991
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
992
-                        $type = $this->tokens[$stackPtr]['type'];
993
-                        echo str_repeat("\t", $depth);
994
-                        echo "=> Ignoring non-curly scope closer for $stackPtr:$type".PHP_EOL;
995
-                    }
996
-                } else {
997
-                    $scopeCloser = $i;
998
-                    $todo        = [
999
-                        $stackPtr,
1000
-                        $opener,
1001
-                    ];
1002
-
1003
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
-                        $type       = $this->tokens[$stackPtr]['type'];
1005
-                        $closerType = $this->tokens[$scopeCloser]['type'];
1006
-                        echo str_repeat("\t", $depth);
1007
-                        echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type".PHP_EOL;
1008
-                    }
1009
-
1010
-                    $validCloser = true;
1011
-                    if (($this->tokens[$stackPtr]['code'] === T_IF || $this->tokens[$stackPtr]['code'] === T_ELSEIF)
1012
-                        && ($tokenType === T_ELSE || $tokenType === T_ELSEIF)
1013
-                    ) {
1014
-                        // To be a closer, this token must have an opener.
1015
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1016
-                            echo str_repeat("\t", $depth);
1017
-                            echo "* closer needs to be tested *".PHP_EOL;
1018
-                        }
1019
-
1020
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1021
-
1022
-                        if (isset($this->tokens[$scopeCloser]['scope_opener']) === false) {
1023
-                            $validCloser = false;
1024
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1025
-                                echo str_repeat("\t", $depth);
1026
-                                echo "* closer is not valid (no opener found) *".PHP_EOL;
1027
-                            }
1028
-                        } else if ($this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['code'] !== $this->tokens[$opener]['code']) {
1029
-                            $validCloser = false;
1030
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1031
-                                echo str_repeat("\t", $depth);
1032
-                                $type       = $this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['type'];
1033
-                                $openerType = $this->tokens[$opener]['type'];
1034
-                                echo "* closer is not valid (mismatched opener type; $type != $openerType) *".PHP_EOL;
1035
-                            }
1036
-                        } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
1037
-                            echo str_repeat("\t", $depth);
1038
-                            echo "* closer was valid *".PHP_EOL;
1039
-                        }
1040
-                    } else {
1041
-                        // The closer was not processed, so we need to
1042
-                        // complete that token as well.
1043
-                        $todo[] = $scopeCloser;
1044
-                    }//end if
1045
-
1046
-                    if ($validCloser === true) {
1047
-                        foreach ($todo as $token) {
1048
-                            $this->tokens[$token]['scope_condition'] = $stackPtr;
1049
-                            $this->tokens[$token]['scope_opener']    = $opener;
1050
-                            $this->tokens[$token]['scope_closer']    = $scopeCloser;
1051
-                        }
1052
-
1053
-                        if ($this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true) {
1054
-                            // As we are going back to where we started originally, restore
1055
-                            // the ignore value back to its original value.
1056
-                            $ignore = $originalIgnore;
1057
-                            return $opener;
1058
-                        } else if ($scopeCloser === $i
1059
-                            && isset($this->scopeOpeners[$tokenType]) === true
1060
-                        ) {
1061
-                            // Unset scope_condition here or else the token will appear to have
1062
-                            // already been processed, and it will be skipped. Normally we want that,
1063
-                            // but in this case, the token is both a closer and an opener, so
1064
-                            // it needs to act like an opener. This is also why we return the
1065
-                            // token before this one; so the closer has a chance to be processed
1066
-                            // a second time, but as an opener.
1067
-                            unset($this->tokens[$scopeCloser]['scope_condition']);
1068
-                            return ($i - 1);
1069
-                        } else {
1070
-                            return $i;
1071
-                        }
1072
-                    } else {
1073
-                        continue;
1074
-                    }//end if
1075
-                }//end if
1076
-            }//end if
1077
-
1078
-            // Is this an opening condition ?
1079
-            if (isset($this->scopeOpeners[$tokenType]) === true) {
1080
-                if ($opener === null) {
1081
-                    if ($tokenType === T_USE) {
1082
-                        // PHP use keywords are special because they can be
1083
-                        // used as blocks but also inline in function definitions.
1084
-                        // So if we find them nested inside another opener, just skip them.
1085
-                        continue;
1086
-                    }
1087
-
1088
-                    if ($tokenType === T_FUNCTION
1089
-                        && $this->tokens[$stackPtr]['code'] !== T_FUNCTION
1090
-                    ) {
1091
-                        // Probably a closure, so process it manually.
1092
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1093
-                            $type = $this->tokens[$stackPtr]['type'];
1094
-                            echo str_repeat("\t", $depth);
1095
-                            echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1096
-                        }
1097
-
1098
-                        if (isset($this->tokens[$i]['scope_closer']) === true) {
1099
-                            // We've already processed this closure.
1100
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1101
-                                echo str_repeat("\t", $depth);
1102
-                                echo '* already processed, skipping *'.PHP_EOL;
1103
-                            }
1104
-
1105
-                            $i = $this->tokens[$i]['scope_closer'];
1106
-                            continue;
1107
-                        }
1108
-
1109
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1110
-                        continue;
1111
-                    }//end if
1112
-
1113
-                    if ($tokenType === T_CLASS) {
1114
-                        // Probably an anonymous class inside another anonymous class,
1115
-                        // so process it manually.
1116
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1117
-                            $type = $this->tokens[$stackPtr]['type'];
1118
-                            echo str_repeat("\t", $depth);
1119
-                            echo "=> Found class before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1120
-                        }
1121
-
1122
-                        if (isset($this->tokens[$i]['scope_closer']) === true) {
1123
-                            // We've already processed this anon class.
1124
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1125
-                                echo str_repeat("\t", $depth);
1126
-                                echo '* already processed, skipping *'.PHP_EOL;
1127
-                            }
1128
-
1129
-                            $i = $this->tokens[$i]['scope_closer'];
1130
-                            continue;
1131
-                        }
1132
-
1133
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1134
-                        continue;
1135
-                    }//end if
1136
-
1137
-                    // Found another opening condition but still haven't
1138
-                    // found our opener, so we are never going to find one.
1139
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1140
-                        $type = $this->tokens[$stackPtr]['type'];
1141
-                        echo str_repeat("\t", $depth);
1142
-                        echo "=> Found new opening condition before scope opener for $stackPtr:$type, ";
1143
-                    }
1144
-
1145
-                    if (($this->tokens[$stackPtr]['code'] === T_IF
1146
-                        || $this->tokens[$stackPtr]['code'] === T_ELSEIF
1147
-                        || $this->tokens[$stackPtr]['code'] === T_ELSE)
1148
-                        && ($this->tokens[$i]['code'] === T_ELSE
1149
-                        || $this->tokens[$i]['code'] === T_ELSEIF)
1150
-                    ) {
1151
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1152
-                            echo "continuing".PHP_EOL;
1153
-                        }
1154
-
1155
-                        return ($i - 1);
1156
-                    } else {
1157
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1158
-                            echo "backtracking".PHP_EOL;
1159
-                        }
1160
-
1161
-                        return $stackPtr;
1162
-                    }
1163
-                }//end if
1164
-
1165
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1166
-                    echo str_repeat("\t", $depth);
1167
-                    echo '* token is an opening condition *'.PHP_EOL;
1168
-                }
1169
-
1170
-                $isShared = ($this->scopeOpeners[$tokenType]['shared'] === true);
1171
-
1172
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
1173
-                    // We've been here before.
1174
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1175
-                        echo str_repeat("\t", $depth);
1176
-                        echo '* already processed, skipping *'.PHP_EOL;
1177
-                    }
1178
-
1179
-                    if ($isShared === false
1180
-                        && isset($this->tokens[$i]['scope_closer']) === true
1181
-                    ) {
1182
-                        $i = $this->tokens[$i]['scope_closer'];
1183
-                    }
1184
-
1185
-                    continue;
1186
-                } else if ($currType === $tokenType
1187
-                    && $isShared === false
1188
-                    && $opener === null
1189
-                ) {
1190
-                    // We haven't yet found our opener, but we have found another
1191
-                    // scope opener which is the same type as us, and we don't
1192
-                    // share openers, so we will never find one.
1193
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1194
-                        echo str_repeat("\t", $depth);
1195
-                        echo '* it was another token\'s opener, bailing *'.PHP_EOL;
1196
-                    }
1197
-
1198
-                    return $stackPtr;
1199
-                } else {
1200
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1201
-                        echo str_repeat("\t", $depth);
1202
-                        echo '* searching for opener *'.PHP_EOL;
1203
-                    }
1204
-
1205
-                    if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1206
-                        $oldIgnore = $ignore;
1207
-                        $ignore    = 0;
1208
-                    }
1209
-
1210
-                    // PHP has a max nesting level for functions. Stop before we hit that limit
1211
-                    // because too many loops means we've run into trouble anyway.
1212
-                    if ($depth > 50) {
1213
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1214
-                            echo str_repeat("\t", $depth);
1215
-                            echo '* reached maximum nesting level; aborting *'.PHP_EOL;
1216
-                        }
1217
-
1218
-                        throw new RuntimeException('Maximum nesting level reached; file could not be processed');
1219
-                    }
1220
-
1221
-                    $oldDepth = $depth;
1222
-                    if ($isShared === true
1223
-                        && isset($this->scopeOpeners[$tokenType]['with'][$currType]) === true
1224
-                    ) {
1225
-                        // Don't allow the depth to increment because this is
1226
-                        // possibly not a true nesting if we are sharing our closer.
1227
-                        // This can happen, for example, when a SWITCH has a large
1228
-                        // number of CASE statements with the same shared BREAK.
1229
-                        $depth--;
1230
-                    }
1231
-
1232
-                    $i     = self::recurseScopeMap($i, ($depth + 1), $ignore);
1233
-                    $depth = $oldDepth;
1234
-
1235
-                    if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1236
-                        $ignore = $oldIgnore;
1237
-                    }
1238
-                }//end if
1239
-            }//end if
1240
-
1241
-            if (isset($this->scopeOpeners[$currType]['start'][$tokenType]) === true
1242
-                && $opener === null
1243
-            ) {
1244
-                if ($tokenType === T_OPEN_CURLY_BRACKET) {
1245
-                    if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true
1246
-                        && $i < $this->tokens[$stackPtr]['parenthesis_closer']
1247
-                    ) {
1248
-                        // We found a curly brace inside the condition of the
1249
-                        // current scope opener, so it must be a string offset.
1250
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
-                            echo str_repeat("\t", $depth);
1252
-                            echo '* ignoring curly brace inside condition *'.PHP_EOL;
1253
-                        }
1254
-
1255
-                        $ignore++;
1256
-                    } else {
1257
-                        // Make sure this is actually an opener and not a
1258
-                        // string offset (e.g., $var{0}).
1259
-                        for ($x = ($i - 1); $x > 0; $x--) {
1260
-                            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === true) {
1261
-                                continue;
1262
-                            } else {
1263
-                                // If the first non-whitespace/comment token looks like this
1264
-                                // brace is a string offset, or this brace is mid-way through
1265
-                                // a new statement, it isn't a scope opener.
1266
-                                $disallowed  = Util\Tokens::$assignmentTokens;
1267
-                                $disallowed += [
1268
-                                    T_DOLLAR           => true,
1269
-                                    T_VARIABLE         => true,
1270
-                                    T_OBJECT_OPERATOR  => true,
1271
-                                    T_COMMA            => true,
1272
-                                    T_OPEN_PARENTHESIS => true,
1273
-                                ];
1274
-
1275
-                                if (isset($disallowed[$this->tokens[$x]['code']]) === true) {
1276
-                                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1277
-                                        echo str_repeat("\t", $depth);
1278
-                                        echo '* ignoring curly brace *'.PHP_EOL;
1279
-                                    }
1280
-
1281
-                                    $ignore++;
1282
-                                }
1283
-
1284
-                                break;
1285
-                            }//end if
1286
-                        }//end for
1287
-                    }//end if
1288
-                }//end if
1289
-
1290
-                if ($ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET) {
1291
-                    // We found the opening scope token for $currType.
1292
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1293
-                        $type = $this->tokens[$stackPtr]['type'];
1294
-                        echo str_repeat("\t", $depth);
1295
-                        echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1296
-                    }
1297
-
1298
-                    $opener = $i;
1299
-                }
1300
-            } else if ($tokenType === T_OPEN_PARENTHESIS) {
1301
-                if (isset($this->tokens[$i]['parenthesis_owner']) === true) {
1302
-                    $owner = $this->tokens[$i]['parenthesis_owner'];
1303
-                    if (isset(Util\Tokens::$scopeOpeners[$this->tokens[$owner]['code']]) === true
1304
-                        && isset($this->tokens[$i]['parenthesis_closer']) === true
1305
-                    ) {
1306
-                        // If we get into here, then we opened a parenthesis for
1307
-                        // a scope (eg. an if or else if) so we need to update the
1308
-                        // start of the line so that when we check to see
1309
-                        // if the closing parenthesis is more than 3 lines away from
1310
-                        // the statement, we check from the closing parenthesis.
1311
-                        $startLine = $this->tokens[$this->tokens[$i]['parenthesis_closer']]['line'];
1312
-                    }
1313
-                }
1314
-            } else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) {
1315
-                // We opened something that we don't have a scope opener for.
1316
-                // Examples of this are curly brackets for string offsets etc.
1317
-                // We want to ignore this so that we don't have an invalid scope
1318
-                // map.
1319
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1320
-                    echo str_repeat("\t", $depth);
1321
-                    echo '* ignoring curly brace *'.PHP_EOL;
1322
-                }
1323
-
1324
-                $ignore++;
1325
-            } else if ($tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0) {
1326
-                // We found the end token for the opener we were ignoring.
1327
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1328
-                    echo str_repeat("\t", $depth);
1329
-                    echo '* finished ignoring curly brace *'.PHP_EOL;
1330
-                }
1331
-
1332
-                $ignore--;
1333
-            } else if ($opener === null
1334
-                && isset($this->scopeOpeners[$currType]) === true
1335
-            ) {
1336
-                // If we still haven't found the opener after 30 lines,
1337
-                // we're not going to find it, unless we know it requires
1338
-                // an opener (in which case we better keep looking) or the last
1339
-                // token was empty (in which case we'll just confirm there is
1340
-                // more code in this file and not just a big comment).
1341
-                if ($this->tokens[$i]['line'] >= ($startLine + 30)
1342
-                    && isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false
1343
-                ) {
1344
-                    if ($this->scopeOpeners[$currType]['strict'] === true) {
1345
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1346
-                            $type  = $this->tokens[$stackPtr]['type'];
1347
-                            $lines = ($this->tokens[$i]['line'] - $startLine);
1348
-                            echo str_repeat("\t", $depth);
1349
-                            echo "=> Still looking for $stackPtr:$type scope opener after $lines lines".PHP_EOL;
1350
-                        }
1351
-                    } else {
1352
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1353
-                            $type = $this->tokens[$stackPtr]['type'];
1354
-                            echo str_repeat("\t", $depth);
1355
-                            echo "=> Couldn't find scope opener for $stackPtr:$type, bailing".PHP_EOL;
1356
-                        }
1357
-
1358
-                        return $stackPtr;
1359
-                    }
1360
-                }
1361
-            } else if ($opener !== null
1362
-                && $tokenType !== T_BREAK
1363
-                && isset($this->endScopeTokens[$tokenType]) === true
1364
-            ) {
1365
-                if (isset($this->tokens[$i]['scope_condition']) === false) {
1366
-                    if ($ignore > 0) {
1367
-                        // We found the end token for the opener we were ignoring.
1368
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1369
-                            echo str_repeat("\t", $depth);
1370
-                            echo '* finished ignoring curly brace *'.PHP_EOL;
1371
-                        }
1372
-
1373
-                        $ignore--;
1374
-                    } else {
1375
-                        // We found a token that closes the scope but it doesn't
1376
-                        // have a condition, so it belongs to another token and
1377
-                        // our token doesn't have a closer, so pretend this is
1378
-                        // the closer.
1379
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1380
-                            $type = $this->tokens[$stackPtr]['type'];
1381
-                            echo str_repeat("\t", $depth);
1382
-                            echo "=> Found (unexpected) scope closer for $stackPtr:$type".PHP_EOL;
1383
-                        }
1384
-
1385
-                        foreach ([$stackPtr, $opener] as $token) {
1386
-                            $this->tokens[$token]['scope_condition'] = $stackPtr;
1387
-                            $this->tokens[$token]['scope_opener']    = $opener;
1388
-                            $this->tokens[$token]['scope_closer']    = $i;
1389
-                        }
1390
-
1391
-                        return ($i - 1);
1392
-                    }//end if
1393
-                }//end if
1394
-            }//end if
1395
-        }//end for
1396
-
1397
-        return $stackPtr;
1398
-
1399
-    }//end recurseScopeMap()
1400
-
1401
-
1402
-    /**
1403
-     * Constructs the level map.
1404
-     *
1405
-     * The level map adds a 'level' index to each token which indicates the
1406
-     * depth that a token within a set of scope blocks. It also adds a
1407
-     * 'conditions' index which is an array of the scope conditions that opened
1408
-     * each of the scopes - position 0 being the first scope opener.
1409
-     *
1410
-     * @return void
1411
-     */
1412
-    private function createLevelMap()
1413
-    {
1414
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1415
-            echo "\t*** START LEVEL MAP ***".PHP_EOL;
1416
-        }
1417
-
1418
-        $this->numTokens = count($this->tokens);
1419
-        $level           = 0;
1420
-        $conditions      = [];
1421
-        $lastOpener      = null;
1422
-        $openers         = [];
1423
-
1424
-        for ($i = 0; $i < $this->numTokens; $i++) {
1425
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1426
-                $type = $this->tokens[$i]['type'];
1427
-                $line = $this->tokens[$i]['line'];
1428
-                $len  = $this->tokens[$i]['length'];
1429
-                $col  = $this->tokens[$i]['column'];
1430
-
1431
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1432
-
1433
-                echo str_repeat("\t", ($level + 1));
1434
-                echo "Process token $i on line $line [col:$col;len:$len;lvl:$level;";
1435
-                if (empty($conditions) !== true) {
1436
-                    $condString = 'conds;';
1437
-                    foreach ($conditions as $condition) {
1438
-                        $condString .= Util\Tokens::tokenName($condition).',';
1439
-                    }
1440
-
1441
-                    echo rtrim($condString, ',').';';
1442
-                }
1443
-
1444
-                echo "]: $type => $content".PHP_EOL;
1445
-            }//end if
1446
-
1447
-            $this->tokens[$i]['level']      = $level;
1448
-            $this->tokens[$i]['conditions'] = $conditions;
1449
-
1450
-            if (isset($this->tokens[$i]['scope_condition']) === true) {
1451
-                // Check to see if this token opened the scope.
1452
-                if ($this->tokens[$i]['scope_opener'] === $i) {
1453
-                    $stackPtr = $this->tokens[$i]['scope_condition'];
1454
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1455
-                        $type = $this->tokens[$stackPtr]['type'];
1456
-                        echo str_repeat("\t", ($level + 1));
1457
-                        echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1458
-                    }
1459
-
1460
-                    $stackPtr = $this->tokens[$i]['scope_condition'];
1461
-
1462
-                    // If we find a scope opener that has a shared closer,
1463
-                    // then we need to go back over the condition map that we
1464
-                    // just created and fix ourselves as we just added some
1465
-                    // conditions where there was none. This happens for T_CASE
1466
-                    // statements that are using the same break statement.
1467
-                    if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $this->tokens[$i]['scope_closer']) {
1468
-                        // This opener shares its closer with the previous opener,
1469
-                        // but we still need to check if the two openers share their
1470
-                        // closer with each other directly (like CASE and DEFAULT)
1471
-                        // or if they are just sharing because one doesn't have a
1472
-                        // closer (like CASE with no BREAK using a SWITCHes closer).
1473
-                        $thisType = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1474
-                        $opener   = $this->tokens[$lastOpener]['scope_condition'];
1475
-
1476
-                        $isShared = isset($this->scopeOpeners[$thisType]['with'][$this->tokens[$opener]['code']]);
1477
-
1478
-                        reset($this->scopeOpeners[$thisType]['end']);
1479
-                        reset($this->scopeOpeners[$this->tokens[$opener]['code']]['end']);
1480
-                        $sameEnd = (current($this->scopeOpeners[$thisType]['end']) === current($this->scopeOpeners[$this->tokens[$opener]['code']]['end']));
1481
-
1482
-                        if ($isShared === true && $sameEnd === true) {
1483
-                            $badToken = $opener;
1484
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1485
-                                $type = $this->tokens[$badToken]['type'];
1486
-                                echo str_repeat("\t", ($level + 1));
1487
-                                echo "* shared closer, cleaning up $badToken:$type *".PHP_EOL;
1488
-                            }
1489
-
1490
-                            for ($x = $this->tokens[$i]['scope_condition']; $x <= $i; $x++) {
1491
-                                $oldConditions = $this->tokens[$x]['conditions'];
1492
-                                $oldLevel      = $this->tokens[$x]['level'];
1493
-                                $this->tokens[$x]['level']--;
1494
-                                unset($this->tokens[$x]['conditions'][$badToken]);
1495
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1496
-                                    $type     = $this->tokens[$x]['type'];
1497
-                                    $oldConds = '';
1498
-                                    foreach ($oldConditions as $condition) {
1499
-                                        $oldConds .= Util\Tokens::tokenName($condition).',';
1500
-                                    }
1501
-
1502
-                                    $oldConds = rtrim($oldConds, ',');
1503
-
1504
-                                    $newConds = '';
1505
-                                    foreach ($this->tokens[$x]['conditions'] as $condition) {
1506
-                                        $newConds .= Util\Tokens::tokenName($condition).',';
1507
-                                    }
1508
-
1509
-                                    $newConds = rtrim($newConds, ',');
1510
-
1511
-                                    $newLevel = $this->tokens[$x]['level'];
1512
-                                    echo str_repeat("\t", ($level + 1));
1513
-                                    echo "* cleaned $x:$type *".PHP_EOL;
1514
-                                    echo str_repeat("\t", ($level + 2));
1515
-                                    echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1516
-                                    echo str_repeat("\t", ($level + 2));
1517
-                                    echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1518
-                                }//end if
1519
-                            }//end for
1520
-
1521
-                            unset($conditions[$badToken]);
1522
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1523
-                                $type = $this->tokens[$badToken]['type'];
1524
-                                echo str_repeat("\t", ($level + 1));
1525
-                                echo "* token $badToken:$type removed from conditions array *".PHP_EOL;
1526
-                            }
1527
-
1528
-                            unset($openers[$lastOpener]);
1529
-
1530
-                            $level--;
1531
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1532
-                                echo str_repeat("\t", ($level + 2));
1533
-                                echo '* level decreased *'.PHP_EOL;
1534
-                            }
1535
-                        }//end if
1536
-                    }//end if
1537
-
1538
-                    $level++;
1539
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1540
-                        echo str_repeat("\t", ($level + 1));
1541
-                        echo '* level increased *'.PHP_EOL;
1542
-                    }
1543
-
1544
-                    $conditions[$stackPtr] = $this->tokens[$stackPtr]['code'];
1545
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1546
-                        $type = $this->tokens[$stackPtr]['type'];
1547
-                        echo str_repeat("\t", ($level + 1));
1548
-                        echo "* token $stackPtr:$type added to conditions array *".PHP_EOL;
1549
-                    }
1550
-
1551
-                    $lastOpener = $this->tokens[$i]['scope_opener'];
1552
-                    if ($lastOpener !== null) {
1553
-                        $openers[$lastOpener] = $lastOpener;
1554
-                    }
1555
-                } else if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $i) {
1556
-                    foreach (array_reverse($openers) as $opener) {
1557
-                        if ($this->tokens[$opener]['scope_closer'] === $i) {
1558
-                            $oldOpener = array_pop($openers);
1559
-                            if (empty($openers) === false) {
1560
-                                $lastOpener           = array_pop($openers);
1561
-                                $openers[$lastOpener] = $lastOpener;
1562
-                            } else {
1563
-                                $lastOpener = null;
1564
-                            }
1565
-
1566
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1567
-                                $type = $this->tokens[$oldOpener]['type'];
1568
-                                echo str_repeat("\t", ($level + 1));
1569
-                                echo "=> Found scope closer for $oldOpener:$type".PHP_EOL;
1570
-                            }
1571
-
1572
-                            $oldCondition = array_pop($conditions);
1573
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1574
-                                echo str_repeat("\t", ($level + 1));
1575
-                                echo '* token '.Util\Tokens::tokenName($oldCondition).' removed from conditions array *'.PHP_EOL;
1576
-                            }
1577
-
1578
-                            // Make sure this closer actually belongs to us.
1579
-                            // Either the condition also has to think this is the
1580
-                            // closer, or it has to allow sharing with us.
1581
-                            $condition = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1582
-                            if ($condition !== $oldCondition) {
1583
-                                if (isset($this->scopeOpeners[$oldCondition]['with'][$condition]) === false) {
1584
-                                    $badToken = $this->tokens[$oldOpener]['scope_condition'];
1585
-
1586
-                                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1587
-                                        $type = Util\Tokens::tokenName($oldCondition);
1588
-                                        echo str_repeat("\t", ($level + 1));
1589
-                                        echo "* scope closer was bad, cleaning up $badToken:$type *".PHP_EOL;
1590
-                                    }
1591
-
1592
-                                    for ($x = ($oldOpener + 1); $x <= $i; $x++) {
1593
-                                        $oldConditions = $this->tokens[$x]['conditions'];
1594
-                                        $oldLevel      = $this->tokens[$x]['level'];
1595
-                                        $this->tokens[$x]['level']--;
1596
-                                        unset($this->tokens[$x]['conditions'][$badToken]);
1597
-                                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1598
-                                            $type     = $this->tokens[$x]['type'];
1599
-                                            $oldConds = '';
1600
-                                            foreach ($oldConditions as $condition) {
1601
-                                                $oldConds .= Util\Tokens::tokenName($condition).',';
1602
-                                            }
1603
-
1604
-                                            $oldConds = rtrim($oldConds, ',');
1605
-
1606
-                                            $newConds = '';
1607
-                                            foreach ($this->tokens[$x]['conditions'] as $condition) {
1608
-                                                $newConds .= Util\Tokens::tokenName($condition).',';
1609
-                                            }
1610
-
1611
-                                            $newConds = rtrim($newConds, ',');
1612
-
1613
-                                            $newLevel = $this->tokens[$x]['level'];
1614
-                                            echo str_repeat("\t", ($level + 1));
1615
-                                            echo "* cleaned $x:$type *".PHP_EOL;
1616
-                                            echo str_repeat("\t", ($level + 2));
1617
-                                            echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1618
-                                            echo str_repeat("\t", ($level + 2));
1619
-                                            echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1620
-                                        }//end if
1621
-                                    }//end for
1622
-                                }//end if
1623
-                            }//end if
1624
-
1625
-                            $level--;
1626
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1627
-                                echo str_repeat("\t", ($level + 2));
1628
-                                echo '* level decreased *'.PHP_EOL;
1629
-                            }
1630
-
1631
-                            $this->tokens[$i]['level']      = $level;
1632
-                            $this->tokens[$i]['conditions'] = $conditions;
1633
-                        }//end if
1634
-                    }//end foreach
1635
-                }//end if
1636
-            }//end if
1637
-        }//end for
1638
-
1639
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1640
-            echo "\t*** END LEVEL MAP ***".PHP_EOL;
1641
-        }
1642
-
1643
-    }//end createLevelMap()
724
+			switch ($this->tokens[$i]['code']) {
725
+			case T_OPEN_SQUARE_BRACKET:
726
+				$squareOpeners[] = $i;
727
+
728
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
729
+					echo str_repeat("\t", count($squareOpeners));
730
+					echo str_repeat("\t", count($curlyOpeners));
731
+					echo "=> Found square bracket opener at $i".PHP_EOL;
732
+				}
733
+				break;
734
+			case T_OPEN_CURLY_BRACKET:
735
+				if (isset($this->tokens[$i]['scope_closer']) === false) {
736
+					$curlyOpeners[] = $i;
737
+
738
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
739
+						echo str_repeat("\t", count($squareOpeners));
740
+						echo str_repeat("\t", count($curlyOpeners));
741
+						echo "=> Found curly bracket opener at $i".PHP_EOL;
742
+					}
743
+				}
744
+				break;
745
+			case T_CLOSE_SQUARE_BRACKET:
746
+				if (empty($squareOpeners) === false) {
747
+					$opener = array_pop($squareOpeners);
748
+					$this->tokens[$i]['bracket_opener']      = $opener;
749
+					$this->tokens[$i]['bracket_closer']      = $i;
750
+					$this->tokens[$opener]['bracket_opener'] = $opener;
751
+					$this->tokens[$opener]['bracket_closer'] = $i;
752
+
753
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
754
+						echo str_repeat("\t", count($squareOpeners));
755
+						echo str_repeat("\t", count($curlyOpeners));
756
+						echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
757
+					}
758
+				}
759
+				break;
760
+			case T_CLOSE_CURLY_BRACKET:
761
+				if (empty($curlyOpeners) === false
762
+					&& isset($this->tokens[$i]['scope_opener']) === false
763
+				) {
764
+					$opener = array_pop($curlyOpeners);
765
+					$this->tokens[$i]['bracket_opener']      = $opener;
766
+					$this->tokens[$i]['bracket_closer']      = $i;
767
+					$this->tokens[$opener]['bracket_opener'] = $opener;
768
+					$this->tokens[$opener]['bracket_closer'] = $i;
769
+
770
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
771
+						echo str_repeat("\t", count($squareOpeners));
772
+						echo str_repeat("\t", count($curlyOpeners));
773
+						echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
774
+					}
775
+				}
776
+				break;
777
+			default:
778
+				continue 2;
779
+			}//end switch
780
+		}//end for
781
+
782
+		// Cleanup for any openers that we didn't find closers for.
783
+		// This typically means there was a syntax error breaking things.
784
+		foreach ($openers as $opener) {
785
+			unset($this->tokens[$opener]['parenthesis_opener']);
786
+			unset($this->tokens[$opener]['parenthesis_owner']);
787
+		}
788
+
789
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
790
+			echo "\t*** END TOKEN MAP ***".PHP_EOL;
791
+		}
792
+
793
+	}//end createTokenMap()
794
+
795
+
796
+	/**
797
+	 * Creates a map for the parenthesis tokens that surround other tokens.
798
+	 *
799
+	 * @return void
800
+	 */
801
+	private function createParenthesisNestingMap()
802
+	{
803
+		$map = [];
804
+		for ($i = 0; $i < $this->numTokens; $i++) {
805
+			if (isset($this->tokens[$i]['parenthesis_opener']) === true
806
+				&& $i === $this->tokens[$i]['parenthesis_opener']
807
+			) {
808
+				if (empty($map) === false) {
809
+					$this->tokens[$i]['nested_parenthesis'] = $map;
810
+				}
811
+
812
+				if (isset($this->tokens[$i]['parenthesis_closer']) === true) {
813
+					$map[$this->tokens[$i]['parenthesis_opener']]
814
+						= $this->tokens[$i]['parenthesis_closer'];
815
+				}
816
+			} else if (isset($this->tokens[$i]['parenthesis_closer']) === true
817
+				&& $i === $this->tokens[$i]['parenthesis_closer']
818
+			) {
819
+				array_pop($map);
820
+				if (empty($map) === false) {
821
+					$this->tokens[$i]['nested_parenthesis'] = $map;
822
+				}
823
+			} else {
824
+				if (empty($map) === false) {
825
+					$this->tokens[$i]['nested_parenthesis'] = $map;
826
+				}
827
+			}//end if
828
+		}//end for
829
+
830
+	}//end createParenthesisNestingMap()
831
+
832
+
833
+	/**
834
+	 * Creates a scope map of tokens that open scopes.
835
+	 *
836
+	 * @return void
837
+	 * @see    recurseScopeMap()
838
+	 */
839
+	private function createScopeMap()
840
+	{
841
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
842
+			echo "\t*** START SCOPE MAP ***".PHP_EOL;
843
+		}
844
+
845
+		for ($i = 0; $i < $this->numTokens; $i++) {
846
+			// Check to see if the current token starts a new scope.
847
+			if (isset($this->scopeOpeners[$this->tokens[$i]['code']]) === true) {
848
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
849
+					$type    = $this->tokens[$i]['type'];
850
+					$content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
851
+					echo "\tStart scope map at $i:$type => $content".PHP_EOL;
852
+				}
853
+
854
+				if (isset($this->tokens[$i]['scope_condition']) === true) {
855
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
856
+						echo "\t* already processed, skipping *".PHP_EOL;
857
+					}
858
+
859
+					continue;
860
+				}
861
+
862
+				$i = $this->recurseScopeMap($i);
863
+			}//end if
864
+		}//end for
865
+
866
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
867
+			echo "\t*** END SCOPE MAP ***".PHP_EOL;
868
+		}
869
+
870
+	}//end createScopeMap()
871
+
872
+
873
+	/**
874
+	 * Recurses though the scope openers to build a scope map.
875
+	 *
876
+	 * @param int $stackPtr The position in the stack of the token that
877
+	 *                      opened the scope (eg. an IF token or FOR token).
878
+	 * @param int $depth    How many scope levels down we are.
879
+	 * @param int $ignore   How many curly braces we are ignoring.
880
+	 *
881
+	 * @return int The position in the stack that closed the scope.
882
+	 */
883
+	private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
884
+	{
885
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
+			echo str_repeat("\t", $depth);
887
+			echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL;
888
+		}
889
+
890
+		$opener    = null;
891
+		$currType  = $this->tokens[$stackPtr]['code'];
892
+		$startLine = $this->tokens[$stackPtr]['line'];
893
+
894
+		// We will need this to restore the value if we end up
895
+		// returning a token ID that causes our calling function to go back
896
+		// over already ignored braces.
897
+		$originalIgnore = $ignore;
898
+
899
+		// If the start token for this scope opener is the same as
900
+		// the scope token, we have already found our opener.
901
+		if (isset($this->scopeOpeners[$currType]['start'][$currType]) === true) {
902
+			$opener = $stackPtr;
903
+		}
904
+
905
+		for ($i = ($stackPtr + 1); $i < $this->numTokens; $i++) {
906
+			$tokenType = $this->tokens[$i]['code'];
907
+
908
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
909
+				$type    = $this->tokens[$i]['type'];
910
+				$line    = $this->tokens[$i]['line'];
911
+				$content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
912
+
913
+				echo str_repeat("\t", $depth);
914
+				echo "Process token $i on line $line [";
915
+				if ($opener !== null) {
916
+					echo "opener:$opener;";
917
+				}
918
+
919
+				if ($ignore > 0) {
920
+					echo "ignore=$ignore;";
921
+				}
922
+
923
+				echo "]: $type => $content".PHP_EOL;
924
+			}//end if
925
+
926
+			// Very special case for IF statements in PHP that can be defined without
927
+			// scope tokens. E.g., if (1) 1; 1 ? (1 ? 1 : 1) : 1;
928
+			// If an IF statement below this one has an opener but no
929
+			// keyword, the opener will be incorrectly assigned to this IF statement.
930
+			// The same case also applies to USE statements, which don't have to have
931
+			// openers, so a following USE statement can cause an incorrect brace match.
932
+			if (($currType === T_IF || $currType === T_ELSE || $currType === T_USE)
933
+				&& $opener === null
934
+				&& ($this->tokens[$i]['code'] === T_SEMICOLON
935
+				|| $this->tokens[$i]['code'] === T_CLOSE_TAG)
936
+			) {
937
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
938
+					$type = $this->tokens[$stackPtr]['type'];
939
+					echo str_repeat("\t", $depth);
940
+					if ($this->tokens[$i]['code'] === T_SEMICOLON) {
941
+						$closerType = 'semicolon';
942
+					} else {
943
+						$closerType = 'close tag';
944
+					}
945
+
946
+					echo "=> Found $closerType before scope opener for $stackPtr:$type, bailing".PHP_EOL;
947
+				}
948
+
949
+				return $i;
950
+			}
951
+
952
+			// Special case for PHP control structures that have no braces.
953
+			// If we find a curly brace closer before we find the opener,
954
+			// we're not going to find an opener. That closer probably belongs to
955
+			// a control structure higher up.
956
+			if ($opener === null
957
+				&& $ignore === 0
958
+				&& $tokenType === T_CLOSE_CURLY_BRACKET
959
+				&& isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
960
+			) {
961
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
962
+					$type = $this->tokens[$stackPtr]['type'];
963
+					echo str_repeat("\t", $depth);
964
+					echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing".PHP_EOL;
965
+				}
966
+
967
+				return ($i - 1);
968
+			}
969
+
970
+			if ($opener !== null
971
+				&& (isset($this->tokens[$i]['scope_opener']) === false
972
+				|| $this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true)
973
+				&& isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
974
+			) {
975
+				if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) {
976
+					// The last opening bracket must have been for a string
977
+					// offset or alike, so let's ignore it.
978
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
979
+						echo str_repeat("\t", $depth);
980
+						echo '* finished ignoring curly brace *'.PHP_EOL;
981
+					}
982
+
983
+					$ignore--;
984
+					continue;
985
+				} else if ($this->tokens[$opener]['code'] === T_OPEN_CURLY_BRACKET
986
+					&& $tokenType !== T_CLOSE_CURLY_BRACKET
987
+				) {
988
+					// The opener is a curly bracket so the closer must be a curly bracket as well.
989
+					// We ignore this closer to handle cases such as T_ELSE or T_ELSEIF being considered
990
+					// a closer of T_IF when it should not.
991
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
992
+						$type = $this->tokens[$stackPtr]['type'];
993
+						echo str_repeat("\t", $depth);
994
+						echo "=> Ignoring non-curly scope closer for $stackPtr:$type".PHP_EOL;
995
+					}
996
+				} else {
997
+					$scopeCloser = $i;
998
+					$todo        = [
999
+						$stackPtr,
1000
+						$opener,
1001
+					];
1002
+
1003
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
+						$type       = $this->tokens[$stackPtr]['type'];
1005
+						$closerType = $this->tokens[$scopeCloser]['type'];
1006
+						echo str_repeat("\t", $depth);
1007
+						echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type".PHP_EOL;
1008
+					}
1009
+
1010
+					$validCloser = true;
1011
+					if (($this->tokens[$stackPtr]['code'] === T_IF || $this->tokens[$stackPtr]['code'] === T_ELSEIF)
1012
+						&& ($tokenType === T_ELSE || $tokenType === T_ELSEIF)
1013
+					) {
1014
+						// To be a closer, this token must have an opener.
1015
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1016
+							echo str_repeat("\t", $depth);
1017
+							echo "* closer needs to be tested *".PHP_EOL;
1018
+						}
1019
+
1020
+						$i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1021
+
1022
+						if (isset($this->tokens[$scopeCloser]['scope_opener']) === false) {
1023
+							$validCloser = false;
1024
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1025
+								echo str_repeat("\t", $depth);
1026
+								echo "* closer is not valid (no opener found) *".PHP_EOL;
1027
+							}
1028
+						} else if ($this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['code'] !== $this->tokens[$opener]['code']) {
1029
+							$validCloser = false;
1030
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1031
+								echo str_repeat("\t", $depth);
1032
+								$type       = $this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['type'];
1033
+								$openerType = $this->tokens[$opener]['type'];
1034
+								echo "* closer is not valid (mismatched opener type; $type != $openerType) *".PHP_EOL;
1035
+							}
1036
+						} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
1037
+							echo str_repeat("\t", $depth);
1038
+							echo "* closer was valid *".PHP_EOL;
1039
+						}
1040
+					} else {
1041
+						// The closer was not processed, so we need to
1042
+						// complete that token as well.
1043
+						$todo[] = $scopeCloser;
1044
+					}//end if
1045
+
1046
+					if ($validCloser === true) {
1047
+						foreach ($todo as $token) {
1048
+							$this->tokens[$token]['scope_condition'] = $stackPtr;
1049
+							$this->tokens[$token]['scope_opener']    = $opener;
1050
+							$this->tokens[$token]['scope_closer']    = $scopeCloser;
1051
+						}
1052
+
1053
+						if ($this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true) {
1054
+							// As we are going back to where we started originally, restore
1055
+							// the ignore value back to its original value.
1056
+							$ignore = $originalIgnore;
1057
+							return $opener;
1058
+						} else if ($scopeCloser === $i
1059
+							&& isset($this->scopeOpeners[$tokenType]) === true
1060
+						) {
1061
+							// Unset scope_condition here or else the token will appear to have
1062
+							// already been processed, and it will be skipped. Normally we want that,
1063
+							// but in this case, the token is both a closer and an opener, so
1064
+							// it needs to act like an opener. This is also why we return the
1065
+							// token before this one; so the closer has a chance to be processed
1066
+							// a second time, but as an opener.
1067
+							unset($this->tokens[$scopeCloser]['scope_condition']);
1068
+							return ($i - 1);
1069
+						} else {
1070
+							return $i;
1071
+						}
1072
+					} else {
1073
+						continue;
1074
+					}//end if
1075
+				}//end if
1076
+			}//end if
1077
+
1078
+			// Is this an opening condition ?
1079
+			if (isset($this->scopeOpeners[$tokenType]) === true) {
1080
+				if ($opener === null) {
1081
+					if ($tokenType === T_USE) {
1082
+						// PHP use keywords are special because they can be
1083
+						// used as blocks but also inline in function definitions.
1084
+						// So if we find them nested inside another opener, just skip them.
1085
+						continue;
1086
+					}
1087
+
1088
+					if ($tokenType === T_FUNCTION
1089
+						&& $this->tokens[$stackPtr]['code'] !== T_FUNCTION
1090
+					) {
1091
+						// Probably a closure, so process it manually.
1092
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1093
+							$type = $this->tokens[$stackPtr]['type'];
1094
+							echo str_repeat("\t", $depth);
1095
+							echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1096
+						}
1097
+
1098
+						if (isset($this->tokens[$i]['scope_closer']) === true) {
1099
+							// We've already processed this closure.
1100
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1101
+								echo str_repeat("\t", $depth);
1102
+								echo '* already processed, skipping *'.PHP_EOL;
1103
+							}
1104
+
1105
+							$i = $this->tokens[$i]['scope_closer'];
1106
+							continue;
1107
+						}
1108
+
1109
+						$i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1110
+						continue;
1111
+					}//end if
1112
+
1113
+					if ($tokenType === T_CLASS) {
1114
+						// Probably an anonymous class inside another anonymous class,
1115
+						// so process it manually.
1116
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1117
+							$type = $this->tokens[$stackPtr]['type'];
1118
+							echo str_repeat("\t", $depth);
1119
+							echo "=> Found class before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1120
+						}
1121
+
1122
+						if (isset($this->tokens[$i]['scope_closer']) === true) {
1123
+							// We've already processed this anon class.
1124
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1125
+								echo str_repeat("\t", $depth);
1126
+								echo '* already processed, skipping *'.PHP_EOL;
1127
+							}
1128
+
1129
+							$i = $this->tokens[$i]['scope_closer'];
1130
+							continue;
1131
+						}
1132
+
1133
+						$i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1134
+						continue;
1135
+					}//end if
1136
+
1137
+					// Found another opening condition but still haven't
1138
+					// found our opener, so we are never going to find one.
1139
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1140
+						$type = $this->tokens[$stackPtr]['type'];
1141
+						echo str_repeat("\t", $depth);
1142
+						echo "=> Found new opening condition before scope opener for $stackPtr:$type, ";
1143
+					}
1144
+
1145
+					if (($this->tokens[$stackPtr]['code'] === T_IF
1146
+						|| $this->tokens[$stackPtr]['code'] === T_ELSEIF
1147
+						|| $this->tokens[$stackPtr]['code'] === T_ELSE)
1148
+						&& ($this->tokens[$i]['code'] === T_ELSE
1149
+						|| $this->tokens[$i]['code'] === T_ELSEIF)
1150
+					) {
1151
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1152
+							echo "continuing".PHP_EOL;
1153
+						}
1154
+
1155
+						return ($i - 1);
1156
+					} else {
1157
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1158
+							echo "backtracking".PHP_EOL;
1159
+						}
1160
+
1161
+						return $stackPtr;
1162
+					}
1163
+				}//end if
1164
+
1165
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1166
+					echo str_repeat("\t", $depth);
1167
+					echo '* token is an opening condition *'.PHP_EOL;
1168
+				}
1169
+
1170
+				$isShared = ($this->scopeOpeners[$tokenType]['shared'] === true);
1171
+
1172
+				if (isset($this->tokens[$i]['scope_condition']) === true) {
1173
+					// We've been here before.
1174
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1175
+						echo str_repeat("\t", $depth);
1176
+						echo '* already processed, skipping *'.PHP_EOL;
1177
+					}
1178
+
1179
+					if ($isShared === false
1180
+						&& isset($this->tokens[$i]['scope_closer']) === true
1181
+					) {
1182
+						$i = $this->tokens[$i]['scope_closer'];
1183
+					}
1184
+
1185
+					continue;
1186
+				} else if ($currType === $tokenType
1187
+					&& $isShared === false
1188
+					&& $opener === null
1189
+				) {
1190
+					// We haven't yet found our opener, but we have found another
1191
+					// scope opener which is the same type as us, and we don't
1192
+					// share openers, so we will never find one.
1193
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1194
+						echo str_repeat("\t", $depth);
1195
+						echo '* it was another token\'s opener, bailing *'.PHP_EOL;
1196
+					}
1197
+
1198
+					return $stackPtr;
1199
+				} else {
1200
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1201
+						echo str_repeat("\t", $depth);
1202
+						echo '* searching for opener *'.PHP_EOL;
1203
+					}
1204
+
1205
+					if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1206
+						$oldIgnore = $ignore;
1207
+						$ignore    = 0;
1208
+					}
1209
+
1210
+					// PHP has a max nesting level for functions. Stop before we hit that limit
1211
+					// because too many loops means we've run into trouble anyway.
1212
+					if ($depth > 50) {
1213
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1214
+							echo str_repeat("\t", $depth);
1215
+							echo '* reached maximum nesting level; aborting *'.PHP_EOL;
1216
+						}
1217
+
1218
+						throw new RuntimeException('Maximum nesting level reached; file could not be processed');
1219
+					}
1220
+
1221
+					$oldDepth = $depth;
1222
+					if ($isShared === true
1223
+						&& isset($this->scopeOpeners[$tokenType]['with'][$currType]) === true
1224
+					) {
1225
+						// Don't allow the depth to increment because this is
1226
+						// possibly not a true nesting if we are sharing our closer.
1227
+						// This can happen, for example, when a SWITCH has a large
1228
+						// number of CASE statements with the same shared BREAK.
1229
+						$depth--;
1230
+					}
1231
+
1232
+					$i     = self::recurseScopeMap($i, ($depth + 1), $ignore);
1233
+					$depth = $oldDepth;
1234
+
1235
+					if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1236
+						$ignore = $oldIgnore;
1237
+					}
1238
+				}//end if
1239
+			}//end if
1240
+
1241
+			if (isset($this->scopeOpeners[$currType]['start'][$tokenType]) === true
1242
+				&& $opener === null
1243
+			) {
1244
+				if ($tokenType === T_OPEN_CURLY_BRACKET) {
1245
+					if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true
1246
+						&& $i < $this->tokens[$stackPtr]['parenthesis_closer']
1247
+					) {
1248
+						// We found a curly brace inside the condition of the
1249
+						// current scope opener, so it must be a string offset.
1250
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
+							echo str_repeat("\t", $depth);
1252
+							echo '* ignoring curly brace inside condition *'.PHP_EOL;
1253
+						}
1254
+
1255
+						$ignore++;
1256
+					} else {
1257
+						// Make sure this is actually an opener and not a
1258
+						// string offset (e.g., $var{0}).
1259
+						for ($x = ($i - 1); $x > 0; $x--) {
1260
+							if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === true) {
1261
+								continue;
1262
+							} else {
1263
+								// If the first non-whitespace/comment token looks like this
1264
+								// brace is a string offset, or this brace is mid-way through
1265
+								// a new statement, it isn't a scope opener.
1266
+								$disallowed  = Util\Tokens::$assignmentTokens;
1267
+								$disallowed += [
1268
+									T_DOLLAR           => true,
1269
+									T_VARIABLE         => true,
1270
+									T_OBJECT_OPERATOR  => true,
1271
+									T_COMMA            => true,
1272
+									T_OPEN_PARENTHESIS => true,
1273
+								];
1274
+
1275
+								if (isset($disallowed[$this->tokens[$x]['code']]) === true) {
1276
+									if (PHP_CODESNIFFER_VERBOSITY > 1) {
1277
+										echo str_repeat("\t", $depth);
1278
+										echo '* ignoring curly brace *'.PHP_EOL;
1279
+									}
1280
+
1281
+									$ignore++;
1282
+								}
1283
+
1284
+								break;
1285
+							}//end if
1286
+						}//end for
1287
+					}//end if
1288
+				}//end if
1289
+
1290
+				if ($ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET) {
1291
+					// We found the opening scope token for $currType.
1292
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1293
+						$type = $this->tokens[$stackPtr]['type'];
1294
+						echo str_repeat("\t", $depth);
1295
+						echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1296
+					}
1297
+
1298
+					$opener = $i;
1299
+				}
1300
+			} else if ($tokenType === T_OPEN_PARENTHESIS) {
1301
+				if (isset($this->tokens[$i]['parenthesis_owner']) === true) {
1302
+					$owner = $this->tokens[$i]['parenthesis_owner'];
1303
+					if (isset(Util\Tokens::$scopeOpeners[$this->tokens[$owner]['code']]) === true
1304
+						&& isset($this->tokens[$i]['parenthesis_closer']) === true
1305
+					) {
1306
+						// If we get into here, then we opened a parenthesis for
1307
+						// a scope (eg. an if or else if) so we need to update the
1308
+						// start of the line so that when we check to see
1309
+						// if the closing parenthesis is more than 3 lines away from
1310
+						// the statement, we check from the closing parenthesis.
1311
+						$startLine = $this->tokens[$this->tokens[$i]['parenthesis_closer']]['line'];
1312
+					}
1313
+				}
1314
+			} else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) {
1315
+				// We opened something that we don't have a scope opener for.
1316
+				// Examples of this are curly brackets for string offsets etc.
1317
+				// We want to ignore this so that we don't have an invalid scope
1318
+				// map.
1319
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1320
+					echo str_repeat("\t", $depth);
1321
+					echo '* ignoring curly brace *'.PHP_EOL;
1322
+				}
1323
+
1324
+				$ignore++;
1325
+			} else if ($tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0) {
1326
+				// We found the end token for the opener we were ignoring.
1327
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1328
+					echo str_repeat("\t", $depth);
1329
+					echo '* finished ignoring curly brace *'.PHP_EOL;
1330
+				}
1331
+
1332
+				$ignore--;
1333
+			} else if ($opener === null
1334
+				&& isset($this->scopeOpeners[$currType]) === true
1335
+			) {
1336
+				// If we still haven't found the opener after 30 lines,
1337
+				// we're not going to find it, unless we know it requires
1338
+				// an opener (in which case we better keep looking) or the last
1339
+				// token was empty (in which case we'll just confirm there is
1340
+				// more code in this file and not just a big comment).
1341
+				if ($this->tokens[$i]['line'] >= ($startLine + 30)
1342
+					&& isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false
1343
+				) {
1344
+					if ($this->scopeOpeners[$currType]['strict'] === true) {
1345
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1346
+							$type  = $this->tokens[$stackPtr]['type'];
1347
+							$lines = ($this->tokens[$i]['line'] - $startLine);
1348
+							echo str_repeat("\t", $depth);
1349
+							echo "=> Still looking for $stackPtr:$type scope opener after $lines lines".PHP_EOL;
1350
+						}
1351
+					} else {
1352
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1353
+							$type = $this->tokens[$stackPtr]['type'];
1354
+							echo str_repeat("\t", $depth);
1355
+							echo "=> Couldn't find scope opener for $stackPtr:$type, bailing".PHP_EOL;
1356
+						}
1357
+
1358
+						return $stackPtr;
1359
+					}
1360
+				}
1361
+			} else if ($opener !== null
1362
+				&& $tokenType !== T_BREAK
1363
+				&& isset($this->endScopeTokens[$tokenType]) === true
1364
+			) {
1365
+				if (isset($this->tokens[$i]['scope_condition']) === false) {
1366
+					if ($ignore > 0) {
1367
+						// We found the end token for the opener we were ignoring.
1368
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1369
+							echo str_repeat("\t", $depth);
1370
+							echo '* finished ignoring curly brace *'.PHP_EOL;
1371
+						}
1372
+
1373
+						$ignore--;
1374
+					} else {
1375
+						// We found a token that closes the scope but it doesn't
1376
+						// have a condition, so it belongs to another token and
1377
+						// our token doesn't have a closer, so pretend this is
1378
+						// the closer.
1379
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1380
+							$type = $this->tokens[$stackPtr]['type'];
1381
+							echo str_repeat("\t", $depth);
1382
+							echo "=> Found (unexpected) scope closer for $stackPtr:$type".PHP_EOL;
1383
+						}
1384
+
1385
+						foreach ([$stackPtr, $opener] as $token) {
1386
+							$this->tokens[$token]['scope_condition'] = $stackPtr;
1387
+							$this->tokens[$token]['scope_opener']    = $opener;
1388
+							$this->tokens[$token]['scope_closer']    = $i;
1389
+						}
1390
+
1391
+						return ($i - 1);
1392
+					}//end if
1393
+				}//end if
1394
+			}//end if
1395
+		}//end for
1396
+
1397
+		return $stackPtr;
1398
+
1399
+	}//end recurseScopeMap()
1400
+
1401
+
1402
+	/**
1403
+	 * Constructs the level map.
1404
+	 *
1405
+	 * The level map adds a 'level' index to each token which indicates the
1406
+	 * depth that a token within a set of scope blocks. It also adds a
1407
+	 * 'conditions' index which is an array of the scope conditions that opened
1408
+	 * each of the scopes - position 0 being the first scope opener.
1409
+	 *
1410
+	 * @return void
1411
+	 */
1412
+	private function createLevelMap()
1413
+	{
1414
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
1415
+			echo "\t*** START LEVEL MAP ***".PHP_EOL;
1416
+		}
1417
+
1418
+		$this->numTokens = count($this->tokens);
1419
+		$level           = 0;
1420
+		$conditions      = [];
1421
+		$lastOpener      = null;
1422
+		$openers         = [];
1423
+
1424
+		for ($i = 0; $i < $this->numTokens; $i++) {
1425
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
1426
+				$type = $this->tokens[$i]['type'];
1427
+				$line = $this->tokens[$i]['line'];
1428
+				$len  = $this->tokens[$i]['length'];
1429
+				$col  = $this->tokens[$i]['column'];
1430
+
1431
+				$content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1432
+
1433
+				echo str_repeat("\t", ($level + 1));
1434
+				echo "Process token $i on line $line [col:$col;len:$len;lvl:$level;";
1435
+				if (empty($conditions) !== true) {
1436
+					$condString = 'conds;';
1437
+					foreach ($conditions as $condition) {
1438
+						$condString .= Util\Tokens::tokenName($condition).',';
1439
+					}
1440
+
1441
+					echo rtrim($condString, ',').';';
1442
+				}
1443
+
1444
+				echo "]: $type => $content".PHP_EOL;
1445
+			}//end if
1446
+
1447
+			$this->tokens[$i]['level']      = $level;
1448
+			$this->tokens[$i]['conditions'] = $conditions;
1449
+
1450
+			if (isset($this->tokens[$i]['scope_condition']) === true) {
1451
+				// Check to see if this token opened the scope.
1452
+				if ($this->tokens[$i]['scope_opener'] === $i) {
1453
+					$stackPtr = $this->tokens[$i]['scope_condition'];
1454
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1455
+						$type = $this->tokens[$stackPtr]['type'];
1456
+						echo str_repeat("\t", ($level + 1));
1457
+						echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1458
+					}
1459
+
1460
+					$stackPtr = $this->tokens[$i]['scope_condition'];
1461
+
1462
+					// If we find a scope opener that has a shared closer,
1463
+					// then we need to go back over the condition map that we
1464
+					// just created and fix ourselves as we just added some
1465
+					// conditions where there was none. This happens for T_CASE
1466
+					// statements that are using the same break statement.
1467
+					if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $this->tokens[$i]['scope_closer']) {
1468
+						// This opener shares its closer with the previous opener,
1469
+						// but we still need to check if the two openers share their
1470
+						// closer with each other directly (like CASE and DEFAULT)
1471
+						// or if they are just sharing because one doesn't have a
1472
+						// closer (like CASE with no BREAK using a SWITCHes closer).
1473
+						$thisType = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1474
+						$opener   = $this->tokens[$lastOpener]['scope_condition'];
1475
+
1476
+						$isShared = isset($this->scopeOpeners[$thisType]['with'][$this->tokens[$opener]['code']]);
1477
+
1478
+						reset($this->scopeOpeners[$thisType]['end']);
1479
+						reset($this->scopeOpeners[$this->tokens[$opener]['code']]['end']);
1480
+						$sameEnd = (current($this->scopeOpeners[$thisType]['end']) === current($this->scopeOpeners[$this->tokens[$opener]['code']]['end']));
1481
+
1482
+						if ($isShared === true && $sameEnd === true) {
1483
+							$badToken = $opener;
1484
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1485
+								$type = $this->tokens[$badToken]['type'];
1486
+								echo str_repeat("\t", ($level + 1));
1487
+								echo "* shared closer, cleaning up $badToken:$type *".PHP_EOL;
1488
+							}
1489
+
1490
+							for ($x = $this->tokens[$i]['scope_condition']; $x <= $i; $x++) {
1491
+								$oldConditions = $this->tokens[$x]['conditions'];
1492
+								$oldLevel      = $this->tokens[$x]['level'];
1493
+								$this->tokens[$x]['level']--;
1494
+								unset($this->tokens[$x]['conditions'][$badToken]);
1495
+								if (PHP_CODESNIFFER_VERBOSITY > 1) {
1496
+									$type     = $this->tokens[$x]['type'];
1497
+									$oldConds = '';
1498
+									foreach ($oldConditions as $condition) {
1499
+										$oldConds .= Util\Tokens::tokenName($condition).',';
1500
+									}
1501
+
1502
+									$oldConds = rtrim($oldConds, ',');
1503
+
1504
+									$newConds = '';
1505
+									foreach ($this->tokens[$x]['conditions'] as $condition) {
1506
+										$newConds .= Util\Tokens::tokenName($condition).',';
1507
+									}
1508
+
1509
+									$newConds = rtrim($newConds, ',');
1510
+
1511
+									$newLevel = $this->tokens[$x]['level'];
1512
+									echo str_repeat("\t", ($level + 1));
1513
+									echo "* cleaned $x:$type *".PHP_EOL;
1514
+									echo str_repeat("\t", ($level + 2));
1515
+									echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1516
+									echo str_repeat("\t", ($level + 2));
1517
+									echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1518
+								}//end if
1519
+							}//end for
1520
+
1521
+							unset($conditions[$badToken]);
1522
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1523
+								$type = $this->tokens[$badToken]['type'];
1524
+								echo str_repeat("\t", ($level + 1));
1525
+								echo "* token $badToken:$type removed from conditions array *".PHP_EOL;
1526
+							}
1527
+
1528
+							unset($openers[$lastOpener]);
1529
+
1530
+							$level--;
1531
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1532
+								echo str_repeat("\t", ($level + 2));
1533
+								echo '* level decreased *'.PHP_EOL;
1534
+							}
1535
+						}//end if
1536
+					}//end if
1537
+
1538
+					$level++;
1539
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1540
+						echo str_repeat("\t", ($level + 1));
1541
+						echo '* level increased *'.PHP_EOL;
1542
+					}
1543
+
1544
+					$conditions[$stackPtr] = $this->tokens[$stackPtr]['code'];
1545
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1546
+						$type = $this->tokens[$stackPtr]['type'];
1547
+						echo str_repeat("\t", ($level + 1));
1548
+						echo "* token $stackPtr:$type added to conditions array *".PHP_EOL;
1549
+					}
1550
+
1551
+					$lastOpener = $this->tokens[$i]['scope_opener'];
1552
+					if ($lastOpener !== null) {
1553
+						$openers[$lastOpener] = $lastOpener;
1554
+					}
1555
+				} else if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $i) {
1556
+					foreach (array_reverse($openers) as $opener) {
1557
+						if ($this->tokens[$opener]['scope_closer'] === $i) {
1558
+							$oldOpener = array_pop($openers);
1559
+							if (empty($openers) === false) {
1560
+								$lastOpener           = array_pop($openers);
1561
+								$openers[$lastOpener] = $lastOpener;
1562
+							} else {
1563
+								$lastOpener = null;
1564
+							}
1565
+
1566
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1567
+								$type = $this->tokens[$oldOpener]['type'];
1568
+								echo str_repeat("\t", ($level + 1));
1569
+								echo "=> Found scope closer for $oldOpener:$type".PHP_EOL;
1570
+							}
1571
+
1572
+							$oldCondition = array_pop($conditions);
1573
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1574
+								echo str_repeat("\t", ($level + 1));
1575
+								echo '* token '.Util\Tokens::tokenName($oldCondition).' removed from conditions array *'.PHP_EOL;
1576
+							}
1577
+
1578
+							// Make sure this closer actually belongs to us.
1579
+							// Either the condition also has to think this is the
1580
+							// closer, or it has to allow sharing with us.
1581
+							$condition = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1582
+							if ($condition !== $oldCondition) {
1583
+								if (isset($this->scopeOpeners[$oldCondition]['with'][$condition]) === false) {
1584
+									$badToken = $this->tokens[$oldOpener]['scope_condition'];
1585
+
1586
+									if (PHP_CODESNIFFER_VERBOSITY > 1) {
1587
+										$type = Util\Tokens::tokenName($oldCondition);
1588
+										echo str_repeat("\t", ($level + 1));
1589
+										echo "* scope closer was bad, cleaning up $badToken:$type *".PHP_EOL;
1590
+									}
1591
+
1592
+									for ($x = ($oldOpener + 1); $x <= $i; $x++) {
1593
+										$oldConditions = $this->tokens[$x]['conditions'];
1594
+										$oldLevel      = $this->tokens[$x]['level'];
1595
+										$this->tokens[$x]['level']--;
1596
+										unset($this->tokens[$x]['conditions'][$badToken]);
1597
+										if (PHP_CODESNIFFER_VERBOSITY > 1) {
1598
+											$type     = $this->tokens[$x]['type'];
1599
+											$oldConds = '';
1600
+											foreach ($oldConditions as $condition) {
1601
+												$oldConds .= Util\Tokens::tokenName($condition).',';
1602
+											}
1603
+
1604
+											$oldConds = rtrim($oldConds, ',');
1605
+
1606
+											$newConds = '';
1607
+											foreach ($this->tokens[$x]['conditions'] as $condition) {
1608
+												$newConds .= Util\Tokens::tokenName($condition).',';
1609
+											}
1610
+
1611
+											$newConds = rtrim($newConds, ',');
1612
+
1613
+											$newLevel = $this->tokens[$x]['level'];
1614
+											echo str_repeat("\t", ($level + 1));
1615
+											echo "* cleaned $x:$type *".PHP_EOL;
1616
+											echo str_repeat("\t", ($level + 2));
1617
+											echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1618
+											echo str_repeat("\t", ($level + 2));
1619
+											echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1620
+										}//end if
1621
+									}//end for
1622
+								}//end if
1623
+							}//end if
1624
+
1625
+							$level--;
1626
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1627
+								echo str_repeat("\t", ($level + 2));
1628
+								echo '* level decreased *'.PHP_EOL;
1629
+							}
1630
+
1631
+							$this->tokens[$i]['level']      = $level;
1632
+							$this->tokens[$i]['conditions'] = $conditions;
1633
+						}//end if
1634
+					}//end foreach
1635
+				}//end if
1636
+			}//end if
1637
+		}//end for
1638
+
1639
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
1640
+			echo "\t*** END LEVEL MAP ***".PHP_EOL;
1641
+		}
1642
+
1643
+	}//end createLevelMap()
1644 1644
 
1645 1645
 
1646 1646
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -722,60 +722,60 @@
 block discarded – undo
722 722
             */
723 723
 
724 724
             switch ($this->tokens[$i]['code']) {
725
-            case T_OPEN_SQUARE_BRACKET:
726
-                $squareOpeners[] = $i;
727
-
728
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
729
-                    echo str_repeat("\t", count($squareOpeners));
730
-                    echo str_repeat("\t", count($curlyOpeners));
731
-                    echo "=> Found square bracket opener at $i".PHP_EOL;
732
-                }
733
-                break;
734
-            case T_OPEN_CURLY_BRACKET:
735
-                if (isset($this->tokens[$i]['scope_closer']) === false) {
736
-                    $curlyOpeners[] = $i;
737
-
738
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
739
-                        echo str_repeat("\t", count($squareOpeners));
740
-                        echo str_repeat("\t", count($curlyOpeners));
741
-                        echo "=> Found curly bracket opener at $i".PHP_EOL;
742
-                    }
743
-                }
744
-                break;
745
-            case T_CLOSE_SQUARE_BRACKET:
746
-                if (empty($squareOpeners) === false) {
747
-                    $opener = array_pop($squareOpeners);
748
-                    $this->tokens[$i]['bracket_opener']      = $opener;
749
-                    $this->tokens[$i]['bracket_closer']      = $i;
750
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
751
-                    $this->tokens[$opener]['bracket_closer'] = $i;
752
-
753
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
754
-                        echo str_repeat("\t", count($squareOpeners));
755
-                        echo str_repeat("\t", count($curlyOpeners));
756
-                        echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
757
-                    }
758
-                }
759
-                break;
760
-            case T_CLOSE_CURLY_BRACKET:
761
-                if (empty($curlyOpeners) === false
762
-                    && isset($this->tokens[$i]['scope_opener']) === false
763
-                ) {
764
-                    $opener = array_pop($curlyOpeners);
765
-                    $this->tokens[$i]['bracket_opener']      = $opener;
766
-                    $this->tokens[$i]['bracket_closer']      = $i;
767
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
768
-                    $this->tokens[$opener]['bracket_closer'] = $i;
769
-
770
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
771
-                        echo str_repeat("\t", count($squareOpeners));
772
-                        echo str_repeat("\t", count($curlyOpeners));
773
-                        echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
774
-                    }
775
-                }
776
-                break;
777
-            default:
778
-                continue 2;
725
+            	case T_OPEN_SQUARE_BRACKET:
726
+                	$squareOpeners[] = $i;
727
+
728
+                	if (PHP_CODESNIFFER_VERBOSITY > 1) {
729
+                    	echo str_repeat("\t", count($squareOpeners));
730
+                    	echo str_repeat("\t", count($curlyOpeners));
731
+                    	echo "=> Found square bracket opener at $i".PHP_EOL;
732
+                	}
733
+                	break;
734
+            	case T_OPEN_CURLY_BRACKET:
735
+                	if (isset($this->tokens[$i]['scope_closer']) === false) {
736
+                    	$curlyOpeners[] = $i;
737
+
738
+                    	if (PHP_CODESNIFFER_VERBOSITY > 1) {
739
+                        	echo str_repeat("\t", count($squareOpeners));
740
+                        	echo str_repeat("\t", count($curlyOpeners));
741
+                        	echo "=> Found curly bracket opener at $i".PHP_EOL;
742
+                    	}
743
+                	}
744
+                	break;
745
+            	case T_CLOSE_SQUARE_BRACKET:
746
+                	if (empty($squareOpeners) === false) {
747
+                    	$opener = array_pop($squareOpeners);
748
+                    	$this->tokens[$i]['bracket_opener']      = $opener;
749
+                    	$this->tokens[$i]['bracket_closer']      = $i;
750
+                    	$this->tokens[$opener]['bracket_opener'] = $opener;
751
+                    	$this->tokens[$opener]['bracket_closer'] = $i;
752
+
753
+                    	if (PHP_CODESNIFFER_VERBOSITY > 1) {
754
+                        	echo str_repeat("\t", count($squareOpeners));
755
+                        	echo str_repeat("\t", count($curlyOpeners));
756
+                        	echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
757
+                    	}
758
+                	}
759
+                	break;
760
+            	case T_CLOSE_CURLY_BRACKET:
761
+                	if (empty($curlyOpeners) === false
762
+                    	&& isset($this->tokens[$i]['scope_opener']) === false
763
+                	) {
764
+                    	$opener = array_pop($curlyOpeners);
765
+                    	$this->tokens[$i]['bracket_opener']      = $opener;
766
+                    	$this->tokens[$i]['bracket_closer']      = $i;
767
+                    	$this->tokens[$opener]['bracket_opener'] = $opener;
768
+                    	$this->tokens[$opener]['bracket_closer'] = $i;
769
+
770
+                    	if (PHP_CODESNIFFER_VERBOSITY > 1) {
771
+                        	echo str_repeat("\t", count($squareOpeners));
772
+                        	echo str_repeat("\t", count($curlyOpeners));
773
+                        	echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
774
+                    	}
775
+                	}
776
+                	break;
777
+            	default:
778
+                	continue 2;
779 779
             }//end switch
780 780
         }//end for
781 781
 
Please login to merge, or discard this patch.
Spacing   +649 added lines, -649 removed lines patch added patch discarded remove patch
@@ -27,14 +27,14 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @var string
29 29
      */
30
-    protected $eolChar = [];
30
+    protected $eolChar = [ ];
31 31
 
32 32
     /**
33 33
      * A token-based representation of the content.
34 34
      *
35 35
      * @var array
36 36
      */
37
-    protected $tokens = [];
37
+    protected $tokens = [ ];
38 38
 
39 39
     /**
40 40
      * The number of tokens in the tokens array.
@@ -48,28 +48,28 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @var array
50 50
      */
51
-    public $scopeOpeners = [];
51
+    public $scopeOpeners = [ ];
52 52
 
53 53
     /**
54 54
      * A list of tokens that end the scope.
55 55
      *
56 56
      * @var array
57 57
      */
58
-    public $endScopeTokens = [];
58
+    public $endScopeTokens = [ ];
59 59
 
60 60
     /**
61 61
      * Known lengths of tokens.
62 62
      *
63 63
      * @var array<int, int>
64 64
      */
65
-    public $knownLengths = [];
65
+    public $knownLengths = [ ];
66 66
 
67 67
     /**
68 68
      * A list of lines being ignored due to error suppression comments.
69 69
      *
70 70
      * @var array
71 71
      */
72
-    public $ignoredLines = [];
72
+    public $ignoredLines = [ ];
73 73
 
74 74
 
75 75
     /**
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
      * @return void
83 83
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
84 84
      */
85
-    public function __construct($content, $config, $eolChar='\n')
85
+    public function __construct( $content, $config, $eolChar = '\n' )
86 86
     {
87 87
         $this->eolChar = $eolChar;
88 88
 
89 89
         $this->config = $config;
90
-        $this->tokens = $this->tokenize($content);
90
+        $this->tokens = $this->tokenize( $content );
91 91
 
92
-        if ($config === null) {
92
+        if ( $config === null ) {
93 93
             return;
94 94
         }
95 95
 
@@ -113,14 +113,14 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @return boolean
115 115
      */
116
-    protected function isMinifiedContent($content, $eolChar='\n')
116
+    protected function isMinifiedContent( $content, $eolChar = '\n' )
117 117
     {
118 118
         // Minified files often have a very large number of characters per line
119 119
         // and cause issues when tokenizing.
120
-        $numChars = strlen($content);
121
-        $numLines = (substr_count($content, $eolChar) + 1);
122
-        $average  = ($numChars / $numLines);
123
-        if ($average > 100) {
120
+        $numChars = strlen( $content );
121
+        $numLines = ( substr_count( $content, $eolChar ) + 1 );
122
+        $average  = ( $numChars / $numLines );
123
+        if ( $average > 100 ) {
124 124
             return true;
125 125
         }
126 126
 
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      *
149 149
      * @return array
150 150
      */
151
-    abstract protected function tokenize($string);
151
+    abstract protected function tokenize( $string );
152 152
 
153 153
 
154 154
     /**
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
     {
172 172
         $currColumn = 1;
173 173
         $lineNumber = 1;
174
-        $eolLen     = strlen($this->eolChar);
174
+        $eolLen     = strlen( $this->eolChar );
175 175
         $ignoring   = null;
176
-        $inTests    = defined('PHP_CODESNIFFER_IN_TESTS');
176
+        $inTests    = defined( 'PHP_CODESNIFFER_IN_TESTS' );
177 177
 
178 178
         $checkEncoding = false;
179
-        if (function_exists('iconv_strlen') === true) {
179
+        if ( function_exists( 'iconv_strlen' ) === true ) {
180 180
             $checkEncoding = true;
181 181
         }
182 182
 
@@ -197,126 +197,126 @@  discard block
 block discarded – undo
197 197
             T_INLINE_HTML              => true,
198 198
         ];
199 199
 
200
-        $this->numTokens = count($this->tokens);
201
-        for ($i = 0; $i < $this->numTokens; $i++) {
202
-            $this->tokens[$i]['line']   = $lineNumber;
203
-            $this->tokens[$i]['column'] = $currColumn;
200
+        $this->numTokens = count( $this->tokens );
201
+        for ( $i = 0; $i < $this->numTokens; $i++ ) {
202
+            $this->tokens[ $i ][ 'line' ]   = $lineNumber;
203
+            $this->tokens[ $i ][ 'column' ] = $currColumn;
204 204
 
205
-            if (isset($this->knownLengths[$this->tokens[$i]['code']]) === true) {
205
+            if ( isset( $this->knownLengths[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
206 206
                 // There are no tabs in the tokens we know the length of.
207
-                $length      = $this->knownLengths[$this->tokens[$i]['code']];
207
+                $length      = $this->knownLengths[ $this->tokens[ $i ][ 'code' ] ];
208 208
                 $currColumn += $length;
209
-            } else if ($tabWidth === 0
210
-                || isset($tokensWithTabs[$this->tokens[$i]['code']]) === false
211
-                || strpos($this->tokens[$i]['content'], "\t") === false
209
+            } else if ( $tabWidth === 0
210
+                || isset( $tokensWithTabs[ $this->tokens[ $i ][ 'code' ] ] ) === false
211
+                || strpos( $this->tokens[ $i ][ 'content' ], "\t" ) === false
212 212
             ) {
213 213
                 // There are no tabs in this content, or we aren't replacing them.
214
-                if ($checkEncoding === true) {
214
+                if ( $checkEncoding === true ) {
215 215
                     // Not using the default encoding, so take a bit more care.
216 216
                     $oldLevel = error_reporting();
217
-                    error_reporting(0);
218
-                    $length = iconv_strlen($this->tokens[$i]['content'], $encoding);
219
-                    error_reporting($oldLevel);
217
+                    error_reporting( 0 );
218
+                    $length = iconv_strlen( $this->tokens[ $i ][ 'content' ], $encoding );
219
+                    error_reporting( $oldLevel );
220 220
 
221
-                    if ($length === false) {
221
+                    if ( $length === false ) {
222 222
                         // String contained invalid characters, so revert to default.
223
-                        $length = strlen($this->tokens[$i]['content']);
223
+                        $length = strlen( $this->tokens[ $i ][ 'content' ] );
224 224
                     }
225 225
                 } else {
226
-                    $length = strlen($this->tokens[$i]['content']);
226
+                    $length = strlen( $this->tokens[ $i ][ 'content' ] );
227 227
                 }
228 228
 
229 229
                 $currColumn += $length;
230 230
             } else {
231
-                $this->replaceTabsInToken($this->tokens[$i]);
232
-                $length      = $this->tokens[$i]['length'];
231
+                $this->replaceTabsInToken( $this->tokens[ $i ] );
232
+                $length      = $this->tokens[ $i ][ 'length' ];
233 233
                 $currColumn += $length;
234 234
             }//end if
235 235
 
236
-            $this->tokens[$i]['length'] = $length;
236
+            $this->tokens[ $i ][ 'length' ] = $length;
237 237
 
238
-            if (isset($this->knownLengths[$this->tokens[$i]['code']]) === false
239
-                && strpos($this->tokens[$i]['content'], $this->eolChar) !== false
238
+            if ( isset( $this->knownLengths[ $this->tokens[ $i ][ 'code' ] ] ) === false
239
+                && strpos( $this->tokens[ $i ][ 'content' ], $this->eolChar ) !== false
240 240
             ) {
241 241
                 $lineNumber++;
242 242
                 $currColumn = 1;
243 243
 
244 244
                 // Newline chars are not counted in the token length.
245
-                $this->tokens[$i]['length'] -= $eolLen;
245
+                $this->tokens[ $i ][ 'length' ] -= $eolLen;
246 246
             }
247 247
 
248
-            if ($this->tokens[$i]['code'] === T_COMMENT
249
-                || $this->tokens[$i]['code'] === T_DOC_COMMENT_STRING
250
-                || $this->tokens[$i]['code'] === T_DOC_COMMENT_TAG
251
-                || ($inTests === true && $this->tokens[$i]['code'] === T_INLINE_HTML)
248
+            if ( $this->tokens[ $i ][ 'code' ] === T_COMMENT
249
+                || $this->tokens[ $i ][ 'code' ] === T_DOC_COMMENT_STRING
250
+                || $this->tokens[ $i ][ 'code' ] === T_DOC_COMMENT_TAG
251
+                || ( $inTests === true && $this->tokens[ $i ][ 'code' ] === T_INLINE_HTML )
252 252
             ) {
253
-                $commentText      = ltrim($this->tokens[$i]['content'], " \t/*");
254
-                $commentText      = rtrim($commentText, " */\t\r\n");
255
-                $commentTextLower = strtolower($commentText);
256
-                if (strpos($commentText, '@codingStandards') !== false) {
253
+                $commentText      = ltrim( $this->tokens[ $i ][ 'content' ], " \t/*" );
254
+                $commentText      = rtrim( $commentText, " */\t\r\n" );
255
+                $commentTextLower = strtolower( $commentText );
256
+                if ( strpos( $commentText, '@codingStandards' ) !== false ) {
257 257
                     // If this comment is the only thing on the line, it tells us
258 258
                     // to ignore the following line. If the line contains other content
259 259
                     // then we are just ignoring this one single line.
260 260
                     $ownLine = false;
261
-                    if ($i > 0) {
262
-                        for ($prev = ($i - 1); $prev >= 0; $prev--) {
263
-                            if ($this->tokens[$prev]['code'] === T_WHITESPACE) {
261
+                    if ( $i > 0 ) {
262
+                        for ( $prev = ( $i - 1 ); $prev >= 0; $prev-- ) {
263
+                            if ( $this->tokens[ $prev ][ 'code' ] === T_WHITESPACE ) {
264 264
                                 continue;
265 265
                             }
266 266
 
267 267
                             break;
268 268
                         }
269 269
 
270
-                        if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
270
+                        if ( $this->tokens[ $prev ][ 'line' ] !== $this->tokens[ $i ][ 'line' ] ) {
271 271
                             $ownLine = true;
272 272
                         }
273 273
                     }
274 274
 
275
-                    if ($ignoring === null
276
-                        && strpos($commentText, '@codingStandardsIgnoreStart') !== false
275
+                    if ( $ignoring === null
276
+                        && strpos( $commentText, '@codingStandardsIgnoreStart' ) !== false
277 277
                     ) {
278
-                        $ignoring = ['.all' => true];
279
-                        if ($ownLine === true) {
280
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
278
+                        $ignoring = [ '.all' => true ];
279
+                        if ( $ownLine === true ) {
280
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoring;
281 281
                         }
282
-                    } else if ($ignoring !== null
283
-                        && strpos($commentText, '@codingStandardsIgnoreEnd') !== false
282
+                    } else if ( $ignoring !== null
283
+                        && strpos( $commentText, '@codingStandardsIgnoreEnd' ) !== false
284 284
                     ) {
285
-                        if ($ownLine === true) {
286
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
285
+                        if ( $ownLine === true ) {
286
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = [ '.all' => true ];
287 287
                         } else {
288
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
288
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoring;
289 289
                         }
290 290
 
291 291
                         $ignoring = null;
292
-                    } else if ($ignoring === null
293
-                        && strpos($commentText, '@codingStandardsIgnoreLine') !== false
292
+                    } else if ( $ignoring === null
293
+                        && strpos( $commentText, '@codingStandardsIgnoreLine' ) !== false
294 294
                     ) {
295
-                        $ignoring = ['.all' => true];
296
-                        if ($ownLine === true) {
297
-                            $this->ignoredLines[$this->tokens[$i]['line']]       = $ignoring;
298
-                            $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoring;
295
+                        $ignoring = [ '.all' => true ];
296
+                        if ( $ownLine === true ) {
297
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ]       = $ignoring;
298
+                            $this->ignoredLines[ ( $this->tokens[ $i ][ 'line' ] + 1 ) ] = $ignoring;
299 299
                         } else {
300
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
300
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoring;
301 301
                         }
302 302
 
303 303
                         $ignoring = null;
304 304
                     }//end if
305
-                } else if (substr($commentTextLower, 0, 6) === 'phpcs:'
306
-                    || substr($commentTextLower, 0, 7) === '@phpcs:'
305
+                } else if ( substr( $commentTextLower, 0, 6 ) === 'phpcs:'
306
+                    || substr( $commentTextLower, 0, 7 ) === '@phpcs:'
307 307
                 ) {
308 308
                     // If the @phpcs: syntax is being used, strip the @ to make
309 309
                     // comparisons easier.
310
-                    if ($commentText[0] === '@') {
311
-                        $commentText      = substr($commentText, 1);
312
-                        $commentTextLower = strtolower($commentText);
310
+                    if ( $commentText[ 0 ] === '@' ) {
311
+                        $commentText      = substr( $commentText, 1 );
312
+                        $commentTextLower = strtolower( $commentText );
313 313
                     }
314 314
 
315 315
                     // If there is a comment on the end, strip it off.
316
-                    $commentStart = strpos($commentTextLower, ' --');
317
-                    if ($commentStart !== false) {
318
-                        $commentText      = substr($commentText, 0, $commentStart);
319
-                        $commentTextLower = strtolower($commentText);
316
+                    $commentStart = strpos( $commentTextLower, ' --' );
317
+                    if ( $commentStart !== false ) {
318
+                        $commentText      = substr( $commentText, 0, $commentStart );
319
+                        $commentTextLower = strtolower( $commentText );
320 320
                     }
321 321
 
322 322
                     // If this comment is the only thing on the line, it tells us
@@ -324,23 +324,23 @@  discard block
 block discarded – undo
324 324
                     // then we are just ignoring this one single line.
325 325
                     $lineHasOtherContent = false;
326 326
                     $lineHasOtherTokens  = false;
327
-                    if ($i > 0) {
328
-                        for ($prev = ($i - 1); $prev > 0; $prev--) {
329
-                            if ($this->tokens[$prev]['line'] !== $this->tokens[$i]['line']) {
327
+                    if ( $i > 0 ) {
328
+                        for ( $prev = ( $i - 1 ); $prev > 0; $prev-- ) {
329
+                            if ( $this->tokens[ $prev ][ 'line' ] !== $this->tokens[ $i ][ 'line' ] ) {
330 330
                                 // Changed lines.
331 331
                                 break;
332 332
                             }
333 333
 
334
-                            if ($this->tokens[$prev]['code'] === T_WHITESPACE
335
-                                || ($this->tokens[$prev]['code'] === T_INLINE_HTML
336
-                                && trim($this->tokens[$prev]['content']) === '')
334
+                            if ( $this->tokens[ $prev ][ 'code' ] === T_WHITESPACE
335
+                                || ( $this->tokens[ $prev ][ 'code' ] === T_INLINE_HTML
336
+                                && trim( $this->tokens[ $prev ][ 'content' ] ) === '' )
337 337
                             ) {
338 338
                                 continue;
339 339
                             }
340 340
 
341 341
                             $lineHasOtherTokens = true;
342 342
 
343
-                            if ($this->tokens[$prev]['code'] === T_OPEN_TAG) {
343
+                            if ( $this->tokens[ $prev ][ 'code' ] === T_OPEN_TAG ) {
344 344
                                 continue;
345 345
                             }
346 346
 
@@ -349,33 +349,33 @@  discard block
 block discarded – undo
349 349
                         }//end for
350 350
 
351 351
                         $changedLines = false;
352
-                        for ($next = $i; $next < $this->numTokens; $next++) {
353
-                            if ($changedLines === true) {
352
+                        for ( $next = $i; $next < $this->numTokens; $next++ ) {
353
+                            if ( $changedLines === true ) {
354 354
                                 // Changed lines.
355 355
                                 break;
356 356
                             }
357 357
 
358
-                            if (isset($this->knownLengths[$this->tokens[$next]['code']]) === false
359
-                                && strpos($this->tokens[$next]['content'], $this->eolChar) !== false
358
+                            if ( isset( $this->knownLengths[ $this->tokens[ $next ][ 'code' ] ] ) === false
359
+                                && strpos( $this->tokens[ $next ][ 'content' ], $this->eolChar ) !== false
360 360
                             ) {
361 361
                                 // Last token on the current line.
362 362
                                 $changedLines = true;
363 363
                             }
364 364
 
365
-                            if ($next === $i) {
365
+                            if ( $next === $i ) {
366 366
                                 continue;
367 367
                             }
368 368
 
369
-                            if ($this->tokens[$next]['code'] === T_WHITESPACE
370
-                                || ($this->tokens[$next]['code'] === T_INLINE_HTML
371
-                                && trim($this->tokens[$next]['content']) === '')
369
+                            if ( $this->tokens[ $next ][ 'code' ] === T_WHITESPACE
370
+                                || ( $this->tokens[ $next ][ 'code' ] === T_INLINE_HTML
371
+                                && trim( $this->tokens[ $next ][ 'content' ] ) === '' )
372 372
                             ) {
373 373
                                 continue;
374 374
                             }
375 375
 
376 376
                             $lineHasOtherTokens = true;
377 377
 
378
-                            if ($this->tokens[$next]['code'] === T_CLOSE_TAG) {
378
+                            if ( $this->tokens[ $next ][ 'code' ] === T_CLOSE_TAG ) {
379 379
                                 continue;
380 380
                             }
381 381
 
@@ -384,178 +384,178 @@  discard block
 block discarded – undo
384 384
                         }//end for
385 385
                     }//end if
386 386
 
387
-                    if (substr($commentTextLower, 0, 9) === 'phpcs:set') {
387
+                    if ( substr( $commentTextLower, 0, 9 ) === 'phpcs:set' ) {
388 388
                         // Ignore standards for complete lines that change sniff settings.
389
-                        if ($lineHasOtherTokens === false) {
390
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
389
+                        if ( $lineHasOtherTokens === false ) {
390
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = [ '.all' => true ];
391 391
                         }
392 392
 
393 393
                         // Need to maintain case here, to get the correct sniff code.
394
-                        $parts = explode(' ', substr($commentText, 10));
395
-                        if (count($parts) >= 2) {
396
-                            $sniffParts = explode('.', $parts[0]);
397
-                            if (count($sniffParts) >= 3) {
398
-                                $this->tokens[$i]['sniffCode']          = array_shift($parts);
399
-                                $this->tokens[$i]['sniffProperty']      = array_shift($parts);
400
-                                $this->tokens[$i]['sniffPropertyValue'] = rtrim(implode(' ', $parts), " */\r\n");
394
+                        $parts = explode( ' ', substr( $commentText, 10 ) );
395
+                        if ( count( $parts ) >= 2 ) {
396
+                            $sniffParts = explode( '.', $parts[ 0 ] );
397
+                            if ( count( $sniffParts ) >= 3 ) {
398
+                                $this->tokens[ $i ][ 'sniffCode' ]          = array_shift( $parts );
399
+                                $this->tokens[ $i ][ 'sniffProperty' ]      = array_shift( $parts );
400
+                                $this->tokens[ $i ][ 'sniffPropertyValue' ] = rtrim( implode( ' ', $parts ), " */\r\n" );
401 401
                             }
402 402
                         }
403 403
 
404
-                        $this->tokens[$i]['code'] = T_PHPCS_SET;
405
-                        $this->tokens[$i]['type'] = 'T_PHPCS_SET';
406
-                    } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile') {
404
+                        $this->tokens[ $i ][ 'code' ] = T_PHPCS_SET;
405
+                        $this->tokens[ $i ][ 'type' ] = 'T_PHPCS_SET';
406
+                    } else if ( substr( $commentTextLower, 0, 16 ) === 'phpcs:ignorefile' ) {
407 407
                         // The whole file will be ignored, but at least set the correct token.
408
-                        $this->tokens[$i]['code'] = T_PHPCS_IGNORE_FILE;
409
-                        $this->tokens[$i]['type'] = 'T_PHPCS_IGNORE_FILE';
410
-                    } else if (substr($commentTextLower, 0, 13) === 'phpcs:disable') {
411
-                        if ($lineHasOtherContent === false) {
408
+                        $this->tokens[ $i ][ 'code' ] = T_PHPCS_IGNORE_FILE;
409
+                        $this->tokens[ $i ][ 'type' ] = 'T_PHPCS_IGNORE_FILE';
410
+                    } else if ( substr( $commentTextLower, 0, 13 ) === 'phpcs:disable' ) {
411
+                        if ( $lineHasOtherContent === false ) {
412 412
                             // Completely ignore the comment line.
413
-                            $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
413
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = [ '.all' => true ];
414 414
                         }
415 415
 
416
-                        if ($ignoring === null) {
417
-                            $ignoring = [];
416
+                        if ( $ignoring === null ) {
417
+                            $ignoring = [ ];
418 418
                         }
419 419
 
420
-                        $disabledSniffs = [];
420
+                        $disabledSniffs = [ ];
421 421
 
422
-                        $additionalText = substr($commentText, 14);
423
-                        if ($additionalText === false) {
424
-                            $ignoring = ['.all' => true];
422
+                        $additionalText = substr( $commentText, 14 );
423
+                        if ( $additionalText === false ) {
424
+                            $ignoring = [ '.all' => true ];
425 425
                         } else {
426
-                            $parts = explode(',', substr($commentText, 13));
427
-                            foreach ($parts as $sniffCode) {
428
-                                $sniffCode = trim($sniffCode);
429
-                                $disabledSniffs[$sniffCode] = true;
430
-                                $ignoring[$sniffCode]       = true;
426
+                            $parts = explode( ',', substr( $commentText, 13 ) );
427
+                            foreach ( $parts as $sniffCode ) {
428
+                                $sniffCode = trim( $sniffCode );
429
+                                $disabledSniffs[ $sniffCode ] = true;
430
+                                $ignoring[ $sniffCode ]       = true;
431 431
 
432 432
                                 // This newly disabled sniff might be disabling an existing
433 433
                                 // enabled exception that we are tracking.
434
-                                if (isset($ignoring['.except']) === true) {
435
-                                    foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
436
-                                        if ($ignoredSniffCode === $sniffCode
437
-                                            || strpos($ignoredSniffCode, $sniffCode.'.') === 0
434
+                                if ( isset( $ignoring[ '.except' ] ) === true ) {
435
+                                    foreach ( array_keys( $ignoring[ '.except' ] ) as $ignoredSniffCode ) {
436
+                                        if ( $ignoredSniffCode === $sniffCode
437
+                                            || strpos( $ignoredSniffCode, $sniffCode . '.' ) === 0
438 438
                                         ) {
439
-                                            unset($ignoring['.except'][$ignoredSniffCode]);
439
+                                            unset( $ignoring[ '.except' ][ $ignoredSniffCode ] );
440 440
                                         }
441 441
                                     }
442 442
 
443
-                                    if (empty($ignoring['.except']) === true) {
444
-                                        unset($ignoring['.except']);
443
+                                    if ( empty( $ignoring[ '.except' ] ) === true ) {
444
+                                        unset( $ignoring[ '.except' ] );
445 445
                                     }
446 446
                                 }
447 447
                             }//end foreach
448 448
                         }//end if
449 449
 
450
-                        $this->tokens[$i]['code']       = T_PHPCS_DISABLE;
451
-                        $this->tokens[$i]['type']       = 'T_PHPCS_DISABLE';
452
-                        $this->tokens[$i]['sniffCodes'] = $disabledSniffs;
453
-                    } else if (substr($commentTextLower, 0, 12) === 'phpcs:enable') {
454
-                        if ($ignoring !== null) {
455
-                            $enabledSniffs = [];
450
+                        $this->tokens[ $i ][ 'code' ]       = T_PHPCS_DISABLE;
451
+                        $this->tokens[ $i ][ 'type' ]       = 'T_PHPCS_DISABLE';
452
+                        $this->tokens[ $i ][ 'sniffCodes' ] = $disabledSniffs;
453
+                    } else if ( substr( $commentTextLower, 0, 12 ) === 'phpcs:enable' ) {
454
+                        if ( $ignoring !== null ) {
455
+                            $enabledSniffs = [ ];
456 456
 
457
-                            $additionalText = substr($commentText, 13);
458
-                            if ($additionalText === false) {
457
+                            $additionalText = substr( $commentText, 13 );
458
+                            if ( $additionalText === false ) {
459 459
                                 $ignoring = null;
460 460
                             } else {
461
-                                $parts = explode(',', substr($commentText, 13));
462
-                                foreach ($parts as $sniffCode) {
463
-                                    $sniffCode = trim($sniffCode);
464
-                                    $enabledSniffs[$sniffCode] = true;
461
+                                $parts = explode( ',', substr( $commentText, 13 ) );
462
+                                foreach ( $parts as $sniffCode ) {
463
+                                    $sniffCode = trim( $sniffCode );
464
+                                    $enabledSniffs[ $sniffCode ] = true;
465 465
 
466 466
                                     // This new enabled sniff might remove previously disabled
467 467
                                     // sniffs if it is actually a standard or category of sniffs.
468
-                                    foreach (array_keys($ignoring) as $ignoredSniffCode) {
469
-                                        if ($ignoredSniffCode === $sniffCode
470
-                                            || strpos($ignoredSniffCode, $sniffCode.'.') === 0
468
+                                    foreach ( array_keys( $ignoring ) as $ignoredSniffCode ) {
469
+                                        if ( $ignoredSniffCode === $sniffCode
470
+                                            || strpos( $ignoredSniffCode, $sniffCode . '.' ) === 0
471 471
                                         ) {
472
-                                            unset($ignoring[$ignoredSniffCode]);
472
+                                            unset( $ignoring[ $ignoredSniffCode ] );
473 473
                                         }
474 474
                                     }
475 475
 
476 476
                                     // This new enabled sniff might be able to clear up
477 477
                                     // previously enabled sniffs if it is actually a standard or
478 478
                                     // category of sniffs.
479
-                                    if (isset($ignoring['.except']) === true) {
480
-                                        foreach (array_keys($ignoring['.except']) as $ignoredSniffCode) {
481
-                                            if ($ignoredSniffCode === $sniffCode
482
-                                                || strpos($ignoredSniffCode, $sniffCode.'.') === 0
479
+                                    if ( isset( $ignoring[ '.except' ] ) === true ) {
480
+                                        foreach ( array_keys( $ignoring[ '.except' ] ) as $ignoredSniffCode ) {
481
+                                            if ( $ignoredSniffCode === $sniffCode
482
+                                                || strpos( $ignoredSniffCode, $sniffCode . '.' ) === 0
483 483
                                             ) {
484
-                                                unset($ignoring['.except'][$ignoredSniffCode]);
484
+                                                unset( $ignoring[ '.except' ][ $ignoredSniffCode ] );
485 485
                                             }
486 486
                                         }
487 487
                                     }
488 488
                                 }//end foreach
489 489
 
490
-                                if (empty($ignoring) === true) {
490
+                                if ( empty( $ignoring ) === true ) {
491 491
                                     $ignoring = null;
492 492
                                 } else {
493
-                                    if (isset($ignoring['.except']) === true) {
494
-                                        $ignoring['.except'] += $enabledSniffs;
493
+                                    if ( isset( $ignoring[ '.except' ] ) === true ) {
494
+                                        $ignoring[ '.except' ] += $enabledSniffs;
495 495
                                     } else {
496
-                                        $ignoring['.except'] = $enabledSniffs;
496
+                                        $ignoring[ '.except' ] = $enabledSniffs;
497 497
                                     }
498 498
                                 }
499 499
                             }//end if
500 500
 
501
-                            if ($lineHasOtherContent === false) {
501
+                            if ( $lineHasOtherContent === false ) {
502 502
                                 // Completely ignore the comment line.
503
-                                $this->ignoredLines[$this->tokens[$i]['line']] = ['.all' => true];
503
+                                $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = [ '.all' => true ];
504 504
                             } else {
505 505
                                 // The comment is on the same line as the code it is ignoring,
506 506
                                 // so respect the new ignore rules.
507
-                                $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
507
+                                $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoring;
508 508
                             }
509 509
 
510
-                            $this->tokens[$i]['sniffCodes'] = $enabledSniffs;
510
+                            $this->tokens[ $i ][ 'sniffCodes' ] = $enabledSniffs;
511 511
                         }//end if
512 512
 
513
-                        $this->tokens[$i]['code'] = T_PHPCS_ENABLE;
514
-                        $this->tokens[$i]['type'] = 'T_PHPCS_ENABLE';
515
-                    } else if (substr($commentTextLower, 0, 12) === 'phpcs:ignore') {
516
-                        $ignoreRules = [];
513
+                        $this->tokens[ $i ][ 'code' ] = T_PHPCS_ENABLE;
514
+                        $this->tokens[ $i ][ 'type' ] = 'T_PHPCS_ENABLE';
515
+                    } else if ( substr( $commentTextLower, 0, 12 ) === 'phpcs:ignore' ) {
516
+                        $ignoreRules = [ ];
517 517
 
518
-                        $additionalText = substr($commentText, 13);
519
-                        if ($additionalText === false) {
520
-                            $ignoreRules = ['.all' => true];
518
+                        $additionalText = substr( $commentText, 13 );
519
+                        if ( $additionalText === false ) {
520
+                            $ignoreRules = [ '.all' => true ];
521 521
                         } else {
522
-                            $parts = explode(',', substr($commentText, 13));
523
-                            foreach ($parts as $sniffCode) {
524
-                                $ignoreRules[trim($sniffCode)] = true;
522
+                            $parts = explode( ',', substr( $commentText, 13 ) );
523
+                            foreach ( $parts as $sniffCode ) {
524
+                                $ignoreRules[ trim( $sniffCode ) ] = true;
525 525
                             }
526 526
                         }
527 527
 
528
-                        $this->tokens[$i]['code']       = T_PHPCS_IGNORE;
529
-                        $this->tokens[$i]['type']       = 'T_PHPCS_IGNORE';
530
-                        $this->tokens[$i]['sniffCodes'] = $ignoreRules;
528
+                        $this->tokens[ $i ][ 'code' ]       = T_PHPCS_IGNORE;
529
+                        $this->tokens[ $i ][ 'type' ]       = 'T_PHPCS_IGNORE';
530
+                        $this->tokens[ $i ][ 'sniffCodes' ] = $ignoreRules;
531 531
 
532
-                        if ($ignoring !== null) {
532
+                        if ( $ignoring !== null ) {
533 533
                             $ignoreRules += $ignoring;
534 534
                         }
535 535
 
536
-                        if ($lineHasOtherContent === false) {
536
+                        if ( $lineHasOtherContent === false ) {
537 537
                             // Completely ignore the comment line, and set the following
538 538
                             // line to include the ignore rules we've set.
539
-                            $this->ignoredLines[$this->tokens[$i]['line']]       = ['.all' => true];
540
-                            $this->ignoredLines[($this->tokens[$i]['line'] + 1)] = $ignoreRules;
539
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ]       = [ '.all' => true ];
540
+                            $this->ignoredLines[ ( $this->tokens[ $i ][ 'line' ] + 1 ) ] = $ignoreRules;
541 541
                         } else {
542 542
                             // The comment is on the same line as the code it is ignoring,
543 543
                             // so respect the ignore rules it set.
544
-                            $this->ignoredLines[$this->tokens[$i]['line']] = $ignoreRules;
544
+                            $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoreRules;
545 545
                         }
546 546
                     }//end if
547 547
                 }//end if
548 548
             }//end if
549 549
 
550
-            if ($ignoring !== null && isset($this->ignoredLines[$this->tokens[$i]['line']]) === false) {
551
-                $this->ignoredLines[$this->tokens[$i]['line']] = $ignoring;
550
+            if ( $ignoring !== null && isset( $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] ) === false ) {
551
+                $this->ignoredLines[ $this->tokens[ $i ][ 'line' ] ] = $ignoring;
552 552
             }
553 553
         }//end for
554 554
 
555 555
         // If annotations are being ignored, we clear out all the ignore rules
556 556
         // but leave the annotations tokenized as normal.
557
-        if ($checkAnnotations === false) {
558
-            $this->ignoredLines = [];
557
+        if ( $checkAnnotations === false ) {
558
+            $this->ignoredLines = [ ];
559 559
         }
560 560
 
561 561
     }//end createPositionMap()
@@ -576,52 +576,52 @@  discard block
 block discarded – undo
576 576
      *
577 577
      * @return void
578 578
      */
579
-    public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null)
579
+    public function replaceTabsInToken( &$token, $prefix = ' ', $padding = ' ', $tabWidth = null )
580 580
     {
581 581
         $checkEncoding = false;
582
-        if (function_exists('iconv_strlen') === true) {
582
+        if ( function_exists( 'iconv_strlen' ) === true ) {
583 583
             $checkEncoding = true;
584 584
         }
585 585
 
586
-        $currColumn = $token['column'];
587
-        if ($tabWidth === null) {
586
+        $currColumn = $token[ 'column' ];
587
+        if ( $tabWidth === null ) {
588 588
             $tabWidth = $this->config->tabWidth;
589
-            if ($tabWidth === 0) {
589
+            if ( $tabWidth === 0 ) {
590 590
                 $tabWidth = 1;
591 591
             }
592 592
         }
593 593
 
594
-        if (rtrim($token['content'], "\t") === '') {
594
+        if ( rtrim( $token[ 'content' ], "\t" ) === '' ) {
595 595
             // String only contains tabs, so we can shortcut the process.
596
-            $numTabs = strlen($token['content']);
596
+            $numTabs = strlen( $token[ 'content' ] );
597 597
 
598
-            $firstTabSize = ($tabWidth - (($currColumn - 1) % $tabWidth));
599
-            $length       = ($firstTabSize + ($tabWidth * ($numTabs - 1)));
600
-            $newContent   = $prefix.str_repeat($padding, ($length - 1));
598
+            $firstTabSize = ( $tabWidth - ( ( $currColumn - 1 ) % $tabWidth ) );
599
+            $length       = ( $firstTabSize + ( $tabWidth * ( $numTabs - 1 ) ) );
600
+            $newContent   = $prefix . str_repeat( $padding, ( $length - 1 ) );
601 601
         } else {
602 602
             // We need to determine the length of each tab.
603
-            $tabs = explode("\t", $token['content']);
603
+            $tabs = explode( "\t", $token[ 'content' ] );
604 604
 
605
-            $numTabs    = (count($tabs) - 1);
605
+            $numTabs    = ( count( $tabs ) - 1 );
606 606
             $tabNum     = 0;
607 607
             $newContent = '';
608 608
             $length     = 0;
609 609
 
610
-            foreach ($tabs as $content) {
611
-                if ($content !== '') {
610
+            foreach ( $tabs as $content ) {
611
+                if ( $content !== '' ) {
612 612
                     $newContent .= $content;
613
-                    if ($checkEncoding === true) {
613
+                    if ( $checkEncoding === true ) {
614 614
                         // Not using the default encoding, so take a bit more care.
615 615
                         $oldLevel = error_reporting();
616
-                        error_reporting(0);
617
-                        $contentLength = iconv_strlen($content, $this->config->encoding);
618
-                        error_reporting($oldLevel);
619
-                        if ($contentLength === false) {
616
+                        error_reporting( 0 );
617
+                        $contentLength = iconv_strlen( $content, $this->config->encoding );
618
+                        error_reporting( $oldLevel );
619
+                        if ( $contentLength === false ) {
620 620
                             // String contained invalid characters, so revert to default.
621
-                            $contentLength = strlen($content);
621
+                            $contentLength = strlen( $content );
622 622
                         }
623 623
                     } else {
624
-                        $contentLength = strlen($content);
624
+                        $contentLength = strlen( $content );
625 625
                     }
626 626
 
627 627
                     $currColumn += $contentLength;
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
                 }
630 630
 
631 631
                 // The last piece of content does not have a tab after it.
632
-                if ($tabNum === $numTabs) {
632
+                if ( $tabNum === $numTabs ) {
633 633
                     break;
634 634
                 }
635 635
 
@@ -638,27 +638,27 @@  discard block
 block discarded – undo
638 638
                 $tabNum++;
639 639
 
640 640
                 // Move the pointer to the next tab stop.
641
-                if (($currColumn % $tabWidth) === 0) {
641
+                if ( ( $currColumn % $tabWidth ) === 0 ) {
642 642
                     // This is the first tab, and we are already at a
643 643
                     // tab stop, so this tab counts as a single space.
644 644
                     $currColumn++;
645 645
                 } else {
646 646
                     $currColumn++;
647
-                    while (($currColumn % $tabWidth) !== 0) {
647
+                    while ( ( $currColumn % $tabWidth ) !== 0 ) {
648 648
                         $currColumn++;
649 649
                     }
650 650
 
651 651
                     $currColumn++;
652 652
                 }
653 653
 
654
-                $length     += ($currColumn - $lastCurrColumn);
655
-                $newContent .= $prefix.str_repeat($padding, ($currColumn - $lastCurrColumn - 1));
654
+                $length     += ( $currColumn - $lastCurrColumn );
655
+                $newContent .= $prefix . str_repeat( $padding, ( $currColumn - $lastCurrColumn - 1 ) );
656 656
             }//end foreach
657 657
         }//end if
658 658
 
659
-        $token['orig_content'] = $token['content'];
660
-        $token['content']      = $newContent;
661
-        $token['length']       = $length;
659
+        $token[ 'orig_content' ] = $token[ 'content' ];
660
+        $token[ 'content' ]      = $newContent;
661
+        $token[ 'length' ]       = $length;
662 662
 
663 663
     }//end replaceTabsInToken()
664 664
 
@@ -670,50 +670,50 @@  discard block
 block discarded – undo
670 670
      */
671 671
     private function createTokenMap()
672 672
     {
673
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
674
-            echo "\t*** START TOKEN MAP ***".PHP_EOL;
673
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
674
+            echo "\t*** START TOKEN MAP ***" . PHP_EOL;
675 675
         }
676 676
 
677
-        $squareOpeners   = [];
678
-        $curlyOpeners    = [];
679
-        $this->numTokens = count($this->tokens);
677
+        $squareOpeners   = [ ];
678
+        $curlyOpeners    = [ ];
679
+        $this->numTokens = count( $this->tokens );
680 680
 
681
-        $openers   = [];
681
+        $openers   = [ ];
682 682
         $openOwner = null;
683 683
 
684
-        for ($i = 0; $i < $this->numTokens; $i++) {
684
+        for ( $i = 0; $i < $this->numTokens; $i++ ) {
685 685
             /*
686 686
                 Parenthesis mapping.
687 687
             */
688 688
 
689
-            if (isset(Util\Tokens::$parenthesisOpeners[$this->tokens[$i]['code']]) === true) {
690
-                $this->tokens[$i]['parenthesis_opener'] = null;
691
-                $this->tokens[$i]['parenthesis_closer'] = null;
692
-                $this->tokens[$i]['parenthesis_owner']  = $i;
689
+            if ( isset( Util\Tokens::$parenthesisOpeners[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
690
+                $this->tokens[ $i ][ 'parenthesis_opener' ] = null;
691
+                $this->tokens[ $i ][ 'parenthesis_closer' ] = null;
692
+                $this->tokens[ $i ][ 'parenthesis_owner' ]  = $i;
693 693
                 $openOwner = $i;
694
-            } else if ($this->tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
695
-                $openers[] = $i;
696
-                $this->tokens[$i]['parenthesis_opener'] = $i;
697
-                if ($openOwner !== null) {
698
-                    $this->tokens[$openOwner]['parenthesis_opener'] = $i;
699
-                    $this->tokens[$i]['parenthesis_owner']          = $openOwner;
694
+            } else if ( $this->tokens[ $i ][ 'code' ] === T_OPEN_PARENTHESIS ) {
695
+                $openers[ ] = $i;
696
+                $this->tokens[ $i ][ 'parenthesis_opener' ] = $i;
697
+                if ( $openOwner !== null ) {
698
+                    $this->tokens[ $openOwner ][ 'parenthesis_opener' ] = $i;
699
+                    $this->tokens[ $i ][ 'parenthesis_owner' ]          = $openOwner;
700 700
                     $openOwner = null;
701 701
                 }
702
-            } else if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS) {
702
+            } else if ( $this->tokens[ $i ][ 'code' ] === T_CLOSE_PARENTHESIS ) {
703 703
                 // Did we set an owner for this set of parenthesis?
704
-                $numOpeners = count($openers);
705
-                if ($numOpeners !== 0) {
706
-                    $opener = array_pop($openers);
707
-                    if (isset($this->tokens[$opener]['parenthesis_owner']) === true) {
708
-                        $owner = $this->tokens[$opener]['parenthesis_owner'];
709
-
710
-                        $this->tokens[$owner]['parenthesis_closer'] = $i;
711
-                        $this->tokens[$i]['parenthesis_owner']      = $owner;
704
+                $numOpeners = count( $openers );
705
+                if ( $numOpeners !== 0 ) {
706
+                    $opener = array_pop( $openers );
707
+                    if ( isset( $this->tokens[ $opener ][ 'parenthesis_owner' ] ) === true ) {
708
+                        $owner = $this->tokens[ $opener ][ 'parenthesis_owner' ];
709
+
710
+                        $this->tokens[ $owner ][ 'parenthesis_closer' ] = $i;
711
+                        $this->tokens[ $i ][ 'parenthesis_owner' ]      = $owner;
712 712
                     }
713 713
 
714
-                    $this->tokens[$i]['parenthesis_opener']      = $opener;
715
-                    $this->tokens[$i]['parenthesis_closer']      = $i;
716
-                    $this->tokens[$opener]['parenthesis_closer'] = $i;
714
+                    $this->tokens[ $i ][ 'parenthesis_opener' ]      = $opener;
715
+                    $this->tokens[ $i ][ 'parenthesis_closer' ]      = $i;
716
+                    $this->tokens[ $opener ][ 'parenthesis_closer' ] = $i;
717 717
                 }
718 718
             }//end if
719 719
 
@@ -721,56 +721,56 @@  discard block
 block discarded – undo
721 721
                 Bracket mapping.
722 722
             */
723 723
 
724
-            switch ($this->tokens[$i]['code']) {
724
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
725 725
             case T_OPEN_SQUARE_BRACKET:
726
-                $squareOpeners[] = $i;
726
+                $squareOpeners[ ] = $i;
727 727
 
728
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
729
-                    echo str_repeat("\t", count($squareOpeners));
730
-                    echo str_repeat("\t", count($curlyOpeners));
731
-                    echo "=> Found square bracket opener at $i".PHP_EOL;
728
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
729
+                    echo str_repeat( "\t", count( $squareOpeners ) );
730
+                    echo str_repeat( "\t", count( $curlyOpeners ) );
731
+                    echo "=> Found square bracket opener at $i" . PHP_EOL;
732 732
                 }
733 733
                 break;
734 734
             case T_OPEN_CURLY_BRACKET:
735
-                if (isset($this->tokens[$i]['scope_closer']) === false) {
736
-                    $curlyOpeners[] = $i;
735
+                if ( isset( $this->tokens[ $i ][ 'scope_closer' ] ) === false ) {
736
+                    $curlyOpeners[ ] = $i;
737 737
 
738
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
739
-                        echo str_repeat("\t", count($squareOpeners));
740
-                        echo str_repeat("\t", count($curlyOpeners));
741
-                        echo "=> Found curly bracket opener at $i".PHP_EOL;
738
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
739
+                        echo str_repeat( "\t", count( $squareOpeners ) );
740
+                        echo str_repeat( "\t", count( $curlyOpeners ) );
741
+                        echo "=> Found curly bracket opener at $i" . PHP_EOL;
742 742
                     }
743 743
                 }
744 744
                 break;
745 745
             case T_CLOSE_SQUARE_BRACKET:
746
-                if (empty($squareOpeners) === false) {
747
-                    $opener = array_pop($squareOpeners);
748
-                    $this->tokens[$i]['bracket_opener']      = $opener;
749
-                    $this->tokens[$i]['bracket_closer']      = $i;
750
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
751
-                    $this->tokens[$opener]['bracket_closer'] = $i;
752
-
753
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
754
-                        echo str_repeat("\t", count($squareOpeners));
755
-                        echo str_repeat("\t", count($curlyOpeners));
756
-                        echo "\t=> Found square bracket closer at $i for $opener".PHP_EOL;
746
+                if ( empty( $squareOpeners ) === false ) {
747
+                    $opener = array_pop( $squareOpeners );
748
+                    $this->tokens[ $i ][ 'bracket_opener' ]      = $opener;
749
+                    $this->tokens[ $i ][ 'bracket_closer' ]      = $i;
750
+                    $this->tokens[ $opener ][ 'bracket_opener' ] = $opener;
751
+                    $this->tokens[ $opener ][ 'bracket_closer' ] = $i;
752
+
753
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
754
+                        echo str_repeat( "\t", count( $squareOpeners ) );
755
+                        echo str_repeat( "\t", count( $curlyOpeners ) );
756
+                        echo "\t=> Found square bracket closer at $i for $opener" . PHP_EOL;
757 757
                     }
758 758
                 }
759 759
                 break;
760 760
             case T_CLOSE_CURLY_BRACKET:
761
-                if (empty($curlyOpeners) === false
762
-                    && isset($this->tokens[$i]['scope_opener']) === false
761
+                if ( empty( $curlyOpeners ) === false
762
+                    && isset( $this->tokens[ $i ][ 'scope_opener' ] ) === false
763 763
                 ) {
764
-                    $opener = array_pop($curlyOpeners);
765
-                    $this->tokens[$i]['bracket_opener']      = $opener;
766
-                    $this->tokens[$i]['bracket_closer']      = $i;
767
-                    $this->tokens[$opener]['bracket_opener'] = $opener;
768
-                    $this->tokens[$opener]['bracket_closer'] = $i;
769
-
770
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
771
-                        echo str_repeat("\t", count($squareOpeners));
772
-                        echo str_repeat("\t", count($curlyOpeners));
773
-                        echo "\t=> Found curly bracket closer at $i for $opener".PHP_EOL;
764
+                    $opener = array_pop( $curlyOpeners );
765
+                    $this->tokens[ $i ][ 'bracket_opener' ]      = $opener;
766
+                    $this->tokens[ $i ][ 'bracket_closer' ]      = $i;
767
+                    $this->tokens[ $opener ][ 'bracket_opener' ] = $opener;
768
+                    $this->tokens[ $opener ][ 'bracket_closer' ] = $i;
769
+
770
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
771
+                        echo str_repeat( "\t", count( $squareOpeners ) );
772
+                        echo str_repeat( "\t", count( $curlyOpeners ) );
773
+                        echo "\t=> Found curly bracket closer at $i for $opener" . PHP_EOL;
774 774
                     }
775 775
                 }
776 776
                 break;
@@ -781,13 +781,13 @@  discard block
 block discarded – undo
781 781
 
782 782
         // Cleanup for any openers that we didn't find closers for.
783 783
         // This typically means there was a syntax error breaking things.
784
-        foreach ($openers as $opener) {
785
-            unset($this->tokens[$opener]['parenthesis_opener']);
786
-            unset($this->tokens[$opener]['parenthesis_owner']);
784
+        foreach ( $openers as $opener ) {
785
+            unset( $this->tokens[ $opener ][ 'parenthesis_opener' ] );
786
+            unset( $this->tokens[ $opener ][ 'parenthesis_owner' ] );
787 787
         }
788 788
 
789
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
790
-            echo "\t*** END TOKEN MAP ***".PHP_EOL;
789
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
790
+            echo "\t*** END TOKEN MAP ***" . PHP_EOL;
791 791
         }
792 792
 
793 793
     }//end createTokenMap()
@@ -800,29 +800,29 @@  discard block
 block discarded – undo
800 800
      */
801 801
     private function createParenthesisNestingMap()
802 802
     {
803
-        $map = [];
804
-        for ($i = 0; $i < $this->numTokens; $i++) {
805
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true
806
-                && $i === $this->tokens[$i]['parenthesis_opener']
803
+        $map = [ ];
804
+        for ( $i = 0; $i < $this->numTokens; $i++ ) {
805
+            if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true
806
+                && $i === $this->tokens[ $i ][ 'parenthesis_opener' ]
807 807
             ) {
808
-                if (empty($map) === false) {
809
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
808
+                if ( empty( $map ) === false ) {
809
+                    $this->tokens[ $i ][ 'nested_parenthesis' ] = $map;
810 810
                 }
811 811
 
812
-                if (isset($this->tokens[$i]['parenthesis_closer']) === true) {
813
-                    $map[$this->tokens[$i]['parenthesis_opener']]
814
-                        = $this->tokens[$i]['parenthesis_closer'];
812
+                if ( isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) === true ) {
813
+                    $map[ $this->tokens[ $i ][ 'parenthesis_opener' ] ]
814
+                        = $this->tokens[ $i ][ 'parenthesis_closer' ];
815 815
                 }
816
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
817
-                && $i === $this->tokens[$i]['parenthesis_closer']
816
+            } else if ( isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) === true
817
+                && $i === $this->tokens[ $i ][ 'parenthesis_closer' ]
818 818
             ) {
819
-                array_pop($map);
820
-                if (empty($map) === false) {
821
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
819
+                array_pop( $map );
820
+                if ( empty( $map ) === false ) {
821
+                    $this->tokens[ $i ][ 'nested_parenthesis' ] = $map;
822 822
                 }
823 823
             } else {
824
-                if (empty($map) === false) {
825
-                    $this->tokens[$i]['nested_parenthesis'] = $map;
824
+                if ( empty( $map ) === false ) {
825
+                    $this->tokens[ $i ][ 'nested_parenthesis' ] = $map;
826 826
                 }
827 827
             }//end if
828 828
         }//end for
@@ -838,33 +838,33 @@  discard block
 block discarded – undo
838 838
      */
839 839
     private function createScopeMap()
840 840
     {
841
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
842
-            echo "\t*** START SCOPE MAP ***".PHP_EOL;
841
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
842
+            echo "\t*** START SCOPE MAP ***" . PHP_EOL;
843 843
         }
844 844
 
845
-        for ($i = 0; $i < $this->numTokens; $i++) {
845
+        for ( $i = 0; $i < $this->numTokens; $i++ ) {
846 846
             // Check to see if the current token starts a new scope.
847
-            if (isset($this->scopeOpeners[$this->tokens[$i]['code']]) === true) {
848
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
849
-                    $type    = $this->tokens[$i]['type'];
850
-                    $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
851
-                    echo "\tStart scope map at $i:$type => $content".PHP_EOL;
847
+            if ( isset( $this->scopeOpeners[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
848
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
849
+                    $type    = $this->tokens[ $i ][ 'type' ];
850
+                    $content = Util\Common::prepareForOutput( $this->tokens[ $i ][ 'content' ] );
851
+                    echo "\tStart scope map at $i:$type => $content" . PHP_EOL;
852 852
                 }
853 853
 
854
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
855
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
856
-                        echo "\t* already processed, skipping *".PHP_EOL;
854
+                if ( isset( $this->tokens[ $i ][ 'scope_condition' ] ) === true ) {
855
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
856
+                        echo "\t* already processed, skipping *" . PHP_EOL;
857 857
                     }
858 858
 
859 859
                     continue;
860 860
                 }
861 861
 
862
-                $i = $this->recurseScopeMap($i);
862
+                $i = $this->recurseScopeMap( $i );
863 863
             }//end if
864 864
         }//end for
865 865
 
866
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
867
-            echo "\t*** END SCOPE MAP ***".PHP_EOL;
866
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
867
+            echo "\t*** END SCOPE MAP ***" . PHP_EOL;
868 868
         }
869 869
 
870 870
     }//end createScopeMap()
@@ -880,16 +880,16 @@  discard block
 block discarded – undo
880 880
      *
881 881
      * @return int The position in the stack that closed the scope.
882 882
      */
883
-    private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
883
+    private function recurseScopeMap( $stackPtr, $depth = 1, &$ignore = 0 )
884 884
     {
885
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
-            echo str_repeat("\t", $depth);
887
-            echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL;
885
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
886
+            echo str_repeat( "\t", $depth );
887
+            echo "=> Begin scope map recursion at token $stackPtr with depth $depth" . PHP_EOL;
888 888
         }
889 889
 
890 890
         $opener    = null;
891
-        $currType  = $this->tokens[$stackPtr]['code'];
892
-        $startLine = $this->tokens[$stackPtr]['line'];
891
+        $currType  = $this->tokens[ $stackPtr ][ 'code' ];
892
+        $startLine = $this->tokens[ $stackPtr ][ 'line' ];
893 893
 
894 894
         // We will need this to restore the value if we end up
895 895
         // returning a token ID that causes our calling function to go back
@@ -898,29 +898,29 @@  discard block
 block discarded – undo
898 898
 
899 899
         // If the start token for this scope opener is the same as
900 900
         // the scope token, we have already found our opener.
901
-        if (isset($this->scopeOpeners[$currType]['start'][$currType]) === true) {
901
+        if ( isset( $this->scopeOpeners[ $currType ][ 'start' ][ $currType ] ) === true ) {
902 902
             $opener = $stackPtr;
903 903
         }
904 904
 
905
-        for ($i = ($stackPtr + 1); $i < $this->numTokens; $i++) {
906
-            $tokenType = $this->tokens[$i]['code'];
905
+        for ( $i = ( $stackPtr + 1 ); $i < $this->numTokens; $i++ ) {
906
+            $tokenType = $this->tokens[ $i ][ 'code' ];
907 907
 
908
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
909
-                $type    = $this->tokens[$i]['type'];
910
-                $line    = $this->tokens[$i]['line'];
911
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
908
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
909
+                $type    = $this->tokens[ $i ][ 'type' ];
910
+                $line    = $this->tokens[ $i ][ 'line' ];
911
+                $content = Util\Common::prepareForOutput( $this->tokens[ $i ][ 'content' ] );
912 912
 
913
-                echo str_repeat("\t", $depth);
913
+                echo str_repeat( "\t", $depth );
914 914
                 echo "Process token $i on line $line [";
915
-                if ($opener !== null) {
915
+                if ( $opener !== null ) {
916 916
                     echo "opener:$opener;";
917 917
                 }
918 918
 
919
-                if ($ignore > 0) {
919
+                if ( $ignore > 0 ) {
920 920
                     echo "ignore=$ignore;";
921 921
                 }
922 922
 
923
-                echo "]: $type => $content".PHP_EOL;
923
+                echo "]: $type => $content" . PHP_EOL;
924 924
             }//end if
925 925
 
926 926
             // Very special case for IF statements in PHP that can be defined without
@@ -929,21 +929,21 @@  discard block
 block discarded – undo
929 929
             // keyword, the opener will be incorrectly assigned to this IF statement.
930 930
             // The same case also applies to USE statements, which don't have to have
931 931
             // openers, so a following USE statement can cause an incorrect brace match.
932
-            if (($currType === T_IF || $currType === T_ELSE || $currType === T_USE)
932
+            if ( ( $currType === T_IF || $currType === T_ELSE || $currType === T_USE )
933 933
                 && $opener === null
934
-                && ($this->tokens[$i]['code'] === T_SEMICOLON
935
-                || $this->tokens[$i]['code'] === T_CLOSE_TAG)
934
+                && ( $this->tokens[ $i ][ 'code' ] === T_SEMICOLON
935
+                || $this->tokens[ $i ][ 'code' ] === T_CLOSE_TAG )
936 936
             ) {
937
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
938
-                    $type = $this->tokens[$stackPtr]['type'];
939
-                    echo str_repeat("\t", $depth);
940
-                    if ($this->tokens[$i]['code'] === T_SEMICOLON) {
937
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
938
+                    $type = $this->tokens[ $stackPtr ][ 'type' ];
939
+                    echo str_repeat( "\t", $depth );
940
+                    if ( $this->tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
941 941
                         $closerType = 'semicolon';
942 942
                     } else {
943 943
                         $closerType = 'close tag';
944 944
                     }
945 945
 
946
-                    echo "=> Found $closerType before scope opener for $stackPtr:$type, bailing".PHP_EOL;
946
+                    echo "=> Found $closerType before scope opener for $stackPtr:$type, bailing" . PHP_EOL;
947 947
                 }
948 948
 
949 949
                 return $i;
@@ -953,45 +953,45 @@  discard block
 block discarded – undo
953 953
             // If we find a curly brace closer before we find the opener,
954 954
             // we're not going to find an opener. That closer probably belongs to
955 955
             // a control structure higher up.
956
-            if ($opener === null
956
+            if ( $opener === null
957 957
                 && $ignore === 0
958 958
                 && $tokenType === T_CLOSE_CURLY_BRACKET
959
-                && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
959
+                && isset( $this->scopeOpeners[ $currType ][ 'end' ][ $tokenType ] ) === true
960 960
             ) {
961
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
962
-                    $type = $this->tokens[$stackPtr]['type'];
963
-                    echo str_repeat("\t", $depth);
964
-                    echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing".PHP_EOL;
961
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
962
+                    $type = $this->tokens[ $stackPtr ][ 'type' ];
963
+                    echo str_repeat( "\t", $depth );
964
+                    echo "=> Found curly brace closer before scope opener for $stackPtr:$type, bailing" . PHP_EOL;
965 965
                 }
966 966
 
967
-                return ($i - 1);
967
+                return ( $i - 1 );
968 968
             }
969 969
 
970
-            if ($opener !== null
971
-                && (isset($this->tokens[$i]['scope_opener']) === false
972
-                || $this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true)
973
-                && isset($this->scopeOpeners[$currType]['end'][$tokenType]) === true
970
+            if ( $opener !== null
971
+                && ( isset( $this->tokens[ $i ][ 'scope_opener' ] ) === false
972
+                || $this->scopeOpeners[ $this->tokens[ $stackPtr ][ 'code' ] ][ 'shared' ] === true )
973
+                && isset( $this->scopeOpeners[ $currType ][ 'end' ][ $tokenType ] ) === true
974 974
             ) {
975
-                if ($ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET) {
975
+                if ( $ignore > 0 && $tokenType === T_CLOSE_CURLY_BRACKET ) {
976 976
                     // The last opening bracket must have been for a string
977 977
                     // offset or alike, so let's ignore it.
978
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
979
-                        echo str_repeat("\t", $depth);
980
-                        echo '* finished ignoring curly brace *'.PHP_EOL;
978
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
979
+                        echo str_repeat( "\t", $depth );
980
+                        echo '* finished ignoring curly brace *' . PHP_EOL;
981 981
                     }
982 982
 
983 983
                     $ignore--;
984 984
                     continue;
985
-                } else if ($this->tokens[$opener]['code'] === T_OPEN_CURLY_BRACKET
985
+                } else if ( $this->tokens[ $opener ][ 'code' ] === T_OPEN_CURLY_BRACKET
986 986
                     && $tokenType !== T_CLOSE_CURLY_BRACKET
987 987
                 ) {
988 988
                     // The opener is a curly bracket so the closer must be a curly bracket as well.
989 989
                     // We ignore this closer to handle cases such as T_ELSE or T_ELSEIF being considered
990 990
                     // a closer of T_IF when it should not.
991
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
992
-                        $type = $this->tokens[$stackPtr]['type'];
993
-                        echo str_repeat("\t", $depth);
994
-                        echo "=> Ignoring non-curly scope closer for $stackPtr:$type".PHP_EOL;
991
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
992
+                        $type = $this->tokens[ $stackPtr ][ 'type' ];
993
+                        echo str_repeat( "\t", $depth );
994
+                        echo "=> Ignoring non-curly scope closer for $stackPtr:$type" . PHP_EOL;
995 995
                     }
996 996
                 } else {
997 997
                     $scopeCloser = $i;
@@ -1000,63 +1000,63 @@  discard block
 block discarded – undo
1000 1000
                         $opener,
1001 1001
                     ];
1002 1002
 
1003
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
-                        $type       = $this->tokens[$stackPtr]['type'];
1005
-                        $closerType = $this->tokens[$scopeCloser]['type'];
1006
-                        echo str_repeat("\t", $depth);
1007
-                        echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type".PHP_EOL;
1003
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1004
+                        $type       = $this->tokens[ $stackPtr ][ 'type' ];
1005
+                        $closerType = $this->tokens[ $scopeCloser ][ 'type' ];
1006
+                        echo str_repeat( "\t", $depth );
1007
+                        echo "=> Found scope closer ($scopeCloser:$closerType) for $stackPtr:$type" . PHP_EOL;
1008 1008
                     }
1009 1009
 
1010 1010
                     $validCloser = true;
1011
-                    if (($this->tokens[$stackPtr]['code'] === T_IF || $this->tokens[$stackPtr]['code'] === T_ELSEIF)
1012
-                        && ($tokenType === T_ELSE || $tokenType === T_ELSEIF)
1011
+                    if ( ( $this->tokens[ $stackPtr ][ 'code' ] === T_IF || $this->tokens[ $stackPtr ][ 'code' ] === T_ELSEIF )
1012
+                        && ( $tokenType === T_ELSE || $tokenType === T_ELSEIF )
1013 1013
                     ) {
1014 1014
                         // To be a closer, this token must have an opener.
1015
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1016
-                            echo str_repeat("\t", $depth);
1017
-                            echo "* closer needs to be tested *".PHP_EOL;
1015
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1016
+                            echo str_repeat( "\t", $depth );
1017
+                            echo "* closer needs to be tested *" . PHP_EOL;
1018 1018
                         }
1019 1019
 
1020
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1020
+                        $i = self::recurseScopeMap( $i, ( $depth + 1 ), $ignore );
1021 1021
 
1022
-                        if (isset($this->tokens[$scopeCloser]['scope_opener']) === false) {
1022
+                        if ( isset( $this->tokens[ $scopeCloser ][ 'scope_opener' ] ) === false ) {
1023 1023
                             $validCloser = false;
1024
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1025
-                                echo str_repeat("\t", $depth);
1026
-                                echo "* closer is not valid (no opener found) *".PHP_EOL;
1024
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1025
+                                echo str_repeat( "\t", $depth );
1026
+                                echo "* closer is not valid (no opener found) *" . PHP_EOL;
1027 1027
                             }
1028
-                        } else if ($this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['code'] !== $this->tokens[$opener]['code']) {
1028
+                        } else if ( $this->tokens[ $this->tokens[ $scopeCloser ][ 'scope_opener' ] ][ 'code' ] !== $this->tokens[ $opener ][ 'code' ] ) {
1029 1029
                             $validCloser = false;
1030
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1031
-                                echo str_repeat("\t", $depth);
1032
-                                $type       = $this->tokens[$this->tokens[$scopeCloser]['scope_opener']]['type'];
1033
-                                $openerType = $this->tokens[$opener]['type'];
1034
-                                echo "* closer is not valid (mismatched opener type; $type != $openerType) *".PHP_EOL;
1030
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1031
+                                echo str_repeat( "\t", $depth );
1032
+                                $type       = $this->tokens[ $this->tokens[ $scopeCloser ][ 'scope_opener' ] ][ 'type' ];
1033
+                                $openerType = $this->tokens[ $opener ][ 'type' ];
1034
+                                echo "* closer is not valid (mismatched opener type; $type != $openerType) *" . PHP_EOL;
1035 1035
                             }
1036
-                        } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
1037
-                            echo str_repeat("\t", $depth);
1038
-                            echo "* closer was valid *".PHP_EOL;
1036
+                        } else if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1037
+                            echo str_repeat( "\t", $depth );
1038
+                            echo "* closer was valid *" . PHP_EOL;
1039 1039
                         }
1040 1040
                     } else {
1041 1041
                         // The closer was not processed, so we need to
1042 1042
                         // complete that token as well.
1043
-                        $todo[] = $scopeCloser;
1043
+                        $todo[ ] = $scopeCloser;
1044 1044
                     }//end if
1045 1045
 
1046
-                    if ($validCloser === true) {
1047
-                        foreach ($todo as $token) {
1048
-                            $this->tokens[$token]['scope_condition'] = $stackPtr;
1049
-                            $this->tokens[$token]['scope_opener']    = $opener;
1050
-                            $this->tokens[$token]['scope_closer']    = $scopeCloser;
1046
+                    if ( $validCloser === true ) {
1047
+                        foreach ( $todo as $token ) {
1048
+                            $this->tokens[ $token ][ 'scope_condition' ] = $stackPtr;
1049
+                            $this->tokens[ $token ][ 'scope_opener' ]    = $opener;
1050
+                            $this->tokens[ $token ][ 'scope_closer' ]    = $scopeCloser;
1051 1051
                         }
1052 1052
 
1053
-                        if ($this->scopeOpeners[$this->tokens[$stackPtr]['code']]['shared'] === true) {
1053
+                        if ( $this->scopeOpeners[ $this->tokens[ $stackPtr ][ 'code' ] ][ 'shared' ] === true ) {
1054 1054
                             // As we are going back to where we started originally, restore
1055 1055
                             // the ignore value back to its original value.
1056 1056
                             $ignore = $originalIgnore;
1057 1057
                             return $opener;
1058
-                        } else if ($scopeCloser === $i
1059
-                            && isset($this->scopeOpeners[$tokenType]) === true
1058
+                        } else if ( $scopeCloser === $i
1059
+                            && isset( $this->scopeOpeners[ $tokenType ] ) === true
1060 1060
                         ) {
1061 1061
                             // Unset scope_condition here or else the token will appear to have
1062 1062
                             // already been processed, and it will be skipped. Normally we want that,
@@ -1064,8 +1064,8 @@  discard block
 block discarded – undo
1064 1064
                             // it needs to act like an opener. This is also why we return the
1065 1065
                             // token before this one; so the closer has a chance to be processed
1066 1066
                             // a second time, but as an opener.
1067
-                            unset($this->tokens[$scopeCloser]['scope_condition']);
1068
-                            return ($i - 1);
1067
+                            unset( $this->tokens[ $scopeCloser ][ 'scope_condition' ] );
1068
+                            return ( $i - 1 );
1069 1069
                         } else {
1070 1070
                             return $i;
1071 1071
                         }
@@ -1076,151 +1076,151 @@  discard block
 block discarded – undo
1076 1076
             }//end if
1077 1077
 
1078 1078
             // Is this an opening condition ?
1079
-            if (isset($this->scopeOpeners[$tokenType]) === true) {
1080
-                if ($opener === null) {
1081
-                    if ($tokenType === T_USE) {
1079
+            if ( isset( $this->scopeOpeners[ $tokenType ] ) === true ) {
1080
+                if ( $opener === null ) {
1081
+                    if ( $tokenType === T_USE ) {
1082 1082
                         // PHP use keywords are special because they can be
1083 1083
                         // used as blocks but also inline in function definitions.
1084 1084
                         // So if we find them nested inside another opener, just skip them.
1085 1085
                         continue;
1086 1086
                     }
1087 1087
 
1088
-                    if ($tokenType === T_FUNCTION
1089
-                        && $this->tokens[$stackPtr]['code'] !== T_FUNCTION
1088
+                    if ( $tokenType === T_FUNCTION
1089
+                        && $this->tokens[ $stackPtr ][ 'code' ] !== T_FUNCTION
1090 1090
                     ) {
1091 1091
                         // Probably a closure, so process it manually.
1092
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1093
-                            $type = $this->tokens[$stackPtr]['type'];
1094
-                            echo str_repeat("\t", $depth);
1095
-                            echo "=> Found function before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1092
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1093
+                            $type = $this->tokens[ $stackPtr ][ 'type' ];
1094
+                            echo str_repeat( "\t", $depth );
1095
+                            echo "=> Found function before scope opener for $stackPtr:$type, processing manually" . PHP_EOL;
1096 1096
                         }
1097 1097
 
1098
-                        if (isset($this->tokens[$i]['scope_closer']) === true) {
1098
+                        if ( isset( $this->tokens[ $i ][ 'scope_closer' ] ) === true ) {
1099 1099
                             // We've already processed this closure.
1100
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1101
-                                echo str_repeat("\t", $depth);
1102
-                                echo '* already processed, skipping *'.PHP_EOL;
1100
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1101
+                                echo str_repeat( "\t", $depth );
1102
+                                echo '* already processed, skipping *' . PHP_EOL;
1103 1103
                             }
1104 1104
 
1105
-                            $i = $this->tokens[$i]['scope_closer'];
1105
+                            $i = $this->tokens[ $i ][ 'scope_closer' ];
1106 1106
                             continue;
1107 1107
                         }
1108 1108
 
1109
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1109
+                        $i = self::recurseScopeMap( $i, ( $depth + 1 ), $ignore );
1110 1110
                         continue;
1111 1111
                     }//end if
1112 1112
 
1113
-                    if ($tokenType === T_CLASS) {
1113
+                    if ( $tokenType === T_CLASS ) {
1114 1114
                         // Probably an anonymous class inside another anonymous class,
1115 1115
                         // so process it manually.
1116
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1117
-                            $type = $this->tokens[$stackPtr]['type'];
1118
-                            echo str_repeat("\t", $depth);
1119
-                            echo "=> Found class before scope opener for $stackPtr:$type, processing manually".PHP_EOL;
1116
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1117
+                            $type = $this->tokens[ $stackPtr ][ 'type' ];
1118
+                            echo str_repeat( "\t", $depth );
1119
+                            echo "=> Found class before scope opener for $stackPtr:$type, processing manually" . PHP_EOL;
1120 1120
                         }
1121 1121
 
1122
-                        if (isset($this->tokens[$i]['scope_closer']) === true) {
1122
+                        if ( isset( $this->tokens[ $i ][ 'scope_closer' ] ) === true ) {
1123 1123
                             // We've already processed this anon class.
1124
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1125
-                                echo str_repeat("\t", $depth);
1126
-                                echo '* already processed, skipping *'.PHP_EOL;
1124
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1125
+                                echo str_repeat( "\t", $depth );
1126
+                                echo '* already processed, skipping *' . PHP_EOL;
1127 1127
                             }
1128 1128
 
1129
-                            $i = $this->tokens[$i]['scope_closer'];
1129
+                            $i = $this->tokens[ $i ][ 'scope_closer' ];
1130 1130
                             continue;
1131 1131
                         }
1132 1132
 
1133
-                        $i = self::recurseScopeMap($i, ($depth + 1), $ignore);
1133
+                        $i = self::recurseScopeMap( $i, ( $depth + 1 ), $ignore );
1134 1134
                         continue;
1135 1135
                     }//end if
1136 1136
 
1137 1137
                     // Found another opening condition but still haven't
1138 1138
                     // found our opener, so we are never going to find one.
1139
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1140
-                        $type = $this->tokens[$stackPtr]['type'];
1141
-                        echo str_repeat("\t", $depth);
1139
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1140
+                        $type = $this->tokens[ $stackPtr ][ 'type' ];
1141
+                        echo str_repeat( "\t", $depth );
1142 1142
                         echo "=> Found new opening condition before scope opener for $stackPtr:$type, ";
1143 1143
                     }
1144 1144
 
1145
-                    if (($this->tokens[$stackPtr]['code'] === T_IF
1146
-                        || $this->tokens[$stackPtr]['code'] === T_ELSEIF
1147
-                        || $this->tokens[$stackPtr]['code'] === T_ELSE)
1148
-                        && ($this->tokens[$i]['code'] === T_ELSE
1149
-                        || $this->tokens[$i]['code'] === T_ELSEIF)
1145
+                    if ( ( $this->tokens[ $stackPtr ][ 'code' ] === T_IF
1146
+                        || $this->tokens[ $stackPtr ][ 'code' ] === T_ELSEIF
1147
+                        || $this->tokens[ $stackPtr ][ 'code' ] === T_ELSE )
1148
+                        && ( $this->tokens[ $i ][ 'code' ] === T_ELSE
1149
+                        || $this->tokens[ $i ][ 'code' ] === T_ELSEIF )
1150 1150
                     ) {
1151
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1152
-                            echo "continuing".PHP_EOL;
1151
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1152
+                            echo "continuing" . PHP_EOL;
1153 1153
                         }
1154 1154
 
1155
-                        return ($i - 1);
1155
+                        return ( $i - 1 );
1156 1156
                     } else {
1157
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1158
-                            echo "backtracking".PHP_EOL;
1157
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1158
+                            echo "backtracking" . PHP_EOL;
1159 1159
                         }
1160 1160
 
1161 1161
                         return $stackPtr;
1162 1162
                     }
1163 1163
                 }//end if
1164 1164
 
1165
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1166
-                    echo str_repeat("\t", $depth);
1167
-                    echo '* token is an opening condition *'.PHP_EOL;
1165
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1166
+                    echo str_repeat( "\t", $depth );
1167
+                    echo '* token is an opening condition *' . PHP_EOL;
1168 1168
                 }
1169 1169
 
1170
-                $isShared = ($this->scopeOpeners[$tokenType]['shared'] === true);
1170
+                $isShared = ( $this->scopeOpeners[ $tokenType ][ 'shared' ] === true );
1171 1171
 
1172
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
1172
+                if ( isset( $this->tokens[ $i ][ 'scope_condition' ] ) === true ) {
1173 1173
                     // We've been here before.
1174
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1175
-                        echo str_repeat("\t", $depth);
1176
-                        echo '* already processed, skipping *'.PHP_EOL;
1174
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1175
+                        echo str_repeat( "\t", $depth );
1176
+                        echo '* already processed, skipping *' . PHP_EOL;
1177 1177
                     }
1178 1178
 
1179
-                    if ($isShared === false
1180
-                        && isset($this->tokens[$i]['scope_closer']) === true
1179
+                    if ( $isShared === false
1180
+                        && isset( $this->tokens[ $i ][ 'scope_closer' ] ) === true
1181 1181
                     ) {
1182
-                        $i = $this->tokens[$i]['scope_closer'];
1182
+                        $i = $this->tokens[ $i ][ 'scope_closer' ];
1183 1183
                     }
1184 1184
 
1185 1185
                     continue;
1186
-                } else if ($currType === $tokenType
1186
+                } else if ( $currType === $tokenType
1187 1187
                     && $isShared === false
1188 1188
                     && $opener === null
1189 1189
                 ) {
1190 1190
                     // We haven't yet found our opener, but we have found another
1191 1191
                     // scope opener which is the same type as us, and we don't
1192 1192
                     // share openers, so we will never find one.
1193
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1194
-                        echo str_repeat("\t", $depth);
1195
-                        echo '* it was another token\'s opener, bailing *'.PHP_EOL;
1193
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1194
+                        echo str_repeat( "\t", $depth );
1195
+                        echo '* it was another token\'s opener, bailing *' . PHP_EOL;
1196 1196
                     }
1197 1197
 
1198 1198
                     return $stackPtr;
1199 1199
                 } else {
1200
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1201
-                        echo str_repeat("\t", $depth);
1202
-                        echo '* searching for opener *'.PHP_EOL;
1200
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1201
+                        echo str_repeat( "\t", $depth );
1202
+                        echo '* searching for opener *' . PHP_EOL;
1203 1203
                     }
1204 1204
 
1205
-                    if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1205
+                    if ( isset( $this->scopeOpeners[ $tokenType ][ 'end' ][ T_CLOSE_CURLY_BRACKET ] ) === true ) {
1206 1206
                         $oldIgnore = $ignore;
1207 1207
                         $ignore    = 0;
1208 1208
                     }
1209 1209
 
1210 1210
                     // PHP has a max nesting level for functions. Stop before we hit that limit
1211 1211
                     // because too many loops means we've run into trouble anyway.
1212
-                    if ($depth > 50) {
1213
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1214
-                            echo str_repeat("\t", $depth);
1215
-                            echo '* reached maximum nesting level; aborting *'.PHP_EOL;
1212
+                    if ( $depth > 50 ) {
1213
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1214
+                            echo str_repeat( "\t", $depth );
1215
+                            echo '* reached maximum nesting level; aborting *' . PHP_EOL;
1216 1216
                         }
1217 1217
 
1218
-                        throw new RuntimeException('Maximum nesting level reached; file could not be processed');
1218
+                        throw new RuntimeException( 'Maximum nesting level reached; file could not be processed' );
1219 1219
                     }
1220 1220
 
1221 1221
                     $oldDepth = $depth;
1222
-                    if ($isShared === true
1223
-                        && isset($this->scopeOpeners[$tokenType]['with'][$currType]) === true
1222
+                    if ( $isShared === true
1223
+                        && isset( $this->scopeOpeners[ $tokenType ][ 'with' ][ $currType ] ) === true
1224 1224
                     ) {
1225 1225
                         // Don't allow the depth to increment because this is
1226 1226
                         // possibly not a true nesting if we are sharing our closer.
@@ -1229,35 +1229,35 @@  discard block
 block discarded – undo
1229 1229
                         $depth--;
1230 1230
                     }
1231 1231
 
1232
-                    $i     = self::recurseScopeMap($i, ($depth + 1), $ignore);
1232
+                    $i     = self::recurseScopeMap( $i, ( $depth + 1 ), $ignore );
1233 1233
                     $depth = $oldDepth;
1234 1234
 
1235
-                    if (isset($this->scopeOpeners[$tokenType]['end'][T_CLOSE_CURLY_BRACKET]) === true) {
1235
+                    if ( isset( $this->scopeOpeners[ $tokenType ][ 'end' ][ T_CLOSE_CURLY_BRACKET ] ) === true ) {
1236 1236
                         $ignore = $oldIgnore;
1237 1237
                     }
1238 1238
                 }//end if
1239 1239
             }//end if
1240 1240
 
1241
-            if (isset($this->scopeOpeners[$currType]['start'][$tokenType]) === true
1241
+            if ( isset( $this->scopeOpeners[ $currType ][ 'start' ][ $tokenType ] ) === true
1242 1242
                 && $opener === null
1243 1243
             ) {
1244
-                if ($tokenType === T_OPEN_CURLY_BRACKET) {
1245
-                    if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true
1246
-                        && $i < $this->tokens[$stackPtr]['parenthesis_closer']
1244
+                if ( $tokenType === T_OPEN_CURLY_BRACKET ) {
1245
+                    if ( isset( $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true
1246
+                        && $i < $this->tokens[ $stackPtr ][ 'parenthesis_closer' ]
1247 1247
                     ) {
1248 1248
                         // We found a curly brace inside the condition of the
1249 1249
                         // current scope opener, so it must be a string offset.
1250
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
-                            echo str_repeat("\t", $depth);
1252
-                            echo '* ignoring curly brace inside condition *'.PHP_EOL;
1250
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1251
+                            echo str_repeat( "\t", $depth );
1252
+                            echo '* ignoring curly brace inside condition *' . PHP_EOL;
1253 1253
                         }
1254 1254
 
1255 1255
                         $ignore++;
1256 1256
                     } else {
1257 1257
                         // Make sure this is actually an opener and not a
1258 1258
                         // string offset (e.g., $var{0}).
1259
-                        for ($x = ($i - 1); $x > 0; $x--) {
1260
-                            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === true) {
1259
+                        for ( $x = ( $i - 1 ); $x > 0; $x-- ) {
1260
+                            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $x ][ 'code' ] ] ) === true ) {
1261 1261
                                 continue;
1262 1262
                             } else {
1263 1263
                                 // If the first non-whitespace/comment token looks like this
@@ -1272,10 +1272,10 @@  discard block
 block discarded – undo
1272 1272
                                     T_OPEN_PARENTHESIS => true,
1273 1273
                                 ];
1274 1274
 
1275
-                                if (isset($disallowed[$this->tokens[$x]['code']]) === true) {
1276
-                                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1277
-                                        echo str_repeat("\t", $depth);
1278
-                                        echo '* ignoring curly brace *'.PHP_EOL;
1275
+                                if ( isset( $disallowed[ $this->tokens[ $x ][ 'code' ] ] ) === true ) {
1276
+                                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1277
+                                        echo str_repeat( "\t", $depth );
1278
+                                        echo '* ignoring curly brace *' . PHP_EOL;
1279 1279
                                     }
1280 1280
 
1281 1281
                                     $ignore++;
@@ -1287,87 +1287,87 @@  discard block
 block discarded – undo
1287 1287
                     }//end if
1288 1288
                 }//end if
1289 1289
 
1290
-                if ($ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET) {
1290
+                if ( $ignore === 0 || $tokenType !== T_OPEN_CURLY_BRACKET ) {
1291 1291
                     // We found the opening scope token for $currType.
1292
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1293
-                        $type = $this->tokens[$stackPtr]['type'];
1294
-                        echo str_repeat("\t", $depth);
1295
-                        echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1292
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1293
+                        $type = $this->tokens[ $stackPtr ][ 'type' ];
1294
+                        echo str_repeat( "\t", $depth );
1295
+                        echo "=> Found scope opener for $stackPtr:$type" . PHP_EOL;
1296 1296
                     }
1297 1297
 
1298 1298
                     $opener = $i;
1299 1299
                 }
1300
-            } else if ($tokenType === T_OPEN_PARENTHESIS) {
1301
-                if (isset($this->tokens[$i]['parenthesis_owner']) === true) {
1302
-                    $owner = $this->tokens[$i]['parenthesis_owner'];
1303
-                    if (isset(Util\Tokens::$scopeOpeners[$this->tokens[$owner]['code']]) === true
1304
-                        && isset($this->tokens[$i]['parenthesis_closer']) === true
1300
+            } else if ( $tokenType === T_OPEN_PARENTHESIS ) {
1301
+                if ( isset( $this->tokens[ $i ][ 'parenthesis_owner' ] ) === true ) {
1302
+                    $owner = $this->tokens[ $i ][ 'parenthesis_owner' ];
1303
+                    if ( isset( Util\Tokens::$scopeOpeners[ $this->tokens[ $owner ][ 'code' ] ] ) === true
1304
+                        && isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) === true
1305 1305
                     ) {
1306 1306
                         // If we get into here, then we opened a parenthesis for
1307 1307
                         // a scope (eg. an if or else if) so we need to update the
1308 1308
                         // start of the line so that when we check to see
1309 1309
                         // if the closing parenthesis is more than 3 lines away from
1310 1310
                         // the statement, we check from the closing parenthesis.
1311
-                        $startLine = $this->tokens[$this->tokens[$i]['parenthesis_closer']]['line'];
1311
+                        $startLine = $this->tokens[ $this->tokens[ $i ][ 'parenthesis_closer' ] ][ 'line' ];
1312 1312
                     }
1313 1313
                 }
1314
-            } else if ($tokenType === T_OPEN_CURLY_BRACKET && $opener !== null) {
1314
+            } else if ( $tokenType === T_OPEN_CURLY_BRACKET && $opener !== null ) {
1315 1315
                 // We opened something that we don't have a scope opener for.
1316 1316
                 // Examples of this are curly brackets for string offsets etc.
1317 1317
                 // We want to ignore this so that we don't have an invalid scope
1318 1318
                 // map.
1319
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1320
-                    echo str_repeat("\t", $depth);
1321
-                    echo '* ignoring curly brace *'.PHP_EOL;
1319
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1320
+                    echo str_repeat( "\t", $depth );
1321
+                    echo '* ignoring curly brace *' . PHP_EOL;
1322 1322
                 }
1323 1323
 
1324 1324
                 $ignore++;
1325
-            } else if ($tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0) {
1325
+            } else if ( $tokenType === T_CLOSE_CURLY_BRACKET && $ignore > 0 ) {
1326 1326
                 // We found the end token for the opener we were ignoring.
1327
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1328
-                    echo str_repeat("\t", $depth);
1329
-                    echo '* finished ignoring curly brace *'.PHP_EOL;
1327
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1328
+                    echo str_repeat( "\t", $depth );
1329
+                    echo '* finished ignoring curly brace *' . PHP_EOL;
1330 1330
                 }
1331 1331
 
1332 1332
                 $ignore--;
1333
-            } else if ($opener === null
1334
-                && isset($this->scopeOpeners[$currType]) === true
1333
+            } else if ( $opener === null
1334
+                && isset( $this->scopeOpeners[ $currType ] ) === true
1335 1335
             ) {
1336 1336
                 // If we still haven't found the opener after 30 lines,
1337 1337
                 // we're not going to find it, unless we know it requires
1338 1338
                 // an opener (in which case we better keep looking) or the last
1339 1339
                 // token was empty (in which case we'll just confirm there is
1340 1340
                 // more code in this file and not just a big comment).
1341
-                if ($this->tokens[$i]['line'] >= ($startLine + 30)
1342
-                    && isset(Util\Tokens::$emptyTokens[$this->tokens[($i - 1)]['code']]) === false
1341
+                if ( $this->tokens[ $i ][ 'line' ] >= ( $startLine + 30 )
1342
+                    && isset( Util\Tokens::$emptyTokens[ $this->tokens[ ( $i - 1 ) ][ 'code' ] ] ) === false
1343 1343
                 ) {
1344
-                    if ($this->scopeOpeners[$currType]['strict'] === true) {
1345
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1346
-                            $type  = $this->tokens[$stackPtr]['type'];
1347
-                            $lines = ($this->tokens[$i]['line'] - $startLine);
1348
-                            echo str_repeat("\t", $depth);
1349
-                            echo "=> Still looking for $stackPtr:$type scope opener after $lines lines".PHP_EOL;
1344
+                    if ( $this->scopeOpeners[ $currType ][ 'strict' ] === true ) {
1345
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1346
+                            $type  = $this->tokens[ $stackPtr ][ 'type' ];
1347
+                            $lines = ( $this->tokens[ $i ][ 'line' ] - $startLine );
1348
+                            echo str_repeat( "\t", $depth );
1349
+                            echo "=> Still looking for $stackPtr:$type scope opener after $lines lines" . PHP_EOL;
1350 1350
                         }
1351 1351
                     } else {
1352
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1353
-                            $type = $this->tokens[$stackPtr]['type'];
1354
-                            echo str_repeat("\t", $depth);
1355
-                            echo "=> Couldn't find scope opener for $stackPtr:$type, bailing".PHP_EOL;
1352
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1353
+                            $type = $this->tokens[ $stackPtr ][ 'type' ];
1354
+                            echo str_repeat( "\t", $depth );
1355
+                            echo "=> Couldn't find scope opener for $stackPtr:$type, bailing" . PHP_EOL;
1356 1356
                         }
1357 1357
 
1358 1358
                         return $stackPtr;
1359 1359
                     }
1360 1360
                 }
1361
-            } else if ($opener !== null
1361
+            } else if ( $opener !== null
1362 1362
                 && $tokenType !== T_BREAK
1363
-                && isset($this->endScopeTokens[$tokenType]) === true
1363
+                && isset( $this->endScopeTokens[ $tokenType ] ) === true
1364 1364
             ) {
1365
-                if (isset($this->tokens[$i]['scope_condition']) === false) {
1366
-                    if ($ignore > 0) {
1365
+                if ( isset( $this->tokens[ $i ][ 'scope_condition' ] ) === false ) {
1366
+                    if ( $ignore > 0 ) {
1367 1367
                         // We found the end token for the opener we were ignoring.
1368
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1369
-                            echo str_repeat("\t", $depth);
1370
-                            echo '* finished ignoring curly brace *'.PHP_EOL;
1368
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1369
+                            echo str_repeat( "\t", $depth );
1370
+                            echo '* finished ignoring curly brace *' . PHP_EOL;
1371 1371
                         }
1372 1372
 
1373 1373
                         $ignore--;
@@ -1376,19 +1376,19 @@  discard block
 block discarded – undo
1376 1376
                         // have a condition, so it belongs to another token and
1377 1377
                         // our token doesn't have a closer, so pretend this is
1378 1378
                         // the closer.
1379
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1380
-                            $type = $this->tokens[$stackPtr]['type'];
1381
-                            echo str_repeat("\t", $depth);
1382
-                            echo "=> Found (unexpected) scope closer for $stackPtr:$type".PHP_EOL;
1379
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1380
+                            $type = $this->tokens[ $stackPtr ][ 'type' ];
1381
+                            echo str_repeat( "\t", $depth );
1382
+                            echo "=> Found (unexpected) scope closer for $stackPtr:$type" . PHP_EOL;
1383 1383
                         }
1384 1384
 
1385
-                        foreach ([$stackPtr, $opener] as $token) {
1386
-                            $this->tokens[$token]['scope_condition'] = $stackPtr;
1387
-                            $this->tokens[$token]['scope_opener']    = $opener;
1388
-                            $this->tokens[$token]['scope_closer']    = $i;
1385
+                        foreach ( [ $stackPtr, $opener ] as $token ) {
1386
+                            $this->tokens[ $token ][ 'scope_condition' ] = $stackPtr;
1387
+                            $this->tokens[ $token ][ 'scope_opener' ]    = $opener;
1388
+                            $this->tokens[ $token ][ 'scope_closer' ]    = $i;
1389 1389
                         }
1390 1390
 
1391
-                        return ($i - 1);
1391
+                        return ( $i - 1 );
1392 1392
                     }//end if
1393 1393
                 }//end if
1394 1394
             }//end if
@@ -1411,233 +1411,233 @@  discard block
 block discarded – undo
1411 1411
      */
1412 1412
     private function createLevelMap()
1413 1413
     {
1414
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1415
-            echo "\t*** START LEVEL MAP ***".PHP_EOL;
1414
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1415
+            echo "\t*** START LEVEL MAP ***" . PHP_EOL;
1416 1416
         }
1417 1417
 
1418
-        $this->numTokens = count($this->tokens);
1418
+        $this->numTokens = count( $this->tokens );
1419 1419
         $level           = 0;
1420
-        $conditions      = [];
1420
+        $conditions      = [ ];
1421 1421
         $lastOpener      = null;
1422
-        $openers         = [];
1422
+        $openers         = [ ];
1423 1423
 
1424
-        for ($i = 0; $i < $this->numTokens; $i++) {
1425
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1426
-                $type = $this->tokens[$i]['type'];
1427
-                $line = $this->tokens[$i]['line'];
1428
-                $len  = $this->tokens[$i]['length'];
1429
-                $col  = $this->tokens[$i]['column'];
1424
+        for ( $i = 0; $i < $this->numTokens; $i++ ) {
1425
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1426
+                $type = $this->tokens[ $i ][ 'type' ];
1427
+                $line = $this->tokens[ $i ][ 'line' ];
1428
+                $len  = $this->tokens[ $i ][ 'length' ];
1429
+                $col  = $this->tokens[ $i ][ 'column' ];
1430 1430
 
1431
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1431
+                $content = Util\Common::prepareForOutput( $this->tokens[ $i ][ 'content' ] );
1432 1432
 
1433
-                echo str_repeat("\t", ($level + 1));
1433
+                echo str_repeat( "\t", ( $level + 1 ) );
1434 1434
                 echo "Process token $i on line $line [col:$col;len:$len;lvl:$level;";
1435
-                if (empty($conditions) !== true) {
1435
+                if ( empty( $conditions ) !== true ) {
1436 1436
                     $condString = 'conds;';
1437
-                    foreach ($conditions as $condition) {
1438
-                        $condString .= Util\Tokens::tokenName($condition).',';
1437
+                    foreach ( $conditions as $condition ) {
1438
+                        $condString .= Util\Tokens::tokenName( $condition ) . ',';
1439 1439
                     }
1440 1440
 
1441
-                    echo rtrim($condString, ',').';';
1441
+                    echo rtrim( $condString, ',' ) . ';';
1442 1442
                 }
1443 1443
 
1444
-                echo "]: $type => $content".PHP_EOL;
1444
+                echo "]: $type => $content" . PHP_EOL;
1445 1445
             }//end if
1446 1446
 
1447
-            $this->tokens[$i]['level']      = $level;
1448
-            $this->tokens[$i]['conditions'] = $conditions;
1447
+            $this->tokens[ $i ][ 'level' ]      = $level;
1448
+            $this->tokens[ $i ][ 'conditions' ] = $conditions;
1449 1449
 
1450
-            if (isset($this->tokens[$i]['scope_condition']) === true) {
1450
+            if ( isset( $this->tokens[ $i ][ 'scope_condition' ] ) === true ) {
1451 1451
                 // Check to see if this token opened the scope.
1452
-                if ($this->tokens[$i]['scope_opener'] === $i) {
1453
-                    $stackPtr = $this->tokens[$i]['scope_condition'];
1454
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1455
-                        $type = $this->tokens[$stackPtr]['type'];
1456
-                        echo str_repeat("\t", ($level + 1));
1457
-                        echo "=> Found scope opener for $stackPtr:$type".PHP_EOL;
1452
+                if ( $this->tokens[ $i ][ 'scope_opener' ] === $i ) {
1453
+                    $stackPtr = $this->tokens[ $i ][ 'scope_condition' ];
1454
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1455
+                        $type = $this->tokens[ $stackPtr ][ 'type' ];
1456
+                        echo str_repeat( "\t", ( $level + 1 ) );
1457
+                        echo "=> Found scope opener for $stackPtr:$type" . PHP_EOL;
1458 1458
                     }
1459 1459
 
1460
-                    $stackPtr = $this->tokens[$i]['scope_condition'];
1460
+                    $stackPtr = $this->tokens[ $i ][ 'scope_condition' ];
1461 1461
 
1462 1462
                     // If we find a scope opener that has a shared closer,
1463 1463
                     // then we need to go back over the condition map that we
1464 1464
                     // just created and fix ourselves as we just added some
1465 1465
                     // conditions where there was none. This happens for T_CASE
1466 1466
                     // statements that are using the same break statement.
1467
-                    if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $this->tokens[$i]['scope_closer']) {
1467
+                    if ( $lastOpener !== null && $this->tokens[ $lastOpener ][ 'scope_closer' ] === $this->tokens[ $i ][ 'scope_closer' ] ) {
1468 1468
                         // This opener shares its closer with the previous opener,
1469 1469
                         // but we still need to check if the two openers share their
1470 1470
                         // closer with each other directly (like CASE and DEFAULT)
1471 1471
                         // or if they are just sharing because one doesn't have a
1472 1472
                         // closer (like CASE with no BREAK using a SWITCHes closer).
1473
-                        $thisType = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1474
-                        $opener   = $this->tokens[$lastOpener]['scope_condition'];
1473
+                        $thisType = $this->tokens[ $this->tokens[ $i ][ 'scope_condition' ] ][ 'code' ];
1474
+                        $opener   = $this->tokens[ $lastOpener ][ 'scope_condition' ];
1475 1475
 
1476
-                        $isShared = isset($this->scopeOpeners[$thisType]['with'][$this->tokens[$opener]['code']]);
1476
+                        $isShared = isset( $this->scopeOpeners[ $thisType ][ 'with' ][ $this->tokens[ $opener ][ 'code' ] ] );
1477 1477
 
1478
-                        reset($this->scopeOpeners[$thisType]['end']);
1479
-                        reset($this->scopeOpeners[$this->tokens[$opener]['code']]['end']);
1480
-                        $sameEnd = (current($this->scopeOpeners[$thisType]['end']) === current($this->scopeOpeners[$this->tokens[$opener]['code']]['end']));
1478
+                        reset( $this->scopeOpeners[ $thisType ][ 'end' ] );
1479
+                        reset( $this->scopeOpeners[ $this->tokens[ $opener ][ 'code' ] ][ 'end' ] );
1480
+                        $sameEnd = ( current( $this->scopeOpeners[ $thisType ][ 'end' ] ) === current( $this->scopeOpeners[ $this->tokens[ $opener ][ 'code' ] ][ 'end' ] ) );
1481 1481
 
1482
-                        if ($isShared === true && $sameEnd === true) {
1482
+                        if ( $isShared === true && $sameEnd === true ) {
1483 1483
                             $badToken = $opener;
1484
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1485
-                                $type = $this->tokens[$badToken]['type'];
1486
-                                echo str_repeat("\t", ($level + 1));
1487
-                                echo "* shared closer, cleaning up $badToken:$type *".PHP_EOL;
1484
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1485
+                                $type = $this->tokens[ $badToken ][ 'type' ];
1486
+                                echo str_repeat( "\t", ( $level + 1 ) );
1487
+                                echo "* shared closer, cleaning up $badToken:$type *" . PHP_EOL;
1488 1488
                             }
1489 1489
 
1490
-                            for ($x = $this->tokens[$i]['scope_condition']; $x <= $i; $x++) {
1491
-                                $oldConditions = $this->tokens[$x]['conditions'];
1492
-                                $oldLevel      = $this->tokens[$x]['level'];
1493
-                                $this->tokens[$x]['level']--;
1494
-                                unset($this->tokens[$x]['conditions'][$badToken]);
1495
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1496
-                                    $type     = $this->tokens[$x]['type'];
1490
+                            for ( $x = $this->tokens[ $i ][ 'scope_condition' ]; $x <= $i; $x++ ) {
1491
+                                $oldConditions = $this->tokens[ $x ][ 'conditions' ];
1492
+                                $oldLevel      = $this->tokens[ $x ][ 'level' ];
1493
+                                $this->tokens[ $x ][ 'level' ]--;
1494
+                                unset( $this->tokens[ $x ][ 'conditions' ][ $badToken ] );
1495
+                                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1496
+                                    $type     = $this->tokens[ $x ][ 'type' ];
1497 1497
                                     $oldConds = '';
1498
-                                    foreach ($oldConditions as $condition) {
1499
-                                        $oldConds .= Util\Tokens::tokenName($condition).',';
1498
+                                    foreach ( $oldConditions as $condition ) {
1499
+                                        $oldConds .= Util\Tokens::tokenName( $condition ) . ',';
1500 1500
                                     }
1501 1501
 
1502
-                                    $oldConds = rtrim($oldConds, ',');
1502
+                                    $oldConds = rtrim( $oldConds, ',' );
1503 1503
 
1504 1504
                                     $newConds = '';
1505
-                                    foreach ($this->tokens[$x]['conditions'] as $condition) {
1506
-                                        $newConds .= Util\Tokens::tokenName($condition).',';
1505
+                                    foreach ( $this->tokens[ $x ][ 'conditions' ] as $condition ) {
1506
+                                        $newConds .= Util\Tokens::tokenName( $condition ) . ',';
1507 1507
                                     }
1508 1508
 
1509
-                                    $newConds = rtrim($newConds, ',');
1509
+                                    $newConds = rtrim( $newConds, ',' );
1510 1510
 
1511
-                                    $newLevel = $this->tokens[$x]['level'];
1512
-                                    echo str_repeat("\t", ($level + 1));
1513
-                                    echo "* cleaned $x:$type *".PHP_EOL;
1514
-                                    echo str_repeat("\t", ($level + 2));
1515
-                                    echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1516
-                                    echo str_repeat("\t", ($level + 2));
1517
-                                    echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1511
+                                    $newLevel = $this->tokens[ $x ][ 'level' ];
1512
+                                    echo str_repeat( "\t", ( $level + 1 ) );
1513
+                                    echo "* cleaned $x:$type *" . PHP_EOL;
1514
+                                    echo str_repeat( "\t", ( $level + 2 ) );
1515
+                                    echo "=> level changed from $oldLevel to $newLevel" . PHP_EOL;
1516
+                                    echo str_repeat( "\t", ( $level + 2 ) );
1517
+                                    echo "=> conditions changed from $oldConds to $newConds" . PHP_EOL;
1518 1518
                                 }//end if
1519 1519
                             }//end for
1520 1520
 
1521
-                            unset($conditions[$badToken]);
1522
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1523
-                                $type = $this->tokens[$badToken]['type'];
1524
-                                echo str_repeat("\t", ($level + 1));
1525
-                                echo "* token $badToken:$type removed from conditions array *".PHP_EOL;
1521
+                            unset( $conditions[ $badToken ] );
1522
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1523
+                                $type = $this->tokens[ $badToken ][ 'type' ];
1524
+                                echo str_repeat( "\t", ( $level + 1 ) );
1525
+                                echo "* token $badToken:$type removed from conditions array *" . PHP_EOL;
1526 1526
                             }
1527 1527
 
1528
-                            unset($openers[$lastOpener]);
1528
+                            unset( $openers[ $lastOpener ] );
1529 1529
 
1530 1530
                             $level--;
1531
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1532
-                                echo str_repeat("\t", ($level + 2));
1533
-                                echo '* level decreased *'.PHP_EOL;
1531
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1532
+                                echo str_repeat( "\t", ( $level + 2 ) );
1533
+                                echo '* level decreased *' . PHP_EOL;
1534 1534
                             }
1535 1535
                         }//end if
1536 1536
                     }//end if
1537 1537
 
1538 1538
                     $level++;
1539
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1540
-                        echo str_repeat("\t", ($level + 1));
1541
-                        echo '* level increased *'.PHP_EOL;
1539
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1540
+                        echo str_repeat( "\t", ( $level + 1 ) );
1541
+                        echo '* level increased *' . PHP_EOL;
1542 1542
                     }
1543 1543
 
1544
-                    $conditions[$stackPtr] = $this->tokens[$stackPtr]['code'];
1545
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1546
-                        $type = $this->tokens[$stackPtr]['type'];
1547
-                        echo str_repeat("\t", ($level + 1));
1548
-                        echo "* token $stackPtr:$type added to conditions array *".PHP_EOL;
1544
+                    $conditions[ $stackPtr ] = $this->tokens[ $stackPtr ][ 'code' ];
1545
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1546
+                        $type = $this->tokens[ $stackPtr ][ 'type' ];
1547
+                        echo str_repeat( "\t", ( $level + 1 ) );
1548
+                        echo "* token $stackPtr:$type added to conditions array *" . PHP_EOL;
1549 1549
                     }
1550 1550
 
1551
-                    $lastOpener = $this->tokens[$i]['scope_opener'];
1552
-                    if ($lastOpener !== null) {
1553
-                        $openers[$lastOpener] = $lastOpener;
1551
+                    $lastOpener = $this->tokens[ $i ][ 'scope_opener' ];
1552
+                    if ( $lastOpener !== null ) {
1553
+                        $openers[ $lastOpener ] = $lastOpener;
1554 1554
                     }
1555
-                } else if ($lastOpener !== null && $this->tokens[$lastOpener]['scope_closer'] === $i) {
1556
-                    foreach (array_reverse($openers) as $opener) {
1557
-                        if ($this->tokens[$opener]['scope_closer'] === $i) {
1558
-                            $oldOpener = array_pop($openers);
1559
-                            if (empty($openers) === false) {
1560
-                                $lastOpener           = array_pop($openers);
1561
-                                $openers[$lastOpener] = $lastOpener;
1555
+                } else if ( $lastOpener !== null && $this->tokens[ $lastOpener ][ 'scope_closer' ] === $i ) {
1556
+                    foreach ( array_reverse( $openers ) as $opener ) {
1557
+                        if ( $this->tokens[ $opener ][ 'scope_closer' ] === $i ) {
1558
+                            $oldOpener = array_pop( $openers );
1559
+                            if ( empty( $openers ) === false ) {
1560
+                                $lastOpener           = array_pop( $openers );
1561
+                                $openers[ $lastOpener ] = $lastOpener;
1562 1562
                             } else {
1563 1563
                                 $lastOpener = null;
1564 1564
                             }
1565 1565
 
1566
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1567
-                                $type = $this->tokens[$oldOpener]['type'];
1568
-                                echo str_repeat("\t", ($level + 1));
1569
-                                echo "=> Found scope closer for $oldOpener:$type".PHP_EOL;
1566
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1567
+                                $type = $this->tokens[ $oldOpener ][ 'type' ];
1568
+                                echo str_repeat( "\t", ( $level + 1 ) );
1569
+                                echo "=> Found scope closer for $oldOpener:$type" . PHP_EOL;
1570 1570
                             }
1571 1571
 
1572
-                            $oldCondition = array_pop($conditions);
1573
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1574
-                                echo str_repeat("\t", ($level + 1));
1575
-                                echo '* token '.Util\Tokens::tokenName($oldCondition).' removed from conditions array *'.PHP_EOL;
1572
+                            $oldCondition = array_pop( $conditions );
1573
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1574
+                                echo str_repeat( "\t", ( $level + 1 ) );
1575
+                                echo '* token ' . Util\Tokens::tokenName( $oldCondition ) . ' removed from conditions array *' . PHP_EOL;
1576 1576
                             }
1577 1577
 
1578 1578
                             // Make sure this closer actually belongs to us.
1579 1579
                             // Either the condition also has to think this is the
1580 1580
                             // closer, or it has to allow sharing with us.
1581
-                            $condition = $this->tokens[$this->tokens[$i]['scope_condition']]['code'];
1582
-                            if ($condition !== $oldCondition) {
1583
-                                if (isset($this->scopeOpeners[$oldCondition]['with'][$condition]) === false) {
1584
-                                    $badToken = $this->tokens[$oldOpener]['scope_condition'];
1585
-
1586
-                                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1587
-                                        $type = Util\Tokens::tokenName($oldCondition);
1588
-                                        echo str_repeat("\t", ($level + 1));
1589
-                                        echo "* scope closer was bad, cleaning up $badToken:$type *".PHP_EOL;
1581
+                            $condition = $this->tokens[ $this->tokens[ $i ][ 'scope_condition' ] ][ 'code' ];
1582
+                            if ( $condition !== $oldCondition ) {
1583
+                                if ( isset( $this->scopeOpeners[ $oldCondition ][ 'with' ][ $condition ] ) === false ) {
1584
+                                    $badToken = $this->tokens[ $oldOpener ][ 'scope_condition' ];
1585
+
1586
+                                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1587
+                                        $type = Util\Tokens::tokenName( $oldCondition );
1588
+                                        echo str_repeat( "\t", ( $level + 1 ) );
1589
+                                        echo "* scope closer was bad, cleaning up $badToken:$type *" . PHP_EOL;
1590 1590
                                     }
1591 1591
 
1592
-                                    for ($x = ($oldOpener + 1); $x <= $i; $x++) {
1593
-                                        $oldConditions = $this->tokens[$x]['conditions'];
1594
-                                        $oldLevel      = $this->tokens[$x]['level'];
1595
-                                        $this->tokens[$x]['level']--;
1596
-                                        unset($this->tokens[$x]['conditions'][$badToken]);
1597
-                                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1598
-                                            $type     = $this->tokens[$x]['type'];
1592
+                                    for ( $x = ( $oldOpener + 1 ); $x <= $i; $x++ ) {
1593
+                                        $oldConditions = $this->tokens[ $x ][ 'conditions' ];
1594
+                                        $oldLevel      = $this->tokens[ $x ][ 'level' ];
1595
+                                        $this->tokens[ $x ][ 'level' ]--;
1596
+                                        unset( $this->tokens[ $x ][ 'conditions' ][ $badToken ] );
1597
+                                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1598
+                                            $type     = $this->tokens[ $x ][ 'type' ];
1599 1599
                                             $oldConds = '';
1600
-                                            foreach ($oldConditions as $condition) {
1601
-                                                $oldConds .= Util\Tokens::tokenName($condition).',';
1600
+                                            foreach ( $oldConditions as $condition ) {
1601
+                                                $oldConds .= Util\Tokens::tokenName( $condition ) . ',';
1602 1602
                                             }
1603 1603
 
1604
-                                            $oldConds = rtrim($oldConds, ',');
1604
+                                            $oldConds = rtrim( $oldConds, ',' );
1605 1605
 
1606 1606
                                             $newConds = '';
1607
-                                            foreach ($this->tokens[$x]['conditions'] as $condition) {
1608
-                                                $newConds .= Util\Tokens::tokenName($condition).',';
1607
+                                            foreach ( $this->tokens[ $x ][ 'conditions' ] as $condition ) {
1608
+                                                $newConds .= Util\Tokens::tokenName( $condition ) . ',';
1609 1609
                                             }
1610 1610
 
1611
-                                            $newConds = rtrim($newConds, ',');
1611
+                                            $newConds = rtrim( $newConds, ',' );
1612 1612
 
1613
-                                            $newLevel = $this->tokens[$x]['level'];
1614
-                                            echo str_repeat("\t", ($level + 1));
1615
-                                            echo "* cleaned $x:$type *".PHP_EOL;
1616
-                                            echo str_repeat("\t", ($level + 2));
1617
-                                            echo "=> level changed from $oldLevel to $newLevel".PHP_EOL;
1618
-                                            echo str_repeat("\t", ($level + 2));
1619
-                                            echo "=> conditions changed from $oldConds to $newConds".PHP_EOL;
1613
+                                            $newLevel = $this->tokens[ $x ][ 'level' ];
1614
+                                            echo str_repeat( "\t", ( $level + 1 ) );
1615
+                                            echo "* cleaned $x:$type *" . PHP_EOL;
1616
+                                            echo str_repeat( "\t", ( $level + 2 ) );
1617
+                                            echo "=> level changed from $oldLevel to $newLevel" . PHP_EOL;
1618
+                                            echo str_repeat( "\t", ( $level + 2 ) );
1619
+                                            echo "=> conditions changed from $oldConds to $newConds" . PHP_EOL;
1620 1620
                                         }//end if
1621 1621
                                     }//end for
1622 1622
                                 }//end if
1623 1623
                             }//end if
1624 1624
 
1625 1625
                             $level--;
1626
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1627
-                                echo str_repeat("\t", ($level + 2));
1628
-                                echo '* level decreased *'.PHP_EOL;
1626
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1627
+                                echo str_repeat( "\t", ( $level + 2 ) );
1628
+                                echo '* level decreased *' . PHP_EOL;
1629 1629
                             }
1630 1630
 
1631
-                            $this->tokens[$i]['level']      = $level;
1632
-                            $this->tokens[$i]['conditions'] = $conditions;
1631
+                            $this->tokens[ $i ][ 'level' ]      = $level;
1632
+                            $this->tokens[ $i ][ 'conditions' ] = $conditions;
1633 1633
                         }//end if
1634 1634
                     }//end foreach
1635 1635
                 }//end if
1636 1636
             }//end if
1637 1637
         }//end for
1638 1638
 
1639
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1640
-            echo "\t*** END LEVEL MAP ***".PHP_EOL;
1639
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1640
+            echo "\t*** END LEVEL MAP ***" . PHP_EOL;
1641 1641
         }
1642 1642
 
1643 1643
     }//end createLevelMap()
Please login to merge, or discard this patch.
Braces   +11 added lines, -22 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Exceptions\RuntimeException;
13 13
 use PHP_CodeSniffer\Util;
14 14
 
15
-abstract class Tokenizer
16
-{
15
+abstract class Tokenizer {
17 16
 
18 17
     /**
19 18
      * The config data for the run.
@@ -82,8 +81,7 @@  discard block
 block discarded – undo
82 81
      * @return void
83 82
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
84 83
      */
85
-    public function __construct($content, $config, $eolChar='\n')
86
-    {
84
+    public function __construct($content, $config, $eolChar='\n') {
87 85
         $this->eolChar = $eolChar;
88 86
 
89 87
         $this->config = $config;
@@ -113,8 +111,7 @@  discard block
 block discarded – undo
113 111
      *
114 112
      * @return boolean
115 113
      */
116
-    protected function isMinifiedContent($content, $eolChar='\n')
117
-    {
114
+    protected function isMinifiedContent($content, $eolChar='\n') {
118 115
         // Minified files often have a very large number of characters per line
119 116
         // and cause issues when tokenizing.
120 117
         $numChars = strlen($content);
@@ -134,8 +131,7 @@  discard block
 block discarded – undo
134 131
      *
135 132
      * @return array
136 133
      */
137
-    public function getTokens()
138
-    {
134
+    public function getTokens() {
139 135
         return $this->tokens;
140 136
 
141 137
     }//end getTokens()
@@ -167,8 +163,7 @@  discard block
 block discarded – undo
167 163
      *
168 164
      * @return void
169 165
      */
170
-    private function createPositionMap()
171
-    {
166
+    private function createPositionMap() {
172 167
         $currColumn = 1;
173 168
         $lineNumber = 1;
174 169
         $eolLen     = strlen($this->eolChar);
@@ -576,8 +571,7 @@  discard block
 block discarded – undo
576 571
      *
577 572
      * @return void
578 573
      */
579
-    public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null)
580
-    {
574
+    public function replaceTabsInToken(&$token, $prefix=' ', $padding=' ', $tabWidth=null) {
581 575
         $checkEncoding = false;
582 576
         if (function_exists('iconv_strlen') === true) {
583 577
             $checkEncoding = true;
@@ -668,8 +662,7 @@  discard block
 block discarded – undo
668 662
      *
669 663
      * @return void
670 664
      */
671
-    private function createTokenMap()
672
-    {
665
+    private function createTokenMap() {
673 666
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
674 667
             echo "\t*** START TOKEN MAP ***".PHP_EOL;
675 668
         }
@@ -798,8 +791,7 @@  discard block
 block discarded – undo
798 791
      *
799 792
      * @return void
800 793
      */
801
-    private function createParenthesisNestingMap()
802
-    {
794
+    private function createParenthesisNestingMap() {
803 795
         $map = [];
804 796
         for ($i = 0; $i < $this->numTokens; $i++) {
805 797
             if (isset($this->tokens[$i]['parenthesis_opener']) === true
@@ -836,8 +828,7 @@  discard block
 block discarded – undo
836 828
      * @return void
837 829
      * @see    recurseScopeMap()
838 830
      */
839
-    private function createScopeMap()
840
-    {
831
+    private function createScopeMap() {
841 832
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
842 833
             echo "\t*** START SCOPE MAP ***".PHP_EOL;
843 834
         }
@@ -880,8 +871,7 @@  discard block
 block discarded – undo
880 871
      *
881 872
      * @return int The position in the stack that closed the scope.
882 873
      */
883
-    private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0)
884
-    {
874
+    private function recurseScopeMap($stackPtr, $depth=1, &$ignore=0) {
885 875
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
886 876
             echo str_repeat("\t", $depth);
887 877
             echo "=> Begin scope map recursion at token $stackPtr with depth $depth".PHP_EOL;
@@ -1409,8 +1399,7 @@  discard block
 block discarded – undo
1409 1399
      *
1410 1400
      * @return void
1411 1401
      */
1412
-    private function createLevelMap()
1413
-    {
1402
+    private function createLevelMap() {
1414 1403
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
1415 1404
             echo "\t*** START LEVEL MAP ***".PHP_EOL;
1416 1405
         }
Please login to merge, or discard this patch.
vendor/wp-coding-standards/wpcs/WordPress/PHPCSHelper.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@
 block discarded – undo
93 93
 	 *
94 94
 	 * @param \PHP_CodeSniffer\Files\File $phpcsFile Optional. The current file being processed.
95 95
 	 *
96
-	 * @return bool True if annotations should be ignored, false otherwise.
96
+	 * @return boolean|null True if annotations should be ignored, false otherwise.
97 97
 	 */
98 98
 	public static function ignore_annotations( File $phpcsFile = null ) {
99 99
 		if ( isset( $phpcsFile, $phpcsFile->config->annotations ) ) {
Please login to merge, or discard this patch.
vendor/wp-coding-standards/wpcs/WordPress/Sniff.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -951,7 +951,7 @@  discard block
 block discarded – undo
951 951
 	 * @param bool   $is_error  Optional. Whether to report the message as an 'error' or 'warning'.
952 952
 	 *                          Defaults to true (error).
953 953
 	 * @param string $code      Optional error code for the message. Defaults to 'Found'.
954
-	 * @param array  $data      Optional input for the data replacements.
954
+	 * @param string[]  $data      Optional input for the data replacements.
955 955
 	 * @param int    $severity  Optional. Severity level. Defaults to 0 which will translate to
956 956
 	 *                          the PHPCS default severity level.
957 957
 	 * @return bool
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
 	 * @param bool   $is_error  Optional. Whether to report the message as an 'error' or 'warning'.
971 971
 	 *                          Defaults to true (error).
972 972
 	 * @param string $code      Optional error code for the message. Defaults to 'Found'.
973
-	 * @param array  $data      Optional input for the data replacements.
973
+	 * @param string[]  $data      Optional input for the data replacements.
974 974
 	 * @param int    $severity  Optional. Severity level. Defaults to 0 which will translate to
975 975
 	 *                          the PHPCS default severity level.
976 976
 	 * @return bool
Please login to merge, or discard this patch.
Spacing   +193 added lines, -193 removed lines patch added patch discarded remove patch
@@ -1105,10 +1105,10 @@  discard block
 block discarded – undo
1105 1105
 	protected function get_last_ptr_on_line( $stackPtr ) {
1106 1106
 
1107 1107
 		$tokens      = $this->tokens;
1108
-		$currentLine = $tokens[ $stackPtr ]['line'];
1108
+		$currentLine = $tokens[ $stackPtr ][ 'line' ];
1109 1109
 		$nextPtr     = ( $stackPtr + 1 );
1110 1110
 
1111
-		while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ]['line'] === $currentLine ) {
1111
+		while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ][ 'line' ] === $currentLine ) {
1112 1112
 			$nextPtr++;
1113 1113
 			// Do nothing, we just want the last token of the line.
1114 1114
 		}
@@ -1186,27 +1186,27 @@  discard block
 block discarded – undo
1186 1186
 
1187 1187
 		if ( false !== $end_of_statement ) {
1188 1188
 			// If the statement was ended by a semicolon, check if there is a whitelist comment directly after it.
1189
-			if ( \T_SEMICOLON === $this->tokens[ $end_of_statement ]['code'] ) {
1189
+			if ( \T_SEMICOLON === $this->tokens[ $end_of_statement ][ 'code' ] ) {
1190 1190
 				$lastPtr = $this->phpcsFile->findNext( \T_WHITESPACE, ( $end_of_statement + 1 ), null, true );
1191
-			} elseif ( \T_CLOSE_TAG === $this->tokens[ $end_of_statement ]['code'] ) {
1191
+			} elseif ( \T_CLOSE_TAG === $this->tokens[ $end_of_statement ][ 'code' ] ) {
1192 1192
 				// If the semicolon was left out and it was terminated by an ending tag, we need to look backwards.
1193 1193
 				$lastPtr = $this->phpcsFile->findPrevious( \T_WHITESPACE, ( $end_of_statement - 1 ), null, true );
1194 1194
 			}
1195 1195
 
1196
-			if ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code']
1197
-					|| ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] )
1198
-					&& \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) )
1199
-				&& $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line']
1200
-				&& preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1
1196
+			if ( ( \T_COMMENT === $this->tokens[ $lastPtr ][ 'code' ]
1197
+					|| ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] )
1198
+					&& \T_PHPCS_SET !== $this->tokens[ $lastPtr ][ 'code' ] ) )
1199
+				&& $this->tokens[ $lastPtr ][ 'line' ] === $this->tokens[ $end_of_statement ][ 'line' ]
1200
+				&& preg_match( $regex, $this->tokens[ $lastPtr ][ 'content' ] ) === 1
1201 1201
 			) {
1202 1202
 				if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false
1203
-					&& isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false
1203
+					&& isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) === false
1204 1204
 				) {
1205 1205
 					$this->phpcsFile->addWarning(
1206 1206
 						$deprecation_notice,
1207 1207
 						$lastPtr,
1208 1208
 						$deprecation_code,
1209
-						array( $this->tokens[ $lastPtr ]['content'] )
1209
+						array( $this->tokens[ $lastPtr ][ 'content' ] )
1210 1210
 					);
1211 1211
 
1212 1212
 					$thrown_notices[ $filename ][ $lastPtr ] = true;
@@ -1221,20 +1221,20 @@  discard block
 block discarded – undo
1221 1221
 		$end_of_line = $this->get_last_ptr_on_line( $stackPtr );
1222 1222
 		$lastPtr     = $this->phpcsFile->findPrevious( \T_WHITESPACE, $end_of_line, null, true );
1223 1223
 
1224
-		if ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code']
1225
-				|| ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] )
1226
-				&& \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) )
1227
-			&& $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line']
1228
-			&& preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1
1224
+		if ( ( \T_COMMENT === $this->tokens[ $lastPtr ][ 'code' ]
1225
+				|| ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] )
1226
+				&& \T_PHPCS_SET !== $this->tokens[ $lastPtr ][ 'code' ] ) )
1227
+			&& $this->tokens[ $lastPtr ][ 'line' ] === $this->tokens[ $stackPtr ][ 'line' ]
1228
+			&& preg_match( $regex, $this->tokens[ $lastPtr ][ 'content' ] ) === 1
1229 1229
 		) {
1230 1230
 			if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false
1231
-				&& isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false
1231
+				&& isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) === false
1232 1232
 			) {
1233 1233
 				$this->phpcsFile->addWarning(
1234 1234
 					$deprecation_notice,
1235 1235
 					$lastPtr,
1236 1236
 					$deprecation_code,
1237
-					array( $this->tokens[ $lastPtr ]['content'] )
1237
+					array( $this->tokens[ $lastPtr ][ 'content' ] )
1238 1238
 				);
1239 1239
 
1240 1240
 				$thrown_notices[ $filename ][ $lastPtr ] = true;
@@ -1268,7 +1268,7 @@  discard block
 block discarded – undo
1268 1268
 			return false;
1269 1269
 		}
1270 1270
 
1271
-		$conditions = $this->tokens[ $stackPtr ]['conditions'];
1271
+		$conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
1272 1272
 		foreach ( $conditions as $token => $condition ) {
1273 1273
 			if ( $token === $functionToken ) {
1274 1274
 				// Only examine the conditions the function is nested in, not those nested within the function.
@@ -1303,7 +1303,7 @@  discard block
 block discarded – undo
1303 1303
 	 */
1304 1304
 	protected function is_test_class( $stackPtr ) {
1305 1305
 
1306
-		if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === false ) {
1306
+		if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) === false ) {
1307 1307
 			return false;
1308 1308
 		}
1309 1309
 
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 
1335 1335
 		// Does the class/trait extend one of the whitelisted test classes ?
1336 1336
 		$extendedClassName = $this->phpcsFile->findExtendedClassName( $stackPtr );
1337
-		if ( '\\' === $extendedClassName[0] ) {
1337
+		if ( '\\' === $extendedClassName[ 0 ] ) {
1338 1338
 			if ( isset( $whitelist[ substr( $extendedClassName, 1 ) ] ) ) {
1339 1339
 				return true;
1340 1340
 			}
@@ -1380,7 +1380,7 @@  discard block
 block discarded – undo
1380 1380
 		);
1381 1381
 
1382 1382
 		// Must be a variable, constant or closing square bracket (see below).
1383
-		if ( ! isset( $valid[ $this->tokens[ $stackPtr ]['code'] ] ) ) {
1383
+		if ( ! isset( $valid[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) {
1384 1384
 			return false;
1385 1385
 		}
1386 1386
 
@@ -1399,15 +1399,15 @@  discard block
 block discarded – undo
1399 1399
 		}
1400 1400
 
1401 1401
 		// If the next token is an assignment, that's all we need to know.
1402
-		if ( isset( Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) {
1402
+		if ( isset( Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ][ 'code' ] ] ) ) {
1403 1403
 			return true;
1404 1404
 		}
1405 1405
 
1406 1406
 		// Check if this is an array assignment, e.g., `$var['key'] = 'val';` .
1407
-		if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ]['code']
1408
-			&& isset( $this->tokens[ $next_non_empty ]['bracket_closer'] )
1407
+		if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ][ 'code' ]
1408
+			&& isset( $this->tokens[ $next_non_empty ][ 'bracket_closer' ] )
1409 1409
 		) {
1410
-			return $this->is_assignment( $this->tokens[ $next_non_empty ]['bracket_closer'] );
1410
+			return $this->is_assignment( $this->tokens[ $next_non_empty ][ 'bracket_closer' ] );
1411 1411
 		}
1412 1412
 
1413 1413
 		return false;
@@ -1444,12 +1444,12 @@  discard block
 block discarded – undo
1444 1444
 
1445 1445
 		// If we're in a function, only look inside of it.
1446 1446
 		// Once PHPCS 3.5.0 comes out this should be changed to the new Conditions::GetLastCondition() method.
1447
-		if ( isset( $tokens[ $stackPtr ]['conditions'] ) === true ) {
1448
-			$conditions = $tokens[ $stackPtr ]['conditions'];
1447
+		if ( isset( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) {
1448
+			$conditions = $tokens[ $stackPtr ][ 'conditions' ];
1449 1449
 			$conditions = array_reverse( $conditions, true );
1450 1450
 			foreach ( $conditions as $tokenPtr => $condition ) {
1451 1451
 				if ( \T_FUNCTION === $condition || \T_CLOSURE === $condition ) {
1452
-					$start = $tokens[ $tokenPtr ]['scope_opener'];
1452
+					$start = $tokens[ $tokenPtr ][ 'scope_opener' ];
1453 1453
 					break;
1454 1454
 				}
1455 1455
 			}
@@ -1470,23 +1470,23 @@  discard block
 block discarded – undo
1470 1470
 		// If this superglobal is inside such a check, look for the nonce after it as well,
1471 1471
 		// all the way to the end of the scope.
1472 1472
 		if ( true === $allow_nonce_after ) {
1473
-			$end = ( 0 === $start ) ? $this->phpcsFile->numTokens : $tokens[ $start ]['scope_closer'];
1473
+			$end = ( 0 === $start ) ? $this->phpcsFile->numTokens : $tokens[ $start ][ 'scope_closer' ];
1474 1474
 		}
1475 1475
 
1476 1476
 		// Check if we've looked here before.
1477 1477
 		$filename = $this->phpcsFile->getFilename();
1478 1478
 
1479 1479
 		if (
1480
-			$filename === $last['file']
1481
-			&& $start === $last['start']
1480
+			$filename === $last[ 'file' ]
1481
+			&& $start === $last[ 'start' ]
1482 1482
 		) {
1483 1483
 
1484
-			if ( false !== $last['nonce_check'] ) {
1484
+			if ( false !== $last[ 'nonce_check' ] ) {
1485 1485
 				// If we have already found an nonce check in this scope, we just
1486 1486
 				// need to check whether it comes before this token. It is OK if the
1487 1487
 				// check is after the token though, if this was only a isset() check.
1488
-				return ( true === $allow_nonce_after || $last['nonce_check'] < $stackPtr );
1489
-			} elseif ( $end <= $last['end'] ) {
1488
+				return ( true === $allow_nonce_after || $last[ 'nonce_check' ] < $stackPtr );
1489
+			} elseif ( $end <= $last[ 'end' ] ) {
1490 1490
 				// If not, we can still go ahead and return false if we've already
1491 1491
 				// checked to the end of the search area.
1492 1492
 				return false;
@@ -1494,7 +1494,7 @@  discard block
 block discarded – undo
1494 1494
 
1495 1495
 			// We haven't checked this far yet, but we can still save work by
1496 1496
 			// skipping over the part we've already checked.
1497
-			$start = $last['end'];
1497
+			$start = $last[ 'end' ];
1498 1498
 		} else {
1499 1499
 			$last = array(
1500 1500
 				'file'  => $filename,
@@ -1506,23 +1506,23 @@  discard block
 block discarded – undo
1506 1506
 		// Loop through the tokens looking for nonce verification functions.
1507 1507
 		for ( $i = $start; $i < $end; $i++ ) {
1508 1508
 			// Skip over nested closed scope constructs.
1509
-			if ( \T_FUNCTION === $tokens[ $i ]['code']
1510
-				|| \T_CLOSURE === $tokens[ $i ]['code']
1511
-				|| isset( Tokens::$ooScopeTokens[ $tokens[ $i ]['code'] ] )
1509
+			if ( \T_FUNCTION === $tokens[ $i ][ 'code' ]
1510
+				|| \T_CLOSURE === $tokens[ $i ][ 'code' ]
1511
+				|| isset( Tokens::$ooScopeTokens[ $tokens[ $i ][ 'code' ] ] )
1512 1512
 			) {
1513
-				if ( isset( $tokens[ $i ]['scope_closer'] ) ) {
1514
-					$i = $tokens[ $i ]['scope_closer'];
1513
+				if ( isset( $tokens[ $i ][ 'scope_closer' ] ) ) {
1514
+					$i = $tokens[ $i ][ 'scope_closer' ];
1515 1515
 				}
1516 1516
 				continue;
1517 1517
 			}
1518 1518
 
1519 1519
 			// If this isn't a function name, skip it.
1520
-			if ( \T_STRING !== $tokens[ $i ]['code'] ) {
1520
+			if ( \T_STRING !== $tokens[ $i ][ 'code' ] ) {
1521 1521
 				continue;
1522 1522
 			}
1523 1523
 
1524 1524
 			// If this is one of the nonce verification functions, we can bail out.
1525
-			if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ]['content'] ] ) ) {
1525
+			if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ][ 'content' ] ] ) ) {
1526 1526
 				/*
1527 1527
 				 * Now, make sure it is a call to a global function.
1528 1528
 				 */
@@ -1534,13 +1534,13 @@  discard block
 block discarded – undo
1534 1534
 					continue;
1535 1535
 				}
1536 1536
 
1537
-				$last['nonce_check'] = $i;
1537
+				$last[ 'nonce_check' ] = $i;
1538 1538
 				return true;
1539 1539
 			}
1540 1540
 		}
1541 1541
 
1542 1542
 		// We're still here, so no luck.
1543
-		$last['nonce_check'] = false;
1543
+		$last[ 'nonce_check' ] = false;
1544 1544
 
1545 1545
 		return false;
1546 1546
 	}
@@ -1558,11 +1558,11 @@  discard block
 block discarded – undo
1558 1558
 	 */
1559 1559
 	protected function is_in_isset_or_empty( $stackPtr ) {
1560 1560
 
1561
-		if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
1561
+		if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
1562 1562
 			return false;
1563 1563
 		}
1564 1564
 
1565
-		$nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis'];
1565
+		$nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
1566 1566
 
1567 1567
 		end( $nested_parenthesis );
1568 1568
 		$open_parenthesis = key( $nested_parenthesis );
@@ -1572,7 +1572,7 @@  discard block
 block discarded – undo
1572 1572
 			return false;
1573 1573
 		}
1574 1574
 
1575
-		$previous_code = $this->tokens[ $previous_non_empty ]['code'];
1575
+		$previous_code = $this->tokens[ $previous_non_empty ][ 'code' ];
1576 1576
 		if ( \T_ISSET === $previous_code || \T_EMPTY === $previous_code ) {
1577 1577
 			return true;
1578 1578
 		}
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
 		$functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions );
1586 1586
 		if ( false !== $functionPtr ) {
1587 1587
 			$second_param = $this->get_function_call_parameter( $functionPtr, 2 );
1588
-			if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) {
1588
+			if ( $stackPtr >= $second_param[ 'start' ] && $stackPtr <= $second_param[ 'end' ] ) {
1589 1589
 				return true;
1590 1590
 			}
1591 1591
 		}
@@ -1612,8 +1612,8 @@  discard block
 block discarded – undo
1612 1612
 			return false;
1613 1613
 		}
1614 1614
 
1615
-		if ( \T_OBJECT_OPERATOR !== $this->tokens[ $before ]['code']
1616
-			&& \T_DOUBLE_COLON !== $this->tokens[ $before ]['code']
1615
+		if ( \T_OBJECT_OPERATOR !== $this->tokens[ $before ][ 'code' ]
1616
+			&& \T_DOUBLE_COLON !== $this->tokens[ $before ][ 'code' ]
1617 1617
 		) {
1618 1618
 			return false;
1619 1619
 		}
@@ -1640,7 +1640,7 @@  discard block
 block discarded – undo
1640 1640
 			return false;
1641 1641
 		}
1642 1642
 
1643
-		if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ]['code'] ) {
1643
+		if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ][ 'code' ] ) {
1644 1644
 			return false;
1645 1645
 		}
1646 1646
 
@@ -1649,8 +1649,8 @@  discard block
 block discarded – undo
1649 1649
 			return false;
1650 1650
 		}
1651 1651
 
1652
-		if ( \T_STRING !== $this->tokens[ $before_prev ]['code']
1653
-			&& \T_NAMESPACE !== $this->tokens[ $before_prev ]['code']
1652
+		if ( \T_STRING !== $this->tokens[ $before_prev ][ 'code' ]
1653
+			&& \T_NAMESPACE !== $this->tokens[ $before_prev ][ 'code' ]
1654 1654
 		) {
1655 1655
 			return false;
1656 1656
 		}
@@ -1691,11 +1691,11 @@  discard block
 block discarded – undo
1691 1691
 	 * @return int|bool Stack pointer to the function call T_STRING token or false otherwise.
1692 1692
 	 */
1693 1693
 	protected function is_in_function_call( $stackPtr, $valid_functions, $global = true, $allow_nested = false ) {
1694
-		if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
1694
+		if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
1695 1695
 			return false;
1696 1696
 		}
1697 1697
 
1698
-		$nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis'];
1698
+		$nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
1699 1699
 		if ( false === $allow_nested ) {
1700 1700
 			$nested_parenthesis = array_reverse( $nested_parenthesis, true );
1701 1701
 		}
@@ -1703,11 +1703,11 @@  discard block
 block discarded – undo
1703 1703
 		foreach ( $nested_parenthesis as $open => $close ) {
1704 1704
 
1705 1705
 			$prev_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $open - 1 ), null, true, null, true );
1706
-			if ( false === $prev_non_empty || \T_STRING !== $this->tokens[ $prev_non_empty ]['code'] ) {
1706
+			if ( false === $prev_non_empty || \T_STRING !== $this->tokens[ $prev_non_empty ][ 'code' ] ) {
1707 1707
 				continue;
1708 1708
 			}
1709 1709
 
1710
-			if ( isset( $valid_functions[ strtolower( $this->tokens[ $prev_non_empty ]['content'] ) ] ) === false ) {
1710
+			if ( isset( $valid_functions[ strtolower( $this->tokens[ $prev_non_empty ][ 'content' ] ) ] ) === false ) {
1711 1711
 				if ( false === $allow_nested ) {
1712 1712
 					// Function call encountered, but not to one of the allowed functions.
1713 1713
 					return false;
@@ -1752,7 +1752,7 @@  discard block
 block discarded – undo
1752 1752
 		 * The return can never be `0` as there will always be a PHP open tag before the
1753 1753
 		 * function call.
1754 1754
 		 */
1755
-		return (bool) $this->is_in_function_call( $stackPtr, $this->typeTestFunctions );
1755
+		return (bool)$this->is_in_function_call( $stackPtr, $this->typeTestFunctions );
1756 1756
 	}
1757 1757
 
1758 1758
 	/**
@@ -1773,7 +1773,7 @@  discard block
 block discarded – undo
1773 1773
 
1774 1774
 		// If this isn't set, we know the value must have only been casted, because
1775 1775
 		// is_sanitized() would have returned false otherwise.
1776
-		if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
1776
+		if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
1777 1777
 			return true;
1778 1778
 		}
1779 1779
 
@@ -1785,7 +1785,7 @@  discard block
 block discarded – undo
1785 1785
 
1786 1786
 		// The only parentheses should belong to the sanitizing function. If there's
1787 1787
 		// more than one set, this isn't *only* sanitization.
1788
-		return ( \count( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) === 1 );
1788
+		return ( \count( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === 1 );
1789 1789
 	}
1790 1790
 
1791 1791
 	/**
@@ -1812,7 +1812,7 @@  discard block
 block discarded – undo
1812 1812
 		}
1813 1813
 
1814 1814
 		// Check if it is a safe cast.
1815
-		return isset( $this->safe_casts[ $this->tokens[ $prev ]['code'] ] );
1815
+		return isset( $this->safe_casts[ $this->tokens[ $prev ][ 'code' ] ] );
1816 1816
 	}
1817 1817
 
1818 1818
 	/**
@@ -1834,7 +1834,7 @@  discard block
 block discarded – undo
1834 1834
 		}
1835 1835
 
1836 1836
 		// If this isn't within a function call, we know already that it's not safe.
1837
-		if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
1837
+		if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
1838 1838
 			if ( $require_unslash ) {
1839 1839
 				$this->add_unslash_error( $stackPtr );
1840 1840
 			}
@@ -1843,13 +1843,13 @@  discard block
 block discarded – undo
1843 1843
 		}
1844 1844
 
1845 1845
 		// Get the function that it's in.
1846
-		$nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis'];
1846
+		$nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
1847 1847
 		$nested_openers     = array_keys( $nested_parenthesis );
1848 1848
 		$function_opener    = array_pop( $nested_openers );
1849 1849
 		$functionPtr        = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $function_opener - 1 ), null, true, null, true );
1850 1850
 
1851 1851
 		// If it is just being unset, the value isn't used at all, so it's safe.
1852
-		if ( \T_UNSET === $this->tokens[ $functionPtr ]['code'] ) {
1852
+		if ( \T_UNSET === $this->tokens[ $functionPtr ][ 'code' ] ) {
1853 1853
 			return true;
1854 1854
 		}
1855 1855
 
@@ -1869,7 +1869,7 @@  discard block
 block discarded – undo
1869 1869
 			return false;
1870 1870
 		}
1871 1871
 
1872
-		$functionName = $this->tokens[ $functionPtr ]['content'];
1872
+		$functionName = $this->tokens[ $functionPtr ][ 'content' ];
1873 1873
 
1874 1874
 		// Check if an unslashing function is being used.
1875 1875
 		if ( isset( $this->unslashingFunctions[ $functionName ] ) ) {
@@ -1888,7 +1888,7 @@  discard block
 block discarded – undo
1888 1888
 			}
1889 1889
 
1890 1890
 			$functionPtr  = $higherFunctionPtr;
1891
-			$functionName = $this->tokens[ $functionPtr ]['content'];
1891
+			$functionName = $this->tokens[ $functionPtr ][ 'content' ];
1892 1892
 
1893 1893
 		} else {
1894 1894
 			$is_unslashed = false;
@@ -1907,13 +1907,13 @@  discard block
 block discarded – undo
1907 1907
 				 */
1908 1908
 				$first_non_empty = $this->phpcsFile->findNext(
1909 1909
 					Tokens::$emptyTokens,
1910
-					$callback['start'],
1911
-					( $callback['end'] + 1 ),
1910
+					$callback[ 'start' ],
1911
+					( $callback[ 'end' ] + 1 ),
1912 1912
 					true
1913 1913
 				);
1914 1914
 
1915
-				if ( false !== $first_non_empty && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $first_non_empty ]['code'] ) {
1916
-					$functionName = $this->strip_quotes( $this->tokens[ $first_non_empty ]['content'] );
1915
+				if ( false !== $first_non_empty && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $first_non_empty ][ 'code' ] ) {
1916
+					$functionName = $this->strip_quotes( $this->tokens[ $first_non_empty ][ 'content' ] );
1917 1917
 				}
1918 1918
 			}
1919 1919
 		}
@@ -1944,7 +1944,7 @@  discard block
 block discarded – undo
1944 1944
 			'%s data not unslashed before sanitization. Use wp_unslash() or similar',
1945 1945
 			$stackPtr,
1946 1946
 			'MissingUnslash',
1947
-			array( $this->tokens[ $stackPtr ]['content'] )
1947
+			array( $this->tokens[ $stackPtr ][ 'content' ] )
1948 1948
 		);
1949 1949
 	}
1950 1950
 
@@ -1966,7 +1966,7 @@  discard block
 block discarded – undo
1966 1966
 
1967 1967
 		$keys = array();
1968 1968
 
1969
-		if ( \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) {
1969
+		if ( \T_VARIABLE !== $this->tokens[ $stackPtr ][ 'code' ] ) {
1970 1970
 			return $keys;
1971 1971
 		}
1972 1972
 
@@ -1983,19 +1983,19 @@  discard block
 block discarded – undo
1983 1983
 
1984 1984
 			// If it isn't a bracket, this isn't an array-access.
1985 1985
 			if ( false === $open_bracket
1986
-				|| \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code']
1987
-				|| ! isset( $this->tokens[ $open_bracket ]['bracket_closer'] )
1986
+				|| \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ][ 'code' ]
1987
+				|| ! isset( $this->tokens[ $open_bracket ][ 'bracket_closer' ] )
1988 1988
 			) {
1989 1989
 				break;
1990 1990
 			}
1991 1991
 
1992 1992
 			$key = $this->phpcsFile->getTokensAsString(
1993 1993
 				( $open_bracket + 1 ),
1994
-				( $this->tokens[ $open_bracket ]['bracket_closer'] - $open_bracket - 1 )
1994
+				( $this->tokens[ $open_bracket ][ 'bracket_closer' ] - $open_bracket - 1 )
1995 1995
 			);
1996 1996
 
1997
-			$keys[]  = trim( $key );
1998
-			$current = $this->tokens[ $open_bracket ]['bracket_closer'];
1997
+			$keys[ ]  = trim( $key );
1998
+			$current = $this->tokens[ $open_bracket ][ 'bracket_closer' ];
1999 1999
 		} while ( isset( $this->tokens[ $current ] ) && true === $all );
2000 2000
 
2001 2001
 		return $keys;
@@ -2017,8 +2017,8 @@  discard block
 block discarded – undo
2017 2017
 
2018 2018
 		$keys = $this->get_array_access_keys( $stackPtr, false );
2019 2019
 
2020
-		if ( isset( $keys[0] ) ) {
2021
-			return $keys[0];
2020
+		if ( isset( $keys[ 0 ] ) ) {
2021
+			return $keys[ 0 ];
2022 2022
 		}
2023 2023
 
2024 2024
 		return false;
@@ -2072,22 +2072,22 @@  discard block
 block discarded – undo
2072 2072
 			 */
2073 2073
 
2074 2074
 			// If there are no conditions, there's no validation.
2075
-			if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) {
2075
+			if ( empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) {
2076 2076
 				return false;
2077 2077
 			}
2078 2078
 
2079
-			$conditions = $this->tokens[ $stackPtr ]['conditions'];
2079
+			$conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
2080 2080
 			end( $conditions ); // Get closest condition.
2081 2081
 			$conditionPtr = key( $conditions );
2082 2082
 			$condition    = $this->tokens[ $conditionPtr ];
2083 2083
 
2084
-			if ( ! isset( $condition['parenthesis_opener'] ) ) {
2084
+			if ( ! isset( $condition[ 'parenthesis_opener' ] ) ) {
2085 2085
 				// Live coding or parse error.
2086 2086
 				return false;
2087 2087
 			}
2088 2088
 
2089
-			$scope_start = $condition['parenthesis_opener'];
2090
-			$scope_end   = $condition['parenthesis_closer'];
2089
+			$scope_start = $condition[ 'parenthesis_opener' ];
2090
+			$scope_end   = $condition[ 'parenthesis_closer' ];
2091 2091
 
2092 2092
 		} else {
2093 2093
 			/*
@@ -2102,14 +2102,14 @@  discard block
 block discarded – undo
2102 2102
 
2103 2103
 			// If so, we check only within the function, otherwise the whole file.
2104 2104
 			if ( false !== $function ) {
2105
-				$scope_start = $this->tokens[ $function ]['scope_opener'];
2105
+				$scope_start = $this->tokens[ $function ][ 'scope_opener' ];
2106 2106
 			} else {
2107 2107
 				// Check if we are in a closure.
2108 2108
 				$closure = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE );
2109 2109
 
2110 2110
 				// If so, we check only within the closure.
2111 2111
 				if ( false !== $closure ) {
2112
-					$scope_start = $this->tokens[ $closure ]['scope_opener'];
2112
+					$scope_start = $this->tokens[ $closure ][ 'scope_opener' ];
2113 2113
 				}
2114 2114
 			}
2115 2115
 
@@ -2117,7 +2117,7 @@  discard block
 block discarded – undo
2117 2117
 		}
2118 2118
 
2119 2119
 		if ( ! empty( $array_keys ) && ! is_array( $array_keys ) ) {
2120
-			$array_keys = (array) $array_keys;
2120
+			$array_keys = (array)$array_keys;
2121 2121
 		}
2122 2122
 
2123 2123
 		$bare_array_keys = array_map( array( $this, 'strip_quotes' ), $array_keys );
@@ -2133,28 +2133,28 @@  discard block
 block discarded – undo
2133 2133
 		// phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below.
2134 2134
 		for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) {
2135 2135
 
2136
-			if ( isset( $targets[ $this->tokens[ $i ]['code'] ] ) === false ) {
2136
+			if ( isset( $targets[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
2137 2137
 				continue;
2138 2138
 			}
2139 2139
 
2140
-			switch ( $targets[ $this->tokens[ $i ]['code'] ] ) {
2140
+			switch ( $targets[ $this->tokens[ $i ][ 'code' ] ] ) {
2141 2141
 				case 'construct':
2142 2142
 					$issetOpener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true );
2143
-					if ( false === $issetOpener || \T_OPEN_PARENTHESIS !== $this->tokens[ $issetOpener ]['code'] ) {
2143
+					if ( false === $issetOpener || \T_OPEN_PARENTHESIS !== $this->tokens[ $issetOpener ][ 'code' ] ) {
2144 2144
 						// Parse error or live coding.
2145 2145
 						continue 2;
2146 2146
 					}
2147 2147
 
2148
-					$issetCloser = $this->tokens[ $issetOpener ]['parenthesis_closer'];
2148
+					$issetCloser = $this->tokens[ $issetOpener ][ 'parenthesis_closer' ];
2149 2149
 
2150 2150
 					// Look for this variable. We purposely stomp $i from the parent loop.
2151 2151
 					for ( $i = ( $issetOpener + 1 ); $i < $issetCloser; $i++ ) {
2152 2152
 
2153
-						if ( \T_VARIABLE !== $this->tokens[ $i ]['code'] ) {
2153
+						if ( \T_VARIABLE !== $this->tokens[ $i ][ 'code' ] ) {
2154 2154
 							continue;
2155 2155
 						}
2156 2156
 
2157
-						if ( $this->tokens[ $stackPtr ]['content'] !== $this->tokens[ $i ]['content'] ) {
2157
+						if ( $this->tokens[ $stackPtr ][ 'content' ] !== $this->tokens[ $i ][ 'content' ] ) {
2158 2158
 							continue;
2159 2159
 						}
2160 2160
 
@@ -2176,14 +2176,14 @@  discard block
 block discarded – undo
2176 2176
 
2177 2177
 				case 'function_call':
2178 2178
 					// Only check calls to array_key_exists() and key_exists().
2179
-					if ( 'array_key_exists' !== $this->tokens[ $i ]['content']
2180
-						&& 'key_exists' !== $this->tokens[ $i ]['content']
2179
+					if ( 'array_key_exists' !== $this->tokens[ $i ][ 'content' ]
2180
+						&& 'key_exists' !== $this->tokens[ $i ][ 'content' ]
2181 2181
 					) {
2182 2182
 						continue 2;
2183 2183
 					}
2184 2184
 
2185 2185
 					$next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true );
2186
-					if ( false === $next_non_empty || \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ]['code'] ) {
2186
+					if ( false === $next_non_empty || \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ][ 'code' ] ) {
2187 2187
 						// Not a function call.
2188 2188
 						continue 2;
2189 2189
 					}
@@ -2203,10 +2203,10 @@  discard block
 block discarded – undo
2203 2203
 						continue 2;
2204 2204
 					}
2205 2205
 
2206
-					$param2_first_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, $params[2]['start'], ( $params[2]['end'] + 1 ), true );
2206
+					$param2_first_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, $params[ 2 ][ 'start' ], ( $params[ 2 ][ 'end' ] + 1 ), true );
2207 2207
 					if ( false === $param2_first_token
2208
-						|| \T_VARIABLE !== $this->tokens[ $param2_first_token ]['code']
2209
-						|| $this->tokens[ $param2_first_token ]['content'] !== $this->tokens[ $stackPtr ]['content']
2208
+						|| \T_VARIABLE !== $this->tokens[ $param2_first_token ][ 'code' ]
2209
+						|| $this->tokens[ $param2_first_token ][ 'content' ] !== $this->tokens[ $stackPtr ][ 'content' ]
2210 2210
 					) {
2211 2211
 						continue 2;
2212 2212
 					}
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
 
2234 2234
 						// If that failed, try getting an exact match for the subset against the
2235 2235
 						// second parameter and the last key against the first.
2236
-						if ( $bare_keys === $found_keys && $this->strip_quotes( $params[1]['raw'] ) === $last_key ) {
2236
+						if ( $bare_keys === $found_keys && $this->strip_quotes( $params[ 1 ][ 'raw' ] ) === $last_key ) {
2237 2237
 							return true;
2238 2238
 						}
2239 2239
 
@@ -2248,8 +2248,8 @@  discard block
 block discarded – undo
2248 2248
 					do {
2249 2249
 						$prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true, null, true );
2250 2250
 						// Skip over array keys, like $_GET['key']['subkey'].
2251
-						if ( \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $prev ]['code'] ) {
2252
-							$prev = $this->tokens[ $prev ]['bracket_opener'];
2251
+						if ( \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $prev ][ 'code' ] ) {
2252
+							$prev = $this->tokens[ $prev ][ 'bracket_opener' ];
2253 2253
 							continue;
2254 2254
 						}
2255 2255
 
@@ -2257,11 +2257,11 @@  discard block
 block discarded – undo
2257 2257
 					} while ( $prev >= ( $scope_start + 1 ) );
2258 2258
 
2259 2259
 					// We should now have reached the variable.
2260
-					if ( \T_VARIABLE !== $this->tokens[ $prev ]['code'] ) {
2260
+					if ( \T_VARIABLE !== $this->tokens[ $prev ][ 'code' ] ) {
2261 2261
 						continue 2;
2262 2262
 					}
2263 2263
 
2264
-					if ( $this->tokens[ $prev ]['content'] !== $this->tokens[ $stackPtr ]['content'] ) {
2264
+					if ( $this->tokens[ $prev ][ 'content' ] !== $this->tokens[ $stackPtr ][ 'content' ] ) {
2265 2265
 						continue 2;
2266 2266
 					}
2267 2267
 
@@ -2310,13 +2310,13 @@  discard block
 block discarded – undo
2310 2310
 		}
2311 2311
 
2312 2312
 		// We first check if this is a switch statement (switch ( $var )).
2313
-		if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
2314
-			$nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis'];
2313
+		if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
2314
+			$nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
2315 2315
 			$close_parenthesis  = end( $nested_parenthesis );
2316 2316
 
2317 2317
 			if (
2318
-				isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] )
2319
-				&& \T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code']
2318
+				isset( $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] )
2319
+				&& \T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ][ 'code' ]
2320 2320
 			) {
2321 2321
 				return true;
2322 2322
 			}
@@ -2331,7 +2331,7 @@  discard block
 block discarded – undo
2331 2331
 			true
2332 2332
 		);
2333 2333
 
2334
-		if ( isset( $comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) {
2334
+		if ( isset( $comparisonTokens[ $this->tokens[ $previous_token ][ 'code' ] ] ) ) {
2335 2335
 			return true;
2336 2336
 		}
2337 2337
 
@@ -2344,17 +2344,17 @@  discard block
 block discarded – undo
2344 2344
 		);
2345 2345
 
2346 2346
 		// This might be an opening square bracket in the case of arrays ($var['a']).
2347
-		while ( false !== $next_token && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) {
2347
+		while ( false !== $next_token && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ][ 'code' ] ) {
2348 2348
 
2349 2349
 			$next_token = $this->phpcsFile->findNext(
2350 2350
 				Tokens::$emptyTokens,
2351
-				( $this->tokens[ $next_token ]['bracket_closer'] + 1 ),
2351
+				( $this->tokens[ $next_token ][ 'bracket_closer' ] + 1 ),
2352 2352
 				null,
2353 2353
 				true
2354 2354
 			);
2355 2355
 		}
2356 2356
 
2357
-		if ( false !== $next_token && isset( $comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) {
2357
+		if ( false !== $next_token && isset( $comparisonTokens[ $this->tokens[ $next_token ][ 'code' ] ] ) ) {
2358 2358
 			return true;
2359 2359
 		}
2360 2360
 
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
 			return false;
2378 2378
 		}
2379 2379
 
2380
-		$function_name = $this->tokens[ $function_ptr ]['content'];
2380
+		$function_name = $this->tokens[ $function_ptr ][ 'content' ];
2381 2381
 		if ( true === $this->arrayCompareFunctions[ $function_name ] ) {
2382 2382
 			return true;
2383 2383
 		}
@@ -2412,7 +2412,7 @@  discard block
 block discarded – undo
2412 2412
 		// USE keywords inside closures.
2413 2413
 		$next = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true );
2414 2414
 
2415
-		if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] ) {
2415
+		if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ] ) {
2416 2416
 			return 'closure';
2417 2417
 		}
2418 2418
 
@@ -2445,8 +2445,8 @@  discard block
 block discarded – undo
2445 2445
 		$variables = array();
2446 2446
 		if ( preg_match_all( '/(?P<backslashes>\\\\*)\$(?P<symbol>\w+)/', $string, $match_sets, \PREG_SET_ORDER ) ) {
2447 2447
 			foreach ( $match_sets as $matches ) {
2448
-				if ( ! isset( $matches['backslashes'] ) || ( \strlen( $matches['backslashes'] ) % 2 ) === 0 ) {
2449
-					$variables[] = $matches['symbol'];
2448
+				if ( ! isset( $matches[ 'backslashes' ] ) || ( \strlen( $matches[ 'backslashes' ] ) % 2 ) === 0 ) {
2449
+					$variables[ ] = $matches[ 'symbol' ];
2450 2450
 				}
2451 2451
 			}
2452 2452
 		}
@@ -2498,19 +2498,19 @@  discard block
 block discarded – undo
2498 2498
 		}
2499 2499
 
2500 2500
 		// Is this one of the tokens this function handles ?
2501
-		if ( false === \in_array( $this->tokens[ $stackPtr ]['code'], array( \T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY ), true ) ) {
2501
+		if ( false === \in_array( $this->tokens[ $stackPtr ][ 'code' ], array( \T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY ), true ) ) {
2502 2502
 			return false;
2503 2503
 		}
2504 2504
 
2505 2505
 		$next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true );
2506 2506
 
2507 2507
 		// Deal with short array syntax.
2508
-		if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ]['type'] ) {
2509
-			if ( false === isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) {
2508
+		if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ][ 'type' ] ) {
2509
+			if ( false === isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) {
2510 2510
 				return false;
2511 2511
 			}
2512 2512
 
2513
-			if ( $next_non_empty === $this->tokens[ $stackPtr ]['bracket_closer'] ) {
2513
+			if ( $next_non_empty === $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) {
2514 2514
 				// No parameters.
2515 2515
 				return false;
2516 2516
 			} else {
@@ -2520,15 +2520,15 @@  discard block
 block discarded – undo
2520 2520
 
2521 2521
 		// Deal with function calls & long arrays.
2522 2522
 		// Next non-empty token should be the open parenthesis.
2523
-		if ( false === $next_non_empty && \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ]['code'] ) {
2523
+		if ( false === $next_non_empty && \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ][ 'code' ] ) {
2524 2524
 			return false;
2525 2525
 		}
2526 2526
 
2527
-		if ( false === isset( $this->tokens[ $next_non_empty ]['parenthesis_closer'] ) ) {
2527
+		if ( false === isset( $this->tokens[ $next_non_empty ][ 'parenthesis_closer' ] ) ) {
2528 2528
 			return false;
2529 2529
 		}
2530 2530
 
2531
-		$close_parenthesis   = $this->tokens[ $next_non_empty ]['parenthesis_closer'];
2531
+		$close_parenthesis   = $this->tokens[ $next_non_empty ][ 'parenthesis_closer' ];
2532 2532
 		$next_next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), ( $close_parenthesis + 1 ), true );
2533 2533
 
2534 2534
 		if ( $next_next_non_empty === $close_parenthesis ) {
@@ -2599,67 +2599,67 @@  discard block
 block discarded – undo
2599 2599
 		 */
2600 2600
 
2601 2601
 		// Mark the beginning and end tokens.
2602
-		if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ]['type'] ) {
2602
+		if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ][ 'type' ] ) {
2603 2603
 			$opener = $stackPtr;
2604
-			$closer = $this->tokens[ $stackPtr ]['bracket_closer'];
2604
+			$closer = $this->tokens[ $stackPtr ][ 'bracket_closer' ];
2605 2605
 
2606 2606
 			$nestedParenthesisCount = 0;
2607 2607
 		} else {
2608 2608
 			$opener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true );
2609
-			$closer = $this->tokens[ $opener ]['parenthesis_closer'];
2609
+			$closer = $this->tokens[ $opener ][ 'parenthesis_closer' ];
2610 2610
 
2611 2611
 			$nestedParenthesisCount = 1;
2612 2612
 		}
2613 2613
 
2614 2614
 		// Which nesting level is the one we are interested in ?
2615
-		if ( isset( $this->tokens[ $opener ]['nested_parenthesis'] ) ) {
2616
-			$nestedParenthesisCount += \count( $this->tokens[ $opener ]['nested_parenthesis'] );
2615
+		if ( isset( $this->tokens[ $opener ][ 'nested_parenthesis' ] ) ) {
2616
+			$nestedParenthesisCount += \count( $this->tokens[ $opener ][ 'nested_parenthesis' ] );
2617 2617
 		}
2618 2618
 
2619 2619
 		$parameters  = array();
2620 2620
 		$next_comma  = $opener;
2621 2621
 		$param_start = ( $opener + 1 );
2622 2622
 		$cnt         = 1;
2623
-		while ( $next_comma = $this->phpcsFile->findNext( array( \T_COMMA, $this->tokens[ $closer ]['code'], \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $next_comma + 1 ), ( $closer + 1 ) ) ) {
2623
+		while ( $next_comma = $this->phpcsFile->findNext( array( \T_COMMA, $this->tokens[ $closer ][ 'code' ], \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $next_comma + 1 ), ( $closer + 1 ) ) ) {
2624 2624
 			// Ignore anything within short array definition brackets.
2625
-			if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $next_comma ]['type']
2626
-				&& ( isset( $this->tokens[ $next_comma ]['bracket_opener'] )
2627
-					&& $this->tokens[ $next_comma ]['bracket_opener'] === $next_comma )
2628
-				&& isset( $this->tokens[ $next_comma ]['bracket_closer'] )
2625
+			if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $next_comma ][ 'type' ]
2626
+				&& ( isset( $this->tokens[ $next_comma ][ 'bracket_opener' ] )
2627
+					&& $this->tokens[ $next_comma ][ 'bracket_opener' ] === $next_comma )
2628
+				&& isset( $this->tokens[ $next_comma ][ 'bracket_closer' ] )
2629 2629
 			) {
2630 2630
 				// Skip forward to the end of the short array definition.
2631
-				$next_comma = $this->tokens[ $next_comma ]['bracket_closer'];
2631
+				$next_comma = $this->tokens[ $next_comma ][ 'bracket_closer' ];
2632 2632
 				continue;
2633 2633
 			}
2634 2634
 
2635 2635
 			// Skip past closures passed as function parameters.
2636
-			if ( 'T_CLOSURE' === $this->tokens[ $next_comma ]['type']
2637
-				&& ( isset( $this->tokens[ $next_comma ]['scope_condition'] )
2638
-					&& $this->tokens[ $next_comma ]['scope_condition'] === $next_comma )
2639
-				&& isset( $this->tokens[ $next_comma ]['scope_closer'] )
2636
+			if ( 'T_CLOSURE' === $this->tokens[ $next_comma ][ 'type' ]
2637
+				&& ( isset( $this->tokens[ $next_comma ][ 'scope_condition' ] )
2638
+					&& $this->tokens[ $next_comma ][ 'scope_condition' ] === $next_comma )
2639
+				&& isset( $this->tokens[ $next_comma ][ 'scope_closer' ] )
2640 2640
 			) {
2641 2641
 				// Skip forward to the end of the closure declaration.
2642
-				$next_comma = $this->tokens[ $next_comma ]['scope_closer'];
2642
+				$next_comma = $this->tokens[ $next_comma ][ 'scope_closer' ];
2643 2643
 				continue;
2644 2644
 			}
2645 2645
 
2646 2646
 			// Ignore comma's at a lower nesting level.
2647
-			if ( \T_COMMA === $this->tokens[ $next_comma ]['code']
2648
-				&& isset( $this->tokens[ $next_comma ]['nested_parenthesis'] )
2649
-				&& \count( $this->tokens[ $next_comma ]['nested_parenthesis'] ) !== $nestedParenthesisCount
2647
+			if ( \T_COMMA === $this->tokens[ $next_comma ][ 'code' ]
2648
+				&& isset( $this->tokens[ $next_comma ][ 'nested_parenthesis' ] )
2649
+				&& \count( $this->tokens[ $next_comma ][ 'nested_parenthesis' ] ) !== $nestedParenthesisCount
2650 2650
 			) {
2651 2651
 				continue;
2652 2652
 			}
2653 2653
 
2654 2654
 			// Ignore closing parenthesis/bracket if not 'ours'.
2655
-			if ( $this->tokens[ $next_comma ]['type'] === $this->tokens[ $closer ]['type'] && $next_comma !== $closer ) {
2655
+			if ( $this->tokens[ $next_comma ][ 'type' ] === $this->tokens[ $closer ][ 'type' ] && $next_comma !== $closer ) {
2656 2656
 				continue;
2657 2657
 			}
2658 2658
 
2659 2659
 			// Ok, we've reached the end of the parameter.
2660
-			$parameters[ $cnt ]['start'] = $param_start;
2661
-			$parameters[ $cnt ]['end']   = ( $next_comma - 1 );
2662
-			$parameters[ $cnt ]['raw']   = trim( $this->phpcsFile->getTokensAsString( $param_start, ( $next_comma - $param_start ) ) );
2660
+			$parameters[ $cnt ][ 'start' ] = $param_start;
2661
+			$parameters[ $cnt ][ 'end' ]   = ( $next_comma - 1 );
2662
+			$parameters[ $cnt ][ 'raw' ]   = trim( $this->phpcsFile->getTokensAsString( $param_start, ( $next_comma - $param_start ) ) );
2663 2663
 
2664 2664
 			/*
2665 2665
 			 * Check if there are more tokens before the closing parenthesis.
@@ -2720,20 +2720,20 @@  discard block
 block discarded – undo
2720 2720
 		/*
2721 2721
 		 * Determine the array opener & closer.
2722 2722
 		 */
2723
-		if ( \T_ARRAY === $this->tokens[ $stackPtr ]['code'] ) {
2724
-			if ( isset( $this->tokens[ $stackPtr ]['parenthesis_opener'] ) ) {
2725
-				$opener = $this->tokens[ $stackPtr ]['parenthesis_opener'];
2723
+		if ( \T_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] ) {
2724
+			if ( isset( $this->tokens[ $stackPtr ][ 'parenthesis_opener' ] ) ) {
2725
+				$opener = $this->tokens[ $stackPtr ][ 'parenthesis_opener' ];
2726 2726
 
2727
-				if ( isset( $this->tokens[ $opener ]['parenthesis_closer'] ) ) {
2728
-					$closer = $this->tokens[ $opener ]['parenthesis_closer'];
2727
+				if ( isset( $this->tokens[ $opener ][ 'parenthesis_closer' ] ) ) {
2728
+					$closer = $this->tokens[ $opener ][ 'parenthesis_closer' ];
2729 2729
 				}
2730 2730
 			}
2731 2731
 		} else {
2732 2732
 			// Short array syntax.
2733 2733
 			$opener = $stackPtr;
2734 2734
 
2735
-			if ( isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) {
2736
-				$closer = $this->tokens[ $stackPtr ]['bracket_closer'];
2735
+			if ( isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) {
2736
+				$closer = $this->tokens[ $stackPtr ][ 'bracket_closer' ];
2737 2737
 			}
2738 2738
 		}
2739 2739
 
@@ -2765,7 +2765,7 @@  discard block
 block discarded – undo
2765 2765
 		}
2766 2766
 
2767 2767
 		// Check for scoped namespace {}.
2768
-		if ( ! empty( $this->tokens[ $stackPtr ]['conditions'] ) ) {
2768
+		if ( ! empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) {
2769 2769
 			$namespacePtr = $this->phpcsFile->getCondition( $stackPtr, \T_NAMESPACE );
2770 2770
 			if ( false !== $namespacePtr ) {
2771 2771
 				$namespace = $this->get_declared_namespace_name( $namespacePtr );
@@ -2792,8 +2792,8 @@  discard block
 block discarded – undo
2792 2792
 			$previousNSToken = $this->phpcsFile->findPrevious( \T_NAMESPACE, ( $previousNSToken - 1 ) );
2793 2793
 
2794 2794
 			// Stop if we encounter a scoped namespace declaration as we already know we're not in one.
2795
-			if ( ! empty( $this->tokens[ $previousNSToken ]['scope_condition'] )
2796
-				&& $this->tokens[ $previousNSToken ]['scope_condition'] === $previousNSToken
2795
+			if ( ! empty( $this->tokens[ $previousNSToken ][ 'scope_condition' ] )
2796
+				&& $this->tokens[ $previousNSToken ][ 'scope_condition' ] === $previousNSToken
2797 2797
 			) {
2798 2798
 				break;
2799 2799
 			}
@@ -2831,17 +2831,17 @@  discard block
 block discarded – undo
2831 2831
 			return false;
2832 2832
 		}
2833 2833
 
2834
-		if ( \T_NAMESPACE !== $this->tokens[ $stackPtr ]['code'] ) {
2834
+		if ( \T_NAMESPACE !== $this->tokens[ $stackPtr ][ 'code' ] ) {
2835 2835
 			return false;
2836 2836
 		}
2837 2837
 
2838 2838
 		$nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true );
2839
-		if ( \T_NS_SEPARATOR === $this->tokens[ $nextToken ]['code'] ) {
2839
+		if ( \T_NS_SEPARATOR === $this->tokens[ $nextToken ][ 'code' ] ) {
2840 2840
 			// Not a namespace declaration, but use of, i.e. `namespace\someFunction();`.
2841 2841
 			return false;
2842 2842
 		}
2843 2843
 
2844
-		if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $nextToken ]['code'] ) {
2844
+		if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $nextToken ][ 'code' ] ) {
2845 2845
 			// Declaration for global namespace when using multiple namespaces in a file.
2846 2846
 			// I.e.: `namespace {}`.
2847 2847
 			return '';
@@ -2852,12 +2852,12 @@  discard block
 block discarded – undo
2852 2852
 			\T_STRING       => true,
2853 2853
 			\T_NS_SEPARATOR => true,
2854 2854
 		);
2855
-		$validTokens    = $acceptedTokens + Tokens::$emptyTokens;
2855
+		$validTokens = $acceptedTokens + Tokens::$emptyTokens;
2856 2856
 
2857 2857
 		$namespaceName = '';
2858
-		while ( isset( $validTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) {
2859
-			if ( isset( $acceptedTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) {
2860
-				$namespaceName .= trim( $this->tokens[ $nextToken ]['content'] );
2858
+		while ( isset( $validTokens[ $this->tokens[ $nextToken ][ 'code' ] ] ) ) {
2859
+			if ( isset( $acceptedTokens[ $this->tokens[ $nextToken ][ 'code' ] ] ) ) {
2860
+				$namespaceName .= trim( $this->tokens[ $nextToken ][ 'content' ] );
2861 2861
 			}
2862 2862
 			++$nextToken;
2863 2863
 		}
@@ -2875,7 +2875,7 @@  discard block
 block discarded – undo
2875 2875
 	 * @return bool
2876 2876
 	 */
2877 2877
 	public function is_class_constant( $stackPtr ) {
2878
-		if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_CONST !== $this->tokens[ $stackPtr ]['code'] ) {
2878
+		if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_CONST !== $this->tokens[ $stackPtr ][ 'code' ] ) {
2879 2879
 			return false;
2880 2880
 		}
2881 2881
 
@@ -2899,7 +2899,7 @@  discard block
 block discarded – undo
2899 2899
 	 * @return bool
2900 2900
 	 */
2901 2901
 	public function is_class_property( $stackPtr ) {
2902
-		if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) {
2902
+		if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_VARIABLE !== $this->tokens[ $stackPtr ][ 'code' ] ) {
2903 2903
 			return false;
2904 2904
 		}
2905 2905
 
@@ -2913,14 +2913,14 @@  discard block
 block discarded – undo
2913 2913
 		$scopePtr = $this->valid_direct_scope( $stackPtr, $valid_scopes );
2914 2914
 		if ( false !== $scopePtr ) {
2915 2915
 			// Make sure it's not a method parameter.
2916
-			if ( empty( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
2916
+			if ( empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
2917 2917
 				return true;
2918 2918
 			} else {
2919
-				$parenthesis  = array_keys( $this->tokens[ $stackPtr ]['nested_parenthesis'] );
2919
+				$parenthesis  = array_keys( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] );
2920 2920
 				$deepest_open = array_pop( $parenthesis );
2921 2921
 				if ( $deepest_open < $scopePtr
2922
-					|| isset( $this->tokens[ $deepest_open ]['parenthesis_owner'] ) === false
2923
-					|| \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code']
2922
+					|| isset( $this->tokens[ $deepest_open ][ 'parenthesis_owner' ] ) === false
2923
+					|| \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ][ 'parenthesis_owner' ] ][ 'code' ]
2924 2924
 				) {
2925 2925
 					return true;
2926 2926
 				}
@@ -2947,21 +2947,21 @@  discard block
 block discarded – undo
2947 2947
 	 * @return int|bool StackPtr to the scope if valid, false otherwise.
2948 2948
 	 */
2949 2949
 	protected function valid_direct_scope( $stackPtr, array $valid_scopes ) {
2950
-		if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) {
2950
+		if ( empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) {
2951 2951
 			return false;
2952 2952
 		}
2953 2953
 
2954 2954
 		/*
2955 2955
 		 * Check only the direct wrapping scope of the token.
2956 2956
 		 */
2957
-		$conditions = array_keys( $this->tokens[ $stackPtr ]['conditions'] );
2957
+		$conditions = array_keys( $this->tokens[ $stackPtr ][ 'conditions' ] );
2958 2958
 		$ptr        = array_pop( $conditions );
2959 2959
 
2960 2960
 		if ( ! isset( $this->tokens[ $ptr ] ) ) {
2961 2961
 			return false;
2962 2962
 		}
2963 2963
 
2964
-		if ( isset( $valid_scopes[ $this->tokens[ $ptr ]['type'] ] ) ) {
2964
+		if ( isset( $valid_scopes[ $this->tokens[ $ptr ][ 'type' ] ] ) ) {
2965 2965
 			return $ptr;
2966 2966
 		}
2967 2967
 
@@ -2991,8 +2991,8 @@  discard block
 block discarded – undo
2991 2991
 	protected function is_wpdb_method_call( $stackPtr, $target_methods ) {
2992 2992
 
2993 2993
 		// Check for wpdb.
2994
-		if ( ( \T_VARIABLE === $this->tokens[ $stackPtr ]['code'] && '$wpdb' !== $this->tokens[ $stackPtr ]['content'] )
2995
-			|| ( \T_STRING === $this->tokens[ $stackPtr ]['code'] && 'wpdb' !== $this->tokens[ $stackPtr ]['content'] )
2994
+		if ( ( \T_VARIABLE === $this->tokens[ $stackPtr ][ 'code' ] && '$wpdb' !== $this->tokens[ $stackPtr ][ 'content' ] )
2995
+			|| ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] && 'wpdb' !== $this->tokens[ $stackPtr ][ 'content' ] )
2996 2996
 		) {
2997 2997
 			return false;
2998 2998
 		}
@@ -3015,7 +3015,7 @@  discard block
 block discarded – undo
3015 3015
 			return false;
3016 3016
 		}
3017 3017
 
3018
-		if ( \T_STRING === $this->tokens[ $methodPtr ]['code'] && property_exists( $this, 'methodPtr' ) ) {
3018
+		if ( \T_STRING === $this->tokens[ $methodPtr ][ 'code' ] && property_exists( $this, 'methodPtr' ) ) {
3019 3019
 			$this->methodPtr = $methodPtr;
3020 3020
 		}
3021 3021
 
@@ -3030,21 +3030,21 @@  discard block
 block discarded – undo
3030 3030
 			$this->i = $opening_paren;
3031 3031
 		}
3032 3032
 
3033
-		if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $opening_paren ]['code']
3034
-			|| ! isset( $this->tokens[ $opening_paren ]['parenthesis_closer'] )
3033
+		if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $opening_paren ][ 'code' ]
3034
+			|| ! isset( $this->tokens[ $opening_paren ][ 'parenthesis_closer' ] )
3035 3035
 		) {
3036 3036
 			return false;
3037 3037
 		}
3038 3038
 
3039 3039
 		// Check that this is one of the methods that we are interested in.
3040
-		if ( ! isset( $target_methods[ $this->tokens[ $methodPtr ]['content'] ] ) ) {
3040
+		if ( ! isset( $target_methods[ $this->tokens[ $methodPtr ][ 'content' ] ] ) ) {
3041 3041
 			return false;
3042 3042
 		}
3043 3043
 
3044 3044
 		// Find the end of the first parameter.
3045 3045
 		$end = $this->phpcsFile->findEndOfStatement( $opening_paren + 1 );
3046 3046
 
3047
-		if ( \T_COMMA !== $this->tokens[ $end ]['code'] ) {
3047
+		if ( \T_COMMA !== $this->tokens[ $end ][ 'code' ] ) {
3048 3048
 			++$end;
3049 3049
 		}
3050 3050
 
@@ -3071,14 +3071,14 @@  discard block
 block discarded – undo
3071 3071
 		}
3072 3072
 
3073 3073
 		// Is this one of the tokens this function handles ?
3074
-		if ( \T_STRING !== $this->tokens[ $stackPtr ]['code'] ) {
3074
+		if ( \T_STRING !== $this->tokens[ $stackPtr ][ 'code' ] ) {
3075 3075
 			return false;
3076 3076
 		}
3077 3077
 
3078 3078
 		$next = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true );
3079 3079
 		if ( false !== $next
3080
-			&& ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code']
3081
-				|| \T_DOUBLE_COLON === $this->tokens[ $next ]['code'] )
3080
+			&& ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ]
3081
+				|| \T_DOUBLE_COLON === $this->tokens[ $next ][ 'code' ] )
3082 3082
 		) {
3083 3083
 			// Function call or declaration.
3084 3084
 			return false;
@@ -3108,7 +3108,7 @@  discard block
 block discarded – undo
3108 3108
 
3109 3109
 		$prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true );
3110 3110
 		if ( false !== $prev
3111
-			&& isset( $tokens_to_ignore[ $this->tokens[ $prev ]['type'] ] )
3111
+			&& isset( $tokens_to_ignore[ $this->tokens[ $prev ][ 'type' ] ] )
3112 3112
 		) {
3113 3113
 			// Not the use of a constant.
3114 3114
 			return false;
@@ -3120,7 +3120,7 @@  discard block
 block discarded – undo
3120 3120
 		}
3121 3121
 
3122 3122
 		if ( false !== $prev
3123
-			&& \T_CONST === $this->tokens[ $prev ]['code']
3123
+			&& \T_CONST === $this->tokens[ $prev ][ 'code' ]
3124 3124
 			&& $this->is_class_constant( $prev )
3125 3125
 		) {
3126 3126
 			// Class constant declaration of the same name.
@@ -3131,17 +3131,17 @@  discard block
 block discarded – undo
3131 3131
 		 * Deal with a number of variations of use statements.
3132 3132
 		 */
3133 3133
 		for ( $i = $stackPtr; $i > 0; $i-- ) {
3134
-			if ( $this->tokens[ $i ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) {
3134
+			if ( $this->tokens[ $i ][ 'line' ] !== $this->tokens[ $stackPtr ][ 'line' ] ) {
3135 3135
 				break;
3136 3136
 			}
3137 3137
 		}
3138 3138
 
3139 3139
 		$firstOnLine = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true );
3140
-		if ( false !== $firstOnLine && \T_USE === $this->tokens[ $firstOnLine ]['code'] ) {
3140
+		if ( false !== $firstOnLine && \T_USE === $this->tokens[ $firstOnLine ][ 'code' ] ) {
3141 3141
 			$nextOnLine = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $firstOnLine + 1 ), null, true );
3142 3142
 			if ( false !== $nextOnLine ) {
3143
-				if ( \T_STRING === $this->tokens[ $nextOnLine ]['code']
3144
-					&& 'const' === $this->tokens[ $nextOnLine ]['content']
3143
+				if ( \T_STRING === $this->tokens[ $nextOnLine ][ 'code' ]
3144
+					&& 'const' === $this->tokens[ $nextOnLine ][ 'content' ]
3145 3145
 				) {
3146 3146
 					$hasNsSep = $this->phpcsFile->findNext( \T_NS_SEPARATOR, ( $nextOnLine + 1 ), $stackPtr );
3147 3147
 					if ( false !== $hasNsSep ) {
@@ -3169,18 +3169,18 @@  discard block
 block discarded – undo
3169 3169
 	 * @return bool True if it is. False otherwise.
3170 3170
 	 */
3171 3171
 	protected function is_foreach_as( $stackPtr ) {
3172
-		if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) {
3172
+		if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) {
3173 3173
 			return false;
3174 3174
 		}
3175 3175
 
3176
-		$nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis'];
3176
+		$nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
3177 3177
 		$close_parenthesis  = end( $nested_parenthesis );
3178 3178
 		$open_parenthesis   = key( $nested_parenthesis );
3179
-		if ( ! isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ) ) {
3179
+		if ( ! isset( $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ) ) {
3180 3180
 			return false;
3181 3181
 		}
3182 3182
 
3183
-		if ( \T_FOREACH !== $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code'] ) {
3183
+		if ( \T_FOREACH !== $this->tokens[ $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ][ 'code' ] ) {
3184 3184
 			return false;
3185 3185
 		}
3186 3186
 
Please login to merge, or discard this patch.