Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractPatternSniff.php 1 patch
Spacing   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @var array
38 38
      */
39
-    private $parsedPatterns = [];
39
+    private $parsedPatterns = [ ];
40 40
 
41 41
     /**
42 42
      * Tokens that this sniff wishes to process outside of the patterns.
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
      * @see registerSupplementary()
46 46
      * @see processSupplementary()
47 47
      */
48
-    private $supplementaryTokens = [];
48
+    private $supplementaryTokens = [ ];
49 49
 
50 50
     /**
51 51
      * Positions in the stack where errors have occurred.
52 52
      *
53 53
      * @var array<int, bool>
54 54
      */
55
-    private $errorPos = [];
55
+    private $errorPos = [ ];
56 56
 
57 57
 
58 58
     /**
@@ -60,10 +60,10 @@  discard block
 block discarded – undo
60 60
      *
61 61
      * @param boolean $ignoreComments If true, comments will be ignored.
62 62
      */
63
-    public function __construct($ignoreComments=null)
63
+    public function __construct( $ignoreComments = null )
64 64
     {
65 65
         // This is here for backwards compatibility.
66
-        if ($ignoreComments !== null) {
66
+        if ( $ignoreComments !== null ) {
67 67
             $this->ignoreComments = $ignoreComments;
68 68
         }
69 69
 
@@ -83,17 +83,17 @@  discard block
 block discarded – undo
83 83
      */
84 84
     final public function register()
85 85
     {
86
-        $listenTypes = [];
86
+        $listenTypes = [ ];
87 87
         $patterns    = $this->getPatterns();
88 88
 
89
-        foreach ($patterns as $pattern) {
90
-            $parsedPattern = $this->parse($pattern);
89
+        foreach ( $patterns as $pattern ) {
90
+            $parsedPattern = $this->parse( $pattern );
91 91
 
92 92
             // Find a token position in the pattern that we can use
93 93
             // for a listener token.
94
-            $pos           = $this->getListenerTokenPos($parsedPattern);
95
-            $tokenType     = $parsedPattern[$pos]['token'];
96
-            $listenTypes[] = $tokenType;
94
+            $pos           = $this->getListenerTokenPos( $parsedPattern );
95
+            $tokenType     = $parsedPattern[ $pos ][ 'token' ];
96
+            $listenTypes[ ] = $tokenType;
97 97
 
98 98
             $patternArray = [
99 99
                 'listen_pos'   => $pos,
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
                 'pattern_code' => $pattern,
102 102
             ];
103 103
 
104
-            if (isset($this->parsedPatterns[$tokenType]) === false) {
105
-                $this->parsedPatterns[$tokenType] = [];
104
+            if ( isset( $this->parsedPatterns[ $tokenType ] ) === false ) {
105
+                $this->parsedPatterns[ $tokenType ] = [ ];
106 106
             }
107 107
 
108
-            $this->parsedPatterns[$tokenType][] = $patternArray;
108
+            $this->parsedPatterns[ $tokenType ][ ] = $patternArray;
109 109
         }//end foreach
110 110
 
111
-        return array_unique(array_merge($listenTypes, $this->supplementaryTokens));
111
+        return array_unique( array_merge( $listenTypes, $this->supplementaryTokens ) );
112 112
 
113 113
     }//end register()
114 114
 
@@ -129,13 +129,13 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return array<int, int>
131 131
      */
132
-    private function getPatternTokenTypes($pattern)
132
+    private function getPatternTokenTypes( $pattern )
133 133
     {
134
-        $tokenTypes = [];
135
-        foreach ($pattern as $pos => $patternInfo) {
136
-            if ($patternInfo['type'] === 'token') {
137
-                if (isset($tokenTypes[$patternInfo['token']]) === false) {
138
-                    $tokenTypes[$patternInfo['token']] = $pos;
134
+        $tokenTypes = [ ];
135
+        foreach ( $pattern as $pos => $patternInfo ) {
136
+            if ( $patternInfo[ 'type' ] === 'token' ) {
137
+                if ( isset( $tokenTypes[ $patternInfo[ 'token' ] ] ) === false ) {
138
+                    $tokenTypes[ $patternInfo[ 'token' ] ] = $pos;
139 139
                 }
140 140
             }
141 141
         }
@@ -155,19 +155,19 @@  discard block
 block discarded – undo
155 155
      *             as the listener.
156 156
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If we could not determine a token to listen for.
157 157
      */
158
-    private function getListenerTokenPos($pattern)
158
+    private function getListenerTokenPos( $pattern )
159 159
     {
160
-        $tokenTypes = $this->getPatternTokenTypes($pattern);
161
-        $tokenCodes = array_keys($tokenTypes);
162
-        $token      = Tokens::getHighestWeightedToken($tokenCodes);
160
+        $tokenTypes = $this->getPatternTokenTypes( $pattern );
161
+        $tokenCodes = array_keys( $tokenTypes );
162
+        $token      = Tokens::getHighestWeightedToken( $tokenCodes );
163 163
 
164 164
         // If we could not get a token.
165
-        if ($token === false) {
165
+        if ( $token === false ) {
166 166
             $error = 'Could not determine a token to listen for';
167
-            throw new RuntimeException($error);
167
+            throw new RuntimeException( $error );
168 168
         }
169 169
 
170
-        return $tokenTypes[$token];
170
+        return $tokenTypes[ $token ];
171 171
 
172 172
     }//end getListenerTokenPos()
173 173
 
@@ -184,55 +184,55 @@  discard block
 block discarded – undo
184 184
      * @return void
185 185
      * @see    register()
186 186
      */
187
-    final public function process(File $phpcsFile, $stackPtr)
187
+    final public function process( File $phpcsFile, $stackPtr )
188 188
     {
189 189
         $file = $phpcsFile->getFilename();
190
-        if ($this->currFile !== $file) {
190
+        if ( $this->currFile !== $file ) {
191 191
             // We have changed files, so clean up.
192
-            $this->errorPos = [];
192
+            $this->errorPos = [ ];
193 193
             $this->currFile = $file;
194 194
         }
195 195
 
196 196
         $tokens = $phpcsFile->getTokens();
197 197
 
198
-        if (in_array($tokens[$stackPtr]['code'], $this->supplementaryTokens, true) === true) {
199
-            $this->processSupplementary($phpcsFile, $stackPtr);
198
+        if ( in_array( $tokens[ $stackPtr ][ 'code' ], $this->supplementaryTokens, true ) === true ) {
199
+            $this->processSupplementary( $phpcsFile, $stackPtr );
200 200
         }
201 201
 
202
-        $type = $tokens[$stackPtr]['code'];
202
+        $type = $tokens[ $stackPtr ][ 'code' ];
203 203
 
204 204
         // If the type is not set, then it must have been a token registered
205 205
         // with registerSupplementary().
206
-        if (isset($this->parsedPatterns[$type]) === false) {
206
+        if ( isset( $this->parsedPatterns[ $type ] ) === false ) {
207 207
             return;
208 208
         }
209 209
 
210
-        $allErrors = [];
210
+        $allErrors = [ ];
211 211
 
212 212
         // Loop over each pattern that is listening to the current token type
213 213
         // that we are processing.
214
-        foreach ($this->parsedPatterns[$type] as $patternInfo) {
214
+        foreach ( $this->parsedPatterns[ $type ] as $patternInfo ) {
215 215
             // If processPattern returns false, then the pattern that we are
216 216
             // checking the code with must not be designed to check that code.
217
-            $errors = $this->processPattern($patternInfo, $phpcsFile, $stackPtr);
218
-            if ($errors === false) {
217
+            $errors = $this->processPattern( $patternInfo, $phpcsFile, $stackPtr );
218
+            if ( $errors === false ) {
219 219
                 // The pattern didn't match.
220 220
                 continue;
221
-            } else if (empty($errors) === true) {
221
+            } else if ( empty( $errors ) === true ) {
222 222
                 // The pattern matched, but there were no errors.
223 223
                 break;
224 224
             }
225 225
 
226
-            foreach ($errors as $stackPtr => $error) {
227
-                if (isset($this->errorPos[$stackPtr]) === false) {
228
-                    $this->errorPos[$stackPtr] = true;
229
-                    $allErrors[$stackPtr]      = $error;
226
+            foreach ( $errors as $stackPtr => $error ) {
227
+                if ( isset( $this->errorPos[ $stackPtr ] ) === false ) {
228
+                    $this->errorPos[ $stackPtr ] = true;
229
+                    $allErrors[ $stackPtr ]      = $error;
230 230
                 }
231 231
             }
232 232
         }
233 233
 
234
-        foreach ($allErrors as $stackPtr => $error) {
235
-            $phpcsFile->addError($error, $stackPtr, 'Found');
234
+        foreach ( $allErrors as $stackPtr => $error ) {
235
+            $phpcsFile->addError( $error, $stackPtr, 'Found' );
236 236
         }
237 237
 
238 238
     }//end process()
@@ -252,37 +252,37 @@  discard block
 block discarded – undo
252 252
      *
253 253
      * @return array
254 254
      */
255
-    protected function processPattern($patternInfo, File $phpcsFile, $stackPtr)
255
+    protected function processPattern( $patternInfo, File $phpcsFile, $stackPtr )
256 256
     {
257 257
         $tokens      = $phpcsFile->getTokens();
258
-        $pattern     = $patternInfo['pattern'];
259
-        $patternCode = $patternInfo['pattern_code'];
260
-        $errors      = [];
258
+        $pattern     = $patternInfo[ 'pattern' ];
259
+        $patternCode = $patternInfo[ 'pattern_code' ];
260
+        $errors      = [ ];
261 261
         $found       = '';
262 262
 
263
-        $ignoreTokens = [T_WHITESPACE => T_WHITESPACE];
264
-        if ($this->ignoreComments === true) {
263
+        $ignoreTokens = [ T_WHITESPACE => T_WHITESPACE ];
264
+        if ( $this->ignoreComments === true ) {
265 265
             $ignoreTokens += Tokens::$commentTokens;
266 266
         }
267 267
 
268 268
         $origStackPtr = $stackPtr;
269 269
         $hasError     = false;
270 270
 
271
-        if ($patternInfo['listen_pos'] > 0) {
271
+        if ( $patternInfo[ 'listen_pos' ] > 0 ) {
272 272
             $stackPtr--;
273 273
 
274
-            for ($i = ($patternInfo['listen_pos'] - 1); $i >= 0; $i--) {
275
-                if ($pattern[$i]['type'] === 'token') {
276
-                    if ($pattern[$i]['token'] === T_WHITESPACE) {
277
-                        if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
278
-                            $found = $tokens[$stackPtr]['content'].$found;
274
+            for ( $i = ( $patternInfo[ 'listen_pos' ] - 1 ); $i >= 0; $i-- ) {
275
+                if ( $pattern[ $i ][ 'type' ] === 'token' ) {
276
+                    if ( $pattern[ $i ][ 'token' ] === T_WHITESPACE ) {
277
+                        if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
278
+                            $found = $tokens[ $stackPtr ][ 'content' ] . $found;
279 279
                         }
280 280
 
281 281
                         // Only check the size of the whitespace if this is not
282 282
                         // the first token. We don't care about the size of
283 283
                         // leading whitespace, just that there is some.
284
-                        if ($i !== 0) {
285
-                            if ($tokens[$stackPtr]['content'] !== $pattern[$i]['value']) {
284
+                        if ( $i !== 0 ) {
285
+                            if ( $tokens[ $stackPtr ][ 'content' ] !== $pattern[ $i ][ 'value' ] ) {
286 286
                                 $hasError = true;
287 287
                             }
288 288
                         }
@@ -297,8 +297,8 @@  discard block
 block discarded – undo
297 297
                             true
298 298
                         );
299 299
 
300
-                        if ($prev === false
301
-                            || $tokens[$prev]['code'] !== $pattern[$i]['token']
300
+                        if ( $prev === false
301
+                            || $tokens[ $prev ][ 'code' ] !== $pattern[ $i ][ 'token' ]
302 302
                         ) {
303 303
                             return false;
304 304
                         }
@@ -306,23 +306,23 @@  discard block
 block discarded – undo
306 306
                         // If we skipped past some whitespace tokens, then add them
307 307
                         // to the found string.
308 308
                         $tokenContent = $phpcsFile->getTokensAsString(
309
-                            ($prev + 1),
310
-                            ($stackPtr - $prev - 1)
309
+                            ( $prev + 1 ),
310
+                            ( $stackPtr - $prev - 1 )
311 311
                         );
312 312
 
313
-                        $found = $tokens[$prev]['content'].$tokenContent.$found;
313
+                        $found = $tokens[ $prev ][ 'content' ] . $tokenContent . $found;
314 314
 
315
-                        if (isset($pattern[($i - 1)]) === true
316
-                            && $pattern[($i - 1)]['type'] === 'skip'
315
+                        if ( isset( $pattern[ ( $i - 1 ) ] ) === true
316
+                            && $pattern[ ( $i - 1 ) ][ 'type' ] === 'skip'
317 317
                         ) {
318 318
                             $stackPtr = $prev;
319 319
                         } else {
320
-                            $stackPtr = ($prev - 1);
320
+                            $stackPtr = ( $prev - 1 );
321 321
                         }
322 322
                     }//end if
323
-                } else if ($pattern[$i]['type'] === 'skip') {
323
+                } else if ( $pattern[ $i ][ 'type' ] === 'skip' ) {
324 324
                     // Skip to next piece of relevant code.
325
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
325
+                    if ( $pattern[ $i ][ 'to' ] === 'parenthesis_closer' ) {
326 326
                         $to = 'parenthesis_opener';
327 327
                     } else {
328 328
                         $to = 'scope_opener';
@@ -336,75 +336,75 @@  discard block
 block discarded – undo
336 336
                         true
337 337
                     );
338 338
 
339
-                    if ($next === false || isset($tokens[$next][$to]) === false) {
339
+                    if ( $next === false || isset( $tokens[ $next ][ $to ] ) === false ) {
340 340
                         // If there was not opener, then we must be
341 341
                         // using the wrong pattern.
342 342
                         return false;
343 343
                     }
344 344
 
345
-                    if ($to === 'parenthesis_opener') {
346
-                        $found = '{'.$found;
345
+                    if ( $to === 'parenthesis_opener' ) {
346
+                        $found = '{' . $found;
347 347
                     } else {
348
-                        $found = '('.$found;
348
+                        $found = '(' . $found;
349 349
                     }
350 350
 
351
-                    $found = '...'.$found;
351
+                    $found = '...' . $found;
352 352
 
353 353
                     // Skip to the opening token.
354
-                    $stackPtr = ($tokens[$next][$to] - 1);
355
-                } else if ($pattern[$i]['type'] === 'string') {
354
+                    $stackPtr = ( $tokens[ $next ][ $to ] - 1 );
355
+                } else if ( $pattern[ $i ][ 'type' ] === 'string' ) {
356 356
                     $found = 'abc';
357
-                } else if ($pattern[$i]['type'] === 'newline') {
358
-                    if ($this->ignoreComments === true
359
-                        && isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true
357
+                } else if ( $pattern[ $i ][ 'type' ] === 'newline' ) {
358
+                    if ( $this->ignoreComments === true
359
+                        && isset( Tokens::$commentTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true
360 360
                     ) {
361 361
                         $startComment = $phpcsFile->findPrevious(
362 362
                             Tokens::$commentTokens,
363
-                            ($stackPtr - 1),
363
+                            ( $stackPtr - 1 ),
364 364
                             null,
365 365
                             true
366 366
                         );
367 367
 
368
-                        if ($tokens[$startComment]['line'] !== $tokens[($startComment + 1)]['line']) {
368
+                        if ( $tokens[ $startComment ][ 'line' ] !== $tokens[ ( $startComment + 1 ) ][ 'line' ] ) {
369 369
                             $startComment++;
370 370
                         }
371 371
 
372 372
                         $tokenContent = $phpcsFile->getTokensAsString(
373 373
                             $startComment,
374
-                            ($stackPtr - $startComment + 1)
374
+                            ( $stackPtr - $startComment + 1 )
375 375
                         );
376 376
 
377
-                        $found    = $tokenContent.$found;
378
-                        $stackPtr = ($startComment - 1);
377
+                        $found    = $tokenContent . $found;
378
+                        $stackPtr = ( $startComment - 1 );
379 379
                     }
380 380
 
381
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
382
-                        if ($tokens[$stackPtr]['content'] !== $phpcsFile->eolChar) {
383
-                            $found = $tokens[$stackPtr]['content'].$found;
381
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
382
+                        if ( $tokens[ $stackPtr ][ 'content' ] !== $phpcsFile->eolChar ) {
383
+                            $found = $tokens[ $stackPtr ][ 'content' ] . $found;
384 384
 
385 385
                             // This may just be an indent that comes after a newline
386 386
                             // so check the token before to make sure. If it is a newline, we
387 387
                             // can ignore the error here.
388
-                            if (($tokens[($stackPtr - 1)]['content'] !== $phpcsFile->eolChar)
389
-                                && ($this->ignoreComments === true
390
-                                && isset(Tokens::$commentTokens[$tokens[($stackPtr - 1)]['code']]) === false)
388
+                            if ( ( $tokens[ ( $stackPtr - 1 ) ][ 'content' ] !== $phpcsFile->eolChar )
389
+                                && ( $this->ignoreComments === true
390
+                                && isset( Tokens::$commentTokens[ $tokens[ ( $stackPtr - 1 ) ][ 'code' ] ] ) === false )
391 391
                             ) {
392 392
                                 $hasError = true;
393 393
                             } else {
394 394
                                 $stackPtr--;
395 395
                             }
396 396
                         } else {
397
-                            $found = 'EOL'.$found;
397
+                            $found = 'EOL' . $found;
398 398
                         }
399 399
                     } else {
400
-                        $found    = $tokens[$stackPtr]['content'].$found;
400
+                        $found    = $tokens[ $stackPtr ][ 'content' ] . $found;
401 401
                         $hasError = true;
402 402
                     }//end if
403 403
 
404
-                    if ($hasError === false && $pattern[($i - 1)]['type'] !== 'newline') {
404
+                    if ( $hasError === false && $pattern[ ( $i - 1 ) ][ 'type' ] !== 'newline' ) {
405 405
                         // Make sure they only have 1 newline.
406
-                        $prev = $phpcsFile->findPrevious($ignoreTokens, ($stackPtr - 1), null, true);
407
-                        if ($prev !== false && $tokens[$prev]['line'] !== $tokens[$stackPtr]['line']) {
406
+                        $prev = $phpcsFile->findPrevious( $ignoreTokens, ( $stackPtr - 1 ), null, true );
407
+                        if ( $prev !== false && $tokens[ $prev ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) {
408 408
                             $hasError = true;
409 409
                         }
410 410
                     }
@@ -414,38 +414,38 @@  discard block
 block discarded – undo
414 414
 
415 415
         $stackPtr          = $origStackPtr;
416 416
         $lastAddedStackPtr = null;
417
-        $patternLen        = count($pattern);
417
+        $patternLen        = count( $pattern );
418 418
 
419
-        for ($i = $patternInfo['listen_pos']; $i < $patternLen; $i++) {
420
-            if (isset($tokens[$stackPtr]) === false) {
419
+        for ( $i = $patternInfo[ 'listen_pos' ]; $i < $patternLen; $i++ ) {
420
+            if ( isset( $tokens[ $stackPtr ] ) === false ) {
421 421
                 break;
422 422
             }
423 423
 
424
-            if ($pattern[$i]['type'] === 'token') {
425
-                if ($pattern[$i]['token'] === T_WHITESPACE) {
426
-                    if ($this->ignoreComments === true) {
424
+            if ( $pattern[ $i ][ 'type' ] === 'token' ) {
425
+                if ( $pattern[ $i ][ 'token' ] === T_WHITESPACE ) {
426
+                    if ( $this->ignoreComments === true ) {
427 427
                         // If we are ignoring comments, check to see if this current
428 428
                         // token is a comment. If so skip it.
429
-                        if (isset(Tokens::$commentTokens[$tokens[$stackPtr]['code']]) === true) {
429
+                        if ( isset( Tokens::$commentTokens[ $tokens[ $stackPtr ][ 'code' ] ] ) === true ) {
430 430
                             continue;
431 431
                         }
432 432
 
433 433
                         // If the next token is a comment, the we need to skip the
434 434
                         // current token as we should allow a space before a
435 435
                         // comment for readability.
436
-                        if (isset($tokens[($stackPtr + 1)]) === true
437
-                            && isset(Tokens::$commentTokens[$tokens[($stackPtr + 1)]['code']]) === true
436
+                        if ( isset( $tokens[ ( $stackPtr + 1 ) ] ) === true
437
+                            && isset( Tokens::$commentTokens[ $tokens[ ( $stackPtr + 1 ) ][ 'code' ] ] ) === true
438 438
                         ) {
439 439
                             continue;
440 440
                         }
441 441
                     }
442 442
 
443 443
                     $tokenContent = '';
444
-                    if ($tokens[$stackPtr]['code'] === T_WHITESPACE) {
445
-                        if (isset($pattern[($i + 1)]) === false) {
444
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_WHITESPACE ) {
445
+                        if ( isset( $pattern[ ( $i + 1 ) ] ) === false ) {
446 446
                             // This is the last token in the pattern, so just compare
447 447
                             // the next token of content.
448
-                            $tokenContent = $tokens[$stackPtr]['content'];
448
+                            $tokenContent = $tokens[ $stackPtr ][ 'content' ];
449 449
                         } else {
450 450
                             // Get all the whitespace to the next token.
451 451
                             $next = $phpcsFile->findNext(
@@ -457,34 +457,34 @@  discard block
 block discarded – undo
457 457
 
458 458
                             $tokenContent = $phpcsFile->getTokensAsString(
459 459
                                 $stackPtr,
460
-                                ($next - $stackPtr)
460
+                                ( $next - $stackPtr )
461 461
                             );
462 462
 
463 463
                             $lastAddedStackPtr = $stackPtr;
464 464
                             $stackPtr          = $next;
465 465
                         }//end if
466 466
 
467
-                        if ($stackPtr !== $lastAddedStackPtr) {
467
+                        if ( $stackPtr !== $lastAddedStackPtr ) {
468 468
                             $found .= $tokenContent;
469 469
                         }
470 470
                     } else {
471
-                        if ($stackPtr !== $lastAddedStackPtr) {
472
-                            $found            .= $tokens[$stackPtr]['content'];
471
+                        if ( $stackPtr !== $lastAddedStackPtr ) {
472
+                            $found            .= $tokens[ $stackPtr ][ 'content' ];
473 473
                             $lastAddedStackPtr = $stackPtr;
474 474
                         }
475 475
                     }//end if
476 476
 
477
-                    if (isset($pattern[($i + 1)]) === true
478
-                        && $pattern[($i + 1)]['type'] === 'skip'
477
+                    if ( isset( $pattern[ ( $i + 1 ) ] ) === true
478
+                        && $pattern[ ( $i + 1 ) ][ 'type' ] === 'skip'
479 479
                     ) {
480 480
                         // The next token is a skip token, so we just need to make
481 481
                         // sure the whitespace we found has *at least* the
482 482
                         // whitespace required.
483
-                        if (strpos($tokenContent, $pattern[$i]['value']) !== 0) {
483
+                        if ( strpos( $tokenContent, $pattern[ $i ][ 'value' ] ) !== 0 ) {
484 484
                             $hasError = true;
485 485
                         }
486 486
                     } else {
487
-                        if ($tokenContent !== $pattern[$i]['value']) {
487
+                        if ( $tokenContent !== $pattern[ $i ][ 'value' ] ) {
488 488
                             $hasError = true;
489 489
                         }
490 490
                     }
@@ -499,18 +499,18 @@  discard block
 block discarded – undo
499 499
                         true
500 500
                     );
501 501
 
502
-                    if ($next === false
503
-                        || $tokens[$next]['code'] !== $pattern[$i]['token']
502
+                    if ( $next === false
503
+                        || $tokens[ $next ][ 'code' ] !== $pattern[ $i ][ 'token' ]
504 504
                     ) {
505 505
                         // The next important token did not match the pattern.
506 506
                         return false;
507 507
                     }
508 508
 
509
-                    if ($lastAddedStackPtr !== null) {
510
-                        if (($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET
511
-                            || $tokens[$next]['code'] === T_CLOSE_CURLY_BRACKET)
512
-                            && isset($tokens[$next]['scope_condition']) === true
513
-                            && $tokens[$next]['scope_condition'] > $lastAddedStackPtr
509
+                    if ( $lastAddedStackPtr !== null ) {
510
+                        if ( ( $tokens[ $next ][ 'code' ] === T_OPEN_CURLY_BRACKET
511
+                            || $tokens[ $next ][ 'code' ] === T_CLOSE_CURLY_BRACKET )
512
+                            && isset( $tokens[ $next ][ 'scope_condition' ] ) === true
513
+                            && $tokens[ $next ][ 'scope_condition' ] > $lastAddedStackPtr
514 514
                         ) {
515 515
                             // This is a brace, but the owner of it is after the current
516 516
                             // token, which means it does not belong to any token in
@@ -518,10 +518,10 @@  discard block
 block discarded – undo
518 518
                             return false;
519 519
                         }
520 520
 
521
-                        if (($tokens[$next]['code'] === T_OPEN_PARENTHESIS
522
-                            || $tokens[$next]['code'] === T_CLOSE_PARENTHESIS)
523
-                            && isset($tokens[$next]['parenthesis_owner']) === true
524
-                            && $tokens[$next]['parenthesis_owner'] > $lastAddedStackPtr
521
+                        if ( ( $tokens[ $next ][ 'code' ] === T_OPEN_PARENTHESIS
522
+                            || $tokens[ $next ][ 'code' ] === T_CLOSE_PARENTHESIS )
523
+                            && isset( $tokens[ $next ][ 'parenthesis_owner' ] ) === true
524
+                            && $tokens[ $next ][ 'parenthesis_owner' ] > $lastAddedStackPtr
525 525
                         ) {
526 526
                             // This is a bracket, but the owner of it is after the current
527 527
                             // token, which means it does not belong to any token in
@@ -532,11 +532,11 @@  discard block
 block discarded – undo
532 532
 
533 533
                     // If we skipped past some whitespace tokens, then add them
534 534
                     // to the found string.
535
-                    if (($next - $stackPtr) > 0) {
535
+                    if ( ( $next - $stackPtr ) > 0 ) {
536 536
                         $hasComment = false;
537
-                        for ($j = $stackPtr; $j < $next; $j++) {
538
-                            $found .= $tokens[$j]['content'];
539
-                            if (isset(Tokens::$commentTokens[$tokens[$j]['code']]) === true) {
537
+                        for ( $j = $stackPtr; $j < $next; $j++ ) {
538
+                            $found .= $tokens[ $j ][ 'content' ];
539
+                            if ( isset( Tokens::$commentTokens[ $tokens[ $j ][ 'code' ] ] ) === true ) {
540 540
                                 $hasComment = true;
541 541
                             }
542 542
                         }
@@ -545,9 +545,9 @@  discard block
 block discarded – undo
545 545
                         // whitespace or comment is not allowed. If we are
546 546
                         // ignoring comments, there needs to be at least one
547 547
                         // comment for this to be allowed.
548
-                        if ($this->ignoreComments === false
549
-                            || ($this->ignoreComments === true
550
-                            && $hasComment === false)
548
+                        if ( $this->ignoreComments === false
549
+                            || ( $this->ignoreComments === true
550
+                            && $hasComment === false )
551 551
                         ) {
552 552
                             $hasError = true;
553 553
                         }
@@ -555,32 +555,32 @@  discard block
 block discarded – undo
555 555
                         // Even when ignoring comments, we are not allowed to include
556 556
                         // newlines without the pattern specifying them, so
557 557
                         // everything should be on the same line.
558
-                        if ($tokens[$next]['line'] !== $tokens[$stackPtr]['line']) {
558
+                        if ( $tokens[ $next ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) {
559 559
                             $hasError = true;
560 560
                         }
561 561
                     }//end if
562 562
 
563
-                    if ($next !== $lastAddedStackPtr) {
564
-                        $found            .= $tokens[$next]['content'];
563
+                    if ( $next !== $lastAddedStackPtr ) {
564
+                        $found            .= $tokens[ $next ][ 'content' ];
565 565
                         $lastAddedStackPtr = $next;
566 566
                     }
567 567
 
568
-                    if (isset($pattern[($i + 1)]) === true
569
-                        && $pattern[($i + 1)]['type'] === 'skip'
568
+                    if ( isset( $pattern[ ( $i + 1 ) ] ) === true
569
+                        && $pattern[ ( $i + 1 ) ][ 'type' ] === 'skip'
570 570
                     ) {
571 571
                         $stackPtr = $next;
572 572
                     } else {
573
-                        $stackPtr = ($next + 1);
573
+                        $stackPtr = ( $next + 1 );
574 574
                     }
575 575
                 }//end if
576
-            } else if ($pattern[$i]['type'] === 'skip') {
577
-                if ($pattern[$i]['to'] === 'unknown') {
576
+            } else if ( $pattern[ $i ][ 'type' ] === 'skip' ) {
577
+                if ( $pattern[ $i ][ 'to' ] === 'unknown' ) {
578 578
                     $next = $phpcsFile->findNext(
579
-                        $pattern[($i + 1)]['token'],
579
+                        $pattern[ ( $i + 1 ) ][ 'token' ],
580 580
                         $stackPtr
581 581
                     );
582 582
 
583
-                    if ($next === false) {
583
+                    if ( $next === false ) {
584 584
                         // Couldn't find the next token, so we must
585 585
                         // be using the wrong pattern.
586 586
                         return false;
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
                         $stackPtr
596 596
                     );
597 597
 
598
-                    if ($next === false
599
-                        || isset($tokens[$next][$pattern[$i]['to']]) === false
598
+                    if ( $next === false
599
+                        || isset( $tokens[ $next ][ $pattern[ $i ][ 'to' ] ] ) === false
600 600
                     ) {
601 601
                         // If there was not opener, then we must
602 602
                         // be using the wrong pattern.
@@ -604,50 +604,50 @@  discard block
 block discarded – undo
604 604
                     }
605 605
 
606 606
                     $found .= '...';
607
-                    if ($pattern[$i]['to'] === 'parenthesis_closer') {
607
+                    if ( $pattern[ $i ][ 'to' ] === 'parenthesis_closer' ) {
608 608
                         $found .= ')';
609 609
                     } else {
610 610
                         $found .= '}';
611 611
                     }
612 612
 
613 613
                     // Skip to the closing token.
614
-                    $stackPtr = ($tokens[$next][$pattern[$i]['to']] + 1);
614
+                    $stackPtr = ( $tokens[ $next ][ $pattern[ $i ][ 'to' ] ] + 1 );
615 615
                 }//end if
616
-            } else if ($pattern[$i]['type'] === 'string') {
617
-                if ($tokens[$stackPtr]['code'] !== T_STRING) {
616
+            } else if ( $pattern[ $i ][ 'type' ] === 'string' ) {
617
+                if ( $tokens[ $stackPtr ][ 'code' ] !== T_STRING ) {
618 618
                     $hasError = true;
619 619
                 }
620 620
 
621
-                if ($stackPtr !== $lastAddedStackPtr) {
621
+                if ( $stackPtr !== $lastAddedStackPtr ) {
622 622
                     $found            .= 'abc';
623 623
                     $lastAddedStackPtr = $stackPtr;
624 624
                 }
625 625
 
626 626
                 $stackPtr++;
627
-            } else if ($pattern[$i]['type'] === 'newline') {
627
+            } else if ( $pattern[ $i ][ 'type' ] === 'newline' ) {
628 628
                 // Find the next token that contains a newline character.
629 629
                 $newline = 0;
630
-                for ($j = $stackPtr; $j < $phpcsFile->numTokens; $j++) {
631
-                    if (strpos($tokens[$j]['content'], $phpcsFile->eolChar) !== false) {
630
+                for ( $j = $stackPtr; $j < $phpcsFile->numTokens; $j++ ) {
631
+                    if ( strpos( $tokens[ $j ][ 'content' ], $phpcsFile->eolChar ) !== false ) {
632 632
                         $newline = $j;
633 633
                         break;
634 634
                     }
635 635
                 }
636 636
 
637
-                if ($newline === 0) {
637
+                if ( $newline === 0 ) {
638 638
                     // We didn't find a newline character in the rest of the file.
639
-                    $next     = ($phpcsFile->numTokens - 1);
639
+                    $next     = ( $phpcsFile->numTokens - 1 );
640 640
                     $hasError = true;
641 641
                 } else {
642
-                    if ($this->ignoreComments === false) {
642
+                    if ( $this->ignoreComments === false ) {
643 643
                         // The newline character cannot be part of a comment.
644
-                        if (isset(Tokens::$commentTokens[$tokens[$newline]['code']]) === true) {
644
+                        if ( isset( Tokens::$commentTokens[ $tokens[ $newline ][ 'code' ] ] ) === true ) {
645 645
                             $hasError = true;
646 646
                         }
647 647
                     }
648 648
 
649
-                    if ($newline === $stackPtr) {
650
-                        $next = ($stackPtr + 1);
649
+                    if ( $newline === $stackPtr ) {
650
+                        $next = ( $stackPtr + 1 );
651 651
                     } else {
652 652
                         // Check that there were no significant tokens that we
653 653
                         // skipped over to find our newline character.
@@ -658,31 +658,31 @@  discard block
 block discarded – undo
658 658
                             true
659 659
                         );
660 660
 
661
-                        if ($next < $newline) {
661
+                        if ( $next < $newline ) {
662 662
                             // We skipped a non-ignored token.
663 663
                             $hasError = true;
664 664
                         } else {
665
-                            $next = ($newline + 1);
665
+                            $next = ( $newline + 1 );
666 666
                         }
667 667
                     }
668 668
                 }//end if
669 669
 
670
-                if ($stackPtr !== $lastAddedStackPtr) {
670
+                if ( $stackPtr !== $lastAddedStackPtr ) {
671 671
                     $found .= $phpcsFile->getTokensAsString(
672 672
                         $stackPtr,
673
-                        ($next - $stackPtr)
673
+                        ( $next - $stackPtr )
674 674
                     );
675 675
 
676
-                    $lastAddedStackPtr = ($next - 1);
676
+                    $lastAddedStackPtr = ( $next - 1 );
677 677
                 }
678 678
 
679 679
                 $stackPtr = $next;
680 680
             }//end if
681 681
         }//end for
682 682
 
683
-        if ($hasError === true) {
684
-            $error = $this->prepareError($found, $patternCode);
685
-            $errors[$origStackPtr] = $error;
683
+        if ( $hasError === true ) {
684
+            $error = $this->prepareError( $found, $patternCode );
685
+            $errors[ $origStackPtr ] = $error;
686 686
         }
687 687
 
688 688
         return $errors;
@@ -698,14 +698,14 @@  discard block
 block discarded – undo
698 698
      *
699 699
      * @return string The error message.
700 700
      */
701
-    protected function prepareError($found, $patternCode)
701
+    protected function prepareError( $found, $patternCode )
702 702
     {
703
-        $found    = str_replace("\r\n", '\n', $found);
704
-        $found    = str_replace("\n", '\n', $found);
705
-        $found    = str_replace("\r", '\n', $found);
706
-        $found    = str_replace("\t", '\t', $found);
707
-        $found    = str_replace('EOL', '\n', $found);
708
-        $expected = str_replace('EOL', '\n', $patternCode);
703
+        $found    = str_replace( "\r\n", '\n', $found );
704
+        $found    = str_replace( "\n", '\n', $found );
705
+        $found    = str_replace( "\r", '\n', $found );
706
+        $found    = str_replace( "\t", '\t', $found );
707
+        $found    = str_replace( 'EOL', '\n', $found );
708
+        $expected = str_replace( 'EOL', '\n', $patternCode );
709 709
 
710 710
         $error = "Expected \"$expected\"; found \"$found\"";
711 711
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
      */
735 735
     protected function registerSupplementary()
736 736
     {
737
-        return [];
737
+        return [ ];
738 738
 
739 739
     }//end registerSupplementary()
740 740
 
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
       * @return void
751 751
       * @see    registerSupplementary()
752 752
       */
753
-    protected function processSupplementary(File $phpcsFile, $stackPtr)
753
+    protected function processSupplementary( File $phpcsFile, $stackPtr )
754 754
     {
755 755
 
756 756
     }//end processSupplementary()
@@ -765,70 +765,70 @@  discard block
 block discarded – undo
765 765
      * @see    createSkipPattern()
766 766
      * @see    createTokenPattern()
767 767
      */
768
-    private function parse($pattern)
768
+    private function parse( $pattern )
769 769
     {
770
-        $patterns   = [];
771
-        $length     = strlen($pattern);
770
+        $patterns   = [ ];
771
+        $length     = strlen( $pattern );
772 772
         $lastToken  = 0;
773 773
         $firstToken = 0;
774 774
 
775
-        for ($i = 0; $i < $length; $i++) {
775
+        for ( $i = 0; $i < $length; $i++ ) {
776 776
             $specialPattern = false;
777
-            $isLastChar     = ($i === ($length - 1));
777
+            $isLastChar     = ( $i === ( $length - 1 ) );
778 778
             $oldFirstToken  = $firstToken;
779 779
 
780
-            if (substr($pattern, $i, 3) === '...') {
780
+            if ( substr( $pattern, $i, 3 ) === '...' ) {
781 781
                 // It's a skip pattern. The skip pattern requires the
782 782
                 // content of the token in the "from" position and the token
783 783
                 // to skip to.
784
-                $specialPattern = $this->createSkipPattern($pattern, ($i - 1));
785
-                $lastToken      = ($i - $firstToken);
786
-                $firstToken     = ($i + 3);
784
+                $specialPattern = $this->createSkipPattern( $pattern, ( $i - 1 ) );
785
+                $lastToken      = ( $i - $firstToken );
786
+                $firstToken     = ( $i + 3 );
787 787
                 $i += 2;
788 788
 
789
-                if ($specialPattern['to'] !== 'unknown') {
789
+                if ( $specialPattern[ 'to' ] !== 'unknown' ) {
790 790
                     $firstToken++;
791 791
                 }
792
-            } else if (substr($pattern, $i, 3) === 'abc') {
793
-                $specialPattern = ['type' => 'string'];
794
-                $lastToken      = ($i - $firstToken);
795
-                $firstToken     = ($i + 3);
792
+            } else if ( substr( $pattern, $i, 3 ) === 'abc' ) {
793
+                $specialPattern = [ 'type' => 'string' ];
794
+                $lastToken      = ( $i - $firstToken );
795
+                $firstToken     = ( $i + 3 );
796 796
                 $i += 2;
797
-            } else if (substr($pattern, $i, 3) === 'EOL') {
798
-                $specialPattern = ['type' => 'newline'];
799
-                $lastToken      = ($i - $firstToken);
800
-                $firstToken     = ($i + 3);
797
+            } else if ( substr( $pattern, $i, 3 ) === 'EOL' ) {
798
+                $specialPattern = [ 'type' => 'newline' ];
799
+                $lastToken      = ( $i - $firstToken );
800
+                $firstToken     = ( $i + 3 );
801 801
                 $i += 2;
802 802
             }//end if
803 803
 
804
-            if ($specialPattern !== false || $isLastChar === true) {
804
+            if ( $specialPattern !== false || $isLastChar === true ) {
805 805
                 // If we are at the end of the string, don't worry about a limit.
806
-                if ($isLastChar === true) {
806
+                if ( $isLastChar === true ) {
807 807
                     // Get the string from the end of the last skip pattern, if any,
808 808
                     // to the end of the pattern string.
809
-                    $str = substr($pattern, $oldFirstToken);
809
+                    $str = substr( $pattern, $oldFirstToken );
810 810
                 } else {
811 811
                     // Get the string from the end of the last special pattern,
812 812
                     // if any, to the start of this special pattern.
813
-                    if ($lastToken === 0) {
813
+                    if ( $lastToken === 0 ) {
814 814
                         // Note that if the last special token was zero characters ago,
815 815
                         // there will be nothing to process so we can skip this bit.
816 816
                         // This happens if you have something like: EOL... in your pattern.
817 817
                         $str = '';
818 818
                     } else {
819
-                        $str = substr($pattern, $oldFirstToken, $lastToken);
819
+                        $str = substr( $pattern, $oldFirstToken, $lastToken );
820 820
                     }
821 821
                 }
822 822
 
823
-                if ($str !== '') {
824
-                    $tokenPatterns = $this->createTokenPattern($str);
825
-                    foreach ($tokenPatterns as $tokenPattern) {
826
-                        $patterns[] = $tokenPattern;
823
+                if ( $str !== '' ) {
824
+                    $tokenPatterns = $this->createTokenPattern( $str );
825
+                    foreach ( $tokenPatterns as $tokenPattern ) {
826
+                        $patterns[ ] = $tokenPattern;
827 827
                     }
828 828
                 }
829 829
 
830 830
                 // Make sure we don't skip the last token.
831
-                if ($isLastChar === false && $i === ($length - 1)) {
831
+                if ( $isLastChar === false && $i === ( $length - 1 ) ) {
832 832
                     $i--;
833 833
                 }
834 834
             }//end if
@@ -836,8 +836,8 @@  discard block
 block discarded – undo
836 836
             // Add the skip pattern *after* we have processed
837 837
             // all the tokens from the end of the last skip pattern
838 838
             // to the start of this skip pattern.
839
-            if ($specialPattern !== false) {
840
-                $patterns[] = $specialPattern;
839
+            if ( $specialPattern !== false ) {
840
+                $patterns[ ] = $specialPattern;
841 841
             }
842 842
         }//end for
843 843
 
@@ -856,24 +856,24 @@  discard block
 block discarded – undo
856 856
      * @see    createTokenPattern()
857 857
      * @see    parse()
858 858
      */
859
-    private function createSkipPattern($pattern, $from)
859
+    private function createSkipPattern( $pattern, $from )
860 860
     {
861
-        $skip = ['type' => 'skip'];
861
+        $skip = [ 'type' => 'skip' ];
862 862
 
863 863
         $nestedParenthesis = 0;
864 864
         $nestedBraces      = 0;
865
-        for ($start = $from; $start >= 0; $start--) {
866
-            switch ($pattern[$start]) {
865
+        for ( $start = $from; $start >= 0; $start-- ) {
866
+            switch ( $pattern[ $start ] ) {
867 867
             case '(':
868
-                if ($nestedParenthesis === 0) {
869
-                    $skip['to'] = 'parenthesis_closer';
868
+                if ( $nestedParenthesis === 0 ) {
869
+                    $skip[ 'to' ] = 'parenthesis_closer';
870 870
                 }
871 871
 
872 872
                 $nestedParenthesis--;
873 873
                 break;
874 874
             case '{':
875
-                if ($nestedBraces === 0) {
876
-                    $skip['to'] = 'scope_closer';
875
+                if ( $nestedBraces === 0 ) {
876
+                    $skip[ 'to' ] = 'scope_closer';
877 877
                 }
878 878
 
879 879
                 $nestedBraces--;
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
                 break;
887 887
             }//end switch
888 888
 
889
-            if (isset($skip['to']) === true) {
889
+            if ( isset( $skip[ 'to' ] ) === true ) {
890 890
                 break;
891 891
             }
892 892
         }//end for
893 893
 
894
-        if (isset($skip['to']) === false) {
895
-            $skip['to'] = 'unknown';
894
+        if ( isset( $skip[ 'to' ] ) === false ) {
895
+            $skip[ 'to' ] = 'unknown';
896 896
         }
897 897
 
898 898
         return $skip;
@@ -909,22 +909,22 @@  discard block
 block discarded – undo
909 909
      * @see    createSkipPattern()
910 910
      * @see    parse()
911 911
      */
912
-    private function createTokenPattern($str)
912
+    private function createTokenPattern( $str )
913 913
     {
914 914
         // Don't add a space after the closing php tag as it will add a new
915 915
         // whitespace token.
916
-        $tokenizer = new PHP('<?php '.$str.'?>', null);
916
+        $tokenizer = new PHP( '<?php ' . $str . '?>', null );
917 917
 
918 918
         // Remove the <?php tag from the front and the end php tag from the back.
919 919
         $tokens = $tokenizer->getTokens();
920
-        $tokens = array_slice($tokens, 1, (count($tokens) - 2));
920
+        $tokens = array_slice( $tokens, 1, ( count( $tokens ) - 2 ) );
921 921
 
922
-        $patterns = [];
923
-        foreach ($tokens as $patternInfo) {
924
-            $patterns[] = [
922
+        $patterns = [ ];
923
+        foreach ( $tokens as $patternInfo ) {
924
+            $patterns[ ] = [
925 925
                 'type'  => 'token',
926
-                'token' => $patternInfo['code'],
927
-                'value' => $patternInfo['content'],
926
+                'token' => $patternInfo[ 'code' ],
927
+                'value' => $patternInfo[ 'content' ],
928 928
             ];
929 929
         }
930 930
 
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractArraySniff.php 1 patch
Spacing   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -40,123 +40,123 @@  discard block
 block discarded – undo
40 40
      *
41 41
      * @return void
42 42
      */
43
-    public function process(File $phpcsFile, $stackPtr)
43
+    public function process( File $phpcsFile, $stackPtr )
44 44
     {
45 45
         $tokens = $phpcsFile->getTokens();
46 46
 
47
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
48
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no');
47
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
48
+            $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'no' );
49 49
 
50
-            $arrayStart = $tokens[$stackPtr]['parenthesis_opener'];
51
-            if (isset($tokens[$arrayStart]['parenthesis_closer']) === false) {
50
+            $arrayStart = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
51
+            if ( isset( $tokens[ $arrayStart ][ 'parenthesis_closer' ] ) === false ) {
52 52
                 // Incomplete array.
53 53
                 return;
54 54
             }
55 55
 
56
-            $arrayEnd = $tokens[$arrayStart]['parenthesis_closer'];
56
+            $arrayEnd = $tokens[ $arrayStart ][ 'parenthesis_closer' ];
57 57
         } else {
58
-            $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'yes');
58
+            $phpcsFile->recordMetric( $stackPtr, 'Short array syntax used', 'yes' );
59 59
             $arrayStart = $stackPtr;
60
-            $arrayEnd   = $tokens[$stackPtr]['bracket_closer'];
60
+            $arrayEnd   = $tokens[ $stackPtr ][ 'bracket_closer' ];
61 61
         }
62 62
 
63
-        $lastContent = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrayEnd - 1), null, true);
64
-        if ($tokens[$lastContent]['code'] === T_COMMA) {
63
+        $lastContent = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $arrayEnd - 1 ), null, true );
64
+        if ( $tokens[ $lastContent ][ 'code' ] === T_COMMA ) {
65 65
             // Last array item ends with a comma.
66
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'yes');
66
+            $phpcsFile->recordMetric( $stackPtr, 'Array end comma', 'yes' );
67 67
             $lastArrayToken = $lastContent;
68 68
         } else {
69
-            $phpcsFile->recordMetric($stackPtr, 'Array end comma', 'no');
69
+            $phpcsFile->recordMetric( $stackPtr, 'Array end comma', 'no' );
70 70
             $lastArrayToken = $arrayEnd;
71 71
         }
72 72
 
73
-        if ($tokens[$stackPtr]['code'] === T_ARRAY) {
74
-            $lastToken = $tokens[$stackPtr]['parenthesis_opener'];
73
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
74
+            $lastToken = $tokens[ $stackPtr ][ 'parenthesis_opener' ];
75 75
         } else {
76 76
             $lastToken = $stackPtr;
77 77
         }
78 78
 
79 79
         $keyUsed = false;
80
-        $indices = [];
80
+        $indices = [ ];
81 81
 
82
-        for ($checkToken = ($stackPtr + 1); $checkToken <= $lastArrayToken; $checkToken++) {
82
+        for ( $checkToken = ( $stackPtr + 1 ); $checkToken <= $lastArrayToken; $checkToken++ ) {
83 83
             // Skip bracketed statements, like function calls.
84
-            if ($tokens[$checkToken]['code'] === T_OPEN_PARENTHESIS
85
-                && (isset($tokens[$checkToken]['parenthesis_owner']) === false
86
-                || $tokens[$checkToken]['parenthesis_owner'] !== $stackPtr)
84
+            if ( $tokens[ $checkToken ][ 'code' ] === T_OPEN_PARENTHESIS
85
+                && ( isset( $tokens[ $checkToken ][ 'parenthesis_owner' ] ) === false
86
+                || $tokens[ $checkToken ][ 'parenthesis_owner' ] !== $stackPtr )
87 87
             ) {
88
-                $checkToken = $tokens[$checkToken]['parenthesis_closer'];
88
+                $checkToken = $tokens[ $checkToken ][ 'parenthesis_closer' ];
89 89
                 continue;
90 90
             }
91 91
 
92
-            if ($tokens[$checkToken]['code'] === T_ARRAY
93
-                || $tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY
94
-                || $tokens[$checkToken]['code'] === T_CLOSURE
92
+            if ( $tokens[ $checkToken ][ 'code' ] === T_ARRAY
93
+                || $tokens[ $checkToken ][ 'code' ] === T_OPEN_SHORT_ARRAY
94
+                || $tokens[ $checkToken ][ 'code' ] === T_CLOSURE
95 95
             ) {
96 96
                 // Let subsequent calls of this test handle nested arrays.
97
-                if ($tokens[$lastToken]['code'] !== T_DOUBLE_ARROW) {
98
-                    $indices[] = ['value_start' => $checkToken];
97
+                if ( $tokens[ $lastToken ][ 'code' ] !== T_DOUBLE_ARROW ) {
98
+                    $indices[ ] = [ 'value_start' => $checkToken ];
99 99
                     $lastToken = $checkToken;
100 100
                 }
101 101
 
102
-                if ($tokens[$checkToken]['code'] === T_ARRAY) {
103
-                    $checkToken = $tokens[$tokens[$checkToken]['parenthesis_opener']]['parenthesis_closer'];
104
-                } else if ($tokens[$checkToken]['code'] === T_OPEN_SHORT_ARRAY) {
105
-                    $checkToken = $tokens[$checkToken]['bracket_closer'];
102
+                if ( $tokens[ $checkToken ][ 'code' ] === T_ARRAY ) {
103
+                    $checkToken = $tokens[ $tokens[ $checkToken ][ 'parenthesis_opener' ] ][ 'parenthesis_closer' ];
104
+                } else if ( $tokens[ $checkToken ][ 'code' ] === T_OPEN_SHORT_ARRAY ) {
105
+                    $checkToken = $tokens[ $checkToken ][ 'bracket_closer' ];
106 106
                 } else {
107 107
                     // T_CLOSURE.
108
-                    $checkToken = $tokens[$checkToken]['scope_closer'];
108
+                    $checkToken = $tokens[ $checkToken ][ 'scope_closer' ];
109 109
                 }
110 110
 
111
-                $checkToken = $phpcsFile->findNext(T_WHITESPACE, ($checkToken + 1), null, true);
111
+                $checkToken = $phpcsFile->findNext( T_WHITESPACE, ( $checkToken + 1 ), null, true );
112 112
                 $lastToken  = $checkToken;
113
-                if ($tokens[$checkToken]['code'] !== T_COMMA) {
113
+                if ( $tokens[ $checkToken ][ 'code' ] !== T_COMMA ) {
114 114
                     $checkToken--;
115 115
                 }
116 116
 
117 117
                 continue;
118 118
             }//end if
119 119
 
120
-            if ($tokens[$checkToken]['code'] !== T_DOUBLE_ARROW
121
-                && $tokens[$checkToken]['code'] !== T_COMMA
120
+            if ( $tokens[ $checkToken ][ 'code' ] !== T_DOUBLE_ARROW
121
+                && $tokens[ $checkToken ][ 'code' ] !== T_COMMA
122 122
                 && $checkToken !== $arrayEnd
123 123
             ) {
124 124
                 continue;
125 125
             }
126 126
 
127
-            if ($tokens[$checkToken]['code'] === T_COMMA
127
+            if ( $tokens[ $checkToken ][ 'code' ] === T_COMMA
128 128
                 || $checkToken === $arrayEnd
129 129
             ) {
130 130
                 $stackPtrCount = 0;
131
-                if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
132
-                    $stackPtrCount = count($tokens[$stackPtr]['nested_parenthesis']);
131
+                if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
132
+                    $stackPtrCount = count( $tokens[ $stackPtr ][ 'nested_parenthesis' ] );
133 133
                 }
134 134
 
135 135
                 $commaCount = 0;
136
-                if (isset($tokens[$checkToken]['nested_parenthesis']) === true) {
137
-                    $commaCount = count($tokens[$checkToken]['nested_parenthesis']);
138
-                    if ($tokens[$stackPtr]['code'] === T_ARRAY) {
136
+                if ( isset( $tokens[ $checkToken ][ 'nested_parenthesis' ] ) === true ) {
137
+                    $commaCount = count( $tokens[ $checkToken ][ 'nested_parenthesis' ] );
138
+                    if ( $tokens[ $stackPtr ][ 'code' ] === T_ARRAY ) {
139 139
                         // Remove parenthesis that are used to define the array.
140 140
                         $commaCount--;
141 141
                     }
142 142
                 }
143 143
 
144
-                if ($commaCount > $stackPtrCount) {
144
+                if ( $commaCount > $stackPtrCount ) {
145 145
                     // This comma is inside more parenthesis than the ARRAY keyword,
146 146
                     // so it is actually a comma used to do things like
147 147
                     // separate arguments in a function call.
148 148
                     continue;
149 149
                 }
150 150
 
151
-                if ($keyUsed === false) {
151
+                if ( $keyUsed === false ) {
152 152
                     $valueContent = $phpcsFile->findNext(
153 153
                         Tokens::$emptyTokens,
154
-                        ($lastToken + 1),
154
+                        ( $lastToken + 1 ),
155 155
                         $checkToken,
156 156
                         true
157 157
                     );
158 158
 
159
-                    $indices[] = ['value_start' => $valueContent];
159
+                    $indices[ ] = [ 'value_start' => $valueContent ];
160 160
                 }
161 161
 
162 162
                 $lastToken = $checkToken;
@@ -164,22 +164,22 @@  discard block
 block discarded – undo
164 164
                 continue;
165 165
             }//end if
166 166
 
167
-            if ($tokens[$checkToken]['code'] === T_DOUBLE_ARROW) {
167
+            if ( $tokens[ $checkToken ][ 'code' ] === T_DOUBLE_ARROW ) {
168 168
                 $keyUsed = true;
169 169
 
170 170
                 // Find the start of index that uses this double arrow.
171
-                $indexEnd   = $phpcsFile->findPrevious(T_WHITESPACE, ($checkToken - 1), $arrayStart, true);
172
-                $indexStart = $phpcsFile->findStartOfStatement($indexEnd);
171
+                $indexEnd   = $phpcsFile->findPrevious( T_WHITESPACE, ( $checkToken - 1 ), $arrayStart, true );
172
+                $indexStart = $phpcsFile->findStartOfStatement( $indexEnd );
173 173
 
174 174
                 // Find the value of this index.
175 175
                 $nextContent = $phpcsFile->findNext(
176 176
                     Tokens::$emptyTokens,
177
-                    ($checkToken + 1),
177
+                    ( $checkToken + 1 ),
178 178
                     $arrayEnd,
179 179
                     true
180 180
                 );
181 181
 
182
-                $indices[] = [
182
+                $indices[ ] = [
183 183
                     'index_start' => $indexStart,
184 184
                     'index_end'   => $indexEnd,
185 185
                     'arrow'       => $checkToken,
@@ -190,10 +190,10 @@  discard block
 block discarded – undo
190 190
             }//end if
191 191
         }//end for
192 192
 
193
-        if ($tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line']) {
194
-            $this->processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
193
+        if ( $tokens[ $arrayStart ][ 'line' ] === $tokens[ $arrayEnd ][ 'line' ] ) {
194
+            $this->processSingleLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
195 195
         } else {
196
-            $this->processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
196
+            $this->processMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
197 197
         }
198 198
 
199 199
     }//end process()
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @return void
214 214
      */
215
-    abstract protected function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
215
+    abstract protected function processSingleLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
216 216
 
217 217
 
218 218
     /**
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
      *
229 229
      * @return void
230 230
      */
231
-    abstract protected function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices);
231
+    abstract protected function processMultiLineArray( $phpcsFile, $stackPtr, $arrayStart, $arrayEnd, $indices );
232 232
 
233 233
 
234 234
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Sniffs/AbstractVariableSniff.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             T_HEREDOC,
59 59
         ];
60 60
 
61
-        parent::__construct($scopes, $listen, true);
61
+        parent::__construct( $scopes, $listen, true );
62 62
 
63 63
     }//end __construct()
64 64
 
@@ -76,17 +76,17 @@  discard block
 block discarded – undo
76 76
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
77 77
      *                  the rest of the file.
78 78
      */
79
-    final protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
79
+    final protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currScope )
80 80
     {
81 81
         $tokens = $phpcsFile->getTokens();
82 82
 
83
-        if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
84
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
83
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DOUBLE_QUOTED_STRING
84
+            || $tokens[ $stackPtr ][ 'code' ] === T_HEREDOC
85 85
         ) {
86 86
             // Check to see if this string has a variable in it.
87 87
             $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
88
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
89
-                return $this->processVariableInString($phpcsFile, $stackPtr);
88
+            if ( preg_match( $pattern, $tokens[ $stackPtr ][ 'content' ] ) !== 0 ) {
89
+                return $this->processVariableInString( $phpcsFile, $stackPtr );
90 90
             }
91 91
 
92 92
             return;
@@ -95,19 +95,19 @@  discard block
 block discarded – undo
95 95
         // If this token is nested inside a function at a deeper
96 96
         // level than the current OO scope that was found, it's a normal
97 97
         // variable and not a member var.
98
-        $conditions = array_reverse($tokens[$stackPtr]['conditions'], true);
98
+        $conditions = array_reverse( $tokens[ $stackPtr ][ 'conditions' ], true );
99 99
         $inFunction = false;
100
-        foreach ($conditions as $scope => $code) {
101
-            if (isset(Tokens::$ooScopeTokens[$code]) === true) {
100
+        foreach ( $conditions as $scope => $code ) {
101
+            if ( isset( Tokens::$ooScopeTokens[ $code ] ) === true ) {
102 102
                 break;
103 103
             }
104 104
 
105
-            if ($code === T_FUNCTION || $code === T_CLOSURE) {
105
+            if ( $code === T_FUNCTION || $code === T_CLOSURE ) {
106 106
                 $inFunction = true;
107 107
             }
108 108
         }
109 109
 
110
-        if ($scope !== $currScope) {
110
+        if ( $scope !== $currScope ) {
111 111
             // We found a closer scope to this token, so ignore
112 112
             // this particular time through the sniff. We will process
113 113
             // this token when this closer scope is found to avoid
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Just make sure this isn't a variable in a function declaration.
119
-        if ($inFunction === false && isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
120
-            foreach ($tokens[$stackPtr]['nested_parenthesis'] as $opener => $closer) {
121
-                if (isset($tokens[$opener]['parenthesis_owner']) === false) {
119
+        if ( $inFunction === false && isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
120
+            foreach ( $tokens[ $stackPtr ][ 'nested_parenthesis' ] as $opener => $closer ) {
121
+                if ( isset( $tokens[ $opener ][ 'parenthesis_owner' ] ) === false ) {
122 122
                     // Check if this is a USE statement for a closure.
123
-                    $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true);
124
-                    if ($tokens[$prev]['code'] === T_USE) {
123
+                    $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true );
124
+                    if ( $tokens[ $prev ][ 'code' ] === T_USE ) {
125 125
                         $inFunction = true;
126 126
                         break;
127 127
                     }
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
                     continue;
130 130
                 }
131 131
 
132
-                $owner = $tokens[$opener]['parenthesis_owner'];
133
-                if ($tokens[$owner]['code'] === T_FUNCTION
134
-                    || $tokens[$owner]['code'] === T_CLOSURE
132
+                $owner = $tokens[ $opener ][ 'parenthesis_owner' ];
133
+                if ( $tokens[ $owner ][ 'code' ] === T_FUNCTION
134
+                    || $tokens[ $owner ][ 'code' ] === T_CLOSURE
135 135
                 ) {
136 136
                     $inFunction = true;
137 137
                     break;
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
             }
140 140
         }//end if
141 141
 
142
-        if ($inFunction === true) {
143
-            return $this->processVariable($phpcsFile, $stackPtr);
142
+        if ( $inFunction === true ) {
143
+            return $this->processVariable( $phpcsFile, $stackPtr );
144 144
         } else {
145
-            return $this->processMemberVar($phpcsFile, $stackPtr);
145
+            return $this->processMemberVar( $phpcsFile, $stackPtr );
146 146
         }
147 147
 
148 148
     }//end processTokenWithinScope()
@@ -160,19 +160,19 @@  discard block
 block discarded – undo
160 160
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
161 161
      *                  the rest of the file.
162 162
      */
163
-    final protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
163
+    final protected function processTokenOutsideScope( File $phpcsFile, $stackPtr )
164 164
     {
165 165
         $tokens = $phpcsFile->getTokens();
166 166
         // These variables are not member vars.
167
-        if ($tokens[$stackPtr]['code'] === T_VARIABLE) {
168
-            return $this->processVariable($phpcsFile, $stackPtr);
169
-        } else if ($tokens[$stackPtr]['code'] === T_DOUBLE_QUOTED_STRING
170
-            || $tokens[$stackPtr]['code'] === T_HEREDOC
167
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_VARIABLE ) {
168
+            return $this->processVariable( $phpcsFile, $stackPtr );
169
+        } else if ( $tokens[ $stackPtr ][ 'code' ] === T_DOUBLE_QUOTED_STRING
170
+            || $tokens[ $stackPtr ][ 'code' ] === T_HEREDOC
171 171
         ) {
172 172
             // Check to see if this string has a variable in it.
173 173
             $pattern = '|(?<!\\\\)(?:\\\\{2})*\${?[a-zA-Z0-9_]+}?|';
174
-            if (preg_match($pattern, $tokens[$stackPtr]['content']) !== 0) {
175
-                return $this->processVariableInString($phpcsFile, $stackPtr);
174
+            if ( preg_match( $pattern, $tokens[ $stackPtr ][ 'content' ] ) !== 0 ) {
175
+                return $this->processVariableInString( $phpcsFile, $stackPtr );
176 176
             }
177 177
         }
178 178
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
192 192
      *                  the rest of the file.
193 193
      */
194
-    abstract protected function processMemberVar(File $phpcsFile, $stackPtr);
194
+    abstract protected function processMemberVar( File $phpcsFile, $stackPtr );
195 195
 
196 196
 
197 197
     /**
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
207 207
      *                  the rest of the file.
208 208
      */
209
-    abstract protected function processVariable(File $phpcsFile, $stackPtr);
209
+    abstract protected function processVariable( File $phpcsFile, $stackPtr );
210 210
 
211 211
 
212 212
     /**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
      *                  pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
226 226
      *                  the rest of the file.
227 227
      */
228
-    abstract protected function processVariableInString(File $phpcsFile, $stackPtr);
228
+    abstract protected function processVariableInString( File $phpcsFile, $stackPtr );
229 229
 
230 230
 
231 231
 }//end class
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/SpaceAfterCastUnitTest.inc 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,95 +1,95 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$var = (int) $var2;
4 3
 $var = (int)$var2;
5
-$var = (int)  $var2;
4
+$var = (int)$var2;
5
+$var = (int)$var2;
6 6
 
7
-$var = (integer) $var2;
8 7
 $var = (integer)$var2;
9
-$var = (integer)  $var2;
8
+$var = (integer)$var2;
9
+$var = (integer)$var2;
10 10
 
11
-$var = (string) $var2;
12 11
 $var = (string)$var2;
13
-$var = (string)    $var2;
12
+$var = (string)$var2;
13
+$var = (string)$var2;
14 14
 
15
-$var = (float) $var2;
16 15
 $var = (float)$var2;
17
-$var = (float)  $var2;
16
+$var = (float)$var2;
17
+$var = (float)$var2;
18 18
 
19
-$var = (double) $var2;
20 19
 $var = (double)$var2;
21
-$var = (double)  $var2;
20
+$var = (double)$var2;
21
+$var = (double)$var2;
22 22
 
23
-$var = (real) $var2;
24 23
 $var = (real)$var2;
25
-$var = (real)  $var2;
24
+$var = (real)$var2;
25
+$var = (real)$var2;
26 26
 
27
-$var = (array) $var2;
28 27
 $var = (array)$var2;
29
-$var = (array)  $var2;
28
+$var = (array)$var2;
29
+$var = (array)$var2;
30 30
 
31
-$var = (bool) $var2;
32 31
 $var = (bool)$var2;
33
-$var = (bool)  $var2;
32
+$var = (bool)$var2;
33
+$var = (bool)$var2;
34 34
 
35
-$var = (boolean) $var2;
36 35
 $var = (boolean)$var2;
37
-$var = (boolean)  $var2;
36
+$var = (boolean)$var2;
37
+$var = (boolean)$var2;
38 38
 
39
-$var = (object) $var2;
40 39
 $var = (object)$var2;
41
-$var = (object)  $var2;
40
+$var = (object)$var2;
41
+$var = (object)$var2;
42 42
 
43
-$var = (unset) $var2;
44 43
 $var = (unset)$var2;
45
-$var = (unset)          $var2;
44
+$var = (unset)$var2;
45
+$var = (unset)$var2;
46 46
 
47 47
 $var = b"binary $foo";
48 48
 $var = b"binary string";
49 49
 $var = b'binary string';
50
-$var = (binary) $string;
50
+$var = (binary)$string;
51 51
 $var = (binary)$string;
52 52
 
53
-$var = (boolean) /* comment */ $var2;
53
+$var = (boolean)/* comment */ $var2;
54 54
 
55 55
 $var = (int)
56 56
 	$var2;
57 57
 
58
-if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
58
+if ( (string)// phpcs:ignore Standard.Cat.SniffName -- for reasons.
59 59
     $x === 'test'
60 60
 ) {}
61 61
 
62 62
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines true
63 63
 $var = (int)
64
-	$var1 + (bool)  $var2;
64
+	$var1 + (bool)$var2;
65 65
 
66
-if ( (string) // phpcs:ignore Standard.Cat.SniffName -- for reasons.
66
+if ( (string)// phpcs:ignore Standard.Cat.SniffName -- for reasons.
67 67
     $x === 'test'
68 68
 ) {}
69 69
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false
70 70
 
71 71
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 2
72
-$var = (int) $var2;
72
+$var = (int)$var2;
73 73
 $var = (string)$var2;
74
-$var = (array)  $var2;
75
-$var = (unset)        $var2;
76
-$var = (boolean) /* comment */ $var2;
74
+$var = (array)$var2;
75
+$var = (unset)$var2;
76
+$var = (boolean)/* comment */ $var2;
77 77
 
78 78
 $var = (integer)
79 79
 	$var2;
80 80
 
81 81
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 0
82
-$var = (int) $var2;
82
+$var = (int)$var2;
83 83
 $var = (string)$var2;
84
-$var = (array)  $var2;
85
-$var = (unset)        $var2;
86
-$var = (boolean) /* comment */ $var2;
84
+$var = (array)$var2;
85
+$var = (unset)$var2;
86
+$var = (boolean)/* comment */ $var2;
87 87
 
88 88
 $var = (integer)
89 89
 	$var2;
90 90
 
91 91
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines true
92 92
 $var = (int)
93
-	$var1 + (bool)  $var2;
93
+	$var1 + (bool)$var2;
94 94
 // phpcs:set Generic.Formatting.SpaceAfterCast ignoreNewlines false
95 95
 // phpcs:set Generic.Formatting.SpaceAfterCast spacing 1
Please login to merge, or discard this patch.
Standards/Generic/Tests/Formatting/MultipleStatementAlignmentUnitTest.inc 1 patch
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
 // Invalid
36 36
 $var1    .= 'var1';
37
-$var10.= 'var1';
37
+$var10 .= 'var1';
38 38
 $var100 .= 'var1';
39 39
 $var1000 .= 'var1';
40 40
 
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
 
47 47
 // Invalid
48 48
 $var1    = 'var1';
49
-$var10   .= 'var1';
49
+$var10 .= 'var1';
50 50
 $var100  = 'var1';
51
-$var1000.= 'var1';
51
+$var1000 .= 'var1';
52 52
 
53 53
 // Valid
54 54
 $var1  .= 'var1';
@@ -68,43 +68,43 @@  discard block
 block discarded – undo
68 68
 $var = 100;
69 69
 
70 70
 // InValid
71
-$var  = 100;
71
+$var = 100;
72 72
 
73 73
 $commentStart = $phpcsFile->findPrevious();
74 74
 $commentEnd   = $this->_phpcsFile;
75 75
 $expected    .= '...';
76 76
 
77 77
 // Invalid
78
-$this->okButton    = new Button();
78
+$this->okButton = new Button();
79 79
 $content = new MyClass();
80 80
 
81 81
 
82
-$GLOBALS['_PEAR_ERRORSTACK_SINGLETON'] = array();
82
+$GLOBALS[ '_PEAR_ERRORSTACK_SINGLETON' ] = array();
83 83
 
84 84
 class MyClass
85 85
 {
86 86
     const MODE_DEBUG = 'debug';
87 87
     const MODE_DEBUG2 = 'debug';
88 88
 
89
-    var $array[$test] = 'anything';
89
+    var $array[ $test ] = 'anything';
90 90
     var $var          = 'anything';
91 91
 
92
-    const MODE_DEBUG3  = 'debug';
93
-    public $array[$test]    = 'anything';
94
-    private $vara             = 'anything';
95
-    protected $array[($test + 1)] = 'anything';
96
-    var $array[($blah + (10 - $test))] = 'anything';
92
+    const MODE_DEBUG3 = 'debug';
93
+    public $array[ $test ] = 'anything';
94
+    private $vara = 'anything';
95
+    protected $array[ ( $test + 1 ) ] = 'anything';
96
+    var $array[ ( $blah + ( 10 - $test ) ) ] = 'anything';
97 97
 }
98 98
 
99
-function myFunction($var=true)
99
+function myFunction( $var = true )
100 100
 {
101
-    if ($strict === true) {
102
-        $length          = strlen($string);
103
-        $lastCharWasCaps = ($classFormat === false) ? false : true;
101
+    if ( $strict === true ) {
102
+        $length          = strlen( $string );
103
+        $lastCharWasCaps = ( $classFormat === false ) ? false : true;
104 104
 
105
-        for ($i = 1; $i < $length; $i++) {
106
-            $isCaps = (strtoupper($string{$i}) === $string{$i}) ? true : false;
107
-            if ($isCaps === true && $lastCharWasCaps === true) {
105
+        for ( $i = 1; $i < $length; $i++ ) {
106
+            $isCaps = ( strtoupper( $string{$i}) === $string{$i}) ? true : false;
107
+            if ( $isCaps === true && $lastCharWasCaps === true ) {
108 108
                 return false;
109 109
             }
110 110
 
@@ -114,29 +114,29 @@  discard block
 block discarded – undo
114 114
 }
115 115
 
116 116
 // Valid
117
-for ($i = 0; $i < 10; $i += 2) {
118
-    $i = ($i - 1);
117
+for ( $i = 0; $i < 10; $i += 2 ) {
118
+    $i = ( $i - 1 );
119 119
 }
120 120
 
121 121
 // Invalid
122
-foreach ($files as $file) {
123
-    $saves[$file] = array();
124
-    $contents = stripslashes(file_get_contents($file));
125
-    list($assetid, $time, $content) = explode("\n", $contents);
126
-    $saves[$file]['assetid'] = $assetid;
122
+foreach ( $files as $file ) {
123
+    $saves[ $file ] = array();
124
+    $contents = stripslashes( file_get_contents( $file ) );
125
+    list( $assetid, $time, $content ) = explode( "\n", $contents );
126
+    $saves[ $file ][ 'assetid' ] = $assetid;
127 127
 }
128 128
 
129
-$i = ($i - 10);
130
-$ip = ($i - 10);
131
-for ($i = 0; $i < 10; $i += 2) {
132
-    $i = ($i - 10);
129
+$i = ( $i - 10 );
130
+$ip = ( $i - 10 );
131
+for ( $i = 0; $i < 10; $i += 2 ) {
132
+    $i = ( $i - 10 );
133 133
 }
134 134
 
135 135
 // Valid
136 136
 $variable = 12;
137
-$var      = a_very(long_line('that', 'contains'),
138
-                   a_bunch('of long', 'parameters'),
139
-                   'that_need to be aligned with the equal sign');
137
+$var      = a_very( long_line( 'that', 'contains' ),
138
+                   a_bunch( 'of long', 'parameters' ),
139
+                   'that_need to be aligned with the equal sign' );
140 140
 $var2     = 12;
141 141
 
142 142
 // Valid
@@ -148,9 +148,9 @@  discard block
 block discarded – undo
148 148
 
149 149
 // Invalid
150 150
 $variable = 12;
151
-$var      = a_very(long_line('that', 'contains'),
152
-                   a_bunch('of long', 'parameters'),
153
-                   'that_need to be aligned with the equal sign');
151
+$var      = a_very( long_line( 'that', 'contains' ),
152
+                   a_bunch( 'of long', 'parameters' ),
153
+                   'that_need to be aligned with the equal sign' );
154 154
 $var2 = 12;
155 155
 
156 156
 // Invalid
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
 
184 184
 // Valid
185 185
 $error = false;
186
-while (list($h, $f) = getKeyAndValue($handle)) {
186
+while ( list( $h, $f ) = getKeyAndValue( $handle ) ) {
187 187
     $error = true;
188 188
 }
189 189
 
190 190
 // Valid
191 191
 $value = false;
192
-function blah ($value = true) {
192
+function blah( $value = true ) {
193 193
     $value = false;
194
-    if ($value === true) {
194
+    if ( $value === true ) {
195 195
         $value = false;
196 196
     }
197 197
 }
198 198
 
199
-if (TRUE) {
200
-    $args = array('foo' => 'foo');
199
+if ( TRUE ) {
200
+    $args = array( 'foo' => 'foo' );
201 201
     $res  = 'bar';
202 202
 }
203 203
 
@@ -217,13 +217,13 @@  discard block
 block discarded – undo
217 217
 
218 218
 // phpcs:set Generic.Formatting.MultipleStatementAlignment maxPadding 1000
219 219
 
220
-$filterQuery = SquizRoadmap::getSearchQueryFilter($searchParams);
221
-Channels::addToBasket('itemid', $filterQuery);
222
-$query   = DAL::getDALQuery('SquizRoadmapItem', 'getItemIds');
223
-$results = DAL::getAssoc($query, 0);
220
+$filterQuery = SquizRoadmap::getSearchQueryFilter( $searchParams );
221
+Channels::addToBasket( 'itemid', $filterQuery );
222
+$query   = DAL::getDALQuery( 'SquizRoadmapItem', 'getItemIds' );
223
+$results = DAL::getAssoc( $query, 0 );
224 224
 
225
-$path  = BaseSystem::getDataDir('SquizRoadmap').'/items/';
226
-$path .= FileSystem::getHashDir($itemid).'/'.$itemid;
225
+$path  = BaseSystem::getDataDir( 'SquizRoadmap' ) . '/items/';
226
+$path .= FileSystem::getHashDir( $itemid ) . '/' . $itemid;
227 227
 
228 228
 $contents  .= 'if (';
229 229
 $conditions = array();
@@ -234,20 +234,20 @@  discard block
 block discarded – undo
234 234
 $foo = $moooo = 'foo';
235 235
 
236 236
 $foobarbaz = array_map(
237
-    function ($n) {
237
+    function( $n ) {
238 238
         return $n * $n;
239 239
     },
240
-    [1, 2, 3]
240
+    [ 1, 2, 3 ]
241 241
 );
242
-$foo       = 5;
242
+$foo = 5;
243 243
 
244
-$loggerResult = $util->setLogger(new class {
245
-    public function log($msg)
244
+$loggerResult = $util->setLogger( new class {
245
+    public function log( $msg )
246 246
     {
247 247
         echo $msg;
248 248
     }
249 249
 });
250
-$foo          = 5;
250
+$foo = 5;
251 251
 
252 252
 $foo = array(
253 253
     'a' => 'b',
@@ -272,37 +272,37 @@  discard block
 block discarded – undo
272 272
 ];
273 273
 $barbar = 'bar';
274 274
 
275
-function buildForm(FormBuilderInterface $builder, array $options)
275
+function buildForm( FormBuilderInterface $builder, array $options )
276 276
 {
277
-    $transformer = new ContractTransformer($options['contracts']);
278
-    $types       = ['support.contact.question' => ContactData::QUESTION];
277
+    $transformer = new ContractTransformer( $options[ 'contracts' ] );
278
+    $types       = [ 'support.contact.question' => ContactData::QUESTION ];
279 279
 
280
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
280
+    [ $important, $questions, $incidents, $requests ] = $this->createContractBuckets( $options[ 'contracts' ] );
281 281
 }
282 282
 
283
-function buildForm(FormBuilderInterface $builder, array $options)
283
+function buildForm( FormBuilderInterface $builder, array $options )
284 284
 {
285
-    $transformer                                    = new ContractTransformer($options['contracts']);
286
-    $types                                          = ['support.contact.question' => ContactData::QUESTION];
287
-    [$important, $questions, $incidents, $requests] = $this->createContractBuckets($options['contracts']);
285
+    $transformer                                    = new ContractTransformer( $options[ 'contracts' ] );
286
+    $types                                          = [ 'support.contact.question' => ContactData::QUESTION ];
287
+    [ $important, $questions, $incidents, $requests ] = $this->createContractBuckets( $options[ 'contracts' ] );
288 288
 }
289 289
 
290
-$loggerResult = $util->setLogger(new class {
291
-    public function log($msg)
290
+$loggerResult = $util->setLogger( new class {
291
+    public function log( $msg )
292 292
     {
293 293
         $a = $msg;
294 294
         $foobar = $msg;
295 295
         $foo = function() {
296 296
             $a = $msg;
297 297
             $foobar = $msg;
298
-            $loggerResult = $util->setLogger(new class {
299
-                public function log($msg)
298
+            $loggerResult = $util->setLogger( new class {
299
+                public function log( $msg )
300 300
                 {
301 301
                     $a = $msg;
302 302
                     $foobar = $msg;
303 303
                     $foo = function() {
304
-                        foo(function() {
305
-                            foo(function() {
304
+                        foo( function() {
305
+                            foo( function() {
306 306
                                 echo 'hi';
307 307
                             });
308 308
                             $a = $msg;
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
                             $foo = function() {
312 312
 
313 313
                                 $foo = 1;
314
-                                $barbar=2;
314
+                                $barbar = 2;
315 315
                             };
316 316
                             $barbar = function() {
317 317
                                 $foo    = 1;
@@ -319,18 +319,18 @@  discard block
 block discarded – undo
319 319
                             };
320 320
                         });
321 321
                         $a = $msg;
322
-                        $foobar      = $msg;
322
+                        $foobar = $msg;
323 323
                     };
324 324
                     $bar = $msg;
325 325
                 }
326 326
 
327
-                public function log2($msg)
327
+                public function log2( $msg )
328 328
                 {
329 329
                     $a = $msg;
330 330
                     $foobar = $msg;
331 331
                     $foo = function() {
332
-                        foo(function() {
333
-                            foo(function() {
332
+                        foo( function() {
333
+                            foo( function() {
334 334
                                 echo 'hi';
335 335
                             });
336 336
                             $a = $msg;
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
                             $foo = function() {
340 340
 
341 341
                                 $foo = 1;
342
-                                $barbar=2;
342
+                                $barbar = 2;
343 343
                             };
344 344
                             $barbar = function() {
345 345
                                 $foo    = 1;
@@ -347,31 +347,31 @@  discard block
 block discarded – undo
347 347
                             };
348 348
                         });
349 349
                         $a = $msg;
350
-                        $foobar      = $msg;
350
+                        $foobar = $msg;
351 351
                     };
352 352
                     $bar = $msg;
353 353
                 }
354 354
             });
355
-            $foo          = 5;
355
+            $foo = 5;
356 356
         };
357 357
         $bar = $msg;
358 358
     }
359 359
 });
360
-$foo          = 5;
360
+$foo = 5;
361 361
 
362 362
 $foo = [
363
-    0 => function () {
363
+    0 => function() {
364 364
         $foo = 'foo';
365 365
         $barbar = 'bar';
366 366
     },
367
-    1 => function () {
367
+    1 => function() {
368 368
         $foo    = 'foo';
369 369
         $barbar = 'bar';
370 370
     },
371 371
 ];
372 372
 
373 373
 $abc = 'something';
374
-if ($foo) {}
374
+if ( $foo ) {}
375 375
 $defghi = 'longer something';
376 376
 
377 377
 function foo() {
@@ -388,18 +388,18 @@  discard block
 block discarded – undo
388 388
     <?php
389 389
 }
390 390
 
391
-$foo = new Foo([
391
+$foo = new Foo( [
392 392
     $a = new Bar(),
393 393
     $b = new Bar(),
394
-]);
394
+] );
395 395
 
396
-$foo = new Foo([
396
+$foo = new Foo( [
397 397
     $a = new Bar(),
398 398
     $b    = new Bar(),
399
-    $c  = new Bar(),
400
-]);
401
-$foofoo   = new Foo([
399
+    $c = new Bar(),
400
+] );
401
+$foofoo   = new Foo( [
402 402
     $a = new Bar(),
403 403
     $b = new Bar(),
404 404
     $c = new Bar(),
405
-]);
405
+] );
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function getWarningList()
66 66
     {
67
-        return [];
67
+        return [ ];
68 68
 
69 69
     }//end getWarningList()
70 70
 
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/SpaceBeforeCastUnitTest.inc 1 patch
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$a = $a+(bool) $b;
4
-$a = function_call((bool) $b);
5
-if ((bool) $a ===(bool) $b) {}
3
+$a = $a + (bool)$b;
4
+$a = function_call( (bool)$b );
5
+if ( (bool)$a === (bool)$b ) {}
6 6
 
7
-$var = (int) $var2;
8
-$var =(int) $var2;
9
-$var =     (int) $var2;
7
+$var = (int)$var2;
8
+$var = (int)$var2;
9
+$var = (int)$var2;
10 10
 
11
-$var = (integer) $var2;
12
-$var =(integer) $var2;
13
-$var =    (integer) $var2;
11
+$var = (integer)$var2;
12
+$var = (integer)$var2;
13
+$var = (integer)$var2;
14 14
 
15
-$var = (string) $var2;
16
-$var =(string) $var2;
17
-$var =	 (string) $var2;
15
+$var = (string)$var2;
16
+$var = (string)$var2;
17
+$var = (string)$var2;
18 18
 
19
-$var = (float) $var2;
20
-$var =(float) $var2;
21
-$var =			 (float) $var2;
19
+$var = (float)$var2;
20
+$var = (float)$var2;
21
+$var = (float)$var2;
22 22
 
23
-$var = (double) $var2;
24
-$var =(double) $var2;
25
-$var =  (double) $var2;
23
+$var = (double)$var2;
24
+$var = (double)$var2;
25
+$var = (double)$var2;
26 26
 
27
-$var = (real) $var2;
28
-$var =(real) $var2;
29
-$var =    (real) $var2;
27
+$var = (real)$var2;
28
+$var = (real)$var2;
29
+$var = (real)$var2;
30 30
 
31
-$var = (array) $var2;
32
-$var =(array) $var2;
33
-$var =   (array) $var2;
31
+$var = (array)$var2;
32
+$var = (array)$var2;
33
+$var = (array)$var2;
34 34
 
35
-$var = (bool) $var2;
36
-$var =(bool) $var2;
37
-$var =    (bool) $var2;
35
+$var = (bool)$var2;
36
+$var = (bool)$var2;
37
+$var = (bool)$var2;
38 38
 
39
-$var = (boolean) $var2;
40
-$var =(boolean) $var2;
41
-$var =  (boolean) $var2;
39
+$var = (boolean)$var2;
40
+$var = (boolean)$var2;
41
+$var = (boolean)$var2;
42 42
 
43
-$var = (object) $var2;
44
-$var =(object) $var2;
45
-$var =  (object) $var2;
43
+$var = (object)$var2;
44
+$var = (object)$var2;
45
+$var = (object)$var2;
46 46
 
47
-$var = (unset) $var2;
48
-$var =(unset) $var2;
49
-$var =   (unset) $var2;
47
+$var = (unset)$var2;
48
+$var = (unset)$var2;
49
+$var = (unset)$var2;
50 50
 
51 51
 $var = b"binary $foo";
52
-$var =b"binary string";
53
-$var =   b'binary string';
54
-$var = (binary) $string;
55
-$var =(binary) $string;
56
-$var =    (binary) $string;
52
+$var = b"binary string";
53
+$var = b'binary string';
54
+$var = (binary)$string;
55
+$var = (binary)$string;
56
+$var = (binary)$string;
57 57
 
58 58
 $var = array(
59
-	(bool) $a,
59
+	(bool)$a,
60 60
 	array(
61
-        (int) $b,
61
+        (int)$b,
62 62
 	),
63 63
 );
64 64
 
65
-(bool) $a ? echo $b : echo $c;
65
+(bool)$a ? echo $b : echo $c;
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/NoSpaceAfterCastUnitTest.inc 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,51 +1,51 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-$var = (int) $var2;
4 3
 $var = (int)$var2;
5
-$var = (int)  $var2;
4
+$var = (int)$var2;
5
+$var = (int)$var2;
6 6
 
7
-$var = (integer) $var2;
8 7
 $var = (integer)$var2;
9
-$var = (integer)  $var2;
8
+$var = (integer)$var2;
9
+$var = (integer)$var2;
10 10
 
11
-$var = (string) $var2;
12 11
 $var = (string)$var2;
13
-$var = (string)  $var2;
12
+$var = (string)$var2;
13
+$var = (string)$var2;
14 14
 
15
-$var = (float) $var2;
16 15
 $var = (float)$var2;
17
-$var = (float)  $var2;
16
+$var = (float)$var2;
17
+$var = (float)$var2;
18 18
 
19
-$var = (double) $var2;
20 19
 $var = (double)$var2;
21
-$var = (double)  $var2;
20
+$var = (double)$var2;
21
+$var = (double)$var2;
22 22
 
23
-$var = (real) $var2;
24 23
 $var = (real)$var2;
25
-$var = (real)  $var2;
24
+$var = (real)$var2;
25
+$var = (real)$var2;
26 26
 
27
-$var = (array) $var2;
28 27
 $var = (array)$var2;
29
-$var = (array)  $var2;
28
+$var = (array)$var2;
29
+$var = (array)$var2;
30 30
 
31
-$var = (bool) $var2;
32 31
 $var = (bool)$var2;
33
-$var = (bool)  $var2;
32
+$var = (bool)$var2;
33
+$var = (bool)$var2;
34 34
 
35
-$var = (boolean) $var2;
36 35
 $var = (boolean)$var2;
37
-$var = (boolean)  $var2;
36
+$var = (boolean)$var2;
37
+$var = (boolean)$var2;
38 38
 
39
-$var = (object) $var2;
40 39
 $var = (object)$var2;
41
-$var = (object)  $var2;
40
+$var = (object)$var2;
41
+$var = (object)$var2;
42 42
 
43
-$var = (unset) $var2;
44 43
 $var = (unset)$var2;
45
-$var = (unset)  $var2;
44
+$var = (unset)$var2;
45
+$var = (unset)$var2;
46 46
 
47 47
 $var = b"binary $foo";
48 48
 $var = b"binary string";
49 49
 $var = b'binary string';
50
-$var = (binary) $string;
50
+$var = (binary)$string;
51 51
 $var = (binary)$string;
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Formatting/SpaceAfterNotUnitTest.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      *
26 26
      * @return array<int, int>
27 27
      */
28
-    public function getErrorList($testFile='')
28
+    public function getErrorList( $testFile = '' )
29 29
     {
30
-        switch ($testFile) {
30
+        switch ( $testFile ) {
31 31
         case 'SpaceAfterNotUnitTest.inc':
32 32
             return [
33 33
                 3  => 2,
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             ];
68 68
 
69 69
         default:
70
-            return [];
70
+            return [ ];
71 71
         }//end switch
72 72
 
73 73
     }//end getErrorList()
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function getWarningList()
85 85
     {
86
-        return [];
86
+        return [ ];
87 87
 
88 88
     }//end getWarningList()
89 89
 
Please login to merge, or discard this patch.