Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
vendor/squizlabs/php_codesniffer/src/Files/File.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
      * @param string $error    The error message.
706 706
      * @param int    $line     The line on which the error occurred.
707 707
      * @param string $code     A violation code unique to the sniff message.
708
-     * @param array  $data     Replacements for the error message.
708
+     * @param string[]  $data     Replacements for the error message.
709 709
      * @param int    $severity The severity level for this error. A value of 0
710 710
      *                         will be converted into the default severity level.
711 711
      *
@@ -729,7 +729,7 @@  discard block
 block discarded – undo
729 729
      * @param string $warning  The error message.
730 730
      * @param int    $line     The line on which the warning occurred.
731 731
      * @param string $code     A violation code unique to the sniff message.
732
-     * @param array  $data     Replacements for the warning message.
732
+     * @param string[]  $data     Replacements for the warning message.
733 733
      * @param int    $severity The severity level for this warning. A value of 0 will
734 734
      *                         will be converted into the default severity level.
735 735
      *
Please login to merge, or discard this patch.
Indentation   +2461 added lines, -2461 removed lines patch added patch discarded remove patch
@@ -19,2467 +19,2467 @@
 block discarded – undo
19 19
 class File
20 20
 {
21 21
 
22
-    /**
23
-     * The absolute path to the file associated with this object.
24
-     *
25
-     * @var string
26
-     */
27
-    public $path = '';
28
-
29
-    /**
30
-     * The content of the file.
31
-     *
32
-     * @var string
33
-     */
34
-    protected $content = '';
35
-
36
-    /**
37
-     * The config data for the run.
38
-     *
39
-     * @var \PHP_CodeSniffer\Config
40
-     */
41
-    public $config = null;
42
-
43
-    /**
44
-     * The ruleset used for the run.
45
-     *
46
-     * @var \PHP_CodeSniffer\Ruleset
47
-     */
48
-    public $ruleset = null;
49
-
50
-    /**
51
-     * If TRUE, the entire file is being ignored.
52
-     *
53
-     * @var boolean
54
-     */
55
-    public $ignored = false;
56
-
57
-    /**
58
-     * The EOL character this file uses.
59
-     *
60
-     * @var string
61
-     */
62
-    public $eolChar = '';
63
-
64
-    /**
65
-     * The Fixer object to control fixing errors.
66
-     *
67
-     * @var \PHP_CodeSniffer\Fixer
68
-     */
69
-    public $fixer = null;
70
-
71
-    /**
72
-     * The tokenizer being used for this file.
73
-     *
74
-     * @var \PHP_CodeSniffer\Tokenizers\Tokenizer
75
-     */
76
-    public $tokenizer = null;
77
-
78
-    /**
79
-     * The name of the tokenizer being used for this file.
80
-     *
81
-     * @var string
82
-     */
83
-    public $tokenizerType = 'PHP';
84
-
85
-    /**
86
-     * Was the file loaded from cache?
87
-     *
88
-     * If TRUE, the file was loaded from a local cache.
89
-     * If FALSE, the file was tokenized and processed fully.
90
-     *
91
-     * @var boolean
92
-     */
93
-    public $fromCache = false;
94
-
95
-    /**
96
-     * The number of tokens in this file.
97
-     *
98
-     * Stored here to save calling count() everywhere.
99
-     *
100
-     * @var integer
101
-     */
102
-    public $numTokens = 0;
103
-
104
-    /**
105
-     * The tokens stack map.
106
-     *
107
-     * @var array
108
-     */
109
-    protected $tokens = [];
110
-
111
-    /**
112
-     * The errors raised from sniffs.
113
-     *
114
-     * @var array
115
-     * @see getErrors()
116
-     */
117
-    protected $errors = [];
118
-
119
-    /**
120
-     * The warnings raised from sniffs.
121
-     *
122
-     * @var array
123
-     * @see getWarnings()
124
-     */
125
-    protected $warnings = [];
126
-
127
-    /**
128
-     * The metrics recorded by sniffs.
129
-     *
130
-     * @var array
131
-     * @see getMetrics()
132
-     */
133
-    protected $metrics = [];
134
-
135
-    /**
136
-     * The metrics recorded for each token.
137
-     *
138
-     * Stops the same metric being recorded for the same token twice.
139
-     *
140
-     * @var array
141
-     * @see getMetrics()
142
-     */
143
-    private $metricTokens = [];
144
-
145
-    /**
146
-     * The total number of errors raised.
147
-     *
148
-     * @var integer
149
-     */
150
-    protected $errorCount = 0;
151
-
152
-    /**
153
-     * The total number of warnings raised.
154
-     *
155
-     * @var integer
156
-     */
157
-    protected $warningCount = 0;
158
-
159
-    /**
160
-     * The total number of errors and warnings that can be fixed.
161
-     *
162
-     * @var integer
163
-     */
164
-    protected $fixableCount = 0;
165
-
166
-    /**
167
-     * The total number of errors and warnings that were fixed.
168
-     *
169
-     * @var integer
170
-     */
171
-    protected $fixedCount = 0;
172
-
173
-    /**
174
-     * An array of sniffs that are being ignored.
175
-     *
176
-     * @var array
177
-     */
178
-    protected $ignoredListeners = [];
179
-
180
-    /**
181
-     * An array of message codes that are being ignored.
182
-     *
183
-     * @var array
184
-     */
185
-    protected $ignoredCodes = [];
186
-
187
-    /**
188
-     * An array of sniffs listening to this file's processing.
189
-     *
190
-     * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191
-     */
192
-    protected $listeners = [];
193
-
194
-    /**
195
-     * The class name of the sniff currently processing the file.
196
-     *
197
-     * @var string
198
-     */
199
-    protected $activeListener = '';
200
-
201
-    /**
202
-     * An array of sniffs being processed and how long they took.
203
-     *
204
-     * @var array
205
-     */
206
-    protected $listenerTimes = [];
207
-
208
-    /**
209
-     * A cache of often used config settings to improve performance.
210
-     *
211
-     * Storing them here saves 10k+ calls to __get() in the Config class.
212
-     *
213
-     * @var array
214
-     */
215
-    protected $configCache = [];
216
-
217
-
218
-    /**
219
-     * Constructs a file.
220
-     *
221
-     * @param string                   $path    The absolute path to the file to process.
222
-     * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
223
-     * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
224
-     *
225
-     * @return void
226
-     */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
228
-    {
229
-        $this->path    = $path;
230
-        $this->ruleset = $ruleset;
231
-        $this->config  = $config;
232
-        $this->fixer   = new Fixer();
233
-
234
-        $parts     = explode('.', $path);
235
-        $extension = array_pop($parts);
236
-        if (isset($config->extensions[$extension]) === true) {
237
-            $this->tokenizerType = $config->extensions[$extension];
238
-        } else {
239
-            // Revert to default.
240
-            $this->tokenizerType = 'PHP';
241
-        }
242
-
243
-        $this->configCache['cache']           = $this->config->cache;
244
-        $this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
-        $this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
-        $this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
-        $this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
-        $this->configCache['recordErrors']    = $this->config->recordErrors;
249
-        $this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
-        $this->configCache['includePatterns'] = $this->ruleset->includePatterns;
251
-
252
-    }//end __construct()
253
-
254
-
255
-    /**
256
-     * Set the content of the file.
257
-     *
258
-     * Setting the content also calculates the EOL char being used.
259
-     *
260
-     * @param string $content The file content.
261
-     *
262
-     * @return void
263
-     */
264
-    public function setContent($content)
265
-    {
266
-        $this->content = $content;
267
-        $this->tokens  = [];
268
-
269
-        try {
270
-            $this->eolChar = Util\Common::detectLineEndings($content);
271
-        } catch (RuntimeException $e) {
272
-            $this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
273
-            return;
274
-        }
275
-
276
-    }//end setContent()
277
-
278
-
279
-    /**
280
-     * Reloads the content of the file.
281
-     *
282
-     * By default, we have no idea where our content comes from,
283
-     * so we can't do anything.
284
-     *
285
-     * @return void
286
-     */
287
-    public function reloadContent()
288
-    {
289
-
290
-    }//end reloadContent()
291
-
292
-
293
-    /**
294
-     * Disables caching of this file.
295
-     *
296
-     * @return void
297
-     */
298
-    public function disableCaching()
299
-    {
300
-        $this->configCache['cache'] = false;
301
-
302
-    }//end disableCaching()
303
-
304
-
305
-    /**
306
-     * Starts the stack traversal and tells listeners when tokens are found.
307
-     *
308
-     * @return void
309
-     */
310
-    public function process()
311
-    {
312
-        if ($this->ignored === true) {
313
-            return;
314
-        }
315
-
316
-        $this->errors       = [];
317
-        $this->warnings     = [];
318
-        $this->errorCount   = 0;
319
-        $this->warningCount = 0;
320
-        $this->fixableCount = 0;
321
-
322
-        $this->parse();
323
-
324
-        // Check if tokenizer errors cause this file to be ignored.
325
-        if ($this->ignored === true) {
326
-            return;
327
-        }
328
-
329
-        $this->fixer->startFile($this);
330
-
331
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
-            echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
333
-        }
334
-
335
-        $foundCode        = false;
336
-        $listenerIgnoreTo = [];
337
-        $inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
338
-        $checkAnnotations = $this->config->annotations;
339
-
340
-        // Foreach of the listeners that have registered to listen for this
341
-        // token, get them to process it.
342
-        foreach ($this->tokens as $stackPtr => $token) {
343
-            // Check for ignored lines.
344
-            if ($checkAnnotations === true
345
-                && ($token['code'] === T_COMMENT
346
-                || $token['code'] === T_PHPCS_IGNORE_FILE
347
-                || $token['code'] === T_PHPCS_SET
348
-                || $token['code'] === T_DOC_COMMENT_STRING
349
-                || $token['code'] === T_DOC_COMMENT_TAG
350
-                || ($inTests === true && $token['code'] === T_INLINE_HTML))
351
-            ) {
352
-                $commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
-                $commentTextLower = strtolower($commentText);
354
-                if (strpos($commentText, '@codingStandards') !== false) {
355
-                    if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
356
-                        // Ignoring the whole file, just a little late.
357
-                        $this->errors       = [];
358
-                        $this->warnings     = [];
359
-                        $this->errorCount   = 0;
360
-                        $this->warningCount = 0;
361
-                        $this->fixableCount = 0;
362
-                        return;
363
-                    } else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
-                        $start   = strpos($commentText, '@codingStandardsChangeSetting');
365
-                        $comment = substr($commentText, ($start + 30));
366
-                        $parts   = explode(' ', $comment);
367
-                        if (count($parts) >= 2) {
368
-                            $sniffParts = explode('.', $parts[0]);
369
-                            if (count($sniffParts) >= 3) {
370
-                                // If the sniff code is not known to us, it has not been registered in this run.
371
-                                // But don't throw an error as it could be there for a different standard to use.
372
-                                if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
-                                    $listenerCode  = array_shift($parts);
374
-                                    $propertyCode  = array_shift($parts);
375
-                                    $propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
-                                    $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
-                                    $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
378
-                                }
379
-                            }
380
-                        }
381
-                    }//end if
382
-                } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
-                    || substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
384
-                ) {
385
-                    // Ignoring the whole file, just a little late.
386
-                    $this->errors       = [];
387
-                    $this->warnings     = [];
388
-                    $this->errorCount   = 0;
389
-                    $this->warningCount = 0;
390
-                    $this->fixableCount = 0;
391
-                    return;
392
-                } else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
-                    || substr($commentTextLower, 0, 10) === '@phpcs:set'
394
-                ) {
395
-                    if (isset($token['sniffCode']) === true) {
396
-                        $listenerCode = $token['sniffCode'];
397
-                        if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
-                            $propertyCode  = $token['sniffProperty'];
399
-                            $propertyValue = $token['sniffPropertyValue'];
400
-                            $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
-                            $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
402
-                        }
403
-                    }
404
-                }//end if
405
-            }//end if
406
-
407
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
-                $type    = $token['type'];
409
-                $content = Util\Common::prepareForOutput($token['content']);
410
-                echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
411
-            }
412
-
413
-            if ($token['code'] !== T_INLINE_HTML) {
414
-                $foundCode = true;
415
-            }
416
-
417
-            if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
418
-                continue;
419
-            }
420
-
421
-            foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
-                if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
-                    || (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
-                    && $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
425
-                ) {
426
-                    // This sniff is ignoring past this token, or the whole file.
427
-                    continue;
428
-                }
429
-
430
-                // Make sure this sniff supports the tokenizer
431
-                // we are currently using.
432
-                $class = $listenerData['class'];
433
-
434
-                if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
435
-                    continue;
436
-                }
437
-
438
-                // If the file path matches one of our ignore patterns, skip it.
439
-                // While there is support for a type of each pattern
440
-                // (absolute or relative) we don't actually support it here.
441
-                foreach ($listenerData['ignore'] as $pattern) {
442
-                    // We assume a / directory separator, as do the exclude rules
443
-                    // most developers write, so we need a special case for any system
444
-                    // that is different.
445
-                    if (DIRECTORY_SEPARATOR === '\\') {
446
-                        $pattern = str_replace('/', '\\\\', $pattern);
447
-                    }
448
-
449
-                    $pattern = '`'.$pattern.'`i';
450
-                    if (preg_match($pattern, $this->path) === 1) {
451
-                        $this->ignoredListeners[$class] = true;
452
-                        continue(2);
453
-                    }
454
-                }
455
-
456
-                // If the file path does not match one of our include patterns, skip it.
457
-                // While there is support for a type of each pattern
458
-                // (absolute or relative) we don't actually support it here.
459
-                if (empty($listenerData['include']) === false) {
460
-                    $included = false;
461
-                    foreach ($listenerData['include'] as $pattern) {
462
-                        // We assume a / directory separator, as do the exclude rules
463
-                        // most developers write, so we need a special case for any system
464
-                        // that is different.
465
-                        if (DIRECTORY_SEPARATOR === '\\') {
466
-                            $pattern = str_replace('/', '\\\\', $pattern);
467
-                        }
468
-
469
-                        $pattern = '`'.$pattern.'`i';
470
-                        if (preg_match($pattern, $this->path) === 1) {
471
-                            $included = true;
472
-                            break;
473
-                        }
474
-                    }
475
-
476
-                    if ($included === false) {
477
-                        $this->ignoredListeners[$class] = true;
478
-                        continue;
479
-                    }
480
-                }//end if
481
-
482
-                $this->activeListener = $class;
483
-
484
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
-                    $startTime = microtime(true);
486
-                    echo "\t\t\tProcessing ".$this->activeListener.'... ';
487
-                }
488
-
489
-                $ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
-                if ($ignoreTo !== null) {
491
-                    $listenerIgnoreTo[$this->activeListener] = $ignoreTo;
492
-                }
493
-
494
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
-                    $timeTaken = (microtime(true) - $startTime);
496
-                    if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
-                        $this->listenerTimes[$this->activeListener] = 0;
498
-                    }
499
-
500
-                    $this->listenerTimes[$this->activeListener] += $timeTaken;
501
-
502
-                    $timeTaken = round(($timeTaken), 4);
503
-                    echo "DONE in $timeTaken seconds".PHP_EOL;
504
-                }
505
-
506
-                $this->activeListener = '';
507
-            }//end foreach
508
-        }//end foreach
509
-
510
-        // If short open tags are off but the file being checked uses
511
-        // short open tags, the whole content will be inline HTML
512
-        // and nothing will be checked. So try and handle this case.
513
-        // We don't show this error for STDIN because we can't be sure the content
514
-        // actually came directly from the user. It could be something like
515
-        // refs from a Git pre-push hook.
516
-        if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
-            $shortTags = (bool) ini_get('short_open_tag');
518
-            if ($shortTags === false) {
519
-                $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
-                $this->addWarning($error, null, 'Internal.NoCodeFound');
521
-            }
522
-        }
523
-
524
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
-            echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
-            echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
527
-
528
-            asort($this->listenerTimes, SORT_NUMERIC);
529
-            $this->listenerTimes = array_reverse($this->listenerTimes, true);
530
-            foreach ($this->listenerTimes as $listener => $timeTaken) {
531
-                echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
532
-            }
533
-
534
-            echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
535
-        }
536
-
537
-        $this->fixedCount += $this->fixer->getFixCount();
538
-
539
-    }//end process()
540
-
541
-
542
-    /**
543
-     * Tokenizes the file and prepares it for the test run.
544
-     *
545
-     * @return void
546
-     */
547
-    public function parse()
548
-    {
549
-        if (empty($this->tokens) === false) {
550
-            // File has already been parsed.
551
-            return;
552
-        }
553
-
554
-        try {
555
-            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
-            $this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
557
-            $this->tokens    = $this->tokenizer->getTokens();
558
-        } catch (TokenizerException $e) {
559
-            $this->ignored = true;
560
-            $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
562
-                echo "[$this->tokenizerType => tokenizer error]... ";
563
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
564
-                    echo PHP_EOL;
565
-                }
566
-            }
567
-
568
-            return;
569
-        }
570
-
571
-        $this->numTokens = count($this->tokens);
572
-
573
-        // Check for mixed line endings as these can cause tokenizer errors and we
574
-        // should let the user know that the results they get may be incorrect.
575
-        // This is done by removing all backslashes, removing the newline char we
576
-        // detected, then converting newlines chars into text. If any backslashes
577
-        // are left at the end, we have additional newline chars in use.
578
-        $contents = str_replace('\\', '', $this->content);
579
-        $contents = str_replace($this->eolChar, '', $contents);
580
-        $contents = str_replace("\n", '\n', $contents);
581
-        $contents = str_replace("\r", '\r', $contents);
582
-        if (strpos($contents, '\\') !== false) {
583
-            $error = 'File has mixed line endings; this may cause incorrect results';
584
-            $this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
585
-        }
586
-
587
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
-            if ($this->numTokens === 0) {
589
-                $numLines = 0;
590
-            } else {
591
-                $numLines = $this->tokens[($this->numTokens - 1)]['line'];
592
-            }
593
-
594
-            echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
-                echo PHP_EOL;
597
-            }
598
-        }
599
-
600
-    }//end parse()
601
-
602
-
603
-    /**
604
-     * Returns the token stack for this file.
605
-     *
606
-     * @return array
607
-     */
608
-    public function getTokens()
609
-    {
610
-        return $this->tokens;
611
-
612
-    }//end getTokens()
613
-
614
-
615
-    /**
616
-     * Remove vars stored in this file that are no longer required.
617
-     *
618
-     * @return void
619
-     */
620
-    public function cleanUp()
621
-    {
622
-        $this->listenerTimes = null;
623
-        $this->content       = null;
624
-        $this->tokens        = null;
625
-        $this->metricTokens  = null;
626
-        $this->tokenizer     = null;
627
-        $this->fixer         = null;
628
-        $this->config        = null;
629
-        $this->ruleset       = null;
630
-
631
-    }//end cleanUp()
632
-
633
-
634
-    /**
635
-     * Records an error against a specific token in the file.
636
-     *
637
-     * @param string  $error    The error message.
638
-     * @param int     $stackPtr The stack position where the error occurred.
639
-     * @param string  $code     A violation code unique to the sniff message.
640
-     * @param array   $data     Replacements for the error message.
641
-     * @param int     $severity The severity level for this error. A value of 0
642
-     *                          will be converted into the default severity level.
643
-     * @param boolean $fixable  Can the error be fixed by the sniff?
644
-     *
645
-     * @return boolean
646
-     */
647
-    public function addError(
648
-        $error,
649
-        $stackPtr,
650
-        $code,
651
-        $data=[],
652
-        $severity=0,
653
-        $fixable=false
654
-    ) {
655
-        if ($stackPtr === null) {
656
-            $line   = 1;
657
-            $column = 1;
658
-        } else {
659
-            $line   = $this->tokens[$stackPtr]['line'];
660
-            $column = $this->tokens[$stackPtr]['column'];
661
-        }
662
-
663
-        return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
664
-
665
-    }//end addError()
666
-
667
-
668
-    /**
669
-     * Records a warning against a specific token in the file.
670
-     *
671
-     * @param string  $warning  The error message.
672
-     * @param int     $stackPtr The stack position where the error occurred.
673
-     * @param string  $code     A violation code unique to the sniff message.
674
-     * @param array   $data     Replacements for the warning message.
675
-     * @param int     $severity The severity level for this warning. A value of 0
676
-     *                          will be converted into the default severity level.
677
-     * @param boolean $fixable  Can the warning be fixed by the sniff?
678
-     *
679
-     * @return boolean
680
-     */
681
-    public function addWarning(
682
-        $warning,
683
-        $stackPtr,
684
-        $code,
685
-        $data=[],
686
-        $severity=0,
687
-        $fixable=false
688
-    ) {
689
-        if ($stackPtr === null) {
690
-            $line   = 1;
691
-            $column = 1;
692
-        } else {
693
-            $line   = $this->tokens[$stackPtr]['line'];
694
-            $column = $this->tokens[$stackPtr]['column'];
695
-        }
696
-
697
-        return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
698
-
699
-    }//end addWarning()
700
-
701
-
702
-    /**
703
-     * Records an error against a specific line in the file.
704
-     *
705
-     * @param string $error    The error message.
706
-     * @param int    $line     The line on which the error occurred.
707
-     * @param string $code     A violation code unique to the sniff message.
708
-     * @param array  $data     Replacements for the error message.
709
-     * @param int    $severity The severity level for this error. A value of 0
710
-     *                         will be converted into the default severity level.
711
-     *
712
-     * @return boolean
713
-     */
714
-    public function addErrorOnLine(
715
-        $error,
716
-        $line,
717
-        $code,
718
-        $data=[],
719
-        $severity=0
720
-    ) {
721
-        return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
722
-
723
-    }//end addErrorOnLine()
724
-
725
-
726
-    /**
727
-     * Records a warning against a specific token in the file.
728
-     *
729
-     * @param string $warning  The error message.
730
-     * @param int    $line     The line on which the warning occurred.
731
-     * @param string $code     A violation code unique to the sniff message.
732
-     * @param array  $data     Replacements for the warning message.
733
-     * @param int    $severity The severity level for this warning. A value of 0 will
734
-     *                         will be converted into the default severity level.
735
-     *
736
-     * @return boolean
737
-     */
738
-    public function addWarningOnLine(
739
-        $warning,
740
-        $line,
741
-        $code,
742
-        $data=[],
743
-        $severity=0
744
-    ) {
745
-        return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
746
-
747
-    }//end addWarningOnLine()
748
-
749
-
750
-    /**
751
-     * Records a fixable error against a specific token in the file.
752
-     *
753
-     * Returns true if the error was recorded and should be fixed.
754
-     *
755
-     * @param string $error    The error message.
756
-     * @param int    $stackPtr The stack position where the error occurred.
757
-     * @param string $code     A violation code unique to the sniff message.
758
-     * @param array  $data     Replacements for the error message.
759
-     * @param int    $severity The severity level for this error. A value of 0
760
-     *                         will be converted into the default severity level.
761
-     *
762
-     * @return boolean
763
-     */
764
-    public function addFixableError(
765
-        $error,
766
-        $stackPtr,
767
-        $code,
768
-        $data=[],
769
-        $severity=0
770
-    ) {
771
-        $recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
-        if ($recorded === true && $this->fixer->enabled === true) {
773
-            return true;
774
-        }
775
-
776
-        return false;
777
-
778
-    }//end addFixableError()
779
-
780
-
781
-    /**
782
-     * Records a fixable warning against a specific token in the file.
783
-     *
784
-     * Returns true if the warning was recorded and should be fixed.
785
-     *
786
-     * @param string $warning  The error message.
787
-     * @param int    $stackPtr The stack position where the error occurred.
788
-     * @param string $code     A violation code unique to the sniff message.
789
-     * @param array  $data     Replacements for the warning message.
790
-     * @param int    $severity The severity level for this warning. A value of 0
791
-     *                         will be converted into the default severity level.
792
-     *
793
-     * @return boolean
794
-     */
795
-    public function addFixableWarning(
796
-        $warning,
797
-        $stackPtr,
798
-        $code,
799
-        $data=[],
800
-        $severity=0
801
-    ) {
802
-        $recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
-        if ($recorded === true && $this->fixer->enabled === true) {
804
-            return true;
805
-        }
806
-
807
-        return false;
808
-
809
-    }//end addFixableWarning()
810
-
811
-
812
-    /**
813
-     * Adds an error to the error stack.
814
-     *
815
-     * @param boolean $error    Is this an error message?
816
-     * @param string  $message  The text of the message.
817
-     * @param int     $line     The line on which the message occurred.
818
-     * @param int     $column   The column at which the message occurred.
819
-     * @param string  $code     A violation code unique to the sniff message.
820
-     * @param array   $data     Replacements for the message.
821
-     * @param int     $severity The severity level for this message. A value of 0
822
-     *                          will be converted into the default severity level.
823
-     * @param boolean $fixable  Can the problem be fixed by the sniff?
824
-     *
825
-     * @return boolean
826
-     */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
-    {
829
-        // Check if this line is ignoring all message codes.
830
-        if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831
-            return false;
832
-        }
833
-
834
-        // Work out which sniff generated the message.
835
-        $parts = explode('.', $code);
836
-        if ($parts[0] === 'Internal') {
837
-            // An internal message.
838
-            $listenerCode = Util\Common::getSniffCode($this->activeListener);
839
-            $sniffCode    = $code;
840
-            $checkCodes   = [$sniffCode];
841
-        } else {
842
-            if ($parts[0] !== $code) {
843
-                // The full message code has been passed in.
844
-                $sniffCode    = $code;
845
-                $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
846
-            } else {
847
-                $listenerCode = Util\Common::getSniffCode($this->activeListener);
848
-                $sniffCode    = $listenerCode.'.'.$code;
849
-                $parts        = explode('.', $sniffCode);
850
-            }
851
-
852
-            $checkCodes = [
853
-                $sniffCode,
854
-                $parts[0].'.'.$parts[1].'.'.$parts[2],
855
-                $parts[0].'.'.$parts[1],
856
-                $parts[0],
857
-            ];
858
-        }//end if
859
-
860
-        if (isset($this->tokenizer->ignoredLines[$line]) === true) {
861
-            // Check if this line is ignoring this specific message.
862
-            $ignored = false;
863
-            foreach ($checkCodes as $checkCode) {
864
-                if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
865
-                    $ignored = true;
866
-                    break;
867
-                }
868
-            }
869
-
870
-            // If it is ignored, make sure it's not whitelisted.
871
-            if ($ignored === true
872
-                && isset($this->tokenizer->ignoredLines[$line]['.except']) === true
873
-            ) {
874
-                foreach ($checkCodes as $checkCode) {
875
-                    if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
876
-                        $ignored = false;
877
-                        break;
878
-                    }
879
-                }
880
-            }
881
-
882
-            if ($ignored === true) {
883
-                return false;
884
-            }
885
-        }//end if
886
-
887
-        $includeAll = true;
888
-        if ($this->configCache['cache'] === false
889
-            || $this->configCache['recordErrors'] === false
890
-        ) {
891
-            $includeAll = false;
892
-        }
893
-
894
-        // Filter out any messages for sniffs that shouldn't have run
895
-        // due to the use of the --sniffs command line argument.
896
-        if ($includeAll === false
897
-            && ((empty($this->configCache['sniffs']) === false
898
-            && in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
-            || (empty($this->configCache['exclude']) === false
900
-            && in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
901
-        ) {
902
-            return false;
903
-        }
904
-
905
-        // If we know this sniff code is being ignored for this file, return early.
906
-        foreach ($checkCodes as $checkCode) {
907
-            if (isset($this->ignoredCodes[$checkCode]) === true) {
908
-                return false;
909
-            }
910
-        }
911
-
912
-        $oppositeType = 'warning';
913
-        if ($error === false) {
914
-            $oppositeType = 'error';
915
-        }
916
-
917
-        foreach ($checkCodes as $checkCode) {
918
-            // Make sure this message type has not been set to the opposite message type.
919
-            if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
-                && $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
921
-            ) {
922
-                $error = !$error;
923
-                break;
924
-            }
925
-        }
926
-
927
-        if ($error === true) {
928
-            $configSeverity = $this->configCache['errorSeverity'];
929
-            $messageCount   = &$this->errorCount;
930
-            $messages       = &$this->errors;
931
-        } else {
932
-            $configSeverity = $this->configCache['warningSeverity'];
933
-            $messageCount   = &$this->warningCount;
934
-            $messages       = &$this->warnings;
935
-        }
936
-
937
-        if ($includeAll === false && $configSeverity === 0) {
938
-            // Don't bother doing any processing as these messages are just going to
939
-            // be hidden in the reports anyway.
940
-            return false;
941
-        }
942
-
943
-        if ($severity === 0) {
944
-            $severity = 5;
945
-        }
946
-
947
-        foreach ($checkCodes as $checkCode) {
948
-            // Make sure we are interested in this severity level.
949
-            if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
-                $severity = $this->ruleset->ruleset[$checkCode]['severity'];
951
-                break;
952
-            }
953
-        }
954
-
955
-        if ($includeAll === false && $configSeverity > $severity) {
956
-            return false;
957
-        }
958
-
959
-        // Make sure we are not ignoring this file.
960
-        $included = null;
961
-        foreach ($checkCodes as $checkCode) {
962
-            $patterns = null;
963
-
964
-            if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
-                $patterns  = $this->configCache['includePatterns'][$checkCode];
966
-                $excluding = false;
967
-            } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
-                $patterns  = $this->configCache['ignorePatterns'][$checkCode];
969
-                $excluding = true;
970
-            }
971
-
972
-            if ($patterns === null) {
973
-                continue;
974
-            }
975
-
976
-            foreach ($patterns as $pattern => $type) {
977
-                // While there is support for a type of each pattern
978
-                // (absolute or relative) we don't actually support it here.
979
-                $replacements = [
980
-                    '\\,' => ',',
981
-                    '*'   => '.*',
982
-                ];
983
-
984
-                // We assume a / directory separator, as do the exclude rules
985
-                // most developers write, so we need a special case for any system
986
-                // that is different.
987
-                if (DIRECTORY_SEPARATOR === '\\') {
988
-                    $replacements['/'] = '\\\\';
989
-                }
990
-
991
-                $pattern = '`'.strtr($pattern, $replacements).'`i';
992
-                $matched = preg_match($pattern, $this->path);
993
-
994
-                if ($matched === 0) {
995
-                    if ($excluding === false && $included === null) {
996
-                        // This file path is not being included.
997
-                        $included = false;
998
-                    }
999
-
1000
-                    continue;
1001
-                }
1002
-
1003
-                if ($excluding === true) {
1004
-                    // This file path is being excluded.
1005
-                    $this->ignoredCodes[$checkCode] = true;
1006
-                    return false;
1007
-                }
1008
-
1009
-                // This file path is being included.
1010
-                $included = true;
1011
-                break;
1012
-            }//end foreach
1013
-        }//end foreach
1014
-
1015
-        if ($included === false) {
1016
-            // There were include rules set, but this file
1017
-            // path didn't match any of them.
1018
-            return false;
1019
-        }
1020
-
1021
-        $messageCount++;
1022
-        if ($fixable === true) {
1023
-            $this->fixableCount++;
1024
-        }
1025
-
1026
-        if ($this->configCache['recordErrors'] === false
1027
-            && $includeAll === false
1028
-        ) {
1029
-            return true;
1030
-        }
1031
-
1032
-        // Work out the error message.
1033
-        if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
-            $message = $this->ruleset->ruleset[$sniffCode]['message'];
1035
-        }
1036
-
1037
-        if (empty($data) === false) {
1038
-            $message = vsprintf($message, $data);
1039
-        }
1040
-
1041
-        if (isset($messages[$line]) === false) {
1042
-            $messages[$line] = [];
1043
-        }
1044
-
1045
-        if (isset($messages[$line][$column]) === false) {
1046
-            $messages[$line][$column] = [];
1047
-        }
1048
-
1049
-        $messages[$line][$column][] = [
1050
-            'message'  => $message,
1051
-            'source'   => $sniffCode,
1052
-            'listener' => $this->activeListener,
1053
-            'severity' => $severity,
1054
-            'fixable'  => $fixable,
1055
-        ];
1056
-
1057
-        if (PHP_CODESNIFFER_VERBOSITY > 1
1058
-            && $this->fixer->enabled === true
1059
-            && $fixable === true
1060
-        ) {
1061
-            @ob_end_clean();
1062
-            echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1063
-            ob_start();
1064
-        }
1065
-
1066
-        return true;
1067
-
1068
-    }//end addMessage()
1069
-
1070
-
1071
-    /**
1072
-     * Record a metric about the file being examined.
1073
-     *
1074
-     * @param int    $stackPtr The stack position where the metric was recorded.
1075
-     * @param string $metric   The name of the metric being recorded.
1076
-     * @param string $value    The value of the metric being recorded.
1077
-     *
1078
-     * @return boolean
1079
-     */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1081
-    {
1082
-        if (isset($this->metrics[$metric]) === false) {
1083
-            $this->metrics[$metric] = ['values' => [$value => 1]];
1084
-            $this->metricTokens[$metric][$stackPtr] = true;
1085
-        } else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
-            $this->metricTokens[$metric][$stackPtr] = true;
1087
-            if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
-                $this->metrics[$metric]['values'][$value] = 1;
1089
-            } else {
1090
-                $this->metrics[$metric]['values'][$value]++;
1091
-            }
1092
-        }
1093
-
1094
-        return true;
1095
-
1096
-    }//end recordMetric()
1097
-
1098
-
1099
-    /**
1100
-     * Returns the number of errors raised.
1101
-     *
1102
-     * @return int
1103
-     */
1104
-    public function getErrorCount()
1105
-    {
1106
-        return $this->errorCount;
1107
-
1108
-    }//end getErrorCount()
1109
-
1110
-
1111
-    /**
1112
-     * Returns the number of warnings raised.
1113
-     *
1114
-     * @return int
1115
-     */
1116
-    public function getWarningCount()
1117
-    {
1118
-        return $this->warningCount;
1119
-
1120
-    }//end getWarningCount()
1121
-
1122
-
1123
-    /**
1124
-     * Returns the number of fixable errors/warnings raised.
1125
-     *
1126
-     * @return int
1127
-     */
1128
-    public function getFixableCount()
1129
-    {
1130
-        return $this->fixableCount;
1131
-
1132
-    }//end getFixableCount()
1133
-
1134
-
1135
-    /**
1136
-     * Returns the number of fixed errors/warnings.
1137
-     *
1138
-     * @return int
1139
-     */
1140
-    public function getFixedCount()
1141
-    {
1142
-        return $this->fixedCount;
1143
-
1144
-    }//end getFixedCount()
1145
-
1146
-
1147
-    /**
1148
-     * Returns the list of ignored lines.
1149
-     *
1150
-     * @return array
1151
-     */
1152
-    public function getIgnoredLines()
1153
-    {
1154
-        return $this->tokenizer->ignoredLines;
1155
-
1156
-    }//end getIgnoredLines()
1157
-
1158
-
1159
-    /**
1160
-     * Returns the errors raised from processing this file.
1161
-     *
1162
-     * @return array
1163
-     */
1164
-    public function getErrors()
1165
-    {
1166
-        return $this->errors;
1167
-
1168
-    }//end getErrors()
1169
-
1170
-
1171
-    /**
1172
-     * Returns the warnings raised from processing this file.
1173
-     *
1174
-     * @return array
1175
-     */
1176
-    public function getWarnings()
1177
-    {
1178
-        return $this->warnings;
1179
-
1180
-    }//end getWarnings()
1181
-
1182
-
1183
-    /**
1184
-     * Returns the metrics found while processing this file.
1185
-     *
1186
-     * @return array
1187
-     */
1188
-    public function getMetrics()
1189
-    {
1190
-        return $this->metrics;
1191
-
1192
-    }//end getMetrics()
1193
-
1194
-
1195
-    /**
1196
-     * Returns the absolute filename of this file.
1197
-     *
1198
-     * @return string
1199
-     */
1200
-    public function getFilename()
1201
-    {
1202
-        return $this->path;
1203
-
1204
-    }//end getFilename()
1205
-
1206
-
1207
-    /**
1208
-     * Returns the declaration names for classes, interfaces, traits, and functions.
1209
-     *
1210
-     * @param int $stackPtr The position of the declaration token which
1211
-     *                      declared the class, interface, trait, or function.
1212
-     *
1213
-     * @return string|null The name of the class, interface, trait, or function;
1214
-     *                     or NULL if the function or class is anonymous.
1215
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
1216
-     *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217
-     *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218
-     */
1219
-    public function getDeclarationName($stackPtr)
1220
-    {
1221
-        $tokenCode = $this->tokens[$stackPtr]['code'];
1222
-
1223
-        if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1224
-            return null;
1225
-        }
1226
-
1227
-        if ($tokenCode !== T_FUNCTION
1228
-            && $tokenCode !== T_CLASS
1229
-            && $tokenCode !== T_INTERFACE
1230
-            && $tokenCode !== T_TRAIT
1231
-        ) {
1232
-            throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1233
-        }
1234
-
1235
-        if ($tokenCode === T_FUNCTION
1236
-            && strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1237
-        ) {
1238
-            // This is a function declared without the "function" keyword.
1239
-            // So this token is the function name.
1240
-            return $this->tokens[$stackPtr]['content'];
1241
-        }
1242
-
1243
-        $content = null;
1244
-        for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
-            if ($this->tokens[$i]['code'] === T_STRING) {
1246
-                $content = $this->tokens[$i]['content'];
1247
-                break;
1248
-            }
1249
-        }
1250
-
1251
-        return $content;
1252
-
1253
-    }//end getDeclarationName()
1254
-
1255
-
1256
-    /**
1257
-     * Returns the method parameters for the specified function token.
1258
-     *
1259
-     * Each parameter is in the following format:
1260
-     *
1261
-     * <code>
1262
-     *   0 => array(
1263
-     *         'name'              => '$var',  // The variable name.
1264
-     *         'token'             => integer, // The stack pointer to the variable name.
1265
-     *         'content'           => string,  // The full content of the variable definition.
1266
-     *         'pass_by_reference' => boolean, // Is the variable passed by reference?
1267
-     *         'variable_length'   => boolean, // Is the param of variable length through use of `...` ?
1268
-     *         'type_hint'         => string,  // The type hint for the variable.
1269
-     *         'type_hint_token'   => integer, // The stack pointer to the type hint
1270
-     *                                         // or false if there is no type hint.
1271
-     *         'nullable_type'     => boolean, // Is the variable using a nullable type?
1272
-     *        )
1273
-     * </code>
1274
-     *
1275
-     * Parameters with default values have an additional array index of
1276
-     * 'default' with the value of the default as a string.
1277
-     *
1278
-     * @param int $stackPtr The position in the stack of the function token
1279
-     *                      to acquire the parameters for.
1280
-     *
1281
-     * @return array
1282
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283
-     *                                                        type T_FUNCTION or T_CLOSURE.
1284
-     */
1285
-    public function getMethodParameters($stackPtr)
1286
-    {
1287
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289
-        ) {
1290
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1291
-        }
1292
-
1293
-        $opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
-        $closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1295
-
1296
-        $vars            = [];
1297
-        $currVar         = null;
1298
-        $paramStart      = ($opener + 1);
1299
-        $defaultStart    = null;
1300
-        $paramCount      = 0;
1301
-        $passByReference = false;
1302
-        $variableLength  = false;
1303
-        $typeHint        = '';
1304
-        $typeHintToken   = false;
1305
-        $nullableType    = false;
1306
-
1307
-        for ($i = $paramStart; $i <= $closer; $i++) {
1308
-            // Check to see if this token has a parenthesis or bracket opener. If it does
1309
-            // it's likely to be an array which might have arguments in it. This
1310
-            // could cause problems in our parsing below, so lets just skip to the
1311
-            // end of it.
1312
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1313
-                // Don't do this if it's the close parenthesis for the method.
1314
-                if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
-                    $i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1316
-                }
1317
-            }
1318
-
1319
-            if (isset($this->tokens[$i]['bracket_opener']) === true) {
1320
-                // Don't do this if it's the close parenthesis for the method.
1321
-                if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
-                    $i = ($this->tokens[$i]['bracket_closer'] + 1);
1323
-                }
1324
-            }
1325
-
1326
-            switch ($this->tokens[$i]['code']) {
1327
-            case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1329
-                    $passByReference = true;
1330
-                }
1331
-                break;
1332
-            case T_VARIABLE:
1333
-                $currVar = $i;
1334
-                break;
1335
-            case T_ELLIPSIS:
1336
-                $variableLength = true;
1337
-                break;
1338
-            case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1340
-                    $typeHintToken = $i;
1341
-                }
1342
-
1343
-                $typeHint .= $this->tokens[$i]['content'];
1344
-                break;
1345
-            case T_SELF:
1346
-            case T_PARENT:
1347
-            case T_STATIC:
1348
-                // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1351
-                        $typeHintToken = $i;
1352
-                    }
1353
-
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1355
-                }
1356
-                break;
1357
-            case T_STRING:
1358
-                // This is a string, so it may be a type hint, but it could
1359
-                // also be a constant used as a default value.
1360
-                $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1363
-                        $prevComma = $t;
1364
-                        break;
1365
-                    }
1366
-                }
1367
-
1368
-                if ($prevComma !== false) {
1369
-                    $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
-                            $nextEquals = $t;
1373
-                            break;
1374
-                        }
1375
-                    }
1376
-
1377
-                    if ($nextEquals !== false) {
1378
-                        break;
1379
-                    }
1380
-                }
1381
-
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1384
-                        $typeHintToken = $i;
1385
-                    }
1386
-
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1388
-                }
1389
-                break;
1390
-            case T_NS_SEPARATOR:
1391
-                // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1394
-                        $typeHintToken = $i;
1395
-                    }
1396
-
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1398
-                }
1399
-                break;
1400
-            case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1402
-                    $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1404
-                }
1405
-                break;
1406
-            case T_CLOSE_PARENTHESIS:
1407
-            case T_COMMA:
1408
-                // If it's null, then there must be no parameters for this
1409
-                // method.
1410
-                if ($currVar === null) {
1411
-                    continue 2;
1412
-                }
1413
-
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
-
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
-                }
1422
-
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1428
-
1429
-                // Reset the vars, as we are about to process the next parameter.
1430
-                $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1432
-                $passByReference = false;
1433
-                $variableLength  = false;
1434
-                $typeHint        = '';
1435
-                $typeHintToken   = false;
1436
-                $nullableType    = false;
1437
-
1438
-                $paramCount++;
1439
-                break;
1440
-            case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1442
-                break;
1443
-            }//end switch
1444
-        }//end for
1445
-
1446
-        return $vars;
1447
-
1448
-    }//end getMethodParameters()
1449
-
1450
-
1451
-    /**
1452
-     * Returns the visibility and implementation properties of a method.
1453
-     *
1454
-     * The format of the array is:
1455
-     * <code>
1456
-     *   array(
1457
-     *    'scope'                => 'public', // public protected or protected
1458
-     *    'scope_specified'      => true,     // true is scope keyword was found.
1459
-     *    'return_type'          => '',       // the return type of the method.
1460
-     *    'return_type_token'    => integer,  // The stack pointer to the start of the return type
1461
-     *                                        // or false if there is no return type.
1462
-     *    'nullable_return_type' => false,    // true if the return type is nullable.
1463
-     *    'is_abstract'          => false,    // true if the abstract keyword was found.
1464
-     *    'is_final'             => false,    // true if the final keyword was found.
1465
-     *    'is_static'            => false,    // true if the static keyword was found.
1466
-     *    'has_body'             => false,    // true if the method has a body
1467
-     *   );
1468
-     * </code>
1469
-     *
1470
-     * @param int $stackPtr The position in the stack of the function token to
1471
-     *                      acquire the properties for.
1472
-     *
1473
-     * @return array
1474
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475
-     *                                                        T_FUNCTION token.
1476
-     */
1477
-    public function getMethodProperties($stackPtr)
1478
-    {
1479
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481
-        ) {
1482
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1483
-        }
1484
-
1485
-        if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1486
-            $valid = [
1487
-                T_PUBLIC      => T_PUBLIC,
1488
-                T_PRIVATE     => T_PRIVATE,
1489
-                T_PROTECTED   => T_PROTECTED,
1490
-                T_STATIC      => T_STATIC,
1491
-                T_FINAL       => T_FINAL,
1492
-                T_ABSTRACT    => T_ABSTRACT,
1493
-                T_WHITESPACE  => T_WHITESPACE,
1494
-                T_COMMENT     => T_COMMENT,
1495
-                T_DOC_COMMENT => T_DOC_COMMENT,
1496
-            ];
1497
-        } else {
1498
-            $valid = [
1499
-                T_STATIC      => T_STATIC,
1500
-                T_WHITESPACE  => T_WHITESPACE,
1501
-                T_COMMENT     => T_COMMENT,
1502
-                T_DOC_COMMENT => T_DOC_COMMENT,
1503
-            ];
1504
-        }
1505
-
1506
-        $scope          = 'public';
1507
-        $scopeSpecified = false;
1508
-        $isAbstract     = false;
1509
-        $isFinal        = false;
1510
-        $isStatic       = false;
1511
-
1512
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1514
-                break;
1515
-            }
1516
-
1517
-            switch ($this->tokens[$i]['code']) {
1518
-            case T_PUBLIC:
1519
-                $scope          = 'public';
1520
-                $scopeSpecified = true;
1521
-                break;
1522
-            case T_PRIVATE:
1523
-                $scope          = 'private';
1524
-                $scopeSpecified = true;
1525
-                break;
1526
-            case T_PROTECTED:
1527
-                $scope          = 'protected';
1528
-                $scopeSpecified = true;
1529
-                break;
1530
-            case T_ABSTRACT:
1531
-                $isAbstract = true;
1532
-                break;
1533
-            case T_FINAL:
1534
-                $isFinal = true;
1535
-                break;
1536
-            case T_STATIC:
1537
-                $isStatic = true;
1538
-                break;
1539
-            }//end switch
1540
-        }//end for
1541
-
1542
-        $returnType         = '';
1543
-        $returnTypeToken    = false;
1544
-        $nullableReturnType = false;
1545
-        $hasBody            = true;
1546
-
1547
-        if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1548
-            $scopeOpener = null;
1549
-            if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
-                $scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1551
-            }
1552
-
1553
-            $valid = [
1554
-                T_STRING       => T_STRING,
1555
-                T_CALLABLE     => T_CALLABLE,
1556
-                T_SELF         => T_SELF,
1557
-                T_PARENT       => T_PARENT,
1558
-                T_NS_SEPARATOR => T_NS_SEPARATOR,
1559
-            ];
1560
-
1561
-            for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
-                if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
-                    || ($scopeOpener !== null && $i === $scopeOpener)
1564
-                ) {
1565
-                    // End of function definition.
1566
-                    break;
1567
-                }
1568
-
1569
-                if ($this->tokens[$i]['code'] === T_NULLABLE) {
1570
-                    $nullableReturnType = true;
1571
-                }
1572
-
1573
-                if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
-                    if ($returnTypeToken === false) {
1575
-                        $returnTypeToken = $i;
1576
-                    }
1577
-
1578
-                    $returnType .= $this->tokens[$i]['content'];
1579
-                }
1580
-            }
1581
-
1582
-            $end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
-            $hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1584
-        }//end if
1585
-
1586
-        if ($returnType !== '' && $nullableReturnType === true) {
1587
-            $returnType = '?'.$returnType;
1588
-        }
1589
-
1590
-        return [
1591
-            'scope'                => $scope,
1592
-            'scope_specified'      => $scopeSpecified,
1593
-            'return_type'          => $returnType,
1594
-            'return_type_token'    => $returnTypeToken,
1595
-            'nullable_return_type' => $nullableReturnType,
1596
-            'is_abstract'          => $isAbstract,
1597
-            'is_final'             => $isFinal,
1598
-            'is_static'            => $isStatic,
1599
-            'has_body'             => $hasBody,
1600
-        ];
1601
-
1602
-    }//end getMethodProperties()
1603
-
1604
-
1605
-    /**
1606
-     * Returns the visibility and implementation properties of the class member
1607
-     * variable found at the specified position in the stack.
1608
-     *
1609
-     * The format of the array is:
1610
-     *
1611
-     * <code>
1612
-     *   array(
1613
-     *    'scope'           => 'public', // public protected or protected.
1614
-     *    'scope_specified' => false,    // true if the scope was explicitly specified.
1615
-     *    'is_static'       => false,    // true if the static keyword was found.
1616
-     *   );
1617
-     * </code>
1618
-     *
1619
-     * @param int $stackPtr The position in the stack of the T_VARIABLE token to
1620
-     *                      acquire the properties for.
1621
-     *
1622
-     * @return array
1623
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1624
-     *                                                        T_VARIABLE token, or if the position is not
1625
-     *                                                        a class member variable.
1626
-     */
1627
-    public function getMemberProperties($stackPtr)
1628
-    {
1629
-        if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
-            throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631
-        }
1632
-
1633
-        $conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
-        $ptr        = array_pop($conditions);
1635
-        if (isset($this->tokens[$ptr]) === false
1636
-            || ($this->tokens[$ptr]['code'] !== T_CLASS
1637
-            && $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
-            && $this->tokens[$ptr]['code'] !== T_TRAIT)
1639
-        ) {
1640
-            if (isset($this->tokens[$ptr]) === true
1641
-                && $this->tokens[$ptr]['code'] === T_INTERFACE
1642
-            ) {
1643
-                // T_VARIABLEs in interfaces can actually be method arguments
1644
-                // but they wont be seen as being inside the method because there
1645
-                // are no scope openers and closers for abstract methods. If it is in
1646
-                // parentheses, we can be pretty sure it is a method argument.
1647
-                if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
-                    || empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1649
-                ) {
1650
-                    $error = 'Possible parse error: interfaces may not include member vars';
1651
-                    $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
-                    return [];
1653
-                }
1654
-            } else {
1655
-                throw new TokenizerException('$stackPtr is not a class member var');
1656
-            }
1657
-        }
1658
-
1659
-        // Make sure it's not a method parameter.
1660
-        if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
-            $parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
-            $deepestOpen = array_pop($parenthesis);
1663
-            if ($deepestOpen > $ptr
1664
-                && isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
-                && $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1666
-            ) {
1667
-                throw new TokenizerException('$stackPtr is not a class member var');
1668
-            }
1669
-        }
1670
-
1671
-        $valid = [
1672
-            T_PUBLIC    => T_PUBLIC,
1673
-            T_PRIVATE   => T_PRIVATE,
1674
-            T_PROTECTED => T_PROTECTED,
1675
-            T_STATIC    => T_STATIC,
1676
-            T_VAR       => T_VAR,
1677
-        ];
1678
-
1679
-        $valid += Util\Tokens::$emptyTokens;
1680
-
1681
-        $scope          = 'public';
1682
-        $scopeSpecified = false;
1683
-        $isStatic       = false;
1684
-
1685
-        $startOfStatement = $this->findPrevious(
1686
-            [
1687
-                T_SEMICOLON,
1688
-                T_OPEN_CURLY_BRACKET,
1689
-                T_CLOSE_CURLY_BRACKET,
1690
-            ],
1691
-            ($stackPtr - 1)
1692
-        );
1693
-
1694
-        for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1696
-                break;
1697
-            }
1698
-
1699
-            switch ($this->tokens[$i]['code']) {
1700
-            case T_PUBLIC:
1701
-                $scope          = 'public';
1702
-                $scopeSpecified = true;
1703
-                break;
1704
-            case T_PRIVATE:
1705
-                $scope          = 'private';
1706
-                $scopeSpecified = true;
1707
-                break;
1708
-            case T_PROTECTED:
1709
-                $scope          = 'protected';
1710
-                $scopeSpecified = true;
1711
-                break;
1712
-            case T_STATIC:
1713
-                $isStatic = true;
1714
-                break;
1715
-            }
1716
-        }//end for
1717
-
1718
-        return [
1719
-            'scope'           => $scope,
1720
-            'scope_specified' => $scopeSpecified,
1721
-            'is_static'       => $isStatic,
1722
-        ];
1723
-
1724
-    }//end getMemberProperties()
1725
-
1726
-
1727
-    /**
1728
-     * Returns the visibility and implementation properties of a class.
1729
-     *
1730
-     * The format of the array is:
1731
-     * <code>
1732
-     *   array(
1733
-     *    'is_abstract' => false, // true if the abstract keyword was found.
1734
-     *    'is_final'    => false, // true if the final keyword was found.
1735
-     *   );
1736
-     * </code>
1737
-     *
1738
-     * @param int $stackPtr The position in the stack of the T_CLASS token to
1739
-     *                      acquire the properties for.
1740
-     *
1741
-     * @return array
1742
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743
-     *                                                        T_CLASS token.
1744
-     */
1745
-    public function getClassProperties($stackPtr)
1746
-    {
1747
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
-            throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749
-        }
1750
-
1751
-        $valid = [
1752
-            T_FINAL       => T_FINAL,
1753
-            T_ABSTRACT    => T_ABSTRACT,
1754
-            T_WHITESPACE  => T_WHITESPACE,
1755
-            T_COMMENT     => T_COMMENT,
1756
-            T_DOC_COMMENT => T_DOC_COMMENT,
1757
-        ];
1758
-
1759
-        $isAbstract = false;
1760
-        $isFinal    = false;
1761
-
1762
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1764
-                break;
1765
-            }
1766
-
1767
-            switch ($this->tokens[$i]['code']) {
1768
-            case T_ABSTRACT:
1769
-                $isAbstract = true;
1770
-                break;
1771
-
1772
-            case T_FINAL:
1773
-                $isFinal = true;
1774
-                break;
1775
-            }
1776
-        }//end for
1777
-
1778
-        return [
1779
-            'is_abstract' => $isAbstract,
1780
-            'is_final'    => $isFinal,
1781
-        ];
1782
-
1783
-    }//end getClassProperties()
1784
-
1785
-
1786
-    /**
1787
-     * Determine if the passed token is a reference operator.
1788
-     *
1789
-     * Returns true if the specified token position represents a reference.
1790
-     * Returns false if the token represents a bitwise operator.
1791
-     *
1792
-     * @param int $stackPtr The position of the T_BITWISE_AND token.
1793
-     *
1794
-     * @return boolean
1795
-     */
1796
-    public function isReference($stackPtr)
1797
-    {
1798
-        if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799
-            return false;
1800
-        }
1801
-
1802
-        $tokenBefore = $this->findPrevious(
1803
-            Util\Tokens::$emptyTokens,
1804
-            ($stackPtr - 1),
1805
-            null,
1806
-            true
1807
-        );
1808
-
1809
-        if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1810
-            // Function returns a reference.
1811
-            return true;
1812
-        }
1813
-
1814
-        if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1815
-            // Inside a foreach loop or array assignment, this is a reference.
1816
-            return true;
1817
-        }
1818
-
1819
-        if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1820
-            // Inside a foreach loop, this is a reference.
1821
-            return true;
1822
-        }
1823
-
1824
-        if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1825
-            // This is directly after an assignment. It's a reference. Even if
1826
-            // it is part of an operation, the other tests will handle it.
1827
-            return true;
1828
-        }
1829
-
1830
-        $tokenAfter = $this->findNext(
1831
-            Util\Tokens::$emptyTokens,
1832
-            ($stackPtr + 1),
1833
-            null,
1834
-            true
1835
-        );
1836
-
1837
-        if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1838
-            return true;
1839
-        }
1840
-
1841
-        if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
-            $brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
-            $lastBracket = array_pop($brackets);
1844
-            if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
-                $owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
-                if ($owner['code'] === T_FUNCTION
1847
-                    || $owner['code'] === T_CLOSURE
1848
-                ) {
1849
-                    $params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
-                    foreach ($params as $param) {
1851
-                        $varToken = $tokenAfter;
1852
-                        if ($param['variable_length'] === true) {
1853
-                            $varToken = $this->findNext(
1854
-                                (Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
-                                ($stackPtr + 1),
1856
-                                null,
1857
-                                true
1858
-                            );
1859
-                        }
1860
-
1861
-                        if ($param['token'] === $varToken
1862
-                            && $param['pass_by_reference'] === true
1863
-                        ) {
1864
-                            // Function parameter declared to be passed by reference.
1865
-                            return true;
1866
-                        }
1867
-                    }
1868
-                }//end if
1869
-            } else {
1870
-                $prev = false;
1871
-                for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
-                    if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1873
-                        $prev = $t;
1874
-                        break;
1875
-                    }
1876
-                }
1877
-
1878
-                if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1879
-                    // Closure use by reference.
1880
-                    return true;
1881
-                }
1882
-            }//end if
1883
-        }//end if
1884
-
1885
-        // Pass by reference in function calls and assign by reference in arrays.
1886
-        if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
-            || $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
-            || $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1889
-        ) {
1890
-            if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1891
-                return true;
1892
-            } else {
1893
-                $skip   = Util\Tokens::$emptyTokens;
1894
-                $skip[] = T_NS_SEPARATOR;
1895
-                $skip[] = T_SELF;
1896
-                $skip[] = T_PARENT;
1897
-                $skip[] = T_STATIC;
1898
-                $skip[] = T_STRING;
1899
-                $skip[] = T_NAMESPACE;
1900
-                $skip[] = T_DOUBLE_COLON;
1901
-
1902
-                $nextSignificantAfter = $this->findNext(
1903
-                    $skip,
1904
-                    ($stackPtr + 1),
1905
-                    null,
1906
-                    true
1907
-                );
1908
-                if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1909
-                    return true;
1910
-                }
1911
-            }//end if
1912
-        }//end if
1913
-
1914
-        return false;
1915
-
1916
-    }//end isReference()
1917
-
1918
-
1919
-    /**
1920
-     * Returns the content of the tokens from the specified start position in
1921
-     * the token stack for the specified length.
1922
-     *
1923
-     * @param int  $start       The position to start from in the token stack.
1924
-     * @param int  $length      The length of tokens to traverse from the start pos.
1925
-     * @param bool $origContent Whether the original content or the tab replaced
1926
-     *                          content should be used.
1927
-     *
1928
-     * @return string The token contents.
1929
-     */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1931
-    {
1932
-        if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
-            throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934
-        }
1935
-
1936
-        if (is_int($length) === false || $length <= 0) {
1937
-            return '';
1938
-        }
1939
-
1940
-        $str = '';
1941
-        $end = ($start + $length);
1942
-        if ($end > $this->numTokens) {
1943
-            $end = $this->numTokens;
1944
-        }
1945
-
1946
-        for ($i = $start; $i < $end; $i++) {
1947
-            // If tabs are being converted to spaces by the tokeniser, the
1948
-            // original content should be used instead of the converted content.
1949
-            if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
-                $str .= $this->tokens[$i]['orig_content'];
1951
-            } else {
1952
-                $str .= $this->tokens[$i]['content'];
1953
-            }
1954
-        }
1955
-
1956
-        return $str;
1957
-
1958
-    }//end getTokensAsString()
1959
-
1960
-
1961
-    /**
1962
-     * Returns the position of the previous specified token(s).
1963
-     *
1964
-     * If a value is specified, the previous token of the specified type(s)
1965
-     * containing the specified value will be returned.
1966
-     *
1967
-     * Returns false if no token can be found.
1968
-     *
1969
-     * @param int|string|array $types   The type(s) of tokens to search for.
1970
-     * @param int              $start   The position to start searching from in the
1971
-     *                                  token stack.
1972
-     * @param int              $end     The end position to fail if no token is found.
1973
-     *                                  if not specified or null, end will default to
1974
-     *                                  the start of the token stack.
1975
-     * @param bool             $exclude If true, find the previous token that is NOT of
1976
-     *                                  the types specified in $types.
1977
-     * @param string           $value   The value that the token(s) must be equal to.
1978
-     *                                  If value is omitted, tokens with any value will
1979
-     *                                  be returned.
1980
-     * @param bool             $local   If true, tokens outside the current statement
1981
-     *                                  will not be checked. IE. checking will stop
1982
-     *                                  at the previous semi-colon found.
1983
-     *
1984
-     * @return int|bool
1985
-     * @see    findNext()
1986
-     */
1987
-    public function findPrevious(
1988
-        $types,
1989
-        $start,
1990
-        $end=null,
1991
-        $exclude=false,
1992
-        $value=null,
1993
-        $local=false
1994
-    ) {
1995
-        $types = (array) $types;
1996
-
1997
-        if ($end === null) {
1998
-            $end = 0;
1999
-        }
2000
-
2001
-        for ($i = $start; $i >= $end; $i--) {
2002
-            $found = (bool) $exclude;
2003
-            foreach ($types as $type) {
2004
-                if ($this->tokens[$i]['code'] === $type) {
2005
-                    $found = !$exclude;
2006
-                    break;
2007
-                }
2008
-            }
2009
-
2010
-            if ($found === true) {
2011
-                if ($value === null) {
2012
-                    return $i;
2013
-                } else if ($this->tokens[$i]['content'] === $value) {
2014
-                    return $i;
2015
-                }
2016
-            }
2017
-
2018
-            if ($local === true) {
2019
-                if (isset($this->tokens[$i]['scope_opener']) === true
2020
-                    && $i === $this->tokens[$i]['scope_closer']
2021
-                ) {
2022
-                    $i = $this->tokens[$i]['scope_opener'];
2023
-                } else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
-                    && $i === $this->tokens[$i]['bracket_closer']
2025
-                ) {
2026
-                    $i = $this->tokens[$i]['bracket_opener'];
2027
-                } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
-                    && $i === $this->tokens[$i]['parenthesis_closer']
2029
-                ) {
2030
-                    $i = $this->tokens[$i]['parenthesis_opener'];
2031
-                } else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2032
-                    break;
2033
-                }
2034
-            }
2035
-        }//end for
2036
-
2037
-        return false;
2038
-
2039
-    }//end findPrevious()
2040
-
2041
-
2042
-    /**
2043
-     * Returns the position of the next specified token(s).
2044
-     *
2045
-     * If a value is specified, the next token of the specified type(s)
2046
-     * containing the specified value will be returned.
2047
-     *
2048
-     * Returns false if no token can be found.
2049
-     *
2050
-     * @param int|string|array $types   The type(s) of tokens to search for.
2051
-     * @param int              $start   The position to start searching from in the
2052
-     *                                  token stack.
2053
-     * @param int              $end     The end position to fail if no token is found.
2054
-     *                                  if not specified or null, end will default to
2055
-     *                                  the end of the token stack.
2056
-     * @param bool             $exclude If true, find the next token that is NOT of
2057
-     *                                  a type specified in $types.
2058
-     * @param string           $value   The value that the token(s) must be equal to.
2059
-     *                                  If value is omitted, tokens with any value will
2060
-     *                                  be returned.
2061
-     * @param bool             $local   If true, tokens outside the current statement
2062
-     *                                  will not be checked. i.e., checking will stop
2063
-     *                                  at the next semi-colon found.
2064
-     *
2065
-     * @return int|bool
2066
-     * @see    findPrevious()
2067
-     */
2068
-    public function findNext(
2069
-        $types,
2070
-        $start,
2071
-        $end=null,
2072
-        $exclude=false,
2073
-        $value=null,
2074
-        $local=false
2075
-    ) {
2076
-        $types = (array) $types;
2077
-
2078
-        if ($end === null || $end > $this->numTokens) {
2079
-            $end = $this->numTokens;
2080
-        }
2081
-
2082
-        for ($i = $start; $i < $end; $i++) {
2083
-            $found = (bool) $exclude;
2084
-            foreach ($types as $type) {
2085
-                if ($this->tokens[$i]['code'] === $type) {
2086
-                    $found = !$exclude;
2087
-                    break;
2088
-                }
2089
-            }
2090
-
2091
-            if ($found === true) {
2092
-                if ($value === null) {
2093
-                    return $i;
2094
-                } else if ($this->tokens[$i]['content'] === $value) {
2095
-                    return $i;
2096
-                }
2097
-            }
2098
-
2099
-            if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2100
-                break;
2101
-            }
2102
-        }//end for
2103
-
2104
-        return false;
2105
-
2106
-    }//end findNext()
2107
-
2108
-
2109
-    /**
2110
-     * Returns the position of the first non-whitespace token in a statement.
2111
-     *
2112
-     * @param int       $start  The position to start searching from in the token stack.
2113
-     * @param int|array $ignore Token types that should not be considered stop points.
2114
-     *
2115
-     * @return int
2116
-     */
2117
-    public function findStartOfStatement($start, $ignore=null)
2118
-    {
2119
-        $endTokens = Util\Tokens::$blockOpeners;
2120
-
2121
-        $endTokens[T_COLON]            = true;
2122
-        $endTokens[T_COMMA]            = true;
2123
-        $endTokens[T_DOUBLE_ARROW]     = true;
2124
-        $endTokens[T_SEMICOLON]        = true;
2125
-        $endTokens[T_OPEN_TAG]         = true;
2126
-        $endTokens[T_CLOSE_TAG]        = true;
2127
-        $endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
-
2129
-        if ($ignore !== null) {
2130
-            $ignore = (array) $ignore;
2131
-            foreach ($ignore as $code) {
2132
-                unset($endTokens[$code]);
2133
-            }
2134
-        }
2135
-
2136
-        $lastNotEmpty = $start;
2137
-
2138
-        for ($i = $start; $i >= 0; $i--) {
2139
-            if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2140
-                // Found the end of the previous statement.
2141
-                return $lastNotEmpty;
2142
-            }
2143
-
2144
-            if (isset($this->tokens[$i]['scope_opener']) === true
2145
-                && $i === $this->tokens[$i]['scope_closer']
2146
-            ) {
2147
-                // Found the end of the previous scope block.
2148
-                return $lastNotEmpty;
2149
-            }
2150
-
2151
-            // Skip nested statements.
2152
-            if (isset($this->tokens[$i]['bracket_opener']) === true
2153
-                && $i === $this->tokens[$i]['bracket_closer']
2154
-            ) {
2155
-                $i = $this->tokens[$i]['bracket_opener'];
2156
-            } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
-                && $i === $this->tokens[$i]['parenthesis_closer']
2158
-            ) {
2159
-                $i = $this->tokens[$i]['parenthesis_opener'];
2160
-            }
2161
-
2162
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2163
-                $lastNotEmpty = $i;
2164
-            }
2165
-        }//end for
2166
-
2167
-        return 0;
2168
-
2169
-    }//end findStartOfStatement()
2170
-
2171
-
2172
-    /**
2173
-     * Returns the position of the last non-whitespace token in a statement.
2174
-     *
2175
-     * @param int       $start  The position to start searching from in the token stack.
2176
-     * @param int|array $ignore Token types that should not be considered stop points.
2177
-     *
2178
-     * @return int
2179
-     */
2180
-    public function findEndOfStatement($start, $ignore=null)
2181
-    {
2182
-        $endTokens = [
2183
-            T_COLON                => true,
2184
-            T_COMMA                => true,
2185
-            T_DOUBLE_ARROW         => true,
2186
-            T_SEMICOLON            => true,
2187
-            T_CLOSE_PARENTHESIS    => true,
2188
-            T_CLOSE_SQUARE_BRACKET => true,
2189
-            T_CLOSE_CURLY_BRACKET  => true,
2190
-            T_CLOSE_SHORT_ARRAY    => true,
2191
-            T_OPEN_TAG             => true,
2192
-            T_CLOSE_TAG            => true,
2193
-        ];
2194
-
2195
-        if ($ignore !== null) {
2196
-            $ignore = (array) $ignore;
2197
-            foreach ($ignore as $code) {
2198
-                unset($endTokens[$code]);
2199
-            }
2200
-        }
2201
-
2202
-        $lastNotEmpty = $start;
2203
-
2204
-        for ($i = $start; $i < $this->numTokens; $i++) {
2205
-            if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2206
-                // Found the end of the statement.
2207
-                if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
-                    || $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
-                    || $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
-                    || $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
-                    || $this->tokens[$i]['code'] === T_OPEN_TAG
2212
-                    || $this->tokens[$i]['code'] === T_CLOSE_TAG
2213
-                ) {
2214
-                    return $lastNotEmpty;
2215
-                }
2216
-
2217
-                return $i;
2218
-            }
2219
-
2220
-            // Skip nested statements.
2221
-            if (isset($this->tokens[$i]['scope_closer']) === true
2222
-                && ($i === $this->tokens[$i]['scope_opener']
2223
-                || $i === $this->tokens[$i]['scope_condition'])
2224
-            ) {
2225
-                if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
-                    return $this->tokens[$i]['scope_closer'];
2227
-                }
2228
-
2229
-                $i = $this->tokens[$i]['scope_closer'];
2230
-            } else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
-                && $i === $this->tokens[$i]['bracket_opener']
2232
-            ) {
2233
-                $i = $this->tokens[$i]['bracket_closer'];
2234
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
-                && $i === $this->tokens[$i]['parenthesis_opener']
2236
-            ) {
2237
-                $i = $this->tokens[$i]['parenthesis_closer'];
2238
-            }
2239
-
2240
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2241
-                $lastNotEmpty = $i;
2242
-            }
2243
-        }//end for
2244
-
2245
-        return ($this->numTokens - 1);
2246
-
2247
-    }//end findEndOfStatement()
2248
-
2249
-
2250
-    /**
2251
-     * Returns the position of the first token on a line, matching given type.
2252
-     *
2253
-     * Returns false if no token can be found.
2254
-     *
2255
-     * @param int|string|array $types   The type(s) of tokens to search for.
2256
-     * @param int              $start   The position to start searching from in the
2257
-     *                                  token stack. The first token matching on
2258
-     *                                  this line before this token will be returned.
2259
-     * @param bool             $exclude If true, find the token that is NOT of
2260
-     *                                  the types specified in $types.
2261
-     * @param string           $value   The value that the token must be equal to.
2262
-     *                                  If value is omitted, tokens with any value will
2263
-     *                                  be returned.
2264
-     *
2265
-     * @return int | bool
2266
-     */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
-    {
2269
-        if (is_array($types) === false) {
2270
-            $types = [$types];
2271
-        }
2272
-
2273
-        $foundToken = false;
2274
-
2275
-        for ($i = $start; $i >= 0; $i--) {
2276
-            if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2277
-                break;
2278
-            }
2279
-
2280
-            $found = $exclude;
2281
-            foreach ($types as $type) {
2282
-                if ($exclude === false) {
2283
-                    if ($this->tokens[$i]['code'] === $type) {
2284
-                        $found = true;
2285
-                        break;
2286
-                    }
2287
-                } else {
2288
-                    if ($this->tokens[$i]['code'] === $type) {
2289
-                        $found = false;
2290
-                        break;
2291
-                    }
2292
-                }
2293
-            }
2294
-
2295
-            if ($found === true) {
2296
-                if ($value === null) {
2297
-                    $foundToken = $i;
2298
-                } else if ($this->tokens[$i]['content'] === $value) {
2299
-                    $foundToken = $i;
2300
-                }
2301
-            }
2302
-        }//end for
2303
-
2304
-        return $foundToken;
2305
-
2306
-    }//end findFirstOnLine()
2307
-
2308
-
2309
-    /**
2310
-     * Determine if the passed token has a condition of one of the passed types.
2311
-     *
2312
-     * @param int              $stackPtr The position of the token we are checking.
2313
-     * @param int|string|array $types    The type(s) of tokens to search for.
2314
-     *
2315
-     * @return boolean
2316
-     */
2317
-    public function hasCondition($stackPtr, $types)
2318
-    {
2319
-        // Check for the existence of the token.
2320
-        if (isset($this->tokens[$stackPtr]) === false) {
2321
-            return false;
2322
-        }
2323
-
2324
-        // Make sure the token has conditions.
2325
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2326
-            return false;
2327
-        }
2328
-
2329
-        $types      = (array) $types;
2330
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2331
-
2332
-        foreach ($types as $type) {
2333
-            if (in_array($type, $conditions, true) === true) {
2334
-                // We found a token with the required type.
2335
-                return true;
2336
-            }
2337
-        }
2338
-
2339
-        return false;
2340
-
2341
-    }//end hasCondition()
2342
-
2343
-
2344
-    /**
2345
-     * Return the position of the condition for the passed token.
2346
-     *
2347
-     * Returns FALSE if the token does not have the condition.
2348
-     *
2349
-     * @param int        $stackPtr The position of the token we are checking.
2350
-     * @param int|string $type     The type of token to search for.
2351
-     *
2352
-     * @return int
2353
-     */
2354
-    public function getCondition($stackPtr, $type)
2355
-    {
2356
-        // Check for the existence of the token.
2357
-        if (isset($this->tokens[$stackPtr]) === false) {
2358
-            return false;
2359
-        }
2360
-
2361
-        // Make sure the token has conditions.
2362
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2363
-            return false;
2364
-        }
2365
-
2366
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2367
-        foreach ($conditions as $token => $condition) {
2368
-            if ($condition === $type) {
2369
-                return $token;
2370
-            }
2371
-        }
2372
-
2373
-        return false;
2374
-
2375
-    }//end getCondition()
2376
-
2377
-
2378
-    /**
2379
-     * Returns the name of the class that the specified class extends.
2380
-     * (works for classes, anonymous classes and interfaces)
2381
-     *
2382
-     * Returns FALSE on error or if there is no extended class name.
2383
-     *
2384
-     * @param int $stackPtr The stack position of the class.
2385
-     *
2386
-     * @return string|false
2387
-     */
2388
-    public function findExtendedClassName($stackPtr)
2389
-    {
2390
-        // Check for the existence of the token.
2391
-        if (isset($this->tokens[$stackPtr]) === false) {
2392
-            return false;
2393
-        }
2394
-
2395
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
-            && $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2398
-        ) {
2399
-            return false;
2400
-        }
2401
-
2402
-        if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2403
-            return false;
2404
-        }
2405
-
2406
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
-        $extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
-        if (false === $extendsIndex) {
2409
-            return false;
2410
-        }
2411
-
2412
-        $find = [
2413
-            T_NS_SEPARATOR,
2414
-            T_STRING,
2415
-            T_WHITESPACE,
2416
-        ];
2417
-
2418
-        $end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
-        $name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
-        $name = trim($name);
2421
-
2422
-        if ($name === '') {
2423
-            return false;
2424
-        }
2425
-
2426
-        return $name;
2427
-
2428
-    }//end findExtendedClassName()
2429
-
2430
-
2431
-    /**
2432
-     * Returns the names of the interfaces that the specified class implements.
2433
-     *
2434
-     * Returns FALSE on error or if there are no implemented interface names.
2435
-     *
2436
-     * @param int $stackPtr The stack position of the class.
2437
-     *
2438
-     * @return array|false
2439
-     */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2441
-    {
2442
-        // Check for the existence of the token.
2443
-        if (isset($this->tokens[$stackPtr]) === false) {
2444
-            return false;
2445
-        }
2446
-
2447
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2449
-        ) {
2450
-            return false;
2451
-        }
2452
-
2453
-        if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2454
-            return false;
2455
-        }
2456
-
2457
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
-        $implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
-        if ($implementsIndex === false) {
2460
-            return false;
2461
-        }
2462
-
2463
-        $find = [
2464
-            T_NS_SEPARATOR,
2465
-            T_STRING,
2466
-            T_WHITESPACE,
2467
-            T_COMMA,
2468
-        ];
2469
-
2470
-        $end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
-        $name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
-        $name = trim($name);
2473
-
2474
-        if ($name === '') {
2475
-            return false;
2476
-        } else {
2477
-            $names = explode(',', $name);
2478
-            $names = array_map('trim', $names);
2479
-            return $names;
2480
-        }
2481
-
2482
-    }//end findImplementedInterfaceNames()
22
+	/**
23
+	 * The absolute path to the file associated with this object.
24
+	 *
25
+	 * @var string
26
+	 */
27
+	public $path = '';
28
+
29
+	/**
30
+	 * The content of the file.
31
+	 *
32
+	 * @var string
33
+	 */
34
+	protected $content = '';
35
+
36
+	/**
37
+	 * The config data for the run.
38
+	 *
39
+	 * @var \PHP_CodeSniffer\Config
40
+	 */
41
+	public $config = null;
42
+
43
+	/**
44
+	 * The ruleset used for the run.
45
+	 *
46
+	 * @var \PHP_CodeSniffer\Ruleset
47
+	 */
48
+	public $ruleset = null;
49
+
50
+	/**
51
+	 * If TRUE, the entire file is being ignored.
52
+	 *
53
+	 * @var boolean
54
+	 */
55
+	public $ignored = false;
56
+
57
+	/**
58
+	 * The EOL character this file uses.
59
+	 *
60
+	 * @var string
61
+	 */
62
+	public $eolChar = '';
63
+
64
+	/**
65
+	 * The Fixer object to control fixing errors.
66
+	 *
67
+	 * @var \PHP_CodeSniffer\Fixer
68
+	 */
69
+	public $fixer = null;
70
+
71
+	/**
72
+	 * The tokenizer being used for this file.
73
+	 *
74
+	 * @var \PHP_CodeSniffer\Tokenizers\Tokenizer
75
+	 */
76
+	public $tokenizer = null;
77
+
78
+	/**
79
+	 * The name of the tokenizer being used for this file.
80
+	 *
81
+	 * @var string
82
+	 */
83
+	public $tokenizerType = 'PHP';
84
+
85
+	/**
86
+	 * Was the file loaded from cache?
87
+	 *
88
+	 * If TRUE, the file was loaded from a local cache.
89
+	 * If FALSE, the file was tokenized and processed fully.
90
+	 *
91
+	 * @var boolean
92
+	 */
93
+	public $fromCache = false;
94
+
95
+	/**
96
+	 * The number of tokens in this file.
97
+	 *
98
+	 * Stored here to save calling count() everywhere.
99
+	 *
100
+	 * @var integer
101
+	 */
102
+	public $numTokens = 0;
103
+
104
+	/**
105
+	 * The tokens stack map.
106
+	 *
107
+	 * @var array
108
+	 */
109
+	protected $tokens = [];
110
+
111
+	/**
112
+	 * The errors raised from sniffs.
113
+	 *
114
+	 * @var array
115
+	 * @see getErrors()
116
+	 */
117
+	protected $errors = [];
118
+
119
+	/**
120
+	 * The warnings raised from sniffs.
121
+	 *
122
+	 * @var array
123
+	 * @see getWarnings()
124
+	 */
125
+	protected $warnings = [];
126
+
127
+	/**
128
+	 * The metrics recorded by sniffs.
129
+	 *
130
+	 * @var array
131
+	 * @see getMetrics()
132
+	 */
133
+	protected $metrics = [];
134
+
135
+	/**
136
+	 * The metrics recorded for each token.
137
+	 *
138
+	 * Stops the same metric being recorded for the same token twice.
139
+	 *
140
+	 * @var array
141
+	 * @see getMetrics()
142
+	 */
143
+	private $metricTokens = [];
144
+
145
+	/**
146
+	 * The total number of errors raised.
147
+	 *
148
+	 * @var integer
149
+	 */
150
+	protected $errorCount = 0;
151
+
152
+	/**
153
+	 * The total number of warnings raised.
154
+	 *
155
+	 * @var integer
156
+	 */
157
+	protected $warningCount = 0;
158
+
159
+	/**
160
+	 * The total number of errors and warnings that can be fixed.
161
+	 *
162
+	 * @var integer
163
+	 */
164
+	protected $fixableCount = 0;
165
+
166
+	/**
167
+	 * The total number of errors and warnings that were fixed.
168
+	 *
169
+	 * @var integer
170
+	 */
171
+	protected $fixedCount = 0;
172
+
173
+	/**
174
+	 * An array of sniffs that are being ignored.
175
+	 *
176
+	 * @var array
177
+	 */
178
+	protected $ignoredListeners = [];
179
+
180
+	/**
181
+	 * An array of message codes that are being ignored.
182
+	 *
183
+	 * @var array
184
+	 */
185
+	protected $ignoredCodes = [];
186
+
187
+	/**
188
+	 * An array of sniffs listening to this file's processing.
189
+	 *
190
+	 * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191
+	 */
192
+	protected $listeners = [];
193
+
194
+	/**
195
+	 * The class name of the sniff currently processing the file.
196
+	 *
197
+	 * @var string
198
+	 */
199
+	protected $activeListener = '';
200
+
201
+	/**
202
+	 * An array of sniffs being processed and how long they took.
203
+	 *
204
+	 * @var array
205
+	 */
206
+	protected $listenerTimes = [];
207
+
208
+	/**
209
+	 * A cache of often used config settings to improve performance.
210
+	 *
211
+	 * Storing them here saves 10k+ calls to __get() in the Config class.
212
+	 *
213
+	 * @var array
214
+	 */
215
+	protected $configCache = [];
216
+
217
+
218
+	/**
219
+	 * Constructs a file.
220
+	 *
221
+	 * @param string                   $path    The absolute path to the file to process.
222
+	 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
223
+	 * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
224
+	 *
225
+	 * @return void
226
+	 */
227
+	public function __construct($path, Ruleset $ruleset, Config $config)
228
+	{
229
+		$this->path    = $path;
230
+		$this->ruleset = $ruleset;
231
+		$this->config  = $config;
232
+		$this->fixer   = new Fixer();
233
+
234
+		$parts     = explode('.', $path);
235
+		$extension = array_pop($parts);
236
+		if (isset($config->extensions[$extension]) === true) {
237
+			$this->tokenizerType = $config->extensions[$extension];
238
+		} else {
239
+			// Revert to default.
240
+			$this->tokenizerType = 'PHP';
241
+		}
242
+
243
+		$this->configCache['cache']           = $this->config->cache;
244
+		$this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
+		$this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
+		$this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
+		$this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
+		$this->configCache['recordErrors']    = $this->config->recordErrors;
249
+		$this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
+		$this->configCache['includePatterns'] = $this->ruleset->includePatterns;
251
+
252
+	}//end __construct()
253
+
254
+
255
+	/**
256
+	 * Set the content of the file.
257
+	 *
258
+	 * Setting the content also calculates the EOL char being used.
259
+	 *
260
+	 * @param string $content The file content.
261
+	 *
262
+	 * @return void
263
+	 */
264
+	public function setContent($content)
265
+	{
266
+		$this->content = $content;
267
+		$this->tokens  = [];
268
+
269
+		try {
270
+			$this->eolChar = Util\Common::detectLineEndings($content);
271
+		} catch (RuntimeException $e) {
272
+			$this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
273
+			return;
274
+		}
275
+
276
+	}//end setContent()
277
+
278
+
279
+	/**
280
+	 * Reloads the content of the file.
281
+	 *
282
+	 * By default, we have no idea where our content comes from,
283
+	 * so we can't do anything.
284
+	 *
285
+	 * @return void
286
+	 */
287
+	public function reloadContent()
288
+	{
289
+
290
+	}//end reloadContent()
291
+
292
+
293
+	/**
294
+	 * Disables caching of this file.
295
+	 *
296
+	 * @return void
297
+	 */
298
+	public function disableCaching()
299
+	{
300
+		$this->configCache['cache'] = false;
301
+
302
+	}//end disableCaching()
303
+
304
+
305
+	/**
306
+	 * Starts the stack traversal and tells listeners when tokens are found.
307
+	 *
308
+	 * @return void
309
+	 */
310
+	public function process()
311
+	{
312
+		if ($this->ignored === true) {
313
+			return;
314
+		}
315
+
316
+		$this->errors       = [];
317
+		$this->warnings     = [];
318
+		$this->errorCount   = 0;
319
+		$this->warningCount = 0;
320
+		$this->fixableCount = 0;
321
+
322
+		$this->parse();
323
+
324
+		// Check if tokenizer errors cause this file to be ignored.
325
+		if ($this->ignored === true) {
326
+			return;
327
+		}
328
+
329
+		$this->fixer->startFile($this);
330
+
331
+		if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
+			echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
333
+		}
334
+
335
+		$foundCode        = false;
336
+		$listenerIgnoreTo = [];
337
+		$inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
338
+		$checkAnnotations = $this->config->annotations;
339
+
340
+		// Foreach of the listeners that have registered to listen for this
341
+		// token, get them to process it.
342
+		foreach ($this->tokens as $stackPtr => $token) {
343
+			// Check for ignored lines.
344
+			if ($checkAnnotations === true
345
+				&& ($token['code'] === T_COMMENT
346
+				|| $token['code'] === T_PHPCS_IGNORE_FILE
347
+				|| $token['code'] === T_PHPCS_SET
348
+				|| $token['code'] === T_DOC_COMMENT_STRING
349
+				|| $token['code'] === T_DOC_COMMENT_TAG
350
+				|| ($inTests === true && $token['code'] === T_INLINE_HTML))
351
+			) {
352
+				$commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
+				$commentTextLower = strtolower($commentText);
354
+				if (strpos($commentText, '@codingStandards') !== false) {
355
+					if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
356
+						// Ignoring the whole file, just a little late.
357
+						$this->errors       = [];
358
+						$this->warnings     = [];
359
+						$this->errorCount   = 0;
360
+						$this->warningCount = 0;
361
+						$this->fixableCount = 0;
362
+						return;
363
+					} else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
+						$start   = strpos($commentText, '@codingStandardsChangeSetting');
365
+						$comment = substr($commentText, ($start + 30));
366
+						$parts   = explode(' ', $comment);
367
+						if (count($parts) >= 2) {
368
+							$sniffParts = explode('.', $parts[0]);
369
+							if (count($sniffParts) >= 3) {
370
+								// If the sniff code is not known to us, it has not been registered in this run.
371
+								// But don't throw an error as it could be there for a different standard to use.
372
+								if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
+									$listenerCode  = array_shift($parts);
374
+									$propertyCode  = array_shift($parts);
375
+									$propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
+									$listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
+									$this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
378
+								}
379
+							}
380
+						}
381
+					}//end if
382
+				} else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
+					|| substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
384
+				) {
385
+					// Ignoring the whole file, just a little late.
386
+					$this->errors       = [];
387
+					$this->warnings     = [];
388
+					$this->errorCount   = 0;
389
+					$this->warningCount = 0;
390
+					$this->fixableCount = 0;
391
+					return;
392
+				} else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
+					|| substr($commentTextLower, 0, 10) === '@phpcs:set'
394
+				) {
395
+					if (isset($token['sniffCode']) === true) {
396
+						$listenerCode = $token['sniffCode'];
397
+						if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
+							$propertyCode  = $token['sniffProperty'];
399
+							$propertyValue = $token['sniffPropertyValue'];
400
+							$listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
+							$this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
402
+						}
403
+					}
404
+				}//end if
405
+			}//end if
406
+
407
+			if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
+				$type    = $token['type'];
409
+				$content = Util\Common::prepareForOutput($token['content']);
410
+				echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
411
+			}
412
+
413
+			if ($token['code'] !== T_INLINE_HTML) {
414
+				$foundCode = true;
415
+			}
416
+
417
+			if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
418
+				continue;
419
+			}
420
+
421
+			foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
+				if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
+					|| (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
+					&& $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
425
+				) {
426
+					// This sniff is ignoring past this token, or the whole file.
427
+					continue;
428
+				}
429
+
430
+				// Make sure this sniff supports the tokenizer
431
+				// we are currently using.
432
+				$class = $listenerData['class'];
433
+
434
+				if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
435
+					continue;
436
+				}
437
+
438
+				// If the file path matches one of our ignore patterns, skip it.
439
+				// While there is support for a type of each pattern
440
+				// (absolute or relative) we don't actually support it here.
441
+				foreach ($listenerData['ignore'] as $pattern) {
442
+					// We assume a / directory separator, as do the exclude rules
443
+					// most developers write, so we need a special case for any system
444
+					// that is different.
445
+					if (DIRECTORY_SEPARATOR === '\\') {
446
+						$pattern = str_replace('/', '\\\\', $pattern);
447
+					}
448
+
449
+					$pattern = '`'.$pattern.'`i';
450
+					if (preg_match($pattern, $this->path) === 1) {
451
+						$this->ignoredListeners[$class] = true;
452
+						continue(2);
453
+					}
454
+				}
455
+
456
+				// If the file path does not match one of our include patterns, skip it.
457
+				// While there is support for a type of each pattern
458
+				// (absolute or relative) we don't actually support it here.
459
+				if (empty($listenerData['include']) === false) {
460
+					$included = false;
461
+					foreach ($listenerData['include'] as $pattern) {
462
+						// We assume a / directory separator, as do the exclude rules
463
+						// most developers write, so we need a special case for any system
464
+						// that is different.
465
+						if (DIRECTORY_SEPARATOR === '\\') {
466
+							$pattern = str_replace('/', '\\\\', $pattern);
467
+						}
468
+
469
+						$pattern = '`'.$pattern.'`i';
470
+						if (preg_match($pattern, $this->path) === 1) {
471
+							$included = true;
472
+							break;
473
+						}
474
+					}
475
+
476
+					if ($included === false) {
477
+						$this->ignoredListeners[$class] = true;
478
+						continue;
479
+					}
480
+				}//end if
481
+
482
+				$this->activeListener = $class;
483
+
484
+				if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
+					$startTime = microtime(true);
486
+					echo "\t\t\tProcessing ".$this->activeListener.'... ';
487
+				}
488
+
489
+				$ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
+				if ($ignoreTo !== null) {
491
+					$listenerIgnoreTo[$this->activeListener] = $ignoreTo;
492
+				}
493
+
494
+				if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
+					$timeTaken = (microtime(true) - $startTime);
496
+					if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
+						$this->listenerTimes[$this->activeListener] = 0;
498
+					}
499
+
500
+					$this->listenerTimes[$this->activeListener] += $timeTaken;
501
+
502
+					$timeTaken = round(($timeTaken), 4);
503
+					echo "DONE in $timeTaken seconds".PHP_EOL;
504
+				}
505
+
506
+				$this->activeListener = '';
507
+			}//end foreach
508
+		}//end foreach
509
+
510
+		// If short open tags are off but the file being checked uses
511
+		// short open tags, the whole content will be inline HTML
512
+		// and nothing will be checked. So try and handle this case.
513
+		// We don't show this error for STDIN because we can't be sure the content
514
+		// actually came directly from the user. It could be something like
515
+		// refs from a Git pre-push hook.
516
+		if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
+			$shortTags = (bool) ini_get('short_open_tag');
518
+			if ($shortTags === false) {
519
+				$error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
+				$this->addWarning($error, null, 'Internal.NoCodeFound');
521
+			}
522
+		}
523
+
524
+		if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
+			echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
+			echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
527
+
528
+			asort($this->listenerTimes, SORT_NUMERIC);
529
+			$this->listenerTimes = array_reverse($this->listenerTimes, true);
530
+			foreach ($this->listenerTimes as $listener => $timeTaken) {
531
+				echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
532
+			}
533
+
534
+			echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
535
+		}
536
+
537
+		$this->fixedCount += $this->fixer->getFixCount();
538
+
539
+	}//end process()
540
+
541
+
542
+	/**
543
+	 * Tokenizes the file and prepares it for the test run.
544
+	 *
545
+	 * @return void
546
+	 */
547
+	public function parse()
548
+	{
549
+		if (empty($this->tokens) === false) {
550
+			// File has already been parsed.
551
+			return;
552
+		}
553
+
554
+		try {
555
+			$tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
+			$this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
557
+			$this->tokens    = $this->tokenizer->getTokens();
558
+		} catch (TokenizerException $e) {
559
+			$this->ignored = true;
560
+			$this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
562
+				echo "[$this->tokenizerType => tokenizer error]... ";
563
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
564
+					echo PHP_EOL;
565
+				}
566
+			}
567
+
568
+			return;
569
+		}
570
+
571
+		$this->numTokens = count($this->tokens);
572
+
573
+		// Check for mixed line endings as these can cause tokenizer errors and we
574
+		// should let the user know that the results they get may be incorrect.
575
+		// This is done by removing all backslashes, removing the newline char we
576
+		// detected, then converting newlines chars into text. If any backslashes
577
+		// are left at the end, we have additional newline chars in use.
578
+		$contents = str_replace('\\', '', $this->content);
579
+		$contents = str_replace($this->eolChar, '', $contents);
580
+		$contents = str_replace("\n", '\n', $contents);
581
+		$contents = str_replace("\r", '\r', $contents);
582
+		if (strpos($contents, '\\') !== false) {
583
+			$error = 'File has mixed line endings; this may cause incorrect results';
584
+			$this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
585
+		}
586
+
587
+		if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
+			if ($this->numTokens === 0) {
589
+				$numLines = 0;
590
+			} else {
591
+				$numLines = $this->tokens[($this->numTokens - 1)]['line'];
592
+			}
593
+
594
+			echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
+				echo PHP_EOL;
597
+			}
598
+		}
599
+
600
+	}//end parse()
601
+
602
+
603
+	/**
604
+	 * Returns the token stack for this file.
605
+	 *
606
+	 * @return array
607
+	 */
608
+	public function getTokens()
609
+	{
610
+		return $this->tokens;
611
+
612
+	}//end getTokens()
613
+
614
+
615
+	/**
616
+	 * Remove vars stored in this file that are no longer required.
617
+	 *
618
+	 * @return void
619
+	 */
620
+	public function cleanUp()
621
+	{
622
+		$this->listenerTimes = null;
623
+		$this->content       = null;
624
+		$this->tokens        = null;
625
+		$this->metricTokens  = null;
626
+		$this->tokenizer     = null;
627
+		$this->fixer         = null;
628
+		$this->config        = null;
629
+		$this->ruleset       = null;
630
+
631
+	}//end cleanUp()
632
+
633
+
634
+	/**
635
+	 * Records an error against a specific token in the file.
636
+	 *
637
+	 * @param string  $error    The error message.
638
+	 * @param int     $stackPtr The stack position where the error occurred.
639
+	 * @param string  $code     A violation code unique to the sniff message.
640
+	 * @param array   $data     Replacements for the error message.
641
+	 * @param int     $severity The severity level for this error. A value of 0
642
+	 *                          will be converted into the default severity level.
643
+	 * @param boolean $fixable  Can the error be fixed by the sniff?
644
+	 *
645
+	 * @return boolean
646
+	 */
647
+	public function addError(
648
+		$error,
649
+		$stackPtr,
650
+		$code,
651
+		$data=[],
652
+		$severity=0,
653
+		$fixable=false
654
+	) {
655
+		if ($stackPtr === null) {
656
+			$line   = 1;
657
+			$column = 1;
658
+		} else {
659
+			$line   = $this->tokens[$stackPtr]['line'];
660
+			$column = $this->tokens[$stackPtr]['column'];
661
+		}
662
+
663
+		return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
664
+
665
+	}//end addError()
666
+
667
+
668
+	/**
669
+	 * Records a warning against a specific token in the file.
670
+	 *
671
+	 * @param string  $warning  The error message.
672
+	 * @param int     $stackPtr The stack position where the error occurred.
673
+	 * @param string  $code     A violation code unique to the sniff message.
674
+	 * @param array   $data     Replacements for the warning message.
675
+	 * @param int     $severity The severity level for this warning. A value of 0
676
+	 *                          will be converted into the default severity level.
677
+	 * @param boolean $fixable  Can the warning be fixed by the sniff?
678
+	 *
679
+	 * @return boolean
680
+	 */
681
+	public function addWarning(
682
+		$warning,
683
+		$stackPtr,
684
+		$code,
685
+		$data=[],
686
+		$severity=0,
687
+		$fixable=false
688
+	) {
689
+		if ($stackPtr === null) {
690
+			$line   = 1;
691
+			$column = 1;
692
+		} else {
693
+			$line   = $this->tokens[$stackPtr]['line'];
694
+			$column = $this->tokens[$stackPtr]['column'];
695
+		}
696
+
697
+		return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
698
+
699
+	}//end addWarning()
700
+
701
+
702
+	/**
703
+	 * Records an error against a specific line in the file.
704
+	 *
705
+	 * @param string $error    The error message.
706
+	 * @param int    $line     The line on which the error occurred.
707
+	 * @param string $code     A violation code unique to the sniff message.
708
+	 * @param array  $data     Replacements for the error message.
709
+	 * @param int    $severity The severity level for this error. A value of 0
710
+	 *                         will be converted into the default severity level.
711
+	 *
712
+	 * @return boolean
713
+	 */
714
+	public function addErrorOnLine(
715
+		$error,
716
+		$line,
717
+		$code,
718
+		$data=[],
719
+		$severity=0
720
+	) {
721
+		return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
722
+
723
+	}//end addErrorOnLine()
724
+
725
+
726
+	/**
727
+	 * Records a warning against a specific token in the file.
728
+	 *
729
+	 * @param string $warning  The error message.
730
+	 * @param int    $line     The line on which the warning occurred.
731
+	 * @param string $code     A violation code unique to the sniff message.
732
+	 * @param array  $data     Replacements for the warning message.
733
+	 * @param int    $severity The severity level for this warning. A value of 0 will
734
+	 *                         will be converted into the default severity level.
735
+	 *
736
+	 * @return boolean
737
+	 */
738
+	public function addWarningOnLine(
739
+		$warning,
740
+		$line,
741
+		$code,
742
+		$data=[],
743
+		$severity=0
744
+	) {
745
+		return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
746
+
747
+	}//end addWarningOnLine()
748
+
749
+
750
+	/**
751
+	 * Records a fixable error against a specific token in the file.
752
+	 *
753
+	 * Returns true if the error was recorded and should be fixed.
754
+	 *
755
+	 * @param string $error    The error message.
756
+	 * @param int    $stackPtr The stack position where the error occurred.
757
+	 * @param string $code     A violation code unique to the sniff message.
758
+	 * @param array  $data     Replacements for the error message.
759
+	 * @param int    $severity The severity level for this error. A value of 0
760
+	 *                         will be converted into the default severity level.
761
+	 *
762
+	 * @return boolean
763
+	 */
764
+	public function addFixableError(
765
+		$error,
766
+		$stackPtr,
767
+		$code,
768
+		$data=[],
769
+		$severity=0
770
+	) {
771
+		$recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
+		if ($recorded === true && $this->fixer->enabled === true) {
773
+			return true;
774
+		}
775
+
776
+		return false;
777
+
778
+	}//end addFixableError()
779
+
780
+
781
+	/**
782
+	 * Records a fixable warning against a specific token in the file.
783
+	 *
784
+	 * Returns true if the warning was recorded and should be fixed.
785
+	 *
786
+	 * @param string $warning  The error message.
787
+	 * @param int    $stackPtr The stack position where the error occurred.
788
+	 * @param string $code     A violation code unique to the sniff message.
789
+	 * @param array  $data     Replacements for the warning message.
790
+	 * @param int    $severity The severity level for this warning. A value of 0
791
+	 *                         will be converted into the default severity level.
792
+	 *
793
+	 * @return boolean
794
+	 */
795
+	public function addFixableWarning(
796
+		$warning,
797
+		$stackPtr,
798
+		$code,
799
+		$data=[],
800
+		$severity=0
801
+	) {
802
+		$recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
+		if ($recorded === true && $this->fixer->enabled === true) {
804
+			return true;
805
+		}
806
+
807
+		return false;
808
+
809
+	}//end addFixableWarning()
810
+
811
+
812
+	/**
813
+	 * Adds an error to the error stack.
814
+	 *
815
+	 * @param boolean $error    Is this an error message?
816
+	 * @param string  $message  The text of the message.
817
+	 * @param int     $line     The line on which the message occurred.
818
+	 * @param int     $column   The column at which the message occurred.
819
+	 * @param string  $code     A violation code unique to the sniff message.
820
+	 * @param array   $data     Replacements for the message.
821
+	 * @param int     $severity The severity level for this message. A value of 0
822
+	 *                          will be converted into the default severity level.
823
+	 * @param boolean $fixable  Can the problem be fixed by the sniff?
824
+	 *
825
+	 * @return boolean
826
+	 */
827
+	protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
+	{
829
+		// Check if this line is ignoring all message codes.
830
+		if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831
+			return false;
832
+		}
833
+
834
+		// Work out which sniff generated the message.
835
+		$parts = explode('.', $code);
836
+		if ($parts[0] === 'Internal') {
837
+			// An internal message.
838
+			$listenerCode = Util\Common::getSniffCode($this->activeListener);
839
+			$sniffCode    = $code;
840
+			$checkCodes   = [$sniffCode];
841
+		} else {
842
+			if ($parts[0] !== $code) {
843
+				// The full message code has been passed in.
844
+				$sniffCode    = $code;
845
+				$listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
846
+			} else {
847
+				$listenerCode = Util\Common::getSniffCode($this->activeListener);
848
+				$sniffCode    = $listenerCode.'.'.$code;
849
+				$parts        = explode('.', $sniffCode);
850
+			}
851
+
852
+			$checkCodes = [
853
+				$sniffCode,
854
+				$parts[0].'.'.$parts[1].'.'.$parts[2],
855
+				$parts[0].'.'.$parts[1],
856
+				$parts[0],
857
+			];
858
+		}//end if
859
+
860
+		if (isset($this->tokenizer->ignoredLines[$line]) === true) {
861
+			// Check if this line is ignoring this specific message.
862
+			$ignored = false;
863
+			foreach ($checkCodes as $checkCode) {
864
+				if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
865
+					$ignored = true;
866
+					break;
867
+				}
868
+			}
869
+
870
+			// If it is ignored, make sure it's not whitelisted.
871
+			if ($ignored === true
872
+				&& isset($this->tokenizer->ignoredLines[$line]['.except']) === true
873
+			) {
874
+				foreach ($checkCodes as $checkCode) {
875
+					if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
876
+						$ignored = false;
877
+						break;
878
+					}
879
+				}
880
+			}
881
+
882
+			if ($ignored === true) {
883
+				return false;
884
+			}
885
+		}//end if
886
+
887
+		$includeAll = true;
888
+		if ($this->configCache['cache'] === false
889
+			|| $this->configCache['recordErrors'] === false
890
+		) {
891
+			$includeAll = false;
892
+		}
893
+
894
+		// Filter out any messages for sniffs that shouldn't have run
895
+		// due to the use of the --sniffs command line argument.
896
+		if ($includeAll === false
897
+			&& ((empty($this->configCache['sniffs']) === false
898
+			&& in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
+			|| (empty($this->configCache['exclude']) === false
900
+			&& in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
901
+		) {
902
+			return false;
903
+		}
904
+
905
+		// If we know this sniff code is being ignored for this file, return early.
906
+		foreach ($checkCodes as $checkCode) {
907
+			if (isset($this->ignoredCodes[$checkCode]) === true) {
908
+				return false;
909
+			}
910
+		}
911
+
912
+		$oppositeType = 'warning';
913
+		if ($error === false) {
914
+			$oppositeType = 'error';
915
+		}
916
+
917
+		foreach ($checkCodes as $checkCode) {
918
+			// Make sure this message type has not been set to the opposite message type.
919
+			if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
+				&& $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
921
+			) {
922
+				$error = !$error;
923
+				break;
924
+			}
925
+		}
926
+
927
+		if ($error === true) {
928
+			$configSeverity = $this->configCache['errorSeverity'];
929
+			$messageCount   = &$this->errorCount;
930
+			$messages       = &$this->errors;
931
+		} else {
932
+			$configSeverity = $this->configCache['warningSeverity'];
933
+			$messageCount   = &$this->warningCount;
934
+			$messages       = &$this->warnings;
935
+		}
936
+
937
+		if ($includeAll === false && $configSeverity === 0) {
938
+			// Don't bother doing any processing as these messages are just going to
939
+			// be hidden in the reports anyway.
940
+			return false;
941
+		}
942
+
943
+		if ($severity === 0) {
944
+			$severity = 5;
945
+		}
946
+
947
+		foreach ($checkCodes as $checkCode) {
948
+			// Make sure we are interested in this severity level.
949
+			if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
+				$severity = $this->ruleset->ruleset[$checkCode]['severity'];
951
+				break;
952
+			}
953
+		}
954
+
955
+		if ($includeAll === false && $configSeverity > $severity) {
956
+			return false;
957
+		}
958
+
959
+		// Make sure we are not ignoring this file.
960
+		$included = null;
961
+		foreach ($checkCodes as $checkCode) {
962
+			$patterns = null;
963
+
964
+			if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
+				$patterns  = $this->configCache['includePatterns'][$checkCode];
966
+				$excluding = false;
967
+			} else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
+				$patterns  = $this->configCache['ignorePatterns'][$checkCode];
969
+				$excluding = true;
970
+			}
971
+
972
+			if ($patterns === null) {
973
+				continue;
974
+			}
975
+
976
+			foreach ($patterns as $pattern => $type) {
977
+				// While there is support for a type of each pattern
978
+				// (absolute or relative) we don't actually support it here.
979
+				$replacements = [
980
+					'\\,' => ',',
981
+					'*'   => '.*',
982
+				];
983
+
984
+				// We assume a / directory separator, as do the exclude rules
985
+				// most developers write, so we need a special case for any system
986
+				// that is different.
987
+				if (DIRECTORY_SEPARATOR === '\\') {
988
+					$replacements['/'] = '\\\\';
989
+				}
990
+
991
+				$pattern = '`'.strtr($pattern, $replacements).'`i';
992
+				$matched = preg_match($pattern, $this->path);
993
+
994
+				if ($matched === 0) {
995
+					if ($excluding === false && $included === null) {
996
+						// This file path is not being included.
997
+						$included = false;
998
+					}
999
+
1000
+					continue;
1001
+				}
1002
+
1003
+				if ($excluding === true) {
1004
+					// This file path is being excluded.
1005
+					$this->ignoredCodes[$checkCode] = true;
1006
+					return false;
1007
+				}
1008
+
1009
+				// This file path is being included.
1010
+				$included = true;
1011
+				break;
1012
+			}//end foreach
1013
+		}//end foreach
1014
+
1015
+		if ($included === false) {
1016
+			// There were include rules set, but this file
1017
+			// path didn't match any of them.
1018
+			return false;
1019
+		}
1020
+
1021
+		$messageCount++;
1022
+		if ($fixable === true) {
1023
+			$this->fixableCount++;
1024
+		}
1025
+
1026
+		if ($this->configCache['recordErrors'] === false
1027
+			&& $includeAll === false
1028
+		) {
1029
+			return true;
1030
+		}
1031
+
1032
+		// Work out the error message.
1033
+		if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
+			$message = $this->ruleset->ruleset[$sniffCode]['message'];
1035
+		}
1036
+
1037
+		if (empty($data) === false) {
1038
+			$message = vsprintf($message, $data);
1039
+		}
1040
+
1041
+		if (isset($messages[$line]) === false) {
1042
+			$messages[$line] = [];
1043
+		}
1044
+
1045
+		if (isset($messages[$line][$column]) === false) {
1046
+			$messages[$line][$column] = [];
1047
+		}
1048
+
1049
+		$messages[$line][$column][] = [
1050
+			'message'  => $message,
1051
+			'source'   => $sniffCode,
1052
+			'listener' => $this->activeListener,
1053
+			'severity' => $severity,
1054
+			'fixable'  => $fixable,
1055
+		];
1056
+
1057
+		if (PHP_CODESNIFFER_VERBOSITY > 1
1058
+			&& $this->fixer->enabled === true
1059
+			&& $fixable === true
1060
+		) {
1061
+			@ob_end_clean();
1062
+			echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1063
+			ob_start();
1064
+		}
1065
+
1066
+		return true;
1067
+
1068
+	}//end addMessage()
1069
+
1070
+
1071
+	/**
1072
+	 * Record a metric about the file being examined.
1073
+	 *
1074
+	 * @param int    $stackPtr The stack position where the metric was recorded.
1075
+	 * @param string $metric   The name of the metric being recorded.
1076
+	 * @param string $value    The value of the metric being recorded.
1077
+	 *
1078
+	 * @return boolean
1079
+	 */
1080
+	public function recordMetric($stackPtr, $metric, $value)
1081
+	{
1082
+		if (isset($this->metrics[$metric]) === false) {
1083
+			$this->metrics[$metric] = ['values' => [$value => 1]];
1084
+			$this->metricTokens[$metric][$stackPtr] = true;
1085
+		} else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
+			$this->metricTokens[$metric][$stackPtr] = true;
1087
+			if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
+				$this->metrics[$metric]['values'][$value] = 1;
1089
+			} else {
1090
+				$this->metrics[$metric]['values'][$value]++;
1091
+			}
1092
+		}
1093
+
1094
+		return true;
1095
+
1096
+	}//end recordMetric()
1097
+
1098
+
1099
+	/**
1100
+	 * Returns the number of errors raised.
1101
+	 *
1102
+	 * @return int
1103
+	 */
1104
+	public function getErrorCount()
1105
+	{
1106
+		return $this->errorCount;
1107
+
1108
+	}//end getErrorCount()
1109
+
1110
+
1111
+	/**
1112
+	 * Returns the number of warnings raised.
1113
+	 *
1114
+	 * @return int
1115
+	 */
1116
+	public function getWarningCount()
1117
+	{
1118
+		return $this->warningCount;
1119
+
1120
+	}//end getWarningCount()
1121
+
1122
+
1123
+	/**
1124
+	 * Returns the number of fixable errors/warnings raised.
1125
+	 *
1126
+	 * @return int
1127
+	 */
1128
+	public function getFixableCount()
1129
+	{
1130
+		return $this->fixableCount;
1131
+
1132
+	}//end getFixableCount()
1133
+
1134
+
1135
+	/**
1136
+	 * Returns the number of fixed errors/warnings.
1137
+	 *
1138
+	 * @return int
1139
+	 */
1140
+	public function getFixedCount()
1141
+	{
1142
+		return $this->fixedCount;
1143
+
1144
+	}//end getFixedCount()
1145
+
1146
+
1147
+	/**
1148
+	 * Returns the list of ignored lines.
1149
+	 *
1150
+	 * @return array
1151
+	 */
1152
+	public function getIgnoredLines()
1153
+	{
1154
+		return $this->tokenizer->ignoredLines;
1155
+
1156
+	}//end getIgnoredLines()
1157
+
1158
+
1159
+	/**
1160
+	 * Returns the errors raised from processing this file.
1161
+	 *
1162
+	 * @return array
1163
+	 */
1164
+	public function getErrors()
1165
+	{
1166
+		return $this->errors;
1167
+
1168
+	}//end getErrors()
1169
+
1170
+
1171
+	/**
1172
+	 * Returns the warnings raised from processing this file.
1173
+	 *
1174
+	 * @return array
1175
+	 */
1176
+	public function getWarnings()
1177
+	{
1178
+		return $this->warnings;
1179
+
1180
+	}//end getWarnings()
1181
+
1182
+
1183
+	/**
1184
+	 * Returns the metrics found while processing this file.
1185
+	 *
1186
+	 * @return array
1187
+	 */
1188
+	public function getMetrics()
1189
+	{
1190
+		return $this->metrics;
1191
+
1192
+	}//end getMetrics()
1193
+
1194
+
1195
+	/**
1196
+	 * Returns the absolute filename of this file.
1197
+	 *
1198
+	 * @return string
1199
+	 */
1200
+	public function getFilename()
1201
+	{
1202
+		return $this->path;
1203
+
1204
+	}//end getFilename()
1205
+
1206
+
1207
+	/**
1208
+	 * Returns the declaration names for classes, interfaces, traits, and functions.
1209
+	 *
1210
+	 * @param int $stackPtr The position of the declaration token which
1211
+	 *                      declared the class, interface, trait, or function.
1212
+	 *
1213
+	 * @return string|null The name of the class, interface, trait, or function;
1214
+	 *                     or NULL if the function or class is anonymous.
1215
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the specified token is not of type
1216
+	 *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217
+	 *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218
+	 */
1219
+	public function getDeclarationName($stackPtr)
1220
+	{
1221
+		$tokenCode = $this->tokens[$stackPtr]['code'];
1222
+
1223
+		if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1224
+			return null;
1225
+		}
1226
+
1227
+		if ($tokenCode !== T_FUNCTION
1228
+			&& $tokenCode !== T_CLASS
1229
+			&& $tokenCode !== T_INTERFACE
1230
+			&& $tokenCode !== T_TRAIT
1231
+		) {
1232
+			throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1233
+		}
1234
+
1235
+		if ($tokenCode === T_FUNCTION
1236
+			&& strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1237
+		) {
1238
+			// This is a function declared without the "function" keyword.
1239
+			// So this token is the function name.
1240
+			return $this->tokens[$stackPtr]['content'];
1241
+		}
1242
+
1243
+		$content = null;
1244
+		for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
+			if ($this->tokens[$i]['code'] === T_STRING) {
1246
+				$content = $this->tokens[$i]['content'];
1247
+				break;
1248
+			}
1249
+		}
1250
+
1251
+		return $content;
1252
+
1253
+	}//end getDeclarationName()
1254
+
1255
+
1256
+	/**
1257
+	 * Returns the method parameters for the specified function token.
1258
+	 *
1259
+	 * Each parameter is in the following format:
1260
+	 *
1261
+	 * <code>
1262
+	 *   0 => array(
1263
+	 *         'name'              => '$var',  // The variable name.
1264
+	 *         'token'             => integer, // The stack pointer to the variable name.
1265
+	 *         'content'           => string,  // The full content of the variable definition.
1266
+	 *         'pass_by_reference' => boolean, // Is the variable passed by reference?
1267
+	 *         'variable_length'   => boolean, // Is the param of variable length through use of `...` ?
1268
+	 *         'type_hint'         => string,  // The type hint for the variable.
1269
+	 *         'type_hint_token'   => integer, // The stack pointer to the type hint
1270
+	 *                                         // or false if there is no type hint.
1271
+	 *         'nullable_type'     => boolean, // Is the variable using a nullable type?
1272
+	 *        )
1273
+	 * </code>
1274
+	 *
1275
+	 * Parameters with default values have an additional array index of
1276
+	 * 'default' with the value of the default as a string.
1277
+	 *
1278
+	 * @param int $stackPtr The position in the stack of the function token
1279
+	 *                      to acquire the parameters for.
1280
+	 *
1281
+	 * @return array
1282
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283
+	 *                                                        type T_FUNCTION or T_CLOSURE.
1284
+	 */
1285
+	public function getMethodParameters($stackPtr)
1286
+	{
1287
+		if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
+			&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289
+		) {
1290
+			throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1291
+		}
1292
+
1293
+		$opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
+		$closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1295
+
1296
+		$vars            = [];
1297
+		$currVar         = null;
1298
+		$paramStart      = ($opener + 1);
1299
+		$defaultStart    = null;
1300
+		$paramCount      = 0;
1301
+		$passByReference = false;
1302
+		$variableLength  = false;
1303
+		$typeHint        = '';
1304
+		$typeHintToken   = false;
1305
+		$nullableType    = false;
1306
+
1307
+		for ($i = $paramStart; $i <= $closer; $i++) {
1308
+			// Check to see if this token has a parenthesis or bracket opener. If it does
1309
+			// it's likely to be an array which might have arguments in it. This
1310
+			// could cause problems in our parsing below, so lets just skip to the
1311
+			// end of it.
1312
+			if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1313
+				// Don't do this if it's the close parenthesis for the method.
1314
+				if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
+					$i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1316
+				}
1317
+			}
1318
+
1319
+			if (isset($this->tokens[$i]['bracket_opener']) === true) {
1320
+				// Don't do this if it's the close parenthesis for the method.
1321
+				if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
+					$i = ($this->tokens[$i]['bracket_closer'] + 1);
1323
+				}
1324
+			}
1325
+
1326
+			switch ($this->tokens[$i]['code']) {
1327
+			case T_BITWISE_AND:
1328
+				if ($defaultStart === null) {
1329
+					$passByReference = true;
1330
+				}
1331
+				break;
1332
+			case T_VARIABLE:
1333
+				$currVar = $i;
1334
+				break;
1335
+			case T_ELLIPSIS:
1336
+				$variableLength = true;
1337
+				break;
1338
+			case T_CALLABLE:
1339
+				if ($typeHintToken === false) {
1340
+					$typeHintToken = $i;
1341
+				}
1342
+
1343
+				$typeHint .= $this->tokens[$i]['content'];
1344
+				break;
1345
+			case T_SELF:
1346
+			case T_PARENT:
1347
+			case T_STATIC:
1348
+				// Self and parent are valid, static invalid, but was probably intended as type hint.
1349
+				if (isset($defaultStart) === false) {
1350
+					if ($typeHintToken === false) {
1351
+						$typeHintToken = $i;
1352
+					}
1353
+
1354
+					$typeHint .= $this->tokens[$i]['content'];
1355
+				}
1356
+				break;
1357
+			case T_STRING:
1358
+				// This is a string, so it may be a type hint, but it could
1359
+				// also be a constant used as a default value.
1360
+				$prevComma = false;
1361
+				for ($t = $i; $t >= $opener; $t--) {
1362
+					if ($this->tokens[$t]['code'] === T_COMMA) {
1363
+						$prevComma = $t;
1364
+						break;
1365
+					}
1366
+				}
1367
+
1368
+				if ($prevComma !== false) {
1369
+					$nextEquals = false;
1370
+					for ($t = $prevComma; $t < $i; $t++) {
1371
+						if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
+							$nextEquals = $t;
1373
+							break;
1374
+						}
1375
+					}
1376
+
1377
+					if ($nextEquals !== false) {
1378
+						break;
1379
+					}
1380
+				}
1381
+
1382
+				if ($defaultStart === null) {
1383
+					if ($typeHintToken === false) {
1384
+						$typeHintToken = $i;
1385
+					}
1386
+
1387
+					$typeHint .= $this->tokens[$i]['content'];
1388
+				}
1389
+				break;
1390
+			case T_NS_SEPARATOR:
1391
+				// Part of a type hint or default value.
1392
+				if ($defaultStart === null) {
1393
+					if ($typeHintToken === false) {
1394
+						$typeHintToken = $i;
1395
+					}
1396
+
1397
+					$typeHint .= $this->tokens[$i]['content'];
1398
+				}
1399
+				break;
1400
+			case T_NULLABLE:
1401
+				if ($defaultStart === null) {
1402
+					$nullableType = true;
1403
+					$typeHint    .= $this->tokens[$i]['content'];
1404
+				}
1405
+				break;
1406
+			case T_CLOSE_PARENTHESIS:
1407
+			case T_COMMA:
1408
+				// If it's null, then there must be no parameters for this
1409
+				// method.
1410
+				if ($currVar === null) {
1411
+					continue 2;
1412
+				}
1413
+
1414
+				$vars[$paramCount]            = [];
1415
+				$vars[$paramCount]['token']   = $currVar;
1416
+				$vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
+				$vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
+
1419
+				if ($defaultStart !== null) {
1420
+					$vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
+				}
1422
+
1423
+				$vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
+				$vars[$paramCount]['variable_length']   = $variableLength;
1425
+				$vars[$paramCount]['type_hint']         = $typeHint;
1426
+				$vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
+				$vars[$paramCount]['nullable_type']     = $nullableType;
1428
+
1429
+				// Reset the vars, as we are about to process the next parameter.
1430
+				$defaultStart    = null;
1431
+				$paramStart      = ($i + 1);
1432
+				$passByReference = false;
1433
+				$variableLength  = false;
1434
+				$typeHint        = '';
1435
+				$typeHintToken   = false;
1436
+				$nullableType    = false;
1437
+
1438
+				$paramCount++;
1439
+				break;
1440
+			case T_EQUAL:
1441
+				$defaultStart = ($i + 1);
1442
+				break;
1443
+			}//end switch
1444
+		}//end for
1445
+
1446
+		return $vars;
1447
+
1448
+	}//end getMethodParameters()
1449
+
1450
+
1451
+	/**
1452
+	 * Returns the visibility and implementation properties of a method.
1453
+	 *
1454
+	 * The format of the array is:
1455
+	 * <code>
1456
+	 *   array(
1457
+	 *    'scope'                => 'public', // public protected or protected
1458
+	 *    'scope_specified'      => true,     // true is scope keyword was found.
1459
+	 *    'return_type'          => '',       // the return type of the method.
1460
+	 *    'return_type_token'    => integer,  // The stack pointer to the start of the return type
1461
+	 *                                        // or false if there is no return type.
1462
+	 *    'nullable_return_type' => false,    // true if the return type is nullable.
1463
+	 *    'is_abstract'          => false,    // true if the abstract keyword was found.
1464
+	 *    'is_final'             => false,    // true if the final keyword was found.
1465
+	 *    'is_static'            => false,    // true if the static keyword was found.
1466
+	 *    'has_body'             => false,    // true if the method has a body
1467
+	 *   );
1468
+	 * </code>
1469
+	 *
1470
+	 * @param int $stackPtr The position in the stack of the function token to
1471
+	 *                      acquire the properties for.
1472
+	 *
1473
+	 * @return array
1474
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475
+	 *                                                        T_FUNCTION token.
1476
+	 */
1477
+	public function getMethodProperties($stackPtr)
1478
+	{
1479
+		if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
+			&& $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481
+		) {
1482
+			throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1483
+		}
1484
+
1485
+		if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1486
+			$valid = [
1487
+				T_PUBLIC      => T_PUBLIC,
1488
+				T_PRIVATE     => T_PRIVATE,
1489
+				T_PROTECTED   => T_PROTECTED,
1490
+				T_STATIC      => T_STATIC,
1491
+				T_FINAL       => T_FINAL,
1492
+				T_ABSTRACT    => T_ABSTRACT,
1493
+				T_WHITESPACE  => T_WHITESPACE,
1494
+				T_COMMENT     => T_COMMENT,
1495
+				T_DOC_COMMENT => T_DOC_COMMENT,
1496
+			];
1497
+		} else {
1498
+			$valid = [
1499
+				T_STATIC      => T_STATIC,
1500
+				T_WHITESPACE  => T_WHITESPACE,
1501
+				T_COMMENT     => T_COMMENT,
1502
+				T_DOC_COMMENT => T_DOC_COMMENT,
1503
+			];
1504
+		}
1505
+
1506
+		$scope          = 'public';
1507
+		$scopeSpecified = false;
1508
+		$isAbstract     = false;
1509
+		$isFinal        = false;
1510
+		$isStatic       = false;
1511
+
1512
+		for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1514
+				break;
1515
+			}
1516
+
1517
+			switch ($this->tokens[$i]['code']) {
1518
+			case T_PUBLIC:
1519
+				$scope          = 'public';
1520
+				$scopeSpecified = true;
1521
+				break;
1522
+			case T_PRIVATE:
1523
+				$scope          = 'private';
1524
+				$scopeSpecified = true;
1525
+				break;
1526
+			case T_PROTECTED:
1527
+				$scope          = 'protected';
1528
+				$scopeSpecified = true;
1529
+				break;
1530
+			case T_ABSTRACT:
1531
+				$isAbstract = true;
1532
+				break;
1533
+			case T_FINAL:
1534
+				$isFinal = true;
1535
+				break;
1536
+			case T_STATIC:
1537
+				$isStatic = true;
1538
+				break;
1539
+			}//end switch
1540
+		}//end for
1541
+
1542
+		$returnType         = '';
1543
+		$returnTypeToken    = false;
1544
+		$nullableReturnType = false;
1545
+		$hasBody            = true;
1546
+
1547
+		if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1548
+			$scopeOpener = null;
1549
+			if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
+				$scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1551
+			}
1552
+
1553
+			$valid = [
1554
+				T_STRING       => T_STRING,
1555
+				T_CALLABLE     => T_CALLABLE,
1556
+				T_SELF         => T_SELF,
1557
+				T_PARENT       => T_PARENT,
1558
+				T_NS_SEPARATOR => T_NS_SEPARATOR,
1559
+			];
1560
+
1561
+			for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
+				if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
+					|| ($scopeOpener !== null && $i === $scopeOpener)
1564
+				) {
1565
+					// End of function definition.
1566
+					break;
1567
+				}
1568
+
1569
+				if ($this->tokens[$i]['code'] === T_NULLABLE) {
1570
+					$nullableReturnType = true;
1571
+				}
1572
+
1573
+				if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
+					if ($returnTypeToken === false) {
1575
+						$returnTypeToken = $i;
1576
+					}
1577
+
1578
+					$returnType .= $this->tokens[$i]['content'];
1579
+				}
1580
+			}
1581
+
1582
+			$end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
+			$hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1584
+		}//end if
1585
+
1586
+		if ($returnType !== '' && $nullableReturnType === true) {
1587
+			$returnType = '?'.$returnType;
1588
+		}
1589
+
1590
+		return [
1591
+			'scope'                => $scope,
1592
+			'scope_specified'      => $scopeSpecified,
1593
+			'return_type'          => $returnType,
1594
+			'return_type_token'    => $returnTypeToken,
1595
+			'nullable_return_type' => $nullableReturnType,
1596
+			'is_abstract'          => $isAbstract,
1597
+			'is_final'             => $isFinal,
1598
+			'is_static'            => $isStatic,
1599
+			'has_body'             => $hasBody,
1600
+		];
1601
+
1602
+	}//end getMethodProperties()
1603
+
1604
+
1605
+	/**
1606
+	 * Returns the visibility and implementation properties of the class member
1607
+	 * variable found at the specified position in the stack.
1608
+	 *
1609
+	 * The format of the array is:
1610
+	 *
1611
+	 * <code>
1612
+	 *   array(
1613
+	 *    'scope'           => 'public', // public protected or protected.
1614
+	 *    'scope_specified' => false,    // true if the scope was explicitly specified.
1615
+	 *    'is_static'       => false,    // true if the static keyword was found.
1616
+	 *   );
1617
+	 * </code>
1618
+	 *
1619
+	 * @param int $stackPtr The position in the stack of the T_VARIABLE token to
1620
+	 *                      acquire the properties for.
1621
+	 *
1622
+	 * @return array
1623
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1624
+	 *                                                        T_VARIABLE token, or if the position is not
1625
+	 *                                                        a class member variable.
1626
+	 */
1627
+	public function getMemberProperties($stackPtr)
1628
+	{
1629
+		if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
+			throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631
+		}
1632
+
1633
+		$conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
+		$ptr        = array_pop($conditions);
1635
+		if (isset($this->tokens[$ptr]) === false
1636
+			|| ($this->tokens[$ptr]['code'] !== T_CLASS
1637
+			&& $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
+			&& $this->tokens[$ptr]['code'] !== T_TRAIT)
1639
+		) {
1640
+			if (isset($this->tokens[$ptr]) === true
1641
+				&& $this->tokens[$ptr]['code'] === T_INTERFACE
1642
+			) {
1643
+				// T_VARIABLEs in interfaces can actually be method arguments
1644
+				// but they wont be seen as being inside the method because there
1645
+				// are no scope openers and closers for abstract methods. If it is in
1646
+				// parentheses, we can be pretty sure it is a method argument.
1647
+				if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
+					|| empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1649
+				) {
1650
+					$error = 'Possible parse error: interfaces may not include member vars';
1651
+					$this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
+					return [];
1653
+				}
1654
+			} else {
1655
+				throw new TokenizerException('$stackPtr is not a class member var');
1656
+			}
1657
+		}
1658
+
1659
+		// Make sure it's not a method parameter.
1660
+		if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
+			$parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
+			$deepestOpen = array_pop($parenthesis);
1663
+			if ($deepestOpen > $ptr
1664
+				&& isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
+				&& $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1666
+			) {
1667
+				throw new TokenizerException('$stackPtr is not a class member var');
1668
+			}
1669
+		}
1670
+
1671
+		$valid = [
1672
+			T_PUBLIC    => T_PUBLIC,
1673
+			T_PRIVATE   => T_PRIVATE,
1674
+			T_PROTECTED => T_PROTECTED,
1675
+			T_STATIC    => T_STATIC,
1676
+			T_VAR       => T_VAR,
1677
+		];
1678
+
1679
+		$valid += Util\Tokens::$emptyTokens;
1680
+
1681
+		$scope          = 'public';
1682
+		$scopeSpecified = false;
1683
+		$isStatic       = false;
1684
+
1685
+		$startOfStatement = $this->findPrevious(
1686
+			[
1687
+				T_SEMICOLON,
1688
+				T_OPEN_CURLY_BRACKET,
1689
+				T_CLOSE_CURLY_BRACKET,
1690
+			],
1691
+			($stackPtr - 1)
1692
+		);
1693
+
1694
+		for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1696
+				break;
1697
+			}
1698
+
1699
+			switch ($this->tokens[$i]['code']) {
1700
+			case T_PUBLIC:
1701
+				$scope          = 'public';
1702
+				$scopeSpecified = true;
1703
+				break;
1704
+			case T_PRIVATE:
1705
+				$scope          = 'private';
1706
+				$scopeSpecified = true;
1707
+				break;
1708
+			case T_PROTECTED:
1709
+				$scope          = 'protected';
1710
+				$scopeSpecified = true;
1711
+				break;
1712
+			case T_STATIC:
1713
+				$isStatic = true;
1714
+				break;
1715
+			}
1716
+		}//end for
1717
+
1718
+		return [
1719
+			'scope'           => $scope,
1720
+			'scope_specified' => $scopeSpecified,
1721
+			'is_static'       => $isStatic,
1722
+		];
1723
+
1724
+	}//end getMemberProperties()
1725
+
1726
+
1727
+	/**
1728
+	 * Returns the visibility and implementation properties of a class.
1729
+	 *
1730
+	 * The format of the array is:
1731
+	 * <code>
1732
+	 *   array(
1733
+	 *    'is_abstract' => false, // true if the abstract keyword was found.
1734
+	 *    'is_final'    => false, // true if the final keyword was found.
1735
+	 *   );
1736
+	 * </code>
1737
+	 *
1738
+	 * @param int $stackPtr The position in the stack of the T_CLASS token to
1739
+	 *                      acquire the properties for.
1740
+	 *
1741
+	 * @return array
1742
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743
+	 *                                                        T_CLASS token.
1744
+	 */
1745
+	public function getClassProperties($stackPtr)
1746
+	{
1747
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
+			throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749
+		}
1750
+
1751
+		$valid = [
1752
+			T_FINAL       => T_FINAL,
1753
+			T_ABSTRACT    => T_ABSTRACT,
1754
+			T_WHITESPACE  => T_WHITESPACE,
1755
+			T_COMMENT     => T_COMMENT,
1756
+			T_DOC_COMMENT => T_DOC_COMMENT,
1757
+		];
1758
+
1759
+		$isAbstract = false;
1760
+		$isFinal    = false;
1761
+
1762
+		for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
+			if (isset($valid[$this->tokens[$i]['code']]) === false) {
1764
+				break;
1765
+			}
1766
+
1767
+			switch ($this->tokens[$i]['code']) {
1768
+			case T_ABSTRACT:
1769
+				$isAbstract = true;
1770
+				break;
1771
+
1772
+			case T_FINAL:
1773
+				$isFinal = true;
1774
+				break;
1775
+			}
1776
+		}//end for
1777
+
1778
+		return [
1779
+			'is_abstract' => $isAbstract,
1780
+			'is_final'    => $isFinal,
1781
+		];
1782
+
1783
+	}//end getClassProperties()
1784
+
1785
+
1786
+	/**
1787
+	 * Determine if the passed token is a reference operator.
1788
+	 *
1789
+	 * Returns true if the specified token position represents a reference.
1790
+	 * Returns false if the token represents a bitwise operator.
1791
+	 *
1792
+	 * @param int $stackPtr The position of the T_BITWISE_AND token.
1793
+	 *
1794
+	 * @return boolean
1795
+	 */
1796
+	public function isReference($stackPtr)
1797
+	{
1798
+		if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799
+			return false;
1800
+		}
1801
+
1802
+		$tokenBefore = $this->findPrevious(
1803
+			Util\Tokens::$emptyTokens,
1804
+			($stackPtr - 1),
1805
+			null,
1806
+			true
1807
+		);
1808
+
1809
+		if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1810
+			// Function returns a reference.
1811
+			return true;
1812
+		}
1813
+
1814
+		if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1815
+			// Inside a foreach loop or array assignment, this is a reference.
1816
+			return true;
1817
+		}
1818
+
1819
+		if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1820
+			// Inside a foreach loop, this is a reference.
1821
+			return true;
1822
+		}
1823
+
1824
+		if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1825
+			// This is directly after an assignment. It's a reference. Even if
1826
+			// it is part of an operation, the other tests will handle it.
1827
+			return true;
1828
+		}
1829
+
1830
+		$tokenAfter = $this->findNext(
1831
+			Util\Tokens::$emptyTokens,
1832
+			($stackPtr + 1),
1833
+			null,
1834
+			true
1835
+		);
1836
+
1837
+		if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1838
+			return true;
1839
+		}
1840
+
1841
+		if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
+			$brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
+			$lastBracket = array_pop($brackets);
1844
+			if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
+				$owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
+				if ($owner['code'] === T_FUNCTION
1847
+					|| $owner['code'] === T_CLOSURE
1848
+				) {
1849
+					$params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
+					foreach ($params as $param) {
1851
+						$varToken = $tokenAfter;
1852
+						if ($param['variable_length'] === true) {
1853
+							$varToken = $this->findNext(
1854
+								(Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
+								($stackPtr + 1),
1856
+								null,
1857
+								true
1858
+							);
1859
+						}
1860
+
1861
+						if ($param['token'] === $varToken
1862
+							&& $param['pass_by_reference'] === true
1863
+						) {
1864
+							// Function parameter declared to be passed by reference.
1865
+							return true;
1866
+						}
1867
+					}
1868
+				}//end if
1869
+			} else {
1870
+				$prev = false;
1871
+				for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
+					if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1873
+						$prev = $t;
1874
+						break;
1875
+					}
1876
+				}
1877
+
1878
+				if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1879
+					// Closure use by reference.
1880
+					return true;
1881
+				}
1882
+			}//end if
1883
+		}//end if
1884
+
1885
+		// Pass by reference in function calls and assign by reference in arrays.
1886
+		if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
+			|| $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
+			|| $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1889
+		) {
1890
+			if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1891
+				return true;
1892
+			} else {
1893
+				$skip   = Util\Tokens::$emptyTokens;
1894
+				$skip[] = T_NS_SEPARATOR;
1895
+				$skip[] = T_SELF;
1896
+				$skip[] = T_PARENT;
1897
+				$skip[] = T_STATIC;
1898
+				$skip[] = T_STRING;
1899
+				$skip[] = T_NAMESPACE;
1900
+				$skip[] = T_DOUBLE_COLON;
1901
+
1902
+				$nextSignificantAfter = $this->findNext(
1903
+					$skip,
1904
+					($stackPtr + 1),
1905
+					null,
1906
+					true
1907
+				);
1908
+				if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1909
+					return true;
1910
+				}
1911
+			}//end if
1912
+		}//end if
1913
+
1914
+		return false;
1915
+
1916
+	}//end isReference()
1917
+
1918
+
1919
+	/**
1920
+	 * Returns the content of the tokens from the specified start position in
1921
+	 * the token stack for the specified length.
1922
+	 *
1923
+	 * @param int  $start       The position to start from in the token stack.
1924
+	 * @param int  $length      The length of tokens to traverse from the start pos.
1925
+	 * @param bool $origContent Whether the original content or the tab replaced
1926
+	 *                          content should be used.
1927
+	 *
1928
+	 * @return string The token contents.
1929
+	 */
1930
+	public function getTokensAsString($start, $length, $origContent=false)
1931
+	{
1932
+		if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
+			throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934
+		}
1935
+
1936
+		if (is_int($length) === false || $length <= 0) {
1937
+			return '';
1938
+		}
1939
+
1940
+		$str = '';
1941
+		$end = ($start + $length);
1942
+		if ($end > $this->numTokens) {
1943
+			$end = $this->numTokens;
1944
+		}
1945
+
1946
+		for ($i = $start; $i < $end; $i++) {
1947
+			// If tabs are being converted to spaces by the tokeniser, the
1948
+			// original content should be used instead of the converted content.
1949
+			if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
+				$str .= $this->tokens[$i]['orig_content'];
1951
+			} else {
1952
+				$str .= $this->tokens[$i]['content'];
1953
+			}
1954
+		}
1955
+
1956
+		return $str;
1957
+
1958
+	}//end getTokensAsString()
1959
+
1960
+
1961
+	/**
1962
+	 * Returns the position of the previous specified token(s).
1963
+	 *
1964
+	 * If a value is specified, the previous token of the specified type(s)
1965
+	 * containing the specified value will be returned.
1966
+	 *
1967
+	 * Returns false if no token can be found.
1968
+	 *
1969
+	 * @param int|string|array $types   The type(s) of tokens to search for.
1970
+	 * @param int              $start   The position to start searching from in the
1971
+	 *                                  token stack.
1972
+	 * @param int              $end     The end position to fail if no token is found.
1973
+	 *                                  if not specified or null, end will default to
1974
+	 *                                  the start of the token stack.
1975
+	 * @param bool             $exclude If true, find the previous token that is NOT of
1976
+	 *                                  the types specified in $types.
1977
+	 * @param string           $value   The value that the token(s) must be equal to.
1978
+	 *                                  If value is omitted, tokens with any value will
1979
+	 *                                  be returned.
1980
+	 * @param bool             $local   If true, tokens outside the current statement
1981
+	 *                                  will not be checked. IE. checking will stop
1982
+	 *                                  at the previous semi-colon found.
1983
+	 *
1984
+	 * @return int|bool
1985
+	 * @see    findNext()
1986
+	 */
1987
+	public function findPrevious(
1988
+		$types,
1989
+		$start,
1990
+		$end=null,
1991
+		$exclude=false,
1992
+		$value=null,
1993
+		$local=false
1994
+	) {
1995
+		$types = (array) $types;
1996
+
1997
+		if ($end === null) {
1998
+			$end = 0;
1999
+		}
2000
+
2001
+		for ($i = $start; $i >= $end; $i--) {
2002
+			$found = (bool) $exclude;
2003
+			foreach ($types as $type) {
2004
+				if ($this->tokens[$i]['code'] === $type) {
2005
+					$found = !$exclude;
2006
+					break;
2007
+				}
2008
+			}
2009
+
2010
+			if ($found === true) {
2011
+				if ($value === null) {
2012
+					return $i;
2013
+				} else if ($this->tokens[$i]['content'] === $value) {
2014
+					return $i;
2015
+				}
2016
+			}
2017
+
2018
+			if ($local === true) {
2019
+				if (isset($this->tokens[$i]['scope_opener']) === true
2020
+					&& $i === $this->tokens[$i]['scope_closer']
2021
+				) {
2022
+					$i = $this->tokens[$i]['scope_opener'];
2023
+				} else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
+					&& $i === $this->tokens[$i]['bracket_closer']
2025
+				) {
2026
+					$i = $this->tokens[$i]['bracket_opener'];
2027
+				} else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
+					&& $i === $this->tokens[$i]['parenthesis_closer']
2029
+				) {
2030
+					$i = $this->tokens[$i]['parenthesis_opener'];
2031
+				} else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2032
+					break;
2033
+				}
2034
+			}
2035
+		}//end for
2036
+
2037
+		return false;
2038
+
2039
+	}//end findPrevious()
2040
+
2041
+
2042
+	/**
2043
+	 * Returns the position of the next specified token(s).
2044
+	 *
2045
+	 * If a value is specified, the next token of the specified type(s)
2046
+	 * containing the specified value will be returned.
2047
+	 *
2048
+	 * Returns false if no token can be found.
2049
+	 *
2050
+	 * @param int|string|array $types   The type(s) of tokens to search for.
2051
+	 * @param int              $start   The position to start searching from in the
2052
+	 *                                  token stack.
2053
+	 * @param int              $end     The end position to fail if no token is found.
2054
+	 *                                  if not specified or null, end will default to
2055
+	 *                                  the end of the token stack.
2056
+	 * @param bool             $exclude If true, find the next token that is NOT of
2057
+	 *                                  a type specified in $types.
2058
+	 * @param string           $value   The value that the token(s) must be equal to.
2059
+	 *                                  If value is omitted, tokens with any value will
2060
+	 *                                  be returned.
2061
+	 * @param bool             $local   If true, tokens outside the current statement
2062
+	 *                                  will not be checked. i.e., checking will stop
2063
+	 *                                  at the next semi-colon found.
2064
+	 *
2065
+	 * @return int|bool
2066
+	 * @see    findPrevious()
2067
+	 */
2068
+	public function findNext(
2069
+		$types,
2070
+		$start,
2071
+		$end=null,
2072
+		$exclude=false,
2073
+		$value=null,
2074
+		$local=false
2075
+	) {
2076
+		$types = (array) $types;
2077
+
2078
+		if ($end === null || $end > $this->numTokens) {
2079
+			$end = $this->numTokens;
2080
+		}
2081
+
2082
+		for ($i = $start; $i < $end; $i++) {
2083
+			$found = (bool) $exclude;
2084
+			foreach ($types as $type) {
2085
+				if ($this->tokens[$i]['code'] === $type) {
2086
+					$found = !$exclude;
2087
+					break;
2088
+				}
2089
+			}
2090
+
2091
+			if ($found === true) {
2092
+				if ($value === null) {
2093
+					return $i;
2094
+				} else if ($this->tokens[$i]['content'] === $value) {
2095
+					return $i;
2096
+				}
2097
+			}
2098
+
2099
+			if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2100
+				break;
2101
+			}
2102
+		}//end for
2103
+
2104
+		return false;
2105
+
2106
+	}//end findNext()
2107
+
2108
+
2109
+	/**
2110
+	 * Returns the position of the first non-whitespace token in a statement.
2111
+	 *
2112
+	 * @param int       $start  The position to start searching from in the token stack.
2113
+	 * @param int|array $ignore Token types that should not be considered stop points.
2114
+	 *
2115
+	 * @return int
2116
+	 */
2117
+	public function findStartOfStatement($start, $ignore=null)
2118
+	{
2119
+		$endTokens = Util\Tokens::$blockOpeners;
2120
+
2121
+		$endTokens[T_COLON]            = true;
2122
+		$endTokens[T_COMMA]            = true;
2123
+		$endTokens[T_DOUBLE_ARROW]     = true;
2124
+		$endTokens[T_SEMICOLON]        = true;
2125
+		$endTokens[T_OPEN_TAG]         = true;
2126
+		$endTokens[T_CLOSE_TAG]        = true;
2127
+		$endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
+
2129
+		if ($ignore !== null) {
2130
+			$ignore = (array) $ignore;
2131
+			foreach ($ignore as $code) {
2132
+				unset($endTokens[$code]);
2133
+			}
2134
+		}
2135
+
2136
+		$lastNotEmpty = $start;
2137
+
2138
+		for ($i = $start; $i >= 0; $i--) {
2139
+			if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2140
+				// Found the end of the previous statement.
2141
+				return $lastNotEmpty;
2142
+			}
2143
+
2144
+			if (isset($this->tokens[$i]['scope_opener']) === true
2145
+				&& $i === $this->tokens[$i]['scope_closer']
2146
+			) {
2147
+				// Found the end of the previous scope block.
2148
+				return $lastNotEmpty;
2149
+			}
2150
+
2151
+			// Skip nested statements.
2152
+			if (isset($this->tokens[$i]['bracket_opener']) === true
2153
+				&& $i === $this->tokens[$i]['bracket_closer']
2154
+			) {
2155
+				$i = $this->tokens[$i]['bracket_opener'];
2156
+			} else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
+				&& $i === $this->tokens[$i]['parenthesis_closer']
2158
+			) {
2159
+				$i = $this->tokens[$i]['parenthesis_opener'];
2160
+			}
2161
+
2162
+			if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2163
+				$lastNotEmpty = $i;
2164
+			}
2165
+		}//end for
2166
+
2167
+		return 0;
2168
+
2169
+	}//end findStartOfStatement()
2170
+
2171
+
2172
+	/**
2173
+	 * Returns the position of the last non-whitespace token in a statement.
2174
+	 *
2175
+	 * @param int       $start  The position to start searching from in the token stack.
2176
+	 * @param int|array $ignore Token types that should not be considered stop points.
2177
+	 *
2178
+	 * @return int
2179
+	 */
2180
+	public function findEndOfStatement($start, $ignore=null)
2181
+	{
2182
+		$endTokens = [
2183
+			T_COLON                => true,
2184
+			T_COMMA                => true,
2185
+			T_DOUBLE_ARROW         => true,
2186
+			T_SEMICOLON            => true,
2187
+			T_CLOSE_PARENTHESIS    => true,
2188
+			T_CLOSE_SQUARE_BRACKET => true,
2189
+			T_CLOSE_CURLY_BRACKET  => true,
2190
+			T_CLOSE_SHORT_ARRAY    => true,
2191
+			T_OPEN_TAG             => true,
2192
+			T_CLOSE_TAG            => true,
2193
+		];
2194
+
2195
+		if ($ignore !== null) {
2196
+			$ignore = (array) $ignore;
2197
+			foreach ($ignore as $code) {
2198
+				unset($endTokens[$code]);
2199
+			}
2200
+		}
2201
+
2202
+		$lastNotEmpty = $start;
2203
+
2204
+		for ($i = $start; $i < $this->numTokens; $i++) {
2205
+			if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2206
+				// Found the end of the statement.
2207
+				if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
+					|| $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
+					|| $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
+					|| $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
+					|| $this->tokens[$i]['code'] === T_OPEN_TAG
2212
+					|| $this->tokens[$i]['code'] === T_CLOSE_TAG
2213
+				) {
2214
+					return $lastNotEmpty;
2215
+				}
2216
+
2217
+				return $i;
2218
+			}
2219
+
2220
+			// Skip nested statements.
2221
+			if (isset($this->tokens[$i]['scope_closer']) === true
2222
+				&& ($i === $this->tokens[$i]['scope_opener']
2223
+				|| $i === $this->tokens[$i]['scope_condition'])
2224
+			) {
2225
+				if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
+					return $this->tokens[$i]['scope_closer'];
2227
+				}
2228
+
2229
+				$i = $this->tokens[$i]['scope_closer'];
2230
+			} else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
+				&& $i === $this->tokens[$i]['bracket_opener']
2232
+			) {
2233
+				$i = $this->tokens[$i]['bracket_closer'];
2234
+			} else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
+				&& $i === $this->tokens[$i]['parenthesis_opener']
2236
+			) {
2237
+				$i = $this->tokens[$i]['parenthesis_closer'];
2238
+			}
2239
+
2240
+			if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2241
+				$lastNotEmpty = $i;
2242
+			}
2243
+		}//end for
2244
+
2245
+		return ($this->numTokens - 1);
2246
+
2247
+	}//end findEndOfStatement()
2248
+
2249
+
2250
+	/**
2251
+	 * Returns the position of the first token on a line, matching given type.
2252
+	 *
2253
+	 * Returns false if no token can be found.
2254
+	 *
2255
+	 * @param int|string|array $types   The type(s) of tokens to search for.
2256
+	 * @param int              $start   The position to start searching from in the
2257
+	 *                                  token stack. The first token matching on
2258
+	 *                                  this line before this token will be returned.
2259
+	 * @param bool             $exclude If true, find the token that is NOT of
2260
+	 *                                  the types specified in $types.
2261
+	 * @param string           $value   The value that the token must be equal to.
2262
+	 *                                  If value is omitted, tokens with any value will
2263
+	 *                                  be returned.
2264
+	 *
2265
+	 * @return int | bool
2266
+	 */
2267
+	public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
+	{
2269
+		if (is_array($types) === false) {
2270
+			$types = [$types];
2271
+		}
2272
+
2273
+		$foundToken = false;
2274
+
2275
+		for ($i = $start; $i >= 0; $i--) {
2276
+			if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2277
+				break;
2278
+			}
2279
+
2280
+			$found = $exclude;
2281
+			foreach ($types as $type) {
2282
+				if ($exclude === false) {
2283
+					if ($this->tokens[$i]['code'] === $type) {
2284
+						$found = true;
2285
+						break;
2286
+					}
2287
+				} else {
2288
+					if ($this->tokens[$i]['code'] === $type) {
2289
+						$found = false;
2290
+						break;
2291
+					}
2292
+				}
2293
+			}
2294
+
2295
+			if ($found === true) {
2296
+				if ($value === null) {
2297
+					$foundToken = $i;
2298
+				} else if ($this->tokens[$i]['content'] === $value) {
2299
+					$foundToken = $i;
2300
+				}
2301
+			}
2302
+		}//end for
2303
+
2304
+		return $foundToken;
2305
+
2306
+	}//end findFirstOnLine()
2307
+
2308
+
2309
+	/**
2310
+	 * Determine if the passed token has a condition of one of the passed types.
2311
+	 *
2312
+	 * @param int              $stackPtr The position of the token we are checking.
2313
+	 * @param int|string|array $types    The type(s) of tokens to search for.
2314
+	 *
2315
+	 * @return boolean
2316
+	 */
2317
+	public function hasCondition($stackPtr, $types)
2318
+	{
2319
+		// Check for the existence of the token.
2320
+		if (isset($this->tokens[$stackPtr]) === false) {
2321
+			return false;
2322
+		}
2323
+
2324
+		// Make sure the token has conditions.
2325
+		if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2326
+			return false;
2327
+		}
2328
+
2329
+		$types      = (array) $types;
2330
+		$conditions = $this->tokens[$stackPtr]['conditions'];
2331
+
2332
+		foreach ($types as $type) {
2333
+			if (in_array($type, $conditions, true) === true) {
2334
+				// We found a token with the required type.
2335
+				return true;
2336
+			}
2337
+		}
2338
+
2339
+		return false;
2340
+
2341
+	}//end hasCondition()
2342
+
2343
+
2344
+	/**
2345
+	 * Return the position of the condition for the passed token.
2346
+	 *
2347
+	 * Returns FALSE if the token does not have the condition.
2348
+	 *
2349
+	 * @param int        $stackPtr The position of the token we are checking.
2350
+	 * @param int|string $type     The type of token to search for.
2351
+	 *
2352
+	 * @return int
2353
+	 */
2354
+	public function getCondition($stackPtr, $type)
2355
+	{
2356
+		// Check for the existence of the token.
2357
+		if (isset($this->tokens[$stackPtr]) === false) {
2358
+			return false;
2359
+		}
2360
+
2361
+		// Make sure the token has conditions.
2362
+		if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2363
+			return false;
2364
+		}
2365
+
2366
+		$conditions = $this->tokens[$stackPtr]['conditions'];
2367
+		foreach ($conditions as $token => $condition) {
2368
+			if ($condition === $type) {
2369
+				return $token;
2370
+			}
2371
+		}
2372
+
2373
+		return false;
2374
+
2375
+	}//end getCondition()
2376
+
2377
+
2378
+	/**
2379
+	 * Returns the name of the class that the specified class extends.
2380
+	 * (works for classes, anonymous classes and interfaces)
2381
+	 *
2382
+	 * Returns FALSE on error or if there is no extended class name.
2383
+	 *
2384
+	 * @param int $stackPtr The stack position of the class.
2385
+	 *
2386
+	 * @return string|false
2387
+	 */
2388
+	public function findExtendedClassName($stackPtr)
2389
+	{
2390
+		// Check for the existence of the token.
2391
+		if (isset($this->tokens[$stackPtr]) === false) {
2392
+			return false;
2393
+		}
2394
+
2395
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
+			&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
+			&& $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2398
+		) {
2399
+			return false;
2400
+		}
2401
+
2402
+		if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2403
+			return false;
2404
+		}
2405
+
2406
+		$classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
+		$extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
+		if (false === $extendsIndex) {
2409
+			return false;
2410
+		}
2411
+
2412
+		$find = [
2413
+			T_NS_SEPARATOR,
2414
+			T_STRING,
2415
+			T_WHITESPACE,
2416
+		];
2417
+
2418
+		$end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
+		$name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
+		$name = trim($name);
2421
+
2422
+		if ($name === '') {
2423
+			return false;
2424
+		}
2425
+
2426
+		return $name;
2427
+
2428
+	}//end findExtendedClassName()
2429
+
2430
+
2431
+	/**
2432
+	 * Returns the names of the interfaces that the specified class implements.
2433
+	 *
2434
+	 * Returns FALSE on error or if there are no implemented interface names.
2435
+	 *
2436
+	 * @param int $stackPtr The stack position of the class.
2437
+	 *
2438
+	 * @return array|false
2439
+	 */
2440
+	public function findImplementedInterfaceNames($stackPtr)
2441
+	{
2442
+		// Check for the existence of the token.
2443
+		if (isset($this->tokens[$stackPtr]) === false) {
2444
+			return false;
2445
+		}
2446
+
2447
+		if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
+			&& $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2449
+		) {
2450
+			return false;
2451
+		}
2452
+
2453
+		if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2454
+			return false;
2455
+		}
2456
+
2457
+		$classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
+		$implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
+		if ($implementsIndex === false) {
2460
+			return false;
2461
+		}
2462
+
2463
+		$find = [
2464
+			T_NS_SEPARATOR,
2465
+			T_STRING,
2466
+			T_WHITESPACE,
2467
+			T_COMMA,
2468
+		];
2469
+
2470
+		$end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
+		$name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
+		$name = trim($name);
2473
+
2474
+		if ($name === '') {
2475
+			return false;
2476
+		} else {
2477
+			$names = explode(',', $name);
2478
+			$names = array_map('trim', $names);
2479
+			return $names;
2480
+		}
2481
+
2482
+	}//end findImplementedInterfaceNames()
2483 2483
 
2484 2484
 
2485 2485
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1324,122 +1324,122 @@  discard block
 block discarded – undo
1324 1324
             }
1325 1325
 
1326 1326
             switch ($this->tokens[$i]['code']) {
1327
-            case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1329
-                    $passByReference = true;
1330
-                }
1331
-                break;
1332
-            case T_VARIABLE:
1333
-                $currVar = $i;
1334
-                break;
1335
-            case T_ELLIPSIS:
1336
-                $variableLength = true;
1337
-                break;
1338
-            case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1340
-                    $typeHintToken = $i;
1341
-                }
1342
-
1343
-                $typeHint .= $this->tokens[$i]['content'];
1344
-                break;
1345
-            case T_SELF:
1346
-            case T_PARENT:
1347
-            case T_STATIC:
1348
-                // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1351
-                        $typeHintToken = $i;
1352
-                    }
1353
-
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1355
-                }
1356
-                break;
1357
-            case T_STRING:
1358
-                // This is a string, so it may be a type hint, but it could
1359
-                // also be a constant used as a default value.
1360
-                $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1363
-                        $prevComma = $t;
1364
-                        break;
1365
-                    }
1366
-                }
1367
-
1368
-                if ($prevComma !== false) {
1369
-                    $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
-                            $nextEquals = $t;
1373
-                            break;
1374
-                        }
1375
-                    }
1376
-
1377
-                    if ($nextEquals !== false) {
1378
-                        break;
1379
-                    }
1380
-                }
1381
-
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1384
-                        $typeHintToken = $i;
1385
-                    }
1386
-
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1388
-                }
1389
-                break;
1390
-            case T_NS_SEPARATOR:
1391
-                // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1394
-                        $typeHintToken = $i;
1395
-                    }
1396
-
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1398
-                }
1399
-                break;
1400
-            case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1402
-                    $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1404
-                }
1405
-                break;
1406
-            case T_CLOSE_PARENTHESIS:
1407
-            case T_COMMA:
1408
-                // If it's null, then there must be no parameters for this
1409
-                // method.
1410
-                if ($currVar === null) {
1411
-                    continue 2;
1412
-                }
1413
-
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
-
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
-                }
1422
-
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1428
-
1429
-                // Reset the vars, as we are about to process the next parameter.
1430
-                $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1432
-                $passByReference = false;
1433
-                $variableLength  = false;
1434
-                $typeHint        = '';
1435
-                $typeHintToken   = false;
1436
-                $nullableType    = false;
1437
-
1438
-                $paramCount++;
1439
-                break;
1440
-            case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1442
-                break;
1327
+            	case T_BITWISE_AND:
1328
+                	if ($defaultStart === null) {
1329
+                    	$passByReference = true;
1330
+                	}
1331
+                	break;
1332
+            	case T_VARIABLE:
1333
+                	$currVar = $i;
1334
+                	break;
1335
+            	case T_ELLIPSIS:
1336
+                	$variableLength = true;
1337
+                	break;
1338
+            	case T_CALLABLE:
1339
+                	if ($typeHintToken === false) {
1340
+                    	$typeHintToken = $i;
1341
+                	}
1342
+
1343
+                	$typeHint .= $this->tokens[$i]['content'];
1344
+                	break;
1345
+            	case T_SELF:
1346
+            	case T_PARENT:
1347
+            	case T_STATIC:
1348
+                	// Self and parent are valid, static invalid, but was probably intended as type hint.
1349
+                	if (isset($defaultStart) === false) {
1350
+                    	if ($typeHintToken === false) {
1351
+                        	$typeHintToken = $i;
1352
+                    	}
1353
+
1354
+                    	$typeHint .= $this->tokens[$i]['content'];
1355
+                	}
1356
+                	break;
1357
+            	case T_STRING:
1358
+                	// This is a string, so it may be a type hint, but it could
1359
+                	// also be a constant used as a default value.
1360
+                	$prevComma = false;
1361
+                	for ($t = $i; $t >= $opener; $t--) {
1362
+                    	if ($this->tokens[$t]['code'] === T_COMMA) {
1363
+                        	$prevComma = $t;
1364
+                        	break;
1365
+                    	}
1366
+                	}
1367
+
1368
+                	if ($prevComma !== false) {
1369
+                    	$nextEquals = false;
1370
+                    	for ($t = $prevComma; $t < $i; $t++) {
1371
+                        	if ($this->tokens[$t]['code'] === T_EQUAL) {
1372
+                            	$nextEquals = $t;
1373
+                            	break;
1374
+                        	}
1375
+                    	}
1376
+
1377
+                    	if ($nextEquals !== false) {
1378
+                        	break;
1379
+                    	}
1380
+                	}
1381
+
1382
+                	if ($defaultStart === null) {
1383
+                    	if ($typeHintToken === false) {
1384
+                        	$typeHintToken = $i;
1385
+                    	}
1386
+
1387
+                    	$typeHint .= $this->tokens[$i]['content'];
1388
+                	}
1389
+                	break;
1390
+            	case T_NS_SEPARATOR:
1391
+                	// Part of a type hint or default value.
1392
+                	if ($defaultStart === null) {
1393
+                    	if ($typeHintToken === false) {
1394
+                        	$typeHintToken = $i;
1395
+                    	}
1396
+
1397
+                    	$typeHint .= $this->tokens[$i]['content'];
1398
+                	}
1399
+                	break;
1400
+            	case T_NULLABLE:
1401
+                	if ($defaultStart === null) {
1402
+                    	$nullableType = true;
1403
+                    	$typeHint    .= $this->tokens[$i]['content'];
1404
+                	}
1405
+                	break;
1406
+            	case T_CLOSE_PARENTHESIS:
1407
+            	case T_COMMA:
1408
+                	// If it's null, then there must be no parameters for this
1409
+                	// method.
1410
+                	if ($currVar === null) {
1411
+                    	continue 2;
1412
+                	}
1413
+
1414
+                	$vars[$paramCount]            = [];
1415
+                	$vars[$paramCount]['token']   = $currVar;
1416
+                	$vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
+                	$vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1418
+
1419
+                	if ($defaultStart !== null) {
1420
+                    	$vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1421
+                	}
1422
+
1423
+                	$vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
+                	$vars[$paramCount]['variable_length']   = $variableLength;
1425
+                	$vars[$paramCount]['type_hint']         = $typeHint;
1426
+                	$vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
+                	$vars[$paramCount]['nullable_type']     = $nullableType;
1428
+
1429
+                	// Reset the vars, as we are about to process the next parameter.
1430
+                	$defaultStart    = null;
1431
+                	$paramStart      = ($i + 1);
1432
+                	$passByReference = false;
1433
+                	$variableLength  = false;
1434
+                	$typeHint        = '';
1435
+                	$typeHintToken   = false;
1436
+                	$nullableType    = false;
1437
+
1438
+                	$paramCount++;
1439
+                	break;
1440
+            	case T_EQUAL:
1441
+                	$defaultStart = ($i + 1);
1442
+                	break;
1443 1443
             }//end switch
1444 1444
         }//end for
1445 1445
 
@@ -1515,27 +1515,27 @@  discard block
 block discarded – undo
1515 1515
             }
1516 1516
 
1517 1517
             switch ($this->tokens[$i]['code']) {
1518
-            case T_PUBLIC:
1519
-                $scope          = 'public';
1520
-                $scopeSpecified = true;
1521
-                break;
1522
-            case T_PRIVATE:
1523
-                $scope          = 'private';
1524
-                $scopeSpecified = true;
1525
-                break;
1526
-            case T_PROTECTED:
1527
-                $scope          = 'protected';
1528
-                $scopeSpecified = true;
1529
-                break;
1530
-            case T_ABSTRACT:
1531
-                $isAbstract = true;
1532
-                break;
1533
-            case T_FINAL:
1534
-                $isFinal = true;
1535
-                break;
1536
-            case T_STATIC:
1537
-                $isStatic = true;
1538
-                break;
1518
+            	case T_PUBLIC:
1519
+                	$scope          = 'public';
1520
+                	$scopeSpecified = true;
1521
+                	break;
1522
+            	case T_PRIVATE:
1523
+                	$scope          = 'private';
1524
+                	$scopeSpecified = true;
1525
+                	break;
1526
+            	case T_PROTECTED:
1527
+                	$scope          = 'protected';
1528
+                	$scopeSpecified = true;
1529
+                	break;
1530
+            	case T_ABSTRACT:
1531
+                	$isAbstract = true;
1532
+                	break;
1533
+            	case T_FINAL:
1534
+                	$isFinal = true;
1535
+                	break;
1536
+            	case T_STATIC:
1537
+                	$isStatic = true;
1538
+                	break;
1539 1539
             }//end switch
1540 1540
         }//end for
1541 1541
 
@@ -1697,21 +1697,21 @@  discard block
 block discarded – undo
1697 1697
             }
1698 1698
 
1699 1699
             switch ($this->tokens[$i]['code']) {
1700
-            case T_PUBLIC:
1701
-                $scope          = 'public';
1702
-                $scopeSpecified = true;
1703
-                break;
1704
-            case T_PRIVATE:
1705
-                $scope          = 'private';
1706
-                $scopeSpecified = true;
1707
-                break;
1708
-            case T_PROTECTED:
1709
-                $scope          = 'protected';
1710
-                $scopeSpecified = true;
1711
-                break;
1712
-            case T_STATIC:
1713
-                $isStatic = true;
1714
-                break;
1700
+            	case T_PUBLIC:
1701
+                	$scope          = 'public';
1702
+                	$scopeSpecified = true;
1703
+                	break;
1704
+            	case T_PRIVATE:
1705
+                	$scope          = 'private';
1706
+                	$scopeSpecified = true;
1707
+                	break;
1708
+            	case T_PROTECTED:
1709
+                	$scope          = 'protected';
1710
+                	$scopeSpecified = true;
1711
+                	break;
1712
+            	case T_STATIC:
1713
+                	$isStatic = true;
1714
+                	break;
1715 1715
             }
1716 1716
         }//end for
1717 1717
 
@@ -1765,13 +1765,13 @@  discard block
 block discarded – undo
1765 1765
             }
1766 1766
 
1767 1767
             switch ($this->tokens[$i]['code']) {
1768
-            case T_ABSTRACT:
1769
-                $isAbstract = true;
1770
-                break;
1768
+            	case T_ABSTRACT:
1769
+                	$isAbstract = true;
1770
+                	break;
1771 1771
 
1772
-            case T_FINAL:
1773
-                $isFinal = true;
1774
-                break;
1772
+            	case T_FINAL:
1773
+                	$isFinal = true;
1774
+                	break;
1775 1775
             }
1776 1776
         }//end for
1777 1777
 
Please login to merge, or discard this patch.
Spacing   +567 added lines, -567 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @var array
108 108
      */
109
-    protected $tokens = [];
109
+    protected $tokens = [ ];
110 110
 
111 111
     /**
112 112
      * The errors raised from sniffs.
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      * @var array
115 115
      * @see getErrors()
116 116
      */
117
-    protected $errors = [];
117
+    protected $errors = [ ];
118 118
 
119 119
     /**
120 120
      * The warnings raised from sniffs.
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @var array
123 123
      * @see getWarnings()
124 124
      */
125
-    protected $warnings = [];
125
+    protected $warnings = [ ];
126 126
 
127 127
     /**
128 128
      * The metrics recorded by sniffs.
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
      * @var array
131 131
      * @see getMetrics()
132 132
      */
133
-    protected $metrics = [];
133
+    protected $metrics = [ ];
134 134
 
135 135
     /**
136 136
      * The metrics recorded for each token.
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
      * @var array
141 141
      * @see getMetrics()
142 142
      */
143
-    private $metricTokens = [];
143
+    private $metricTokens = [ ];
144 144
 
145 145
     /**
146 146
      * The total number of errors raised.
@@ -175,21 +175,21 @@  discard block
 block discarded – undo
175 175
      *
176 176
      * @var array
177 177
      */
178
-    protected $ignoredListeners = [];
178
+    protected $ignoredListeners = [ ];
179 179
 
180 180
     /**
181 181
      * An array of message codes that are being ignored.
182 182
      *
183 183
      * @var array
184 184
      */
185
-    protected $ignoredCodes = [];
185
+    protected $ignoredCodes = [ ];
186 186
 
187 187
     /**
188 188
      * An array of sniffs listening to this file's processing.
189 189
      *
190 190
      * @var \PHP_CodeSniffer\Sniffs\Sniff[]
191 191
      */
192
-    protected $listeners = [];
192
+    protected $listeners = [ ];
193 193
 
194 194
     /**
195 195
      * The class name of the sniff currently processing the file.
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @var array
205 205
      */
206
-    protected $listenerTimes = [];
206
+    protected $listenerTimes = [ ];
207 207
 
208 208
     /**
209 209
      * A cache of often used config settings to improve performance.
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @var array
214 214
      */
215
-    protected $configCache = [];
215
+    protected $configCache = [ ];
216 216
 
217 217
 
218 218
     /**
@@ -224,30 +224,30 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return void
226 226
      */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
227
+    public function __construct( $path, Ruleset $ruleset, Config $config )
228 228
     {
229 229
         $this->path    = $path;
230 230
         $this->ruleset = $ruleset;
231 231
         $this->config  = $config;
232 232
         $this->fixer   = new Fixer();
233 233
 
234
-        $parts     = explode('.', $path);
235
-        $extension = array_pop($parts);
236
-        if (isset($config->extensions[$extension]) === true) {
237
-            $this->tokenizerType = $config->extensions[$extension];
234
+        $parts     = explode( '.', $path );
235
+        $extension = array_pop( $parts );
236
+        if ( isset( $config->extensions[ $extension ] ) === true ) {
237
+            $this->tokenizerType = $config->extensions[ $extension ];
238 238
         } else {
239 239
             // Revert to default.
240 240
             $this->tokenizerType = 'PHP';
241 241
         }
242 242
 
243
-        $this->configCache['cache']           = $this->config->cache;
244
-        $this->configCache['sniffs']          = array_map('strtolower', $this->config->sniffs);
245
-        $this->configCache['exclude']         = array_map('strtolower', $this->config->exclude);
246
-        $this->configCache['errorSeverity']   = $this->config->errorSeverity;
247
-        $this->configCache['warningSeverity'] = $this->config->warningSeverity;
248
-        $this->configCache['recordErrors']    = $this->config->recordErrors;
249
-        $this->configCache['ignorePatterns']  = $this->ruleset->ignorePatterns;
250
-        $this->configCache['includePatterns'] = $this->ruleset->includePatterns;
243
+        $this->configCache[ 'cache' ]           = $this->config->cache;
244
+        $this->configCache[ 'sniffs' ]          = array_map( 'strtolower', $this->config->sniffs );
245
+        $this->configCache[ 'exclude' ]         = array_map( 'strtolower', $this->config->exclude );
246
+        $this->configCache[ 'errorSeverity' ]   = $this->config->errorSeverity;
247
+        $this->configCache[ 'warningSeverity' ] = $this->config->warningSeverity;
248
+        $this->configCache[ 'recordErrors' ]    = $this->config->recordErrors;
249
+        $this->configCache[ 'ignorePatterns' ]  = $this->ruleset->ignorePatterns;
250
+        $this->configCache[ 'includePatterns' ] = $this->ruleset->includePatterns;
251 251
 
252 252
     }//end __construct()
253 253
 
@@ -261,15 +261,15 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return void
263 263
      */
264
-    public function setContent($content)
264
+    public function setContent( $content )
265 265
     {
266 266
         $this->content = $content;
267
-        $this->tokens  = [];
267
+        $this->tokens  = [ ];
268 268
 
269 269
         try {
270
-            $this->eolChar = Util\Common::detectLineEndings($content);
271
-        } catch (RuntimeException $e) {
272
-            $this->addWarningOnLine($e->getMessage(), 1, 'Internal.DetectLineEndings');
270
+            $this->eolChar = Util\Common::detectLineEndings( $content );
271
+        } catch ( RuntimeException $e ) {
272
+            $this->addWarningOnLine( $e->getMessage(), 1, 'Internal.DetectLineEndings' );
273 273
             return;
274 274
         }
275 275
 
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
      */
298 298
     public function disableCaching()
299 299
     {
300
-        $this->configCache['cache'] = false;
300
+        $this->configCache[ 'cache' ] = false;
301 301
 
302 302
     }//end disableCaching()
303 303
 
@@ -309,12 +309,12 @@  discard block
 block discarded – undo
309 309
      */
310 310
     public function process()
311 311
     {
312
-        if ($this->ignored === true) {
312
+        if ( $this->ignored === true ) {
313 313
             return;
314 314
         }
315 315
 
316
-        $this->errors       = [];
317
-        $this->warnings     = [];
316
+        $this->errors       = [ ];
317
+        $this->warnings     = [ ];
318 318
         $this->errorCount   = 0;
319 319
         $this->warningCount = 0;
320 320
         $this->fixableCount = 0;
@@ -322,106 +322,106 @@  discard block
 block discarded – undo
322 322
         $this->parse();
323 323
 
324 324
         // Check if tokenizer errors cause this file to be ignored.
325
-        if ($this->ignored === true) {
325
+        if ( $this->ignored === true ) {
326 326
             return;
327 327
         }
328 328
 
329
-        $this->fixer->startFile($this);
329
+        $this->fixer->startFile( $this );
330 330
 
331
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
332
-            echo "\t*** START TOKEN PROCESSING ***".PHP_EOL;
331
+        if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
332
+            echo "\t*** START TOKEN PROCESSING ***" . PHP_EOL;
333 333
         }
334 334
 
335 335
         $foundCode        = false;
336
-        $listenerIgnoreTo = [];
337
-        $inTests          = defined('PHP_CODESNIFFER_IN_TESTS');
336
+        $listenerIgnoreTo = [ ];
337
+        $inTests          = defined( 'PHP_CODESNIFFER_IN_TESTS' );
338 338
         $checkAnnotations = $this->config->annotations;
339 339
 
340 340
         // Foreach of the listeners that have registered to listen for this
341 341
         // token, get them to process it.
342
-        foreach ($this->tokens as $stackPtr => $token) {
342
+        foreach ( $this->tokens as $stackPtr => $token ) {
343 343
             // Check for ignored lines.
344
-            if ($checkAnnotations === true
345
-                && ($token['code'] === T_COMMENT
346
-                || $token['code'] === T_PHPCS_IGNORE_FILE
347
-                || $token['code'] === T_PHPCS_SET
348
-                || $token['code'] === T_DOC_COMMENT_STRING
349
-                || $token['code'] === T_DOC_COMMENT_TAG
350
-                || ($inTests === true && $token['code'] === T_INLINE_HTML))
344
+            if ( $checkAnnotations === true
345
+                && ( $token[ 'code' ] === T_COMMENT
346
+                || $token[ 'code' ] === T_PHPCS_IGNORE_FILE
347
+                || $token[ 'code' ] === T_PHPCS_SET
348
+                || $token[ 'code' ] === T_DOC_COMMENT_STRING
349
+                || $token[ 'code' ] === T_DOC_COMMENT_TAG
350
+                || ( $inTests === true && $token[ 'code' ] === T_INLINE_HTML ) )
351 351
             ) {
352
-                $commentText      = ltrim($this->tokens[$stackPtr]['content'], ' /*');
353
-                $commentTextLower = strtolower($commentText);
354
-                if (strpos($commentText, '@codingStandards') !== false) {
355
-                    if (strpos($commentText, '@codingStandardsIgnoreFile') !== false) {
352
+                $commentText      = ltrim( $this->tokens[ $stackPtr ][ 'content' ], ' /*' );
353
+                $commentTextLower = strtolower( $commentText );
354
+                if ( strpos( $commentText, '@codingStandards' ) !== false ) {
355
+                    if ( strpos( $commentText, '@codingStandardsIgnoreFile' ) !== false ) {
356 356
                         // Ignoring the whole file, just a little late.
357
-                        $this->errors       = [];
358
-                        $this->warnings     = [];
357
+                        $this->errors       = [ ];
358
+                        $this->warnings     = [ ];
359 359
                         $this->errorCount   = 0;
360 360
                         $this->warningCount = 0;
361 361
                         $this->fixableCount = 0;
362 362
                         return;
363
-                    } else if (strpos($commentText, '@codingStandardsChangeSetting') !== false) {
364
-                        $start   = strpos($commentText, '@codingStandardsChangeSetting');
365
-                        $comment = substr($commentText, ($start + 30));
366
-                        $parts   = explode(' ', $comment);
367
-                        if (count($parts) >= 2) {
368
-                            $sniffParts = explode('.', $parts[0]);
369
-                            if (count($sniffParts) >= 3) {
363
+                    } else if ( strpos( $commentText, '@codingStandardsChangeSetting' ) !== false ) {
364
+                        $start   = strpos( $commentText, '@codingStandardsChangeSetting' );
365
+                        $comment = substr( $commentText, ( $start + 30 ) );
366
+                        $parts   = explode( ' ', $comment );
367
+                        if ( count( $parts ) >= 2 ) {
368
+                            $sniffParts = explode( '.', $parts[ 0 ] );
369
+                            if ( count( $sniffParts ) >= 3 ) {
370 370
                                 // If the sniff code is not known to us, it has not been registered in this run.
371 371
                                 // But don't throw an error as it could be there for a different standard to use.
372
-                                if (isset($this->ruleset->sniffCodes[$parts[0]]) === true) {
373
-                                    $listenerCode  = array_shift($parts);
374
-                                    $propertyCode  = array_shift($parts);
375
-                                    $propertyValue = rtrim(implode(' ', $parts), " */\r\n");
376
-                                    $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
377
-                                    $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
372
+                                if ( isset( $this->ruleset->sniffCodes[ $parts[ 0 ] ] ) === true ) {
373
+                                    $listenerCode  = array_shift( $parts );
374
+                                    $propertyCode  = array_shift( $parts );
375
+                                    $propertyValue = rtrim( implode( ' ', $parts ), " */\r\n" );
376
+                                    $listenerClass = $this->ruleset->sniffCodes[ $listenerCode ];
377
+                                    $this->ruleset->setSniffProperty( $listenerClass, $propertyCode, $propertyValue );
378 378
                                 }
379 379
                             }
380 380
                         }
381 381
                     }//end if
382
-                } else if (substr($commentTextLower, 0, 16) === 'phpcs:ignorefile'
383
-                    || substr($commentTextLower, 0, 17) === '@phpcs:ignorefile'
382
+                } else if ( substr( $commentTextLower, 0, 16 ) === 'phpcs:ignorefile'
383
+                    || substr( $commentTextLower, 0, 17 ) === '@phpcs:ignorefile'
384 384
                 ) {
385 385
                     // Ignoring the whole file, just a little late.
386
-                    $this->errors       = [];
387
-                    $this->warnings     = [];
386
+                    $this->errors       = [ ];
387
+                    $this->warnings     = [ ];
388 388
                     $this->errorCount   = 0;
389 389
                     $this->warningCount = 0;
390 390
                     $this->fixableCount = 0;
391 391
                     return;
392
-                } else if (substr($commentTextLower, 0, 9) === 'phpcs:set'
393
-                    || substr($commentTextLower, 0, 10) === '@phpcs:set'
392
+                } else if ( substr( $commentTextLower, 0, 9 ) === 'phpcs:set'
393
+                    || substr( $commentTextLower, 0, 10 ) === '@phpcs:set'
394 394
                 ) {
395
-                    if (isset($token['sniffCode']) === true) {
396
-                        $listenerCode = $token['sniffCode'];
397
-                        if (isset($this->ruleset->sniffCodes[$listenerCode]) === true) {
398
-                            $propertyCode  = $token['sniffProperty'];
399
-                            $propertyValue = $token['sniffPropertyValue'];
400
-                            $listenerClass = $this->ruleset->sniffCodes[$listenerCode];
401
-                            $this->ruleset->setSniffProperty($listenerClass, $propertyCode, $propertyValue);
395
+                    if ( isset( $token[ 'sniffCode' ] ) === true ) {
396
+                        $listenerCode = $token[ 'sniffCode' ];
397
+                        if ( isset( $this->ruleset->sniffCodes[ $listenerCode ] ) === true ) {
398
+                            $propertyCode  = $token[ 'sniffProperty' ];
399
+                            $propertyValue = $token[ 'sniffPropertyValue' ];
400
+                            $listenerClass = $this->ruleset->sniffCodes[ $listenerCode ];
401
+                            $this->ruleset->setSniffProperty( $listenerClass, $propertyCode, $propertyValue );
402 402
                         }
403 403
                     }
404 404
                 }//end if
405 405
             }//end if
406 406
 
407
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
408
-                $type    = $token['type'];
409
-                $content = Util\Common::prepareForOutput($token['content']);
410
-                echo "\t\tProcess token $stackPtr: $type => $content".PHP_EOL;
407
+            if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
408
+                $type    = $token[ 'type' ];
409
+                $content = Util\Common::prepareForOutput( $token[ 'content' ] );
410
+                echo "\t\tProcess token $stackPtr: $type => $content" . PHP_EOL;
411 411
             }
412 412
 
413
-            if ($token['code'] !== T_INLINE_HTML) {
413
+            if ( $token[ 'code' ] !== T_INLINE_HTML ) {
414 414
                 $foundCode = true;
415 415
             }
416 416
 
417
-            if (isset($this->ruleset->tokenListeners[$token['code']]) === false) {
417
+            if ( isset( $this->ruleset->tokenListeners[ $token[ 'code' ] ] ) === false ) {
418 418
                 continue;
419 419
             }
420 420
 
421
-            foreach ($this->ruleset->tokenListeners[$token['code']] as $listenerData) {
422
-                if (isset($this->ignoredListeners[$listenerData['class']]) === true
423
-                    || (isset($listenerIgnoreTo[$listenerData['class']]) === true
424
-                    && $listenerIgnoreTo[$listenerData['class']] > $stackPtr)
421
+            foreach ( $this->ruleset->tokenListeners[ $token[ 'code' ] ] as $listenerData ) {
422
+                if ( isset( $this->ignoredListeners[ $listenerData[ 'class' ] ] ) === true
423
+                    || ( isset( $listenerIgnoreTo[ $listenerData[ 'class' ] ] ) === true
424
+                    && $listenerIgnoreTo[ $listenerData[ 'class' ] ] > $stackPtr )
425 425
                 ) {
426 426
                     // This sniff is ignoring past this token, or the whole file.
427 427
                     continue;
@@ -429,78 +429,78 @@  discard block
 block discarded – undo
429 429
 
430 430
                 // Make sure this sniff supports the tokenizer
431 431
                 // we are currently using.
432
-                $class = $listenerData['class'];
432
+                $class = $listenerData[ 'class' ];
433 433
 
434
-                if (isset($listenerData['tokenizers'][$this->tokenizerType]) === false) {
434
+                if ( isset( $listenerData[ 'tokenizers' ][ $this->tokenizerType ] ) === false ) {
435 435
                     continue;
436 436
                 }
437 437
 
438 438
                 // If the file path matches one of our ignore patterns, skip it.
439 439
                 // While there is support for a type of each pattern
440 440
                 // (absolute or relative) we don't actually support it here.
441
-                foreach ($listenerData['ignore'] as $pattern) {
441
+                foreach ( $listenerData[ 'ignore' ] as $pattern ) {
442 442
                     // We assume a / directory separator, as do the exclude rules
443 443
                     // most developers write, so we need a special case for any system
444 444
                     // that is different.
445
-                    if (DIRECTORY_SEPARATOR === '\\') {
446
-                        $pattern = str_replace('/', '\\\\', $pattern);
445
+                    if ( DIRECTORY_SEPARATOR === '\\' ) {
446
+                        $pattern = str_replace( '/', '\\\\', $pattern );
447 447
                     }
448 448
 
449
-                    $pattern = '`'.$pattern.'`i';
450
-                    if (preg_match($pattern, $this->path) === 1) {
451
-                        $this->ignoredListeners[$class] = true;
452
-                        continue(2);
449
+                    $pattern = '`' . $pattern . '`i';
450
+                    if ( preg_match( $pattern, $this->path ) === 1 ) {
451
+                        $this->ignoredListeners[ $class ] = true;
452
+                        continue( 2 );
453 453
                     }
454 454
                 }
455 455
 
456 456
                 // If the file path does not match one of our include patterns, skip it.
457 457
                 // While there is support for a type of each pattern
458 458
                 // (absolute or relative) we don't actually support it here.
459
-                if (empty($listenerData['include']) === false) {
459
+                if ( empty( $listenerData[ 'include' ] ) === false ) {
460 460
                     $included = false;
461
-                    foreach ($listenerData['include'] as $pattern) {
461
+                    foreach ( $listenerData[ 'include' ] as $pattern ) {
462 462
                         // We assume a / directory separator, as do the exclude rules
463 463
                         // most developers write, so we need a special case for any system
464 464
                         // that is different.
465
-                        if (DIRECTORY_SEPARATOR === '\\') {
466
-                            $pattern = str_replace('/', '\\\\', $pattern);
465
+                        if ( DIRECTORY_SEPARATOR === '\\' ) {
466
+                            $pattern = str_replace( '/', '\\\\', $pattern );
467 467
                         }
468 468
 
469
-                        $pattern = '`'.$pattern.'`i';
470
-                        if (preg_match($pattern, $this->path) === 1) {
469
+                        $pattern = '`' . $pattern . '`i';
470
+                        if ( preg_match( $pattern, $this->path ) === 1 ) {
471 471
                             $included = true;
472 472
                             break;
473 473
                         }
474 474
                     }
475 475
 
476
-                    if ($included === false) {
477
-                        $this->ignoredListeners[$class] = true;
476
+                    if ( $included === false ) {
477
+                        $this->ignoredListeners[ $class ] = true;
478 478
                         continue;
479 479
                     }
480 480
                 }//end if
481 481
 
482 482
                 $this->activeListener = $class;
483 483
 
484
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
485
-                    $startTime = microtime(true);
486
-                    echo "\t\t\tProcessing ".$this->activeListener.'... ';
484
+                if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
485
+                    $startTime = microtime( true );
486
+                    echo "\t\t\tProcessing " . $this->activeListener . '... ';
487 487
                 }
488 488
 
489
-                $ignoreTo = $this->ruleset->sniffs[$class]->process($this, $stackPtr);
490
-                if ($ignoreTo !== null) {
491
-                    $listenerIgnoreTo[$this->activeListener] = $ignoreTo;
489
+                $ignoreTo = $this->ruleset->sniffs[ $class ]->process( $this, $stackPtr );
490
+                if ( $ignoreTo !== null ) {
491
+                    $listenerIgnoreTo[ $this->activeListener ] = $ignoreTo;
492 492
                 }
493 493
 
494
-                if (PHP_CODESNIFFER_VERBOSITY > 2) {
495
-                    $timeTaken = (microtime(true) - $startTime);
496
-                    if (isset($this->listenerTimes[$this->activeListener]) === false) {
497
-                        $this->listenerTimes[$this->activeListener] = 0;
494
+                if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
495
+                    $timeTaken = ( microtime( true ) - $startTime );
496
+                    if ( isset( $this->listenerTimes[ $this->activeListener ] ) === false ) {
497
+                        $this->listenerTimes[ $this->activeListener ] = 0;
498 498
                     }
499 499
 
500
-                    $this->listenerTimes[$this->activeListener] += $timeTaken;
500
+                    $this->listenerTimes[ $this->activeListener ] += $timeTaken;
501 501
 
502
-                    $timeTaken = round(($timeTaken), 4);
503
-                    echo "DONE in $timeTaken seconds".PHP_EOL;
502
+                    $timeTaken = round( ( $timeTaken ), 4 );
503
+                    echo "DONE in $timeTaken seconds" . PHP_EOL;
504 504
                 }
505 505
 
506 506
                 $this->activeListener = '';
@@ -513,25 +513,25 @@  discard block
 block discarded – undo
513 513
         // We don't show this error for STDIN because we can't be sure the content
514 514
         // actually came directly from the user. It could be something like
515 515
         // refs from a Git pre-push hook.
516
-        if ($foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN') {
517
-            $shortTags = (bool) ini_get('short_open_tag');
518
-            if ($shortTags === false) {
516
+        if ( $foundCode === false && $this->tokenizerType === 'PHP' && $this->path !== 'STDIN' ) {
517
+            $shortTags = (bool)ini_get( 'short_open_tag' );
518
+            if ( $shortTags === false ) {
519 519
                 $error = 'No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.';
520
-                $this->addWarning($error, null, 'Internal.NoCodeFound');
520
+                $this->addWarning( $error, null, 'Internal.NoCodeFound' );
521 521
             }
522 522
         }
523 523
 
524
-        if (PHP_CODESNIFFER_VERBOSITY > 2) {
525
-            echo "\t*** END TOKEN PROCESSING ***".PHP_EOL;
526
-            echo "\t*** START SNIFF PROCESSING REPORT ***".PHP_EOL;
524
+        if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
525
+            echo "\t*** END TOKEN PROCESSING ***" . PHP_EOL;
526
+            echo "\t*** START SNIFF PROCESSING REPORT ***" . PHP_EOL;
527 527
 
528
-            asort($this->listenerTimes, SORT_NUMERIC);
529
-            $this->listenerTimes = array_reverse($this->listenerTimes, true);
530
-            foreach ($this->listenerTimes as $listener => $timeTaken) {
531
-                echo "\t$listener: ".round(($timeTaken), 4).' secs'.PHP_EOL;
528
+            asort( $this->listenerTimes, SORT_NUMERIC );
529
+            $this->listenerTimes = array_reverse( $this->listenerTimes, true );
530
+            foreach ( $this->listenerTimes as $listener => $timeTaken ) {
531
+                echo "\t$listener: " . round( ( $timeTaken ), 4 ) . ' secs' . PHP_EOL;
532 532
             }
533 533
 
534
-            echo "\t*** END SNIFF PROCESSING REPORT ***".PHP_EOL;
534
+            echo "\t*** END SNIFF PROCESSING REPORT ***" . PHP_EOL;
535 535
         }
536 536
 
537 537
         $this->fixedCount += $this->fixer->getFixCount();
@@ -546,21 +546,21 @@  discard block
 block discarded – undo
546 546
      */
547 547
     public function parse()
548 548
     {
549
-        if (empty($this->tokens) === false) {
549
+        if ( empty( $this->tokens ) === false ) {
550 550
             // File has already been parsed.
551 551
             return;
552 552
         }
553 553
 
554 554
         try {
555
-            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\'.$this->tokenizerType;
556
-            $this->tokenizer = new $tokenizerClass($this->content, $this->config, $this->eolChar);
555
+            $tokenizerClass  = 'PHP_CodeSniffer\Tokenizers\\' . $this->tokenizerType;
556
+            $this->tokenizer = new $tokenizerClass( $this->content, $this->config, $this->eolChar );
557 557
             $this->tokens    = $this->tokenizer->getTokens();
558
-        } catch (TokenizerException $e) {
558
+        } catch ( TokenizerException $e ) {
559 559
             $this->ignored = true;
560
-            $this->addWarning($e->getMessage(), null, 'Internal.Tokenizer.Exception');
561
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
560
+            $this->addWarning( $e->getMessage(), null, 'Internal.Tokenizer.Exception' );
561
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
562 562
                 echo "[$this->tokenizerType => tokenizer error]... ";
563
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
563
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
564 564
                     echo PHP_EOL;
565 565
                 }
566 566
             }
@@ -568,31 +568,31 @@  discard block
 block discarded – undo
568 568
             return;
569 569
         }
570 570
 
571
-        $this->numTokens = count($this->tokens);
571
+        $this->numTokens = count( $this->tokens );
572 572
 
573 573
         // Check for mixed line endings as these can cause tokenizer errors and we
574 574
         // should let the user know that the results they get may be incorrect.
575 575
         // This is done by removing all backslashes, removing the newline char we
576 576
         // detected, then converting newlines chars into text. If any backslashes
577 577
         // are left at the end, we have additional newline chars in use.
578
-        $contents = str_replace('\\', '', $this->content);
579
-        $contents = str_replace($this->eolChar, '', $contents);
580
-        $contents = str_replace("\n", '\n', $contents);
581
-        $contents = str_replace("\r", '\r', $contents);
582
-        if (strpos($contents, '\\') !== false) {
578
+        $contents = str_replace( '\\', '', $this->content );
579
+        $contents = str_replace( $this->eolChar, '', $contents );
580
+        $contents = str_replace( "\n", '\n', $contents );
581
+        $contents = str_replace( "\r", '\r', $contents );
582
+        if ( strpos( $contents, '\\' ) !== false ) {
583 583
             $error = 'File has mixed line endings; this may cause incorrect results';
584
-            $this->addWarningOnLine($error, 1, 'Internal.LineEndings.Mixed');
584
+            $this->addWarningOnLine( $error, 1, 'Internal.LineEndings.Mixed' );
585 585
         }
586 586
 
587
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
588
-            if ($this->numTokens === 0) {
587
+        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
588
+            if ( $this->numTokens === 0 ) {
589 589
                 $numLines = 0;
590 590
             } else {
591
-                $numLines = $this->tokens[($this->numTokens - 1)]['line'];
591
+                $numLines = $this->tokens[ ( $this->numTokens - 1 ) ][ 'line' ];
592 592
             }
593 593
 
594 594
             echo "[$this->tokenizerType => $this->numTokens tokens in $numLines lines]... ";
595
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
595
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
596 596
                 echo PHP_EOL;
597 597
             }
598 598
         }
@@ -648,19 +648,19 @@  discard block
 block discarded – undo
648 648
         $error,
649 649
         $stackPtr,
650 650
         $code,
651
-        $data=[],
652
-        $severity=0,
653
-        $fixable=false
651
+        $data = [ ],
652
+        $severity = 0,
653
+        $fixable = false
654 654
     ) {
655
-        if ($stackPtr === null) {
655
+        if ( $stackPtr === null ) {
656 656
             $line   = 1;
657 657
             $column = 1;
658 658
         } else {
659
-            $line   = $this->tokens[$stackPtr]['line'];
660
-            $column = $this->tokens[$stackPtr]['column'];
659
+            $line   = $this->tokens[ $stackPtr ][ 'line' ];
660
+            $column = $this->tokens[ $stackPtr ][ 'column' ];
661 661
         }
662 662
 
663
-        return $this->addMessage(true, $error, $line, $column, $code, $data, $severity, $fixable);
663
+        return $this->addMessage( true, $error, $line, $column, $code, $data, $severity, $fixable );
664 664
 
665 665
     }//end addError()
666 666
 
@@ -682,19 +682,19 @@  discard block
 block discarded – undo
682 682
         $warning,
683 683
         $stackPtr,
684 684
         $code,
685
-        $data=[],
686
-        $severity=0,
687
-        $fixable=false
685
+        $data = [ ],
686
+        $severity = 0,
687
+        $fixable = false
688 688
     ) {
689
-        if ($stackPtr === null) {
689
+        if ( $stackPtr === null ) {
690 690
             $line   = 1;
691 691
             $column = 1;
692 692
         } else {
693
-            $line   = $this->tokens[$stackPtr]['line'];
694
-            $column = $this->tokens[$stackPtr]['column'];
693
+            $line   = $this->tokens[ $stackPtr ][ 'line' ];
694
+            $column = $this->tokens[ $stackPtr ][ 'column' ];
695 695
         }
696 696
 
697
-        return $this->addMessage(false, $warning, $line, $column, $code, $data, $severity, $fixable);
697
+        return $this->addMessage( false, $warning, $line, $column, $code, $data, $severity, $fixable );
698 698
 
699 699
     }//end addWarning()
700 700
 
@@ -715,10 +715,10 @@  discard block
 block discarded – undo
715 715
         $error,
716 716
         $line,
717 717
         $code,
718
-        $data=[],
719
-        $severity=0
718
+        $data = [ ],
719
+        $severity = 0
720 720
     ) {
721
-        return $this->addMessage(true, $error, $line, 1, $code, $data, $severity, false);
721
+        return $this->addMessage( true, $error, $line, 1, $code, $data, $severity, false );
722 722
 
723 723
     }//end addErrorOnLine()
724 724
 
@@ -739,10 +739,10 @@  discard block
 block discarded – undo
739 739
         $warning,
740 740
         $line,
741 741
         $code,
742
-        $data=[],
743
-        $severity=0
742
+        $data = [ ],
743
+        $severity = 0
744 744
     ) {
745
-        return $this->addMessage(false, $warning, $line, 1, $code, $data, $severity, false);
745
+        return $this->addMessage( false, $warning, $line, 1, $code, $data, $severity, false );
746 746
 
747 747
     }//end addWarningOnLine()
748 748
 
@@ -765,11 +765,11 @@  discard block
 block discarded – undo
765 765
         $error,
766 766
         $stackPtr,
767 767
         $code,
768
-        $data=[],
769
-        $severity=0
768
+        $data = [ ],
769
+        $severity = 0
770 770
     ) {
771
-        $recorded = $this->addError($error, $stackPtr, $code, $data, $severity, true);
772
-        if ($recorded === true && $this->fixer->enabled === true) {
771
+        $recorded = $this->addError( $error, $stackPtr, $code, $data, $severity, true );
772
+        if ( $recorded === true && $this->fixer->enabled === true ) {
773 773
             return true;
774 774
         }
775 775
 
@@ -796,11 +796,11 @@  discard block
 block discarded – undo
796 796
         $warning,
797 797
         $stackPtr,
798 798
         $code,
799
-        $data=[],
800
-        $severity=0
799
+        $data = [ ],
800
+        $severity = 0
801 801
     ) {
802
-        $recorded = $this->addWarning($warning, $stackPtr, $code, $data, $severity, true);
803
-        if ($recorded === true && $this->fixer->enabled === true) {
802
+        $recorded = $this->addWarning( $warning, $stackPtr, $code, $data, $severity, true );
803
+        if ( $recorded === true && $this->fixer->enabled === true ) {
804 804
             return true;
805 805
         }
806 806
 
@@ -824,156 +824,156 @@  discard block
 block discarded – undo
824 824
      *
825 825
      * @return boolean
826 826
      */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
827
+    protected function addMessage( $error, $message, $line, $column, $code, $data, $severity, $fixable )
828 828
     {
829 829
         // Check if this line is ignoring all message codes.
830
-        if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
830
+        if ( isset( $this->tokenizer->ignoredLines[ $line ][ '.all' ] ) === true ) {
831 831
             return false;
832 832
         }
833 833
 
834 834
         // Work out which sniff generated the message.
835
-        $parts = explode('.', $code);
836
-        if ($parts[0] === 'Internal') {
835
+        $parts = explode( '.', $code );
836
+        if ( $parts[ 0 ] === 'Internal' ) {
837 837
             // An internal message.
838
-            $listenerCode = Util\Common::getSniffCode($this->activeListener);
838
+            $listenerCode = Util\Common::getSniffCode( $this->activeListener );
839 839
             $sniffCode    = $code;
840
-            $checkCodes   = [$sniffCode];
840
+            $checkCodes   = [ $sniffCode ];
841 841
         } else {
842
-            if ($parts[0] !== $code) {
842
+            if ( $parts[ 0 ] !== $code ) {
843 843
                 // The full message code has been passed in.
844 844
                 $sniffCode    = $code;
845
-                $listenerCode = substr($sniffCode, 0, strrpos($sniffCode, '.'));
845
+                $listenerCode = substr( $sniffCode, 0, strrpos( $sniffCode, '.' ) );
846 846
             } else {
847
-                $listenerCode = Util\Common::getSniffCode($this->activeListener);
848
-                $sniffCode    = $listenerCode.'.'.$code;
849
-                $parts        = explode('.', $sniffCode);
847
+                $listenerCode = Util\Common::getSniffCode( $this->activeListener );
848
+                $sniffCode    = $listenerCode . '.' . $code;
849
+                $parts        = explode( '.', $sniffCode );
850 850
             }
851 851
 
852 852
             $checkCodes = [
853 853
                 $sniffCode,
854
-                $parts[0].'.'.$parts[1].'.'.$parts[2],
855
-                $parts[0].'.'.$parts[1],
856
-                $parts[0],
854
+                $parts[ 0 ] . '.' . $parts[ 1 ] . '.' . $parts[ 2 ],
855
+                $parts[ 0 ] . '.' . $parts[ 1 ],
856
+                $parts[ 0 ],
857 857
             ];
858 858
         }//end if
859 859
 
860
-        if (isset($this->tokenizer->ignoredLines[$line]) === true) {
860
+        if ( isset( $this->tokenizer->ignoredLines[ $line ] ) === true ) {
861 861
             // Check if this line is ignoring this specific message.
862 862
             $ignored = false;
863
-            foreach ($checkCodes as $checkCode) {
864
-                if (isset($this->tokenizer->ignoredLines[$line][$checkCode]) === true) {
863
+            foreach ( $checkCodes as $checkCode ) {
864
+                if ( isset( $this->tokenizer->ignoredLines[ $line ][ $checkCode ] ) === true ) {
865 865
                     $ignored = true;
866 866
                     break;
867 867
                 }
868 868
             }
869 869
 
870 870
             // If it is ignored, make sure it's not whitelisted.
871
-            if ($ignored === true
872
-                && isset($this->tokenizer->ignoredLines[$line]['.except']) === true
871
+            if ( $ignored === true
872
+                && isset( $this->tokenizer->ignoredLines[ $line ][ '.except' ] ) === true
873 873
             ) {
874
-                foreach ($checkCodes as $checkCode) {
875
-                    if (isset($this->tokenizer->ignoredLines[$line]['.except'][$checkCode]) === true) {
874
+                foreach ( $checkCodes as $checkCode ) {
875
+                    if ( isset( $this->tokenizer->ignoredLines[ $line ][ '.except' ][ $checkCode ] ) === true ) {
876 876
                         $ignored = false;
877 877
                         break;
878 878
                     }
879 879
                 }
880 880
             }
881 881
 
882
-            if ($ignored === true) {
882
+            if ( $ignored === true ) {
883 883
                 return false;
884 884
             }
885 885
         }//end if
886 886
 
887 887
         $includeAll = true;
888
-        if ($this->configCache['cache'] === false
889
-            || $this->configCache['recordErrors'] === false
888
+        if ( $this->configCache[ 'cache' ] === false
889
+            || $this->configCache[ 'recordErrors' ] === false
890 890
         ) {
891 891
             $includeAll = false;
892 892
         }
893 893
 
894 894
         // Filter out any messages for sniffs that shouldn't have run
895 895
         // due to the use of the --sniffs command line argument.
896
-        if ($includeAll === false
897
-            && ((empty($this->configCache['sniffs']) === false
898
-            && in_array(strtolower($listenerCode), $this->configCache['sniffs'], true) === false)
899
-            || (empty($this->configCache['exclude']) === false
900
-            && in_array(strtolower($listenerCode), $this->configCache['exclude'], true) === true))
896
+        if ( $includeAll === false
897
+            && ( ( empty( $this->configCache[ 'sniffs' ] ) === false
898
+            && in_array( strtolower( $listenerCode ), $this->configCache[ 'sniffs' ], true ) === false )
899
+            || ( empty( $this->configCache[ 'exclude' ] ) === false
900
+            && in_array( strtolower( $listenerCode ), $this->configCache[ 'exclude' ], true ) === true ) )
901 901
         ) {
902 902
             return false;
903 903
         }
904 904
 
905 905
         // If we know this sniff code is being ignored for this file, return early.
906
-        foreach ($checkCodes as $checkCode) {
907
-            if (isset($this->ignoredCodes[$checkCode]) === true) {
906
+        foreach ( $checkCodes as $checkCode ) {
907
+            if ( isset( $this->ignoredCodes[ $checkCode ] ) === true ) {
908 908
                 return false;
909 909
             }
910 910
         }
911 911
 
912 912
         $oppositeType = 'warning';
913
-        if ($error === false) {
913
+        if ( $error === false ) {
914 914
             $oppositeType = 'error';
915 915
         }
916 916
 
917
-        foreach ($checkCodes as $checkCode) {
917
+        foreach ( $checkCodes as $checkCode ) {
918 918
             // Make sure this message type has not been set to the opposite message type.
919
-            if (isset($this->ruleset->ruleset[$checkCode]['type']) === true
920
-                && $this->ruleset->ruleset[$checkCode]['type'] === $oppositeType
919
+            if ( isset( $this->ruleset->ruleset[ $checkCode ][ 'type' ] ) === true
920
+                && $this->ruleset->ruleset[ $checkCode ][ 'type' ] === $oppositeType
921 921
             ) {
922
-                $error = !$error;
922
+                $error = ! $error;
923 923
                 break;
924 924
             }
925 925
         }
926 926
 
927
-        if ($error === true) {
928
-            $configSeverity = $this->configCache['errorSeverity'];
927
+        if ( $error === true ) {
928
+            $configSeverity = $this->configCache[ 'errorSeverity' ];
929 929
             $messageCount   = &$this->errorCount;
930 930
             $messages       = &$this->errors;
931 931
         } else {
932
-            $configSeverity = $this->configCache['warningSeverity'];
932
+            $configSeverity = $this->configCache[ 'warningSeverity' ];
933 933
             $messageCount   = &$this->warningCount;
934 934
             $messages       = &$this->warnings;
935 935
         }
936 936
 
937
-        if ($includeAll === false && $configSeverity === 0) {
937
+        if ( $includeAll === false && $configSeverity === 0 ) {
938 938
             // Don't bother doing any processing as these messages are just going to
939 939
             // be hidden in the reports anyway.
940 940
             return false;
941 941
         }
942 942
 
943
-        if ($severity === 0) {
943
+        if ( $severity === 0 ) {
944 944
             $severity = 5;
945 945
         }
946 946
 
947
-        foreach ($checkCodes as $checkCode) {
947
+        foreach ( $checkCodes as $checkCode ) {
948 948
             // Make sure we are interested in this severity level.
949
-            if (isset($this->ruleset->ruleset[$checkCode]['severity']) === true) {
950
-                $severity = $this->ruleset->ruleset[$checkCode]['severity'];
949
+            if ( isset( $this->ruleset->ruleset[ $checkCode ][ 'severity' ] ) === true ) {
950
+                $severity = $this->ruleset->ruleset[ $checkCode ][ 'severity' ];
951 951
                 break;
952 952
             }
953 953
         }
954 954
 
955
-        if ($includeAll === false && $configSeverity > $severity) {
955
+        if ( $includeAll === false && $configSeverity > $severity ) {
956 956
             return false;
957 957
         }
958 958
 
959 959
         // Make sure we are not ignoring this file.
960 960
         $included = null;
961
-        foreach ($checkCodes as $checkCode) {
961
+        foreach ( $checkCodes as $checkCode ) {
962 962
             $patterns = null;
963 963
 
964
-            if (isset($this->configCache['includePatterns'][$checkCode]) === true) {
965
-                $patterns  = $this->configCache['includePatterns'][$checkCode];
964
+            if ( isset( $this->configCache[ 'includePatterns' ][ $checkCode ] ) === true ) {
965
+                $patterns  = $this->configCache[ 'includePatterns' ][ $checkCode ];
966 966
                 $excluding = false;
967
-            } else if (isset($this->configCache['ignorePatterns'][$checkCode]) === true) {
968
-                $patterns  = $this->configCache['ignorePatterns'][$checkCode];
967
+            } else if ( isset( $this->configCache[ 'ignorePatterns' ][ $checkCode ] ) === true ) {
968
+                $patterns  = $this->configCache[ 'ignorePatterns' ][ $checkCode ];
969 969
                 $excluding = true;
970 970
             }
971 971
 
972
-            if ($patterns === null) {
972
+            if ( $patterns === null ) {
973 973
                 continue;
974 974
             }
975 975
 
976
-            foreach ($patterns as $pattern => $type) {
976
+            foreach ( $patterns as $pattern => $type ) {
977 977
                 // While there is support for a type of each pattern
978 978
                 // (absolute or relative) we don't actually support it here.
979 979
                 $replacements = [
@@ -984,15 +984,15 @@  discard block
 block discarded – undo
984 984
                 // We assume a / directory separator, as do the exclude rules
985 985
                 // most developers write, so we need a special case for any system
986 986
                 // that is different.
987
-                if (DIRECTORY_SEPARATOR === '\\') {
988
-                    $replacements['/'] = '\\\\';
987
+                if ( DIRECTORY_SEPARATOR === '\\' ) {
988
+                    $replacements[ '/' ] = '\\\\';
989 989
                 }
990 990
 
991
-                $pattern = '`'.strtr($pattern, $replacements).'`i';
992
-                $matched = preg_match($pattern, $this->path);
991
+                $pattern = '`' . strtr( $pattern, $replacements ) . '`i';
992
+                $matched = preg_match( $pattern, $this->path );
993 993
 
994
-                if ($matched === 0) {
995
-                    if ($excluding === false && $included === null) {
994
+                if ( $matched === 0 ) {
995
+                    if ( $excluding === false && $included === null ) {
996 996
                         // This file path is not being included.
997 997
                         $included = false;
998 998
                     }
@@ -1000,9 +1000,9 @@  discard block
 block discarded – undo
1000 1000
                     continue;
1001 1001
                 }
1002 1002
 
1003
-                if ($excluding === true) {
1003
+                if ( $excluding === true ) {
1004 1004
                     // This file path is being excluded.
1005
-                    $this->ignoredCodes[$checkCode] = true;
1005
+                    $this->ignoredCodes[ $checkCode ] = true;
1006 1006
                     return false;
1007 1007
                 }
1008 1008
 
@@ -1012,41 +1012,41 @@  discard block
 block discarded – undo
1012 1012
             }//end foreach
1013 1013
         }//end foreach
1014 1014
 
1015
-        if ($included === false) {
1015
+        if ( $included === false ) {
1016 1016
             // There were include rules set, but this file
1017 1017
             // path didn't match any of them.
1018 1018
             return false;
1019 1019
         }
1020 1020
 
1021 1021
         $messageCount++;
1022
-        if ($fixable === true) {
1022
+        if ( $fixable === true ) {
1023 1023
             $this->fixableCount++;
1024 1024
         }
1025 1025
 
1026
-        if ($this->configCache['recordErrors'] === false
1026
+        if ( $this->configCache[ 'recordErrors' ] === false
1027 1027
             && $includeAll === false
1028 1028
         ) {
1029 1029
             return true;
1030 1030
         }
1031 1031
 
1032 1032
         // Work out the error message.
1033
-        if (isset($this->ruleset->ruleset[$sniffCode]['message']) === true) {
1034
-            $message = $this->ruleset->ruleset[$sniffCode]['message'];
1033
+        if ( isset( $this->ruleset->ruleset[ $sniffCode ][ 'message' ] ) === true ) {
1034
+            $message = $this->ruleset->ruleset[ $sniffCode ][ 'message' ];
1035 1035
         }
1036 1036
 
1037
-        if (empty($data) === false) {
1038
-            $message = vsprintf($message, $data);
1037
+        if ( empty( $data ) === false ) {
1038
+            $message = vsprintf( $message, $data );
1039 1039
         }
1040 1040
 
1041
-        if (isset($messages[$line]) === false) {
1042
-            $messages[$line] = [];
1041
+        if ( isset( $messages[ $line ] ) === false ) {
1042
+            $messages[ $line ] = [ ];
1043 1043
         }
1044 1044
 
1045
-        if (isset($messages[$line][$column]) === false) {
1046
-            $messages[$line][$column] = [];
1045
+        if ( isset( $messages[ $line ][ $column ] ) === false ) {
1046
+            $messages[ $line ][ $column ] = [ ];
1047 1047
         }
1048 1048
 
1049
-        $messages[$line][$column][] = [
1049
+        $messages[ $line ][ $column ][ ] = [
1050 1050
             'message'  => $message,
1051 1051
             'source'   => $sniffCode,
1052 1052
             'listener' => $this->activeListener,
@@ -1054,12 +1054,12 @@  discard block
 block discarded – undo
1054 1054
             'fixable'  => $fixable,
1055 1055
         ];
1056 1056
 
1057
-        if (PHP_CODESNIFFER_VERBOSITY > 1
1057
+        if ( PHP_CODESNIFFER_VERBOSITY > 1
1058 1058
             && $this->fixer->enabled === true
1059 1059
             && $fixable === true
1060 1060
         ) {
1061 1061
             @ob_end_clean();
1062
-            echo "\tE: [Line $line] $message ($sniffCode)".PHP_EOL;
1062
+            echo "\tE: [Line $line] $message ($sniffCode)" . PHP_EOL;
1063 1063
             ob_start();
1064 1064
         }
1065 1065
 
@@ -1077,17 +1077,17 @@  discard block
 block discarded – undo
1077 1077
      *
1078 1078
      * @return boolean
1079 1079
      */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1080
+    public function recordMetric( $stackPtr, $metric, $value )
1081 1081
     {
1082
-        if (isset($this->metrics[$metric]) === false) {
1083
-            $this->metrics[$metric] = ['values' => [$value => 1]];
1084
-            $this->metricTokens[$metric][$stackPtr] = true;
1085
-        } else if (isset($this->metricTokens[$metric][$stackPtr]) === false) {
1086
-            $this->metricTokens[$metric][$stackPtr] = true;
1087
-            if (isset($this->metrics[$metric]['values'][$value]) === false) {
1088
-                $this->metrics[$metric]['values'][$value] = 1;
1082
+        if ( isset( $this->metrics[ $metric ] ) === false ) {
1083
+            $this->metrics[ $metric ] = [ 'values' => [ $value => 1 ] ];
1084
+            $this->metricTokens[ $metric ][ $stackPtr ] = true;
1085
+        } else if ( isset( $this->metricTokens[ $metric ][ $stackPtr ] ) === false ) {
1086
+            $this->metricTokens[ $metric ][ $stackPtr ] = true;
1087
+            if ( isset( $this->metrics[ $metric ][ 'values' ][ $value ] ) === false ) {
1088
+                $this->metrics[ $metric ][ 'values' ][ $value ] = 1;
1089 1089
             } else {
1090
-                $this->metrics[$metric]['values'][$value]++;
1090
+                $this->metrics[ $metric ][ 'values' ][ $value ]++;
1091 1091
             }
1092 1092
         }
1093 1093
 
@@ -1216,34 +1216,34 @@  discard block
 block discarded – undo
1216 1216
      *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217 1217
      *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218 1218
      */
1219
-    public function getDeclarationName($stackPtr)
1219
+    public function getDeclarationName( $stackPtr )
1220 1220
     {
1221
-        $tokenCode = $this->tokens[$stackPtr]['code'];
1221
+        $tokenCode = $this->tokens[ $stackPtr ][ 'code' ];
1222 1222
 
1223
-        if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
1223
+        if ( $tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE ) {
1224 1224
             return null;
1225 1225
         }
1226 1226
 
1227
-        if ($tokenCode !== T_FUNCTION
1227
+        if ( $tokenCode !== T_FUNCTION
1228 1228
             && $tokenCode !== T_CLASS
1229 1229
             && $tokenCode !== T_INTERFACE
1230 1230
             && $tokenCode !== T_TRAIT
1231 1231
         ) {
1232
-            throw new RuntimeException('Token type "'.$this->tokens[$stackPtr]['type'].'" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT');
1232
+            throw new RuntimeException( 'Token type "' . $this->tokens[ $stackPtr ][ 'type' ] . '" is not T_FUNCTION, T_CLASS, T_INTERFACE or T_TRAIT' );
1233 1233
         }
1234 1234
 
1235
-        if ($tokenCode === T_FUNCTION
1236
-            && strtolower($this->tokens[$stackPtr]['content']) !== 'function'
1235
+        if ( $tokenCode === T_FUNCTION
1236
+            && strtolower( $this->tokens[ $stackPtr ][ 'content' ] ) !== 'function'
1237 1237
         ) {
1238 1238
             // This is a function declared without the "function" keyword.
1239 1239
             // So this token is the function name.
1240
-            return $this->tokens[$stackPtr]['content'];
1240
+            return $this->tokens[ $stackPtr ][ 'content' ];
1241 1241
         }
1242 1242
 
1243 1243
         $content = null;
1244
-        for ($i = $stackPtr; $i < $this->numTokens; $i++) {
1245
-            if ($this->tokens[$i]['code'] === T_STRING) {
1246
-                $content = $this->tokens[$i]['content'];
1244
+        for ( $i = $stackPtr; $i < $this->numTokens; $i++ ) {
1245
+            if ( $this->tokens[ $i ][ 'code' ] === T_STRING ) {
1246
+                $content = $this->tokens[ $i ][ 'content' ];
1247 1247
                 break;
1248 1248
             }
1249 1249
         }
@@ -1282,20 +1282,20 @@  discard block
 block discarded – undo
1282 1282
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283 1283
      *                                                        type T_FUNCTION or T_CLOSURE.
1284 1284
      */
1285
-    public function getMethodParameters($stackPtr)
1285
+    public function getMethodParameters( $stackPtr )
1286 1286
     {
1287
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1287
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_FUNCTION
1288
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_CLOSURE
1289 1289
         ) {
1290
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1290
+            throw new TokenizerException( '$stackPtr must be of type T_FUNCTION or T_CLOSURE' );
1291 1291
         }
1292 1292
 
1293
-        $opener = $this->tokens[$stackPtr]['parenthesis_opener'];
1294
-        $closer = $this->tokens[$stackPtr]['parenthesis_closer'];
1293
+        $opener = $this->tokens[ $stackPtr ][ 'parenthesis_opener' ];
1294
+        $closer = $this->tokens[ $stackPtr ][ 'parenthesis_closer' ];
1295 1295
 
1296
-        $vars            = [];
1296
+        $vars            = [ ];
1297 1297
         $currVar         = null;
1298
-        $paramStart      = ($opener + 1);
1298
+        $paramStart      = ( $opener + 1 );
1299 1299
         $defaultStart    = null;
1300 1300
         $paramCount      = 0;
1301 1301
         $passByReference = false;
@@ -1304,28 +1304,28 @@  discard block
 block discarded – undo
1304 1304
         $typeHintToken   = false;
1305 1305
         $nullableType    = false;
1306 1306
 
1307
-        for ($i = $paramStart; $i <= $closer; $i++) {
1307
+        for ( $i = $paramStart; $i <= $closer; $i++ ) {
1308 1308
             // Check to see if this token has a parenthesis or bracket opener. If it does
1309 1309
             // it's likely to be an array which might have arguments in it. This
1310 1310
             // could cause problems in our parsing below, so lets just skip to the
1311 1311
             // end of it.
1312
-            if (isset($this->tokens[$i]['parenthesis_opener']) === true) {
1312
+            if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true ) {
1313 1313
                 // Don't do this if it's the close parenthesis for the method.
1314
-                if ($i !== $this->tokens[$i]['parenthesis_closer']) {
1315
-                    $i = ($this->tokens[$i]['parenthesis_closer'] + 1);
1314
+                if ( $i !== $this->tokens[ $i ][ 'parenthesis_closer' ] ) {
1315
+                    $i = ( $this->tokens[ $i ][ 'parenthesis_closer' ] + 1 );
1316 1316
                 }
1317 1317
             }
1318 1318
 
1319
-            if (isset($this->tokens[$i]['bracket_opener']) === true) {
1319
+            if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true ) {
1320 1320
                 // Don't do this if it's the close parenthesis for the method.
1321
-                if ($i !== $this->tokens[$i]['bracket_closer']) {
1322
-                    $i = ($this->tokens[$i]['bracket_closer'] + 1);
1321
+                if ( $i !== $this->tokens[ $i ][ 'bracket_closer' ] ) {
1322
+                    $i = ( $this->tokens[ $i ][ 'bracket_closer' ] + 1 );
1323 1323
                 }
1324 1324
             }
1325 1325
 
1326
-            switch ($this->tokens[$i]['code']) {
1326
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1327 1327
             case T_BITWISE_AND:
1328
-                if ($defaultStart === null) {
1328
+                if ( $defaultStart === null ) {
1329 1329
                     $passByReference = true;
1330 1330
                 }
1331 1331
                 break;
@@ -1336,99 +1336,99 @@  discard block
 block discarded – undo
1336 1336
                 $variableLength = true;
1337 1337
                 break;
1338 1338
             case T_CALLABLE:
1339
-                if ($typeHintToken === false) {
1339
+                if ( $typeHintToken === false ) {
1340 1340
                     $typeHintToken = $i;
1341 1341
                 }
1342 1342
 
1343
-                $typeHint .= $this->tokens[$i]['content'];
1343
+                $typeHint .= $this->tokens[ $i ][ 'content' ];
1344 1344
                 break;
1345 1345
             case T_SELF:
1346 1346
             case T_PARENT:
1347 1347
             case T_STATIC:
1348 1348
                 // Self and parent are valid, static invalid, but was probably intended as type hint.
1349
-                if (isset($defaultStart) === false) {
1350
-                    if ($typeHintToken === false) {
1349
+                if ( isset( $defaultStart ) === false ) {
1350
+                    if ( $typeHintToken === false ) {
1351 1351
                         $typeHintToken = $i;
1352 1352
                     }
1353 1353
 
1354
-                    $typeHint .= $this->tokens[$i]['content'];
1354
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1355 1355
                 }
1356 1356
                 break;
1357 1357
             case T_STRING:
1358 1358
                 // This is a string, so it may be a type hint, but it could
1359 1359
                 // also be a constant used as a default value.
1360 1360
                 $prevComma = false;
1361
-                for ($t = $i; $t >= $opener; $t--) {
1362
-                    if ($this->tokens[$t]['code'] === T_COMMA) {
1361
+                for ( $t = $i; $t >= $opener; $t-- ) {
1362
+                    if ( $this->tokens[ $t ][ 'code' ] === T_COMMA ) {
1363 1363
                         $prevComma = $t;
1364 1364
                         break;
1365 1365
                     }
1366 1366
                 }
1367 1367
 
1368
-                if ($prevComma !== false) {
1368
+                if ( $prevComma !== false ) {
1369 1369
                     $nextEquals = false;
1370
-                    for ($t = $prevComma; $t < $i; $t++) {
1371
-                        if ($this->tokens[$t]['code'] === T_EQUAL) {
1370
+                    for ( $t = $prevComma; $t < $i; $t++ ) {
1371
+                        if ( $this->tokens[ $t ][ 'code' ] === T_EQUAL ) {
1372 1372
                             $nextEquals = $t;
1373 1373
                             break;
1374 1374
                         }
1375 1375
                     }
1376 1376
 
1377
-                    if ($nextEquals !== false) {
1377
+                    if ( $nextEquals !== false ) {
1378 1378
                         break;
1379 1379
                     }
1380 1380
                 }
1381 1381
 
1382
-                if ($defaultStart === null) {
1383
-                    if ($typeHintToken === false) {
1382
+                if ( $defaultStart === null ) {
1383
+                    if ( $typeHintToken === false ) {
1384 1384
                         $typeHintToken = $i;
1385 1385
                     }
1386 1386
 
1387
-                    $typeHint .= $this->tokens[$i]['content'];
1387
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1388 1388
                 }
1389 1389
                 break;
1390 1390
             case T_NS_SEPARATOR:
1391 1391
                 // Part of a type hint or default value.
1392
-                if ($defaultStart === null) {
1393
-                    if ($typeHintToken === false) {
1392
+                if ( $defaultStart === null ) {
1393
+                    if ( $typeHintToken === false ) {
1394 1394
                         $typeHintToken = $i;
1395 1395
                     }
1396 1396
 
1397
-                    $typeHint .= $this->tokens[$i]['content'];
1397
+                    $typeHint .= $this->tokens[ $i ][ 'content' ];
1398 1398
                 }
1399 1399
                 break;
1400 1400
             case T_NULLABLE:
1401
-                if ($defaultStart === null) {
1401
+                if ( $defaultStart === null ) {
1402 1402
                     $nullableType = true;
1403
-                    $typeHint    .= $this->tokens[$i]['content'];
1403
+                    $typeHint    .= $this->tokens[ $i ][ 'content' ];
1404 1404
                 }
1405 1405
                 break;
1406 1406
             case T_CLOSE_PARENTHESIS:
1407 1407
             case T_COMMA:
1408 1408
                 // If it's null, then there must be no parameters for this
1409 1409
                 // method.
1410
-                if ($currVar === null) {
1410
+                if ( $currVar === null ) {
1411 1411
                     continue 2;
1412 1412
                 }
1413 1413
 
1414
-                $vars[$paramCount]            = [];
1415
-                $vars[$paramCount]['token']   = $currVar;
1416
-                $vars[$paramCount]['name']    = $this->tokens[$currVar]['content'];
1417
-                $vars[$paramCount]['content'] = trim($this->getTokensAsString($paramStart, ($i - $paramStart)));
1414
+                $vars[ $paramCount ]            = [ ];
1415
+                $vars[ $paramCount ][ 'token' ]   = $currVar;
1416
+                $vars[ $paramCount ][ 'name' ]    = $this->tokens[ $currVar ][ 'content' ];
1417
+                $vars[ $paramCount ][ 'content' ] = trim( $this->getTokensAsString( $paramStart, ( $i - $paramStart ) ) );
1418 1418
 
1419
-                if ($defaultStart !== null) {
1420
-                    $vars[$paramCount]['default'] = trim($this->getTokensAsString($defaultStart, ($i - $defaultStart)));
1419
+                if ( $defaultStart !== null ) {
1420
+                    $vars[ $paramCount ][ 'default' ] = trim( $this->getTokensAsString( $defaultStart, ( $i - $defaultStart ) ) );
1421 1421
                 }
1422 1422
 
1423
-                $vars[$paramCount]['pass_by_reference'] = $passByReference;
1424
-                $vars[$paramCount]['variable_length']   = $variableLength;
1425
-                $vars[$paramCount]['type_hint']         = $typeHint;
1426
-                $vars[$paramCount]['type_hint_token']   = $typeHintToken;
1427
-                $vars[$paramCount]['nullable_type']     = $nullableType;
1423
+                $vars[ $paramCount ][ 'pass_by_reference' ] = $passByReference;
1424
+                $vars[ $paramCount ][ 'variable_length' ]   = $variableLength;
1425
+                $vars[ $paramCount ][ 'type_hint' ]         = $typeHint;
1426
+                $vars[ $paramCount ][ 'type_hint_token' ]   = $typeHintToken;
1427
+                $vars[ $paramCount ][ 'nullable_type' ]     = $nullableType;
1428 1428
 
1429 1429
                 // Reset the vars, as we are about to process the next parameter.
1430 1430
                 $defaultStart    = null;
1431
-                $paramStart      = ($i + 1);
1431
+                $paramStart      = ( $i + 1 );
1432 1432
                 $passByReference = false;
1433 1433
                 $variableLength  = false;
1434 1434
                 $typeHint        = '';
@@ -1438,7 +1438,7 @@  discard block
 block discarded – undo
1438 1438
                 $paramCount++;
1439 1439
                 break;
1440 1440
             case T_EQUAL:
1441
-                $defaultStart = ($i + 1);
1441
+                $defaultStart = ( $i + 1 );
1442 1442
                 break;
1443 1443
             }//end switch
1444 1444
         }//end for
@@ -1474,15 +1474,15 @@  discard block
 block discarded – undo
1474 1474
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475 1475
      *                                                        T_FUNCTION token.
1476 1476
      */
1477
-    public function getMethodProperties($stackPtr)
1477
+    public function getMethodProperties( $stackPtr )
1478 1478
     {
1479
-        if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480
-            && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1479
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_FUNCTION
1480
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_CLOSURE
1481 1481
         ) {
1482
-            throw new TokenizerException('$stackPtr must be of type T_FUNCTION or T_CLOSURE');
1482
+            throw new TokenizerException( '$stackPtr must be of type T_FUNCTION or T_CLOSURE' );
1483 1483
         }
1484 1484
 
1485
-        if ($this->tokens[$stackPtr]['code'] === T_FUNCTION) {
1485
+        if ( $this->tokens[ $stackPtr ][ 'code' ] === T_FUNCTION ) {
1486 1486
             $valid = [
1487 1487
                 T_PUBLIC      => T_PUBLIC,
1488 1488
                 T_PRIVATE     => T_PRIVATE,
@@ -1509,12 +1509,12 @@  discard block
 block discarded – undo
1509 1509
         $isFinal        = false;
1510 1510
         $isStatic       = false;
1511 1511
 
1512
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1513
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1512
+        for ( $i = ( $stackPtr - 1 ); $i > 0; $i-- ) {
1513
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1514 1514
                 break;
1515 1515
             }
1516 1516
 
1517
-            switch ($this->tokens[$i]['code']) {
1517
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1518 1518
             case T_PUBLIC:
1519 1519
                 $scope          = 'public';
1520 1520
                 $scopeSpecified = true;
@@ -1544,10 +1544,10 @@  discard block
 block discarded – undo
1544 1544
         $nullableReturnType = false;
1545 1545
         $hasBody            = true;
1546 1546
 
1547
-        if (isset($this->tokens[$stackPtr]['parenthesis_closer']) === true) {
1547
+        if ( isset( $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === true ) {
1548 1548
             $scopeOpener = null;
1549
-            if (isset($this->tokens[$stackPtr]['scope_opener']) === true) {
1550
-                $scopeOpener = $this->tokens[$stackPtr]['scope_opener'];
1549
+            if ( isset( $this->tokens[ $stackPtr ][ 'scope_opener' ] ) === true ) {
1550
+                $scopeOpener = $this->tokens[ $stackPtr ][ 'scope_opener' ];
1551 1551
             }
1552 1552
 
1553 1553
             $valid = [
@@ -1558,33 +1558,33 @@  discard block
 block discarded – undo
1558 1558
                 T_NS_SEPARATOR => T_NS_SEPARATOR,
1559 1559
             ];
1560 1560
 
1561
-            for ($i = $this->tokens[$stackPtr]['parenthesis_closer']; $i < $this->numTokens; $i++) {
1562
-                if (($scopeOpener === null && $this->tokens[$i]['code'] === T_SEMICOLON)
1563
-                    || ($scopeOpener !== null && $i === $scopeOpener)
1561
+            for ( $i = $this->tokens[ $stackPtr ][ 'parenthesis_closer' ]; $i < $this->numTokens; $i++ ) {
1562
+                if ( ( $scopeOpener === null && $this->tokens[ $i ][ 'code' ] === T_SEMICOLON )
1563
+                    || ( $scopeOpener !== null && $i === $scopeOpener )
1564 1564
                 ) {
1565 1565
                     // End of function definition.
1566 1566
                     break;
1567 1567
                 }
1568 1568
 
1569
-                if ($this->tokens[$i]['code'] === T_NULLABLE) {
1569
+                if ( $this->tokens[ $i ][ 'code' ] === T_NULLABLE ) {
1570 1570
                     $nullableReturnType = true;
1571 1571
                 }
1572 1572
 
1573
-                if (isset($valid[$this->tokens[$i]['code']]) === true) {
1574
-                    if ($returnTypeToken === false) {
1573
+                if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
1574
+                    if ( $returnTypeToken === false ) {
1575 1575
                         $returnTypeToken = $i;
1576 1576
                     }
1577 1577
 
1578
-                    $returnType .= $this->tokens[$i]['content'];
1578
+                    $returnType .= $this->tokens[ $i ][ 'content' ];
1579 1579
                 }
1580 1580
             }
1581 1581
 
1582
-            $end     = $this->findNext([T_OPEN_CURLY_BRACKET, T_SEMICOLON], $this->tokens[$stackPtr]['parenthesis_closer']);
1583
-            $hasBody = $this->tokens[$end]['code'] === T_OPEN_CURLY_BRACKET;
1582
+            $end     = $this->findNext( [ T_OPEN_CURLY_BRACKET, T_SEMICOLON ], $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] );
1583
+            $hasBody = $this->tokens[ $end ][ 'code' ] === T_OPEN_CURLY_BRACKET;
1584 1584
         }//end if
1585 1585
 
1586
-        if ($returnType !== '' && $nullableReturnType === true) {
1587
-            $returnType = '?'.$returnType;
1586
+        if ( $returnType !== '' && $nullableReturnType === true ) {
1587
+            $returnType = '?' . $returnType;
1588 1588
         }
1589 1589
 
1590 1590
         return [
@@ -1624,47 +1624,47 @@  discard block
 block discarded – undo
1624 1624
      *                                                        T_VARIABLE token, or if the position is not
1625 1625
      *                                                        a class member variable.
1626 1626
      */
1627
-    public function getMemberProperties($stackPtr)
1627
+    public function getMemberProperties( $stackPtr )
1628 1628
     {
1629
-        if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630
-            throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1629
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_VARIABLE ) {
1630
+            throw new TokenizerException( '$stackPtr must be of type T_VARIABLE' );
1631 1631
         }
1632 1632
 
1633
-        $conditions = array_keys($this->tokens[$stackPtr]['conditions']);
1634
-        $ptr        = array_pop($conditions);
1635
-        if (isset($this->tokens[$ptr]) === false
1636
-            || ($this->tokens[$ptr]['code'] !== T_CLASS
1637
-            && $this->tokens[$ptr]['code'] !== T_ANON_CLASS
1638
-            && $this->tokens[$ptr]['code'] !== T_TRAIT)
1633
+        $conditions = array_keys( $this->tokens[ $stackPtr ][ 'conditions' ] );
1634
+        $ptr        = array_pop( $conditions );
1635
+        if ( isset( $this->tokens[ $ptr ] ) === false
1636
+            || ( $this->tokens[ $ptr ][ 'code' ] !== T_CLASS
1637
+            && $this->tokens[ $ptr ][ 'code' ] !== T_ANON_CLASS
1638
+            && $this->tokens[ $ptr ][ 'code' ] !== T_TRAIT )
1639 1639
         ) {
1640
-            if (isset($this->tokens[$ptr]) === true
1641
-                && $this->tokens[$ptr]['code'] === T_INTERFACE
1640
+            if ( isset( $this->tokens[ $ptr ] ) === true
1641
+                && $this->tokens[ $ptr ][ 'code' ] === T_INTERFACE
1642 1642
             ) {
1643 1643
                 // T_VARIABLEs in interfaces can actually be method arguments
1644 1644
                 // but they wont be seen as being inside the method because there
1645 1645
                 // are no scope openers and closers for abstract methods. If it is in
1646 1646
                 // parentheses, we can be pretty sure it is a method argument.
1647
-                if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === false
1648
-                    || empty($this->tokens[$stackPtr]['nested_parenthesis']) === true
1647
+                if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false
1648
+                    || empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true
1649 1649
                 ) {
1650 1650
                     $error = 'Possible parse error: interfaces may not include member vars';
1651
-                    $this->addWarning($error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar');
1652
-                    return [];
1651
+                    $this->addWarning( $error, $stackPtr, 'Internal.ParseError.InterfaceHasMemberVar' );
1652
+                    return [ ];
1653 1653
                 }
1654 1654
             } else {
1655
-                throw new TokenizerException('$stackPtr is not a class member var');
1655
+                throw new TokenizerException( '$stackPtr is not a class member var' );
1656 1656
             }
1657 1657
         }
1658 1658
 
1659 1659
         // Make sure it's not a method parameter.
1660
-        if (empty($this->tokens[$stackPtr]['nested_parenthesis']) === false) {
1661
-            $parenthesis = array_keys($this->tokens[$stackPtr]['nested_parenthesis']);
1662
-            $deepestOpen = array_pop($parenthesis);
1663
-            if ($deepestOpen > $ptr
1664
-                && isset($this->tokens[$deepestOpen]['parenthesis_owner']) === true
1665
-                && $this->tokens[$this->tokens[$deepestOpen]['parenthesis_owner']]['code'] === T_FUNCTION
1660
+        if ( empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === false ) {
1661
+            $parenthesis = array_keys( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] );
1662
+            $deepestOpen = array_pop( $parenthesis );
1663
+            if ( $deepestOpen > $ptr
1664
+                && isset( $this->tokens[ $deepestOpen ][ 'parenthesis_owner' ] ) === true
1665
+                && $this->tokens[ $this->tokens[ $deepestOpen ][ 'parenthesis_owner' ] ][ 'code' ] === T_FUNCTION
1666 1666
             ) {
1667
-                throw new TokenizerException('$stackPtr is not a class member var');
1667
+                throw new TokenizerException( '$stackPtr is not a class member var' );
1668 1668
             }
1669 1669
         }
1670 1670
 
@@ -1688,15 +1688,15 @@  discard block
 block discarded – undo
1688 1688
                 T_OPEN_CURLY_BRACKET,
1689 1689
                 T_CLOSE_CURLY_BRACKET,
1690 1690
             ],
1691
-            ($stackPtr - 1)
1691
+            ( $stackPtr - 1 )
1692 1692
         );
1693 1693
 
1694
-        for ($i = ($startOfStatement + 1); $i < $stackPtr; $i++) {
1695
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1694
+        for ( $i = ( $startOfStatement + 1 ); $i < $stackPtr; $i++ ) {
1695
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1696 1696
                 break;
1697 1697
             }
1698 1698
 
1699
-            switch ($this->tokens[$i]['code']) {
1699
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1700 1700
             case T_PUBLIC:
1701 1701
                 $scope          = 'public';
1702 1702
                 $scopeSpecified = true;
@@ -1742,10 +1742,10 @@  discard block
 block discarded – undo
1742 1742
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743 1743
      *                                                        T_CLASS token.
1744 1744
      */
1745
-    public function getClassProperties($stackPtr)
1745
+    public function getClassProperties( $stackPtr )
1746 1746
     {
1747
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748
-            throw new TokenizerException('$stackPtr must be of type T_CLASS');
1747
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS ) {
1748
+            throw new TokenizerException( '$stackPtr must be of type T_CLASS' );
1749 1749
         }
1750 1750
 
1751 1751
         $valid = [
@@ -1759,12 +1759,12 @@  discard block
 block discarded – undo
1759 1759
         $isAbstract = false;
1760 1760
         $isFinal    = false;
1761 1761
 
1762
-        for ($i = ($stackPtr - 1); $i > 0; $i--) {
1763
-            if (isset($valid[$this->tokens[$i]['code']]) === false) {
1762
+        for ( $i = ( $stackPtr - 1 ); $i > 0; $i-- ) {
1763
+            if ( isset( $valid[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
1764 1764
                 break;
1765 1765
             }
1766 1766
 
1767
-            switch ($this->tokens[$i]['code']) {
1767
+            switch ( $this->tokens[ $i ][ 'code' ] ) {
1768 1768
             case T_ABSTRACT:
1769 1769
                 $isAbstract = true;
1770 1770
                 break;
@@ -1793,35 +1793,35 @@  discard block
 block discarded – undo
1793 1793
      *
1794 1794
      * @return boolean
1795 1795
      */
1796
-    public function isReference($stackPtr)
1796
+    public function isReference( $stackPtr )
1797 1797
     {
1798
-        if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1798
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_BITWISE_AND ) {
1799 1799
             return false;
1800 1800
         }
1801 1801
 
1802 1802
         $tokenBefore = $this->findPrevious(
1803 1803
             Util\Tokens::$emptyTokens,
1804
-            ($stackPtr - 1),
1804
+            ( $stackPtr - 1 ),
1805 1805
             null,
1806 1806
             true
1807 1807
         );
1808 1808
 
1809
-        if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
1809
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_FUNCTION ) {
1810 1810
             // Function returns a reference.
1811 1811
             return true;
1812 1812
         }
1813 1813
 
1814
-        if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
1814
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_DOUBLE_ARROW ) {
1815 1815
             // Inside a foreach loop or array assignment, this is a reference.
1816 1816
             return true;
1817 1817
         }
1818 1818
 
1819
-        if ($this->tokens[$tokenBefore]['code'] === T_AS) {
1819
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_AS ) {
1820 1820
             // Inside a foreach loop, this is a reference.
1821 1821
             return true;
1822 1822
         }
1823 1823
 
1824
-        if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
1824
+        if ( isset( Util\Tokens::$assignmentTokens[ $this->tokens[ $tokenBefore ][ 'code' ] ] ) === true ) {
1825 1825
             // This is directly after an assignment. It's a reference. Even if
1826 1826
             // it is part of an operation, the other tests will handle it.
1827 1827
             return true;
@@ -1829,37 +1829,37 @@  discard block
 block discarded – undo
1829 1829
 
1830 1830
         $tokenAfter = $this->findNext(
1831 1831
             Util\Tokens::$emptyTokens,
1832
-            ($stackPtr + 1),
1832
+            ( $stackPtr + 1 ),
1833 1833
             null,
1834 1834
             true
1835 1835
         );
1836 1836
 
1837
-        if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
1837
+        if ( $this->tokens[ $tokenAfter ][ 'code' ] === T_NEW ) {
1838 1838
             return true;
1839 1839
         }
1840 1840
 
1841
-        if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
1842
-            $brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
1843
-            $lastBracket = array_pop($brackets);
1844
-            if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
1845
-                $owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
1846
-                if ($owner['code'] === T_FUNCTION
1847
-                    || $owner['code'] === T_CLOSURE
1841
+        if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) {
1842
+            $brackets    = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ];
1843
+            $lastBracket = array_pop( $brackets );
1844
+            if ( isset( $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] ) === true ) {
1845
+                $owner = $this->tokens[ $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] ];
1846
+                if ( $owner[ 'code' ] === T_FUNCTION
1847
+                    || $owner[ 'code' ] === T_CLOSURE
1848 1848
                 ) {
1849
-                    $params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
1850
-                    foreach ($params as $param) {
1849
+                    $params = $this->getMethodParameters( $this->tokens[ $lastBracket ][ 'parenthesis_owner' ] );
1850
+                    foreach ( $params as $param ) {
1851 1851
                         $varToken = $tokenAfter;
1852
-                        if ($param['variable_length'] === true) {
1852
+                        if ( $param[ 'variable_length' ] === true ) {
1853 1853
                             $varToken = $this->findNext(
1854
-                                (Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
1855
-                                ($stackPtr + 1),
1854
+                                ( Util\Tokens::$emptyTokens + [ T_ELLIPSIS ] ),
1855
+                                ( $stackPtr + 1 ),
1856 1856
                                 null,
1857 1857
                                 true
1858 1858
                             );
1859 1859
                         }
1860 1860
 
1861
-                        if ($param['token'] === $varToken
1862
-                            && $param['pass_by_reference'] === true
1861
+                        if ( $param[ 'token' ] === $varToken
1862
+                            && $param[ 'pass_by_reference' ] === true
1863 1863
                         ) {
1864 1864
                             // Function parameter declared to be passed by reference.
1865 1865
                             return true;
@@ -1868,14 +1868,14 @@  discard block
 block discarded – undo
1868 1868
                 }//end if
1869 1869
             } else {
1870 1870
                 $prev = false;
1871
-                for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
1872
-                    if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
1871
+                for ( $t = ( $this->tokens[ $lastBracket ][ 'parenthesis_opener' ] - 1 ); $t >= 0; $t-- ) {
1872
+                    if ( $this->tokens[ $t ][ 'code' ] !== T_WHITESPACE ) {
1873 1873
                         $prev = $t;
1874 1874
                         break;
1875 1875
                     }
1876 1876
                 }
1877 1877
 
1878
-                if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
1878
+                if ( $prev !== false && $this->tokens[ $prev ][ 'code' ] === T_USE ) {
1879 1879
                     // Closure use by reference.
1880 1880
                     return true;
1881 1881
                 }
@@ -1883,29 +1883,29 @@  discard block
 block discarded – undo
1883 1883
         }//end if
1884 1884
 
1885 1885
         // Pass by reference in function calls and assign by reference in arrays.
1886
-        if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
1887
-            || $this->tokens[$tokenBefore]['code'] === T_COMMA
1888
-            || $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
1886
+        if ( $this->tokens[ $tokenBefore ][ 'code' ] === T_OPEN_PARENTHESIS
1887
+            || $this->tokens[ $tokenBefore ][ 'code' ] === T_COMMA
1888
+            || $this->tokens[ $tokenBefore ][ 'code' ] === T_OPEN_SHORT_ARRAY
1889 1889
         ) {
1890
-            if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
1890
+            if ( $this->tokens[ $tokenAfter ][ 'code' ] === T_VARIABLE ) {
1891 1891
                 return true;
1892 1892
             } else {
1893 1893
                 $skip   = Util\Tokens::$emptyTokens;
1894
-                $skip[] = T_NS_SEPARATOR;
1895
-                $skip[] = T_SELF;
1896
-                $skip[] = T_PARENT;
1897
-                $skip[] = T_STATIC;
1898
-                $skip[] = T_STRING;
1899
-                $skip[] = T_NAMESPACE;
1900
-                $skip[] = T_DOUBLE_COLON;
1894
+                $skip[ ] = T_NS_SEPARATOR;
1895
+                $skip[ ] = T_SELF;
1896
+                $skip[ ] = T_PARENT;
1897
+                $skip[ ] = T_STATIC;
1898
+                $skip[ ] = T_STRING;
1899
+                $skip[ ] = T_NAMESPACE;
1900
+                $skip[ ] = T_DOUBLE_COLON;
1901 1901
 
1902 1902
                 $nextSignificantAfter = $this->findNext(
1903 1903
                     $skip,
1904
-                    ($stackPtr + 1),
1904
+                    ( $stackPtr + 1 ),
1905 1905
                     null,
1906 1906
                     true
1907 1907
                 );
1908
-                if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
1908
+                if ( $this->tokens[ $nextSignificantAfter ][ 'code' ] === T_VARIABLE ) {
1909 1909
                     return true;
1910 1910
                 }
1911 1911
             }//end if
@@ -1927,29 +1927,29 @@  discard block
 block discarded – undo
1927 1927
      *
1928 1928
      * @return string The token contents.
1929 1929
      */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1930
+    public function getTokensAsString( $start, $length, $origContent = false )
1931 1931
     {
1932
-        if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933
-            throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1932
+        if ( is_int( $start ) === false || isset( $this->tokens[ $start ] ) === false ) {
1933
+            throw new RuntimeException( 'The $start position for getTokensAsString() must exist in the token stack' );
1934 1934
         }
1935 1935
 
1936
-        if (is_int($length) === false || $length <= 0) {
1936
+        if ( is_int( $length ) === false || $length <= 0 ) {
1937 1937
             return '';
1938 1938
         }
1939 1939
 
1940 1940
         $str = '';
1941
-        $end = ($start + $length);
1942
-        if ($end > $this->numTokens) {
1941
+        $end = ( $start + $length );
1942
+        if ( $end > $this->numTokens ) {
1943 1943
             $end = $this->numTokens;
1944 1944
         }
1945 1945
 
1946
-        for ($i = $start; $i < $end; $i++) {
1946
+        for ( $i = $start; $i < $end; $i++ ) {
1947 1947
             // If tabs are being converted to spaces by the tokeniser, the
1948 1948
             // original content should be used instead of the converted content.
1949
-            if ($origContent === true && isset($this->tokens[$i]['orig_content']) === true) {
1950
-                $str .= $this->tokens[$i]['orig_content'];
1949
+            if ( $origContent === true && isset( $this->tokens[ $i ][ 'orig_content' ] ) === true ) {
1950
+                $str .= $this->tokens[ $i ][ 'orig_content' ];
1951 1951
             } else {
1952
-                $str .= $this->tokens[$i]['content'];
1952
+                $str .= $this->tokens[ $i ][ 'content' ];
1953 1953
             }
1954 1954
         }
1955 1955
 
@@ -1987,48 +1987,48 @@  discard block
 block discarded – undo
1987 1987
     public function findPrevious(
1988 1988
         $types,
1989 1989
         $start,
1990
-        $end=null,
1991
-        $exclude=false,
1992
-        $value=null,
1993
-        $local=false
1990
+        $end = null,
1991
+        $exclude = false,
1992
+        $value = null,
1993
+        $local = false
1994 1994
     ) {
1995
-        $types = (array) $types;
1995
+        $types = (array)$types;
1996 1996
 
1997
-        if ($end === null) {
1997
+        if ( $end === null ) {
1998 1998
             $end = 0;
1999 1999
         }
2000 2000
 
2001
-        for ($i = $start; $i >= $end; $i--) {
2002
-            $found = (bool) $exclude;
2003
-            foreach ($types as $type) {
2004
-                if ($this->tokens[$i]['code'] === $type) {
2005
-                    $found = !$exclude;
2001
+        for ( $i = $start; $i >= $end; $i-- ) {
2002
+            $found = (bool)$exclude;
2003
+            foreach ( $types as $type ) {
2004
+                if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2005
+                    $found = ! $exclude;
2006 2006
                     break;
2007 2007
                 }
2008 2008
             }
2009 2009
 
2010
-            if ($found === true) {
2011
-                if ($value === null) {
2010
+            if ( $found === true ) {
2011
+                if ( $value === null ) {
2012 2012
                     return $i;
2013
-                } else if ($this->tokens[$i]['content'] === $value) {
2013
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2014 2014
                     return $i;
2015 2015
                 }
2016 2016
             }
2017 2017
 
2018
-            if ($local === true) {
2019
-                if (isset($this->tokens[$i]['scope_opener']) === true
2020
-                    && $i === $this->tokens[$i]['scope_closer']
2018
+            if ( $local === true ) {
2019
+                if ( isset( $this->tokens[ $i ][ 'scope_opener' ] ) === true
2020
+                    && $i === $this->tokens[ $i ][ 'scope_closer' ]
2021 2021
                 ) {
2022
-                    $i = $this->tokens[$i]['scope_opener'];
2023
-                } else if (isset($this->tokens[$i]['bracket_opener']) === true
2024
-                    && $i === $this->tokens[$i]['bracket_closer']
2022
+                    $i = $this->tokens[ $i ][ 'scope_opener' ];
2023
+                } else if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true
2024
+                    && $i === $this->tokens[ $i ][ 'bracket_closer' ]
2025 2025
                 ) {
2026
-                    $i = $this->tokens[$i]['bracket_opener'];
2027
-                } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2028
-                    && $i === $this->tokens[$i]['parenthesis_closer']
2026
+                    $i = $this->tokens[ $i ][ 'bracket_opener' ];
2027
+                } else if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true
2028
+                    && $i === $this->tokens[ $i ][ 'parenthesis_closer' ]
2029 2029
                 ) {
2030
-                    $i = $this->tokens[$i]['parenthesis_opener'];
2031
-                } else if ($this->tokens[$i]['code'] === T_SEMICOLON) {
2030
+                    $i = $this->tokens[ $i ][ 'parenthesis_opener' ];
2031
+                } else if ( $this->tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
2032 2032
                     break;
2033 2033
                 }
2034 2034
             }
@@ -2068,35 +2068,35 @@  discard block
 block discarded – undo
2068 2068
     public function findNext(
2069 2069
         $types,
2070 2070
         $start,
2071
-        $end=null,
2072
-        $exclude=false,
2073
-        $value=null,
2074
-        $local=false
2071
+        $end = null,
2072
+        $exclude = false,
2073
+        $value = null,
2074
+        $local = false
2075 2075
     ) {
2076
-        $types = (array) $types;
2076
+        $types = (array)$types;
2077 2077
 
2078
-        if ($end === null || $end > $this->numTokens) {
2078
+        if ( $end === null || $end > $this->numTokens ) {
2079 2079
             $end = $this->numTokens;
2080 2080
         }
2081 2081
 
2082
-        for ($i = $start; $i < $end; $i++) {
2083
-            $found = (bool) $exclude;
2084
-            foreach ($types as $type) {
2085
-                if ($this->tokens[$i]['code'] === $type) {
2086
-                    $found = !$exclude;
2082
+        for ( $i = $start; $i < $end; $i++ ) {
2083
+            $found = (bool)$exclude;
2084
+            foreach ( $types as $type ) {
2085
+                if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2086
+                    $found = ! $exclude;
2087 2087
                     break;
2088 2088
                 }
2089 2089
             }
2090 2090
 
2091
-            if ($found === true) {
2092
-                if ($value === null) {
2091
+            if ( $found === true ) {
2092
+                if ( $value === null ) {
2093 2093
                     return $i;
2094
-                } else if ($this->tokens[$i]['content'] === $value) {
2094
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2095 2095
                     return $i;
2096 2096
                 }
2097 2097
             }
2098 2098
 
2099
-            if ($local === true && $this->tokens[$i]['code'] === T_SEMICOLON) {
2099
+            if ( $local === true && $this->tokens[ $i ][ 'code' ] === T_SEMICOLON ) {
2100 2100
                 break;
2101 2101
             }
2102 2102
         }//end for
@@ -2114,52 +2114,52 @@  discard block
 block discarded – undo
2114 2114
      *
2115 2115
      * @return int
2116 2116
      */
2117
-    public function findStartOfStatement($start, $ignore=null)
2117
+    public function findStartOfStatement( $start, $ignore = null )
2118 2118
     {
2119 2119
         $endTokens = Util\Tokens::$blockOpeners;
2120 2120
 
2121
-        $endTokens[T_COLON]            = true;
2122
-        $endTokens[T_COMMA]            = true;
2123
-        $endTokens[T_DOUBLE_ARROW]     = true;
2124
-        $endTokens[T_SEMICOLON]        = true;
2125
-        $endTokens[T_OPEN_TAG]         = true;
2126
-        $endTokens[T_CLOSE_TAG]        = true;
2127
-        $endTokens[T_OPEN_SHORT_ARRAY] = true;
2128
-
2129
-        if ($ignore !== null) {
2130
-            $ignore = (array) $ignore;
2131
-            foreach ($ignore as $code) {
2132
-                unset($endTokens[$code]);
2121
+        $endTokens[ T_COLON ]            = true;
2122
+        $endTokens[ T_COMMA ]            = true;
2123
+        $endTokens[ T_DOUBLE_ARROW ]     = true;
2124
+        $endTokens[ T_SEMICOLON ]        = true;
2125
+        $endTokens[ T_OPEN_TAG ]         = true;
2126
+        $endTokens[ T_CLOSE_TAG ]        = true;
2127
+        $endTokens[ T_OPEN_SHORT_ARRAY ] = true;
2128
+
2129
+        if ( $ignore !== null ) {
2130
+            $ignore = (array)$ignore;
2131
+            foreach ( $ignore as $code ) {
2132
+                unset( $endTokens[ $code ] );
2133 2133
             }
2134 2134
         }
2135 2135
 
2136 2136
         $lastNotEmpty = $start;
2137 2137
 
2138
-        for ($i = $start; $i >= 0; $i--) {
2139
-            if (isset($endTokens[$this->tokens[$i]['code']]) === true) {
2138
+        for ( $i = $start; $i >= 0; $i-- ) {
2139
+            if ( isset( $endTokens[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2140 2140
                 // Found the end of the previous statement.
2141 2141
                 return $lastNotEmpty;
2142 2142
             }
2143 2143
 
2144
-            if (isset($this->tokens[$i]['scope_opener']) === true
2145
-                && $i === $this->tokens[$i]['scope_closer']
2144
+            if ( isset( $this->tokens[ $i ][ 'scope_opener' ] ) === true
2145
+                && $i === $this->tokens[ $i ][ 'scope_closer' ]
2146 2146
             ) {
2147 2147
                 // Found the end of the previous scope block.
2148 2148
                 return $lastNotEmpty;
2149 2149
             }
2150 2150
 
2151 2151
             // Skip nested statements.
2152
-            if (isset($this->tokens[$i]['bracket_opener']) === true
2153
-                && $i === $this->tokens[$i]['bracket_closer']
2152
+            if ( isset( $this->tokens[ $i ][ 'bracket_opener' ] ) === true
2153
+                && $i === $this->tokens[ $i ][ 'bracket_closer' ]
2154 2154
             ) {
2155
-                $i = $this->tokens[$i]['bracket_opener'];
2156
-            } else if (isset($this->tokens[$i]['parenthesis_opener']) === true
2157
-                && $i === $this->tokens[$i]['parenthesis_closer']
2155
+                $i = $this->tokens[ $i ][ 'bracket_opener' ];
2156
+            } else if ( isset( $this->tokens[ $i ][ 'parenthesis_opener' ] ) === true
2157
+                && $i === $this->tokens[ $i ][ 'parenthesis_closer' ]
2158 2158
             ) {
2159
-                $i = $this->tokens[$i]['parenthesis_opener'];
2159
+                $i = $this->tokens[ $i ][ 'parenthesis_opener' ];
2160 2160
             }
2161 2161
 
2162
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2162
+            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
2163 2163
                 $lastNotEmpty = $i;
2164 2164
             }
2165 2165
         }//end for
@@ -2177,7 +2177,7 @@  discard block
 block discarded – undo
2177 2177
      *
2178 2178
      * @return int
2179 2179
      */
2180
-    public function findEndOfStatement($start, $ignore=null)
2180
+    public function findEndOfStatement( $start, $ignore = null )
2181 2181
     {
2182 2182
         $endTokens = [
2183 2183
             T_COLON                => true,
@@ -2192,24 +2192,24 @@  discard block
 block discarded – undo
2192 2192
             T_CLOSE_TAG            => true,
2193 2193
         ];
2194 2194
 
2195
-        if ($ignore !== null) {
2196
-            $ignore = (array) $ignore;
2197
-            foreach ($ignore as $code) {
2198
-                unset($endTokens[$code]);
2195
+        if ( $ignore !== null ) {
2196
+            $ignore = (array)$ignore;
2197
+            foreach ( $ignore as $code ) {
2198
+                unset( $endTokens[ $code ] );
2199 2199
             }
2200 2200
         }
2201 2201
 
2202 2202
         $lastNotEmpty = $start;
2203 2203
 
2204
-        for ($i = $start; $i < $this->numTokens; $i++) {
2205
-            if ($i !== $start && isset($endTokens[$this->tokens[$i]['code']]) === true) {
2204
+        for ( $i = $start; $i < $this->numTokens; $i++ ) {
2205
+            if ( $i !== $start && isset( $endTokens[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2206 2206
                 // Found the end of the statement.
2207
-                if ($this->tokens[$i]['code'] === T_CLOSE_PARENTHESIS
2208
-                    || $this->tokens[$i]['code'] === T_CLOSE_SQUARE_BRACKET
2209
-                    || $this->tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET
2210
-                    || $this->tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
2211
-                    || $this->tokens[$i]['code'] === T_OPEN_TAG
2212
-                    || $this->tokens[$i]['code'] === T_CLOSE_TAG
2207
+                if ( $this->tokens[ $i ][ 'code' ] === T_CLOSE_PARENTHESIS
2208
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_SQUARE_BRACKET
2209
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_CURLY_BRACKET
2210
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_SHORT_ARRAY
2211
+                    || $this->tokens[ $i ][ 'code' ] === T_OPEN_TAG
2212
+                    || $this->tokens[ $i ][ 'code' ] === T_CLOSE_TAG
2213 2213
                 ) {
2214 2214
                     return $lastNotEmpty;
2215 2215
                 }
@@ -2218,31 +2218,31 @@  discard block
 block discarded – undo
2218 2218
             }
2219 2219
 
2220 2220
             // Skip nested statements.
2221
-            if (isset($this->tokens[$i]['scope_closer']) === true
2222
-                && ($i === $this->tokens[$i]['scope_opener']
2223
-                || $i === $this->tokens[$i]['scope_condition'])
2221
+            if ( isset( $this->tokens[ $i ][ 'scope_closer' ] ) === true
2222
+                && ( $i === $this->tokens[ $i ][ 'scope_opener' ]
2223
+                || $i === $this->tokens[ $i ][ 'scope_condition' ] )
2224 2224
             ) {
2225
-                if ($i === $start && isset(Util\Tokens::$scopeOpeners[$this->tokens[$i]['code']]) === true) {
2226
-                    return $this->tokens[$i]['scope_closer'];
2225
+                if ( $i === $start && isset( Util\Tokens::$scopeOpeners[ $this->tokens[ $i ][ 'code' ] ] ) === true ) {
2226
+                    return $this->tokens[ $i ][ 'scope_closer' ];
2227 2227
                 }
2228 2228
 
2229
-                $i = $this->tokens[$i]['scope_closer'];
2230
-            } else if (isset($this->tokens[$i]['bracket_closer']) === true
2231
-                && $i === $this->tokens[$i]['bracket_opener']
2229
+                $i = $this->tokens[ $i ][ 'scope_closer' ];
2230
+            } else if ( isset( $this->tokens[ $i ][ 'bracket_closer' ] ) === true
2231
+                && $i === $this->tokens[ $i ][ 'bracket_opener' ]
2232 2232
             ) {
2233
-                $i = $this->tokens[$i]['bracket_closer'];
2234
-            } else if (isset($this->tokens[$i]['parenthesis_closer']) === true
2235
-                && $i === $this->tokens[$i]['parenthesis_opener']
2233
+                $i = $this->tokens[ $i ][ 'bracket_closer' ];
2234
+            } else if ( isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) === true
2235
+                && $i === $this->tokens[ $i ][ 'parenthesis_opener' ]
2236 2236
             ) {
2237
-                $i = $this->tokens[$i]['parenthesis_closer'];
2237
+                $i = $this->tokens[ $i ][ 'parenthesis_closer' ];
2238 2238
             }
2239 2239
 
2240
-            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$i]['code']]) === false) {
2240
+            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) === false ) {
2241 2241
                 $lastNotEmpty = $i;
2242 2242
             }
2243 2243
         }//end for
2244 2244
 
2245
-        return ($this->numTokens - 1);
2245
+        return ( $this->numTokens - 1 );
2246 2246
 
2247 2247
     }//end findEndOfStatement()
2248 2248
 
@@ -2264,38 +2264,38 @@  discard block
 block discarded – undo
2264 2264
      *
2265 2265
      * @return int | bool
2266 2266
      */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2267
+    public function findFirstOnLine( $types, $start, $exclude = false, $value = null )
2268 2268
     {
2269
-        if (is_array($types) === false) {
2270
-            $types = [$types];
2269
+        if ( is_array( $types ) === false ) {
2270
+            $types = [ $types ];
2271 2271
         }
2272 2272
 
2273 2273
         $foundToken = false;
2274 2274
 
2275
-        for ($i = $start; $i >= 0; $i--) {
2276
-            if ($this->tokens[$i]['line'] < $this->tokens[$start]['line']) {
2275
+        for ( $i = $start; $i >= 0; $i-- ) {
2276
+            if ( $this->tokens[ $i ][ 'line' ] < $this->tokens[ $start ][ 'line' ] ) {
2277 2277
                 break;
2278 2278
             }
2279 2279
 
2280 2280
             $found = $exclude;
2281
-            foreach ($types as $type) {
2282
-                if ($exclude === false) {
2283
-                    if ($this->tokens[$i]['code'] === $type) {
2281
+            foreach ( $types as $type ) {
2282
+                if ( $exclude === false ) {
2283
+                    if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2284 2284
                         $found = true;
2285 2285
                         break;
2286 2286
                     }
2287 2287
                 } else {
2288
-                    if ($this->tokens[$i]['code'] === $type) {
2288
+                    if ( $this->tokens[ $i ][ 'code' ] === $type ) {
2289 2289
                         $found = false;
2290 2290
                         break;
2291 2291
                     }
2292 2292
                 }
2293 2293
             }
2294 2294
 
2295
-            if ($found === true) {
2296
-                if ($value === null) {
2295
+            if ( $found === true ) {
2296
+                if ( $value === null ) {
2297 2297
                     $foundToken = $i;
2298
-                } else if ($this->tokens[$i]['content'] === $value) {
2298
+                } else if ( $this->tokens[ $i ][ 'content' ] === $value ) {
2299 2299
                     $foundToken = $i;
2300 2300
                 }
2301 2301
             }
@@ -2314,23 +2314,23 @@  discard block
 block discarded – undo
2314 2314
      *
2315 2315
      * @return boolean
2316 2316
      */
2317
-    public function hasCondition($stackPtr, $types)
2317
+    public function hasCondition( $stackPtr, $types )
2318 2318
     {
2319 2319
         // Check for the existence of the token.
2320
-        if (isset($this->tokens[$stackPtr]) === false) {
2320
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2321 2321
             return false;
2322 2322
         }
2323 2323
 
2324 2324
         // Make sure the token has conditions.
2325
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2325
+        if ( isset( $this->tokens[ $stackPtr ][ 'conditions' ] ) === false ) {
2326 2326
             return false;
2327 2327
         }
2328 2328
 
2329
-        $types      = (array) $types;
2330
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2329
+        $types      = (array)$types;
2330
+        $conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
2331 2331
 
2332
-        foreach ($types as $type) {
2333
-            if (in_array($type, $conditions, true) === true) {
2332
+        foreach ( $types as $type ) {
2333
+            if ( in_array( $type, $conditions, true ) === true ) {
2334 2334
                 // We found a token with the required type.
2335 2335
                 return true;
2336 2336
             }
@@ -2351,21 +2351,21 @@  discard block
 block discarded – undo
2351 2351
      *
2352 2352
      * @return int
2353 2353
      */
2354
-    public function getCondition($stackPtr, $type)
2354
+    public function getCondition( $stackPtr, $type )
2355 2355
     {
2356 2356
         // Check for the existence of the token.
2357
-        if (isset($this->tokens[$stackPtr]) === false) {
2357
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2358 2358
             return false;
2359 2359
         }
2360 2360
 
2361 2361
         // Make sure the token has conditions.
2362
-        if (isset($this->tokens[$stackPtr]['conditions']) === false) {
2362
+        if ( isset( $this->tokens[ $stackPtr ][ 'conditions' ] ) === false ) {
2363 2363
             return false;
2364 2364
         }
2365 2365
 
2366
-        $conditions = $this->tokens[$stackPtr]['conditions'];
2367
-        foreach ($conditions as $token => $condition) {
2368
-            if ($condition === $type) {
2366
+        $conditions = $this->tokens[ $stackPtr ][ 'conditions' ];
2367
+        foreach ( $conditions as $token => $condition ) {
2368
+            if ( $condition === $type ) {
2369 2369
                 return $token;
2370 2370
             }
2371 2371
         }
@@ -2385,27 +2385,27 @@  discard block
 block discarded – undo
2385 2385
      *
2386 2386
      * @return string|false
2387 2387
      */
2388
-    public function findExtendedClassName($stackPtr)
2388
+    public function findExtendedClassName( $stackPtr )
2389 2389
     {
2390 2390
         // Check for the existence of the token.
2391
-        if (isset($this->tokens[$stackPtr]) === false) {
2391
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2392 2392
             return false;
2393 2393
         }
2394 2394
 
2395
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2396
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2397
-            && $this->tokens[$stackPtr]['code'] !== T_INTERFACE
2395
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS
2396
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_ANON_CLASS
2397
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_INTERFACE
2398 2398
         ) {
2399 2399
             return false;
2400 2400
         }
2401 2401
 
2402
-        if (isset($this->tokens[$stackPtr]['scope_opener']) === false) {
2402
+        if ( isset( $this->tokens[ $stackPtr ][ 'scope_opener' ] ) === false ) {
2403 2403
             return false;
2404 2404
         }
2405 2405
 
2406
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2407
-        $extendsIndex     = $this->findNext(T_EXTENDS, $stackPtr, $classOpenerIndex);
2408
-        if (false === $extendsIndex) {
2406
+        $classOpenerIndex = $this->tokens[ $stackPtr ][ 'scope_opener' ];
2407
+        $extendsIndex     = $this->findNext( T_EXTENDS, $stackPtr, $classOpenerIndex );
2408
+        if ( false === $extendsIndex ) {
2409 2409
             return false;
2410 2410
         }
2411 2411
 
@@ -2415,11 +2415,11 @@  discard block
 block discarded – undo
2415 2415
             T_WHITESPACE,
2416 2416
         ];
2417 2417
 
2418
-        $end  = $this->findNext($find, ($extendsIndex + 1), ($classOpenerIndex + 1), true);
2419
-        $name = $this->getTokensAsString(($extendsIndex + 1), ($end - $extendsIndex - 1));
2420
-        $name = trim($name);
2418
+        $end  = $this->findNext( $find, ( $extendsIndex + 1 ), ( $classOpenerIndex + 1 ), true );
2419
+        $name = $this->getTokensAsString( ( $extendsIndex + 1 ), ( $end - $extendsIndex - 1 ) );
2420
+        $name = trim( $name );
2421 2421
 
2422
-        if ($name === '') {
2422
+        if ( $name === '' ) {
2423 2423
             return false;
2424 2424
         }
2425 2425
 
@@ -2437,26 +2437,26 @@  discard block
 block discarded – undo
2437 2437
      *
2438 2438
      * @return array|false
2439 2439
      */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2440
+    public function findImplementedInterfaceNames( $stackPtr )
2441 2441
     {
2442 2442
         // Check for the existence of the token.
2443
-        if (isset($this->tokens[$stackPtr]) === false) {
2443
+        if ( isset( $this->tokens[ $stackPtr ] ) === false ) {
2444 2444
             return false;
2445 2445
         }
2446 2446
 
2447
-        if ($this->tokens[$stackPtr]['code'] !== T_CLASS
2448
-            && $this->tokens[$stackPtr]['code'] !== T_ANON_CLASS
2447
+        if ( $this->tokens[ $stackPtr ][ 'code' ] !== T_CLASS
2448
+            && $this->tokens[ $stackPtr ][ 'code' ] !== T_ANON_CLASS
2449 2449
         ) {
2450 2450
             return false;
2451 2451
         }
2452 2452
 
2453
-        if (isset($this->tokens[$stackPtr]['scope_closer']) === false) {
2453
+        if ( isset( $this->tokens[ $stackPtr ][ 'scope_closer' ] ) === false ) {
2454 2454
             return false;
2455 2455
         }
2456 2456
 
2457
-        $classOpenerIndex = $this->tokens[$stackPtr]['scope_opener'];
2458
-        $implementsIndex  = $this->findNext(T_IMPLEMENTS, $stackPtr, $classOpenerIndex);
2459
-        if ($implementsIndex === false) {
2457
+        $classOpenerIndex = $this->tokens[ $stackPtr ][ 'scope_opener' ];
2458
+        $implementsIndex  = $this->findNext( T_IMPLEMENTS, $stackPtr, $classOpenerIndex );
2459
+        if ( $implementsIndex === false ) {
2460 2460
             return false;
2461 2461
         }
2462 2462
 
@@ -2467,15 +2467,15 @@  discard block
 block discarded – undo
2467 2467
             T_COMMA,
2468 2468
         ];
2469 2469
 
2470
-        $end  = $this->findNext($find, ($implementsIndex + 1), ($classOpenerIndex + 1), true);
2471
-        $name = $this->getTokensAsString(($implementsIndex + 1), ($end - $implementsIndex - 1));
2472
-        $name = trim($name);
2470
+        $end  = $this->findNext( $find, ( $implementsIndex + 1 ), ( $classOpenerIndex + 1 ), true );
2471
+        $name = $this->getTokensAsString( ( $implementsIndex + 1 ), ( $end - $implementsIndex - 1 ) );
2472
+        $name = trim( $name );
2473 2473
 
2474
-        if ($name === '') {
2474
+        if ( $name === '' ) {
2475 2475
             return false;
2476 2476
         } else {
2477
-            $names = explode(',', $name);
2478
-            $names = array_map('trim', $names);
2477
+            $names = explode( ',', $name );
2478
+            $names = array_map( 'trim', $names );
2479 2479
             return $names;
2480 2480
         }
2481 2481
 
Please login to merge, or discard this patch.
Braces   +34 added lines, -68 removed lines patch added patch discarded remove patch
@@ -16,8 +16,7 @@  discard block
 block discarded – undo
16 16
 use PHP_CodeSniffer\Exceptions\RuntimeException;
17 17
 use PHP_CodeSniffer\Exceptions\TokenizerException;
18 18
 
19
-class File
20
-{
19
+class File {
21 20
 
22 21
     /**
23 22
      * The absolute path to the file associated with this object.
@@ -224,8 +223,7 @@  discard block
 block discarded – undo
224 223
      *
225 224
      * @return void
226 225
      */
227
-    public function __construct($path, Ruleset $ruleset, Config $config)
228
-    {
226
+    public function __construct($path, Ruleset $ruleset, Config $config) {
229 227
         $this->path    = $path;
230 228
         $this->ruleset = $ruleset;
231 229
         $this->config  = $config;
@@ -261,8 +259,7 @@  discard block
 block discarded – undo
261 259
      *
262 260
      * @return void
263 261
      */
264
-    public function setContent($content)
265
-    {
262
+    public function setContent($content) {
266 263
         $this->content = $content;
267 264
         $this->tokens  = [];
268 265
 
@@ -284,8 +281,7 @@  discard block
 block discarded – undo
284 281
      *
285 282
      * @return void
286 283
      */
287
-    public function reloadContent()
288
-    {
284
+    public function reloadContent() {
289 285
 
290 286
     }//end reloadContent()
291 287
 
@@ -295,8 +291,7 @@  discard block
 block discarded – undo
295 291
      *
296 292
      * @return void
297 293
      */
298
-    public function disableCaching()
299
-    {
294
+    public function disableCaching() {
300 295
         $this->configCache['cache'] = false;
301 296
 
302 297
     }//end disableCaching()
@@ -307,8 +302,7 @@  discard block
 block discarded – undo
307 302
      *
308 303
      * @return void
309 304
      */
310
-    public function process()
311
-    {
305
+    public function process() {
312 306
         if ($this->ignored === true) {
313 307
             return;
314 308
         }
@@ -544,8 +538,7 @@  discard block
 block discarded – undo
544 538
      *
545 539
      * @return void
546 540
      */
547
-    public function parse()
548
-    {
541
+    public function parse() {
549 542
         if (empty($this->tokens) === false) {
550 543
             // File has already been parsed.
551 544
             return;
@@ -605,8 +598,7 @@  discard block
 block discarded – undo
605 598
      *
606 599
      * @return array
607 600
      */
608
-    public function getTokens()
609
-    {
601
+    public function getTokens() {
610 602
         return $this->tokens;
611 603
 
612 604
     }//end getTokens()
@@ -617,8 +609,7 @@  discard block
 block discarded – undo
617 609
      *
618 610
      * @return void
619 611
      */
620
-    public function cleanUp()
621
-    {
612
+    public function cleanUp() {
622 613
         $this->listenerTimes = null;
623 614
         $this->content       = null;
624 615
         $this->tokens        = null;
@@ -824,8 +815,7 @@  discard block
 block discarded – undo
824 815
      *
825 816
      * @return boolean
826 817
      */
827
-    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable)
828
-    {
818
+    protected function addMessage($error, $message, $line, $column, $code, $data, $severity, $fixable) {
829 819
         // Check if this line is ignoring all message codes.
830 820
         if (isset($this->tokenizer->ignoredLines[$line]['.all']) === true) {
831 821
             return false;
@@ -1077,8 +1067,7 @@  discard block
 block discarded – undo
1077 1067
      *
1078 1068
      * @return boolean
1079 1069
      */
1080
-    public function recordMetric($stackPtr, $metric, $value)
1081
-    {
1070
+    public function recordMetric($stackPtr, $metric, $value) {
1082 1071
         if (isset($this->metrics[$metric]) === false) {
1083 1072
             $this->metrics[$metric] = ['values' => [$value => 1]];
1084 1073
             $this->metricTokens[$metric][$stackPtr] = true;
@@ -1101,8 +1090,7 @@  discard block
 block discarded – undo
1101 1090
      *
1102 1091
      * @return int
1103 1092
      */
1104
-    public function getErrorCount()
1105
-    {
1093
+    public function getErrorCount() {
1106 1094
         return $this->errorCount;
1107 1095
 
1108 1096
     }//end getErrorCount()
@@ -1113,8 +1101,7 @@  discard block
 block discarded – undo
1113 1101
      *
1114 1102
      * @return int
1115 1103
      */
1116
-    public function getWarningCount()
1117
-    {
1104
+    public function getWarningCount() {
1118 1105
         return $this->warningCount;
1119 1106
 
1120 1107
     }//end getWarningCount()
@@ -1125,8 +1112,7 @@  discard block
 block discarded – undo
1125 1112
      *
1126 1113
      * @return int
1127 1114
      */
1128
-    public function getFixableCount()
1129
-    {
1115
+    public function getFixableCount() {
1130 1116
         return $this->fixableCount;
1131 1117
 
1132 1118
     }//end getFixableCount()
@@ -1137,8 +1123,7 @@  discard block
 block discarded – undo
1137 1123
      *
1138 1124
      * @return int
1139 1125
      */
1140
-    public function getFixedCount()
1141
-    {
1126
+    public function getFixedCount() {
1142 1127
         return $this->fixedCount;
1143 1128
 
1144 1129
     }//end getFixedCount()
@@ -1149,8 +1134,7 @@  discard block
 block discarded – undo
1149 1134
      *
1150 1135
      * @return array
1151 1136
      */
1152
-    public function getIgnoredLines()
1153
-    {
1137
+    public function getIgnoredLines() {
1154 1138
         return $this->tokenizer->ignoredLines;
1155 1139
 
1156 1140
     }//end getIgnoredLines()
@@ -1161,8 +1145,7 @@  discard block
 block discarded – undo
1161 1145
      *
1162 1146
      * @return array
1163 1147
      */
1164
-    public function getErrors()
1165
-    {
1148
+    public function getErrors() {
1166 1149
         return $this->errors;
1167 1150
 
1168 1151
     }//end getErrors()
@@ -1173,8 +1156,7 @@  discard block
 block discarded – undo
1173 1156
      *
1174 1157
      * @return array
1175 1158
      */
1176
-    public function getWarnings()
1177
-    {
1159
+    public function getWarnings() {
1178 1160
         return $this->warnings;
1179 1161
 
1180 1162
     }//end getWarnings()
@@ -1185,8 +1167,7 @@  discard block
 block discarded – undo
1185 1167
      *
1186 1168
      * @return array
1187 1169
      */
1188
-    public function getMetrics()
1189
-    {
1170
+    public function getMetrics() {
1190 1171
         return $this->metrics;
1191 1172
 
1192 1173
     }//end getMetrics()
@@ -1197,8 +1178,7 @@  discard block
 block discarded – undo
1197 1178
      *
1198 1179
      * @return string
1199 1180
      */
1200
-    public function getFilename()
1201
-    {
1181
+    public function getFilename() {
1202 1182
         return $this->path;
1203 1183
 
1204 1184
     }//end getFilename()
@@ -1216,8 +1196,7 @@  discard block
 block discarded – undo
1216 1196
      *                                                      T_FUNCTION, T_CLASS, T_ANON_CLASS,
1217 1197
      *                                                      T_CLOSURE, T_TRAIT, or T_INTERFACE.
1218 1198
      */
1219
-    public function getDeclarationName($stackPtr)
1220
-    {
1199
+    public function getDeclarationName($stackPtr) {
1221 1200
         $tokenCode = $this->tokens[$stackPtr]['code'];
1222 1201
 
1223 1202
         if ($tokenCode === T_ANON_CLASS || $tokenCode === T_CLOSURE) {
@@ -1282,8 +1261,7 @@  discard block
 block discarded – undo
1282 1261
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified $stackPtr is not of
1283 1262
      *                                                        type T_FUNCTION or T_CLOSURE.
1284 1263
      */
1285
-    public function getMethodParameters($stackPtr)
1286
-    {
1264
+    public function getMethodParameters($stackPtr) {
1287 1265
         if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1288 1266
             && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1289 1267
         ) {
@@ -1474,8 +1452,7 @@  discard block
 block discarded – undo
1474 1452
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1475 1453
      *                                                        T_FUNCTION token.
1476 1454
      */
1477
-    public function getMethodProperties($stackPtr)
1478
-    {
1455
+    public function getMethodProperties($stackPtr) {
1479 1456
         if ($this->tokens[$stackPtr]['code'] !== T_FUNCTION
1480 1457
             && $this->tokens[$stackPtr]['code'] !== T_CLOSURE
1481 1458
         ) {
@@ -1624,8 +1601,7 @@  discard block
 block discarded – undo
1624 1601
      *                                                        T_VARIABLE token, or if the position is not
1625 1602
      *                                                        a class member variable.
1626 1603
      */
1627
-    public function getMemberProperties($stackPtr)
1628
-    {
1604
+    public function getMemberProperties($stackPtr) {
1629 1605
         if ($this->tokens[$stackPtr]['code'] !== T_VARIABLE) {
1630 1606
             throw new TokenizerException('$stackPtr must be of type T_VARIABLE');
1631 1607
         }
@@ -1742,8 +1718,7 @@  discard block
 block discarded – undo
1742 1718
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the specified position is not a
1743 1719
      *                                                        T_CLASS token.
1744 1720
      */
1745
-    public function getClassProperties($stackPtr)
1746
-    {
1721
+    public function getClassProperties($stackPtr) {
1747 1722
         if ($this->tokens[$stackPtr]['code'] !== T_CLASS) {
1748 1723
             throw new TokenizerException('$stackPtr must be of type T_CLASS');
1749 1724
         }
@@ -1793,8 +1768,7 @@  discard block
 block discarded – undo
1793 1768
      *
1794 1769
      * @return boolean
1795 1770
      */
1796
-    public function isReference($stackPtr)
1797
-    {
1771
+    public function isReference($stackPtr) {
1798 1772
         if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
1799 1773
             return false;
1800 1774
         }
@@ -1927,8 +1901,7 @@  discard block
 block discarded – undo
1927 1901
      *
1928 1902
      * @return string The token contents.
1929 1903
      */
1930
-    public function getTokensAsString($start, $length, $origContent=false)
1931
-    {
1904
+    public function getTokensAsString($start, $length, $origContent=false) {
1932 1905
         if (is_int($start) === false || isset($this->tokens[$start]) === false) {
1933 1906
             throw new RuntimeException('The $start position for getTokensAsString() must exist in the token stack');
1934 1907
         }
@@ -2114,8 +2087,7 @@  discard block
 block discarded – undo
2114 2087
      *
2115 2088
      * @return int
2116 2089
      */
2117
-    public function findStartOfStatement($start, $ignore=null)
2118
-    {
2090
+    public function findStartOfStatement($start, $ignore=null) {
2119 2091
         $endTokens = Util\Tokens::$blockOpeners;
2120 2092
 
2121 2093
         $endTokens[T_COLON]            = true;
@@ -2177,8 +2149,7 @@  discard block
 block discarded – undo
2177 2149
      *
2178 2150
      * @return int
2179 2151
      */
2180
-    public function findEndOfStatement($start, $ignore=null)
2181
-    {
2152
+    public function findEndOfStatement($start, $ignore=null) {
2182 2153
         $endTokens = [
2183 2154
             T_COLON                => true,
2184 2155
             T_COMMA                => true,
@@ -2264,8 +2235,7 @@  discard block
 block discarded – undo
2264 2235
      *
2265 2236
      * @return int | bool
2266 2237
      */
2267
-    public function findFirstOnLine($types, $start, $exclude=false, $value=null)
2268
-    {
2238
+    public function findFirstOnLine($types, $start, $exclude=false, $value=null) {
2269 2239
         if (is_array($types) === false) {
2270 2240
             $types = [$types];
2271 2241
         }
@@ -2314,8 +2284,7 @@  discard block
 block discarded – undo
2314 2284
      *
2315 2285
      * @return boolean
2316 2286
      */
2317
-    public function hasCondition($stackPtr, $types)
2318
-    {
2287
+    public function hasCondition($stackPtr, $types) {
2319 2288
         // Check for the existence of the token.
2320 2289
         if (isset($this->tokens[$stackPtr]) === false) {
2321 2290
             return false;
@@ -2351,8 +2320,7 @@  discard block
 block discarded – undo
2351 2320
      *
2352 2321
      * @return int
2353 2322
      */
2354
-    public function getCondition($stackPtr, $type)
2355
-    {
2323
+    public function getCondition($stackPtr, $type) {
2356 2324
         // Check for the existence of the token.
2357 2325
         if (isset($this->tokens[$stackPtr]) === false) {
2358 2326
             return false;
@@ -2385,8 +2353,7 @@  discard block
 block discarded – undo
2385 2353
      *
2386 2354
      * @return string|false
2387 2355
      */
2388
-    public function findExtendedClassName($stackPtr)
2389
-    {
2356
+    public function findExtendedClassName($stackPtr) {
2390 2357
         // Check for the existence of the token.
2391 2358
         if (isset($this->tokens[$stackPtr]) === false) {
2392 2359
             return false;
@@ -2437,8 +2404,7 @@  discard block
 block discarded – undo
2437 2404
      *
2438 2405
      * @return array|false
2439 2406
      */
2440
-    public function findImplementedInterfaceNames($stackPtr)
2441
-    {
2407
+    public function findImplementedInterfaceNames($stackPtr) {
2442 2408
         // Check for the existence of the token.
2443 2409
         if (isset($this->tokens[$stackPtr]) === false) {
2444 2410
             return false;
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Files/FileList.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -195,7 +195,7 @@
 block discarded – undo
195 195
     /**
196 196
      * Return the file path of the current file being processed.
197 197
      *
198
-     * @return void
198
+     * @return string
199 199
      */
200 200
     public function key()
201 201
     {
Please login to merge, or discard this patch.
Indentation   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -20,228 +20,228 @@
 block discarded – undo
20 20
 class FileList implements \Iterator, \Countable
21 21
 {
22 22
 
23
-    /**
24
-     * A list of file paths that are included in the list.
25
-     *
26
-     * @var array
27
-     */
28
-    private $files = [];
29
-
30
-    /**
31
-     * The number of files in the list.
32
-     *
33
-     * @var integer
34
-     */
35
-    private $numFiles = 0;
36
-
37
-    /**
38
-     * The config data for the run.
39
-     *
40
-     * @var \PHP_CodeSniffer\Config
41
-     */
42
-    public $config = null;
43
-
44
-    /**
45
-     * The ruleset used for the run.
46
-     *
47
-     * @var \PHP_CodeSniffer\Ruleset
48
-     */
49
-    public $ruleset = null;
50
-
51
-    /**
52
-     * An array of patterns to use for skipping files.
53
-     *
54
-     * @var array
55
-     */
56
-    protected $ignorePatterns = [];
57
-
58
-
59
-    /**
60
-     * Constructs a file list and loads in an array of file paths to process.
61
-     *
62
-     * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
63
-     * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
64
-     *
65
-     * @return void
66
-     */
67
-    public function __construct(Config $config, Ruleset $ruleset)
68
-    {
69
-        $this->ruleset = $ruleset;
70
-        $this->config  = $config;
71
-
72
-        $paths = $config->files;
73
-        foreach ($paths as $path) {
74
-            $isPharFile = Util\Common::isPharFile($path);
75
-            if (is_dir($path) === true || $isPharFile === true) {
76
-                if ($isPharFile === true) {
77
-                    $path = 'phar://'.$path;
78
-                }
79
-
80
-                $filterClass = $this->getFilterClass();
81
-
82
-                $di       = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS));
83
-                $filter   = new $filterClass($di, $path, $config, $ruleset);
84
-                $iterator = new \RecursiveIteratorIterator($filter);
85
-
86
-                foreach ($iterator as $file) {
87
-                    $this->files[$file->getPathname()] = null;
88
-                    $this->numFiles++;
89
-                }
90
-            } else {
91
-                $this->addFile($path);
92
-            }//end if
93
-        }//end foreach
94
-
95
-        reset($this->files);
96
-
97
-    }//end __construct()
98
-
99
-
100
-    /**
101
-     * Add a file to the list.
102
-     *
103
-     * If a file object has already been created, it can be passed here.
104
-     * If it is left NULL, it will be created when accessed.
105
-     *
106
-     * @param string                      $path The path to the file being added.
107
-     * @param \PHP_CodeSniffer\Files\File $file The file being added.
108
-     *
109
-     * @return void
110
-     */
111
-    public function addFile($path, $file=null)
112
-    {
113
-        // No filtering is done for STDIN when the filename
114
-        // has not been specified.
115
-        if ($path === 'STDIN') {
116
-            $this->files[$path] = $file;
117
-            $this->numFiles++;
118
-            return;
119
-        }
120
-
121
-        $filterClass = $this->getFilterClass();
122
-
123
-        $di       = new \RecursiveArrayIterator([$path]);
124
-        $filter   = new $filterClass($di, $path, $this->config, $this->ruleset);
125
-        $iterator = new \RecursiveIteratorIterator($filter);
126
-
127
-        foreach ($iterator as $path) {
128
-            $this->files[$path] = $file;
129
-            $this->numFiles++;
130
-        }
131
-
132
-    }//end addFile()
133
-
134
-
135
-    /**
136
-     * Get the class name of the filter being used for the run.
137
-     *
138
-     * @return string
139
-     */
140
-    private function getFilterClass()
141
-    {
142
-        $filterType = $this->config->filter;
143
-
144
-        if ($filterType === null) {
145
-            $filterClass = '\PHP_CodeSniffer\Filters\Filter';
146
-        } else {
147
-            if (strpos($filterType, '.') !== false) {
148
-                // This is a path to a custom filter class.
149
-                $filename = realpath($filterType);
150
-                if ($filename === false) {
151
-                    $error = "ERROR: Custom filter \"$filterType\" not found".PHP_EOL;
152
-                    throw new DeepExitException($error, 3);
153
-                }
154
-
155
-                $filterClass = Autoload::loadFile($filename);
156
-            } else {
157
-                $filterClass = '\PHP_CodeSniffer\Filters\\'.$filterType;
158
-            }
159
-        }
160
-
161
-        return $filterClass;
162
-
163
-    }//end getFilterClass()
164
-
165
-
166
-    /**
167
-     * Rewind the iterator to the first file.
168
-     *
169
-     * @return void
170
-     */
171
-    public function rewind()
172
-    {
173
-        reset($this->files);
174
-
175
-    }//end rewind()
176
-
177
-
178
-    /**
179
-     * Get the file that is currently being processed.
180
-     *
181
-     * @return \PHP_CodeSniffer\Files\File
182
-     */
183
-    public function current()
184
-    {
185
-        $path = key($this->files);
186
-        if ($this->files[$path] === null) {
187
-            $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
188
-        }
189
-
190
-        return $this->files[$path];
191
-
192
-    }//end current()
193
-
194
-
195
-    /**
196
-     * Return the file path of the current file being processed.
197
-     *
198
-     * @return void
199
-     */
200
-    public function key()
201
-    {
202
-        return key($this->files);
203
-
204
-    }//end key()
205
-
206
-
207
-    /**
208
-     * Move forward to the next file.
209
-     *
210
-     * @return void
211
-     */
212
-    public function next()
213
-    {
214
-        next($this->files);
215
-
216
-    }//end next()
217
-
218
-
219
-    /**
220
-     * Checks if current position is valid.
221
-     *
222
-     * @return boolean
223
-     */
224
-    public function valid()
225
-    {
226
-        if (current($this->files) === false) {
227
-            return false;
228
-        }
229
-
230
-        return true;
231
-
232
-    }//end valid()
233
-
234
-
235
-    /**
236
-     * Return the number of files in the list.
237
-     *
238
-     * @return integer
239
-     */
240
-    public function count()
241
-    {
242
-        return $this->numFiles;
243
-
244
-    }//end count()
23
+	/**
24
+	 * A list of file paths that are included in the list.
25
+	 *
26
+	 * @var array
27
+	 */
28
+	private $files = [];
29
+
30
+	/**
31
+	 * The number of files in the list.
32
+	 *
33
+	 * @var integer
34
+	 */
35
+	private $numFiles = 0;
36
+
37
+	/**
38
+	 * The config data for the run.
39
+	 *
40
+	 * @var \PHP_CodeSniffer\Config
41
+	 */
42
+	public $config = null;
43
+
44
+	/**
45
+	 * The ruleset used for the run.
46
+	 *
47
+	 * @var \PHP_CodeSniffer\Ruleset
48
+	 */
49
+	public $ruleset = null;
50
+
51
+	/**
52
+	 * An array of patterns to use for skipping files.
53
+	 *
54
+	 * @var array
55
+	 */
56
+	protected $ignorePatterns = [];
57
+
58
+
59
+	/**
60
+	 * Constructs a file list and loads in an array of file paths to process.
61
+	 *
62
+	 * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
63
+	 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
64
+	 *
65
+	 * @return void
66
+	 */
67
+	public function __construct(Config $config, Ruleset $ruleset)
68
+	{
69
+		$this->ruleset = $ruleset;
70
+		$this->config  = $config;
71
+
72
+		$paths = $config->files;
73
+		foreach ($paths as $path) {
74
+			$isPharFile = Util\Common::isPharFile($path);
75
+			if (is_dir($path) === true || $isPharFile === true) {
76
+				if ($isPharFile === true) {
77
+					$path = 'phar://'.$path;
78
+				}
79
+
80
+				$filterClass = $this->getFilterClass();
81
+
82
+				$di       = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS));
83
+				$filter   = new $filterClass($di, $path, $config, $ruleset);
84
+				$iterator = new \RecursiveIteratorIterator($filter);
85
+
86
+				foreach ($iterator as $file) {
87
+					$this->files[$file->getPathname()] = null;
88
+					$this->numFiles++;
89
+				}
90
+			} else {
91
+				$this->addFile($path);
92
+			}//end if
93
+		}//end foreach
94
+
95
+		reset($this->files);
96
+
97
+	}//end __construct()
98
+
99
+
100
+	/**
101
+	 * Add a file to the list.
102
+	 *
103
+	 * If a file object has already been created, it can be passed here.
104
+	 * If it is left NULL, it will be created when accessed.
105
+	 *
106
+	 * @param string                      $path The path to the file being added.
107
+	 * @param \PHP_CodeSniffer\Files\File $file The file being added.
108
+	 *
109
+	 * @return void
110
+	 */
111
+	public function addFile($path, $file=null)
112
+	{
113
+		// No filtering is done for STDIN when the filename
114
+		// has not been specified.
115
+		if ($path === 'STDIN') {
116
+			$this->files[$path] = $file;
117
+			$this->numFiles++;
118
+			return;
119
+		}
120
+
121
+		$filterClass = $this->getFilterClass();
122
+
123
+		$di       = new \RecursiveArrayIterator([$path]);
124
+		$filter   = new $filterClass($di, $path, $this->config, $this->ruleset);
125
+		$iterator = new \RecursiveIteratorIterator($filter);
126
+
127
+		foreach ($iterator as $path) {
128
+			$this->files[$path] = $file;
129
+			$this->numFiles++;
130
+		}
131
+
132
+	}//end addFile()
133
+
134
+
135
+	/**
136
+	 * Get the class name of the filter being used for the run.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	private function getFilterClass()
141
+	{
142
+		$filterType = $this->config->filter;
143
+
144
+		if ($filterType === null) {
145
+			$filterClass = '\PHP_CodeSniffer\Filters\Filter';
146
+		} else {
147
+			if (strpos($filterType, '.') !== false) {
148
+				// This is a path to a custom filter class.
149
+				$filename = realpath($filterType);
150
+				if ($filename === false) {
151
+					$error = "ERROR: Custom filter \"$filterType\" not found".PHP_EOL;
152
+					throw new DeepExitException($error, 3);
153
+				}
154
+
155
+				$filterClass = Autoload::loadFile($filename);
156
+			} else {
157
+				$filterClass = '\PHP_CodeSniffer\Filters\\'.$filterType;
158
+			}
159
+		}
160
+
161
+		return $filterClass;
162
+
163
+	}//end getFilterClass()
164
+
165
+
166
+	/**
167
+	 * Rewind the iterator to the first file.
168
+	 *
169
+	 * @return void
170
+	 */
171
+	public function rewind()
172
+	{
173
+		reset($this->files);
174
+
175
+	}//end rewind()
176
+
177
+
178
+	/**
179
+	 * Get the file that is currently being processed.
180
+	 *
181
+	 * @return \PHP_CodeSniffer\Files\File
182
+	 */
183
+	public function current()
184
+	{
185
+		$path = key($this->files);
186
+		if ($this->files[$path] === null) {
187
+			$this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
188
+		}
189
+
190
+		return $this->files[$path];
191
+
192
+	}//end current()
193
+
194
+
195
+	/**
196
+	 * Return the file path of the current file being processed.
197
+	 *
198
+	 * @return void
199
+	 */
200
+	public function key()
201
+	{
202
+		return key($this->files);
203
+
204
+	}//end key()
205
+
206
+
207
+	/**
208
+	 * Move forward to the next file.
209
+	 *
210
+	 * @return void
211
+	 */
212
+	public function next()
213
+	{
214
+		next($this->files);
215
+
216
+	}//end next()
217
+
218
+
219
+	/**
220
+	 * Checks if current position is valid.
221
+	 *
222
+	 * @return boolean
223
+	 */
224
+	public function valid()
225
+	{
226
+		if (current($this->files) === false) {
227
+			return false;
228
+		}
229
+
230
+		return true;
231
+
232
+	}//end valid()
233
+
234
+
235
+	/**
236
+	 * Return the number of files in the list.
237
+	 *
238
+	 * @return integer
239
+	 */
240
+	public function count()
241
+	{
242
+		return $this->numFiles;
243
+
244
+	}//end count()
245 245
 
246 246
 
247 247
 }//end class
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
      *
26 26
      * @var array
27 27
      */
28
-    private $files = [];
28
+    private $files = [ ];
29 29
 
30 30
     /**
31 31
      * The number of files in the list.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      *
54 54
      * @var array
55 55
      */
56
-    protected $ignorePatterns = [];
56
+    protected $ignorePatterns = [ ];
57 57
 
58 58
 
59 59
     /**
@@ -64,35 +64,35 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return void
66 66
      */
67
-    public function __construct(Config $config, Ruleset $ruleset)
67
+    public function __construct( Config $config, Ruleset $ruleset )
68 68
     {
69 69
         $this->ruleset = $ruleset;
70 70
         $this->config  = $config;
71 71
 
72 72
         $paths = $config->files;
73
-        foreach ($paths as $path) {
74
-            $isPharFile = Util\Common::isPharFile($path);
75
-            if (is_dir($path) === true || $isPharFile === true) {
76
-                if ($isPharFile === true) {
77
-                    $path = 'phar://'.$path;
73
+        foreach ( $paths as $path ) {
74
+            $isPharFile = Util\Common::isPharFile( $path );
75
+            if ( is_dir( $path ) === true || $isPharFile === true ) {
76
+                if ( $isPharFile === true ) {
77
+                    $path = 'phar://' . $path;
78 78
                 }
79 79
 
80 80
                 $filterClass = $this->getFilterClass();
81 81
 
82
-                $di       = new \RecursiveDirectoryIterator($path, (\RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS));
83
-                $filter   = new $filterClass($di, $path, $config, $ruleset);
84
-                $iterator = new \RecursiveIteratorIterator($filter);
82
+                $di       = new \RecursiveDirectoryIterator( $path, ( \RecursiveDirectoryIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS ) );
83
+                $filter   = new $filterClass( $di, $path, $config, $ruleset );
84
+                $iterator = new \RecursiveIteratorIterator( $filter );
85 85
 
86
-                foreach ($iterator as $file) {
87
-                    $this->files[$file->getPathname()] = null;
86
+                foreach ( $iterator as $file ) {
87
+                    $this->files[ $file->getPathname() ] = null;
88 88
                     $this->numFiles++;
89 89
                 }
90 90
             } else {
91
-                $this->addFile($path);
91
+                $this->addFile( $path );
92 92
             }//end if
93 93
         }//end foreach
94 94
 
95
-        reset($this->files);
95
+        reset( $this->files );
96 96
 
97 97
     }//end __construct()
98 98
 
@@ -108,24 +108,24 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @return void
110 110
      */
111
-    public function addFile($path, $file=null)
111
+    public function addFile( $path, $file = null )
112 112
     {
113 113
         // No filtering is done for STDIN when the filename
114 114
         // has not been specified.
115
-        if ($path === 'STDIN') {
116
-            $this->files[$path] = $file;
115
+        if ( $path === 'STDIN' ) {
116
+            $this->files[ $path ] = $file;
117 117
             $this->numFiles++;
118 118
             return;
119 119
         }
120 120
 
121 121
         $filterClass = $this->getFilterClass();
122 122
 
123
-        $di       = new \RecursiveArrayIterator([$path]);
124
-        $filter   = new $filterClass($di, $path, $this->config, $this->ruleset);
125
-        $iterator = new \RecursiveIteratorIterator($filter);
123
+        $di       = new \RecursiveArrayIterator( [ $path ] );
124
+        $filter   = new $filterClass( $di, $path, $this->config, $this->ruleset );
125
+        $iterator = new \RecursiveIteratorIterator( $filter );
126 126
 
127
-        foreach ($iterator as $path) {
128
-            $this->files[$path] = $file;
127
+        foreach ( $iterator as $path ) {
128
+            $this->files[ $path ] = $file;
129 129
             $this->numFiles++;
130 130
         }
131 131
 
@@ -141,20 +141,20 @@  discard block
 block discarded – undo
141 141
     {
142 142
         $filterType = $this->config->filter;
143 143
 
144
-        if ($filterType === null) {
144
+        if ( $filterType === null ) {
145 145
             $filterClass = '\PHP_CodeSniffer\Filters\Filter';
146 146
         } else {
147
-            if (strpos($filterType, '.') !== false) {
147
+            if ( strpos( $filterType, '.' ) !== false ) {
148 148
                 // This is a path to a custom filter class.
149
-                $filename = realpath($filterType);
150
-                if ($filename === false) {
151
-                    $error = "ERROR: Custom filter \"$filterType\" not found".PHP_EOL;
152
-                    throw new DeepExitException($error, 3);
149
+                $filename = realpath( $filterType );
150
+                if ( $filename === false ) {
151
+                    $error = "ERROR: Custom filter \"$filterType\" not found" . PHP_EOL;
152
+                    throw new DeepExitException( $error, 3 );
153 153
                 }
154 154
 
155
-                $filterClass = Autoload::loadFile($filename);
155
+                $filterClass = Autoload::loadFile( $filename );
156 156
             } else {
157
-                $filterClass = '\PHP_CodeSniffer\Filters\\'.$filterType;
157
+                $filterClass = '\PHP_CodeSniffer\Filters\\' . $filterType;
158 158
             }
159 159
         }
160 160
 
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
      */
171 171
     public function rewind()
172 172
     {
173
-        reset($this->files);
173
+        reset( $this->files );
174 174
 
175 175
     }//end rewind()
176 176
 
@@ -182,12 +182,12 @@  discard block
 block discarded – undo
182 182
      */
183 183
     public function current()
184 184
     {
185
-        $path = key($this->files);
186
-        if ($this->files[$path] === null) {
187
-            $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
185
+        $path = key( $this->files );
186
+        if ( $this->files[ $path ] === null ) {
187
+            $this->files[ $path ] = new LocalFile( $path, $this->ruleset, $this->config );
188 188
         }
189 189
 
190
-        return $this->files[$path];
190
+        return $this->files[ $path ];
191 191
 
192 192
     }//end current()
193 193
 
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function key()
201 201
     {
202
-        return key($this->files);
202
+        return key( $this->files );
203 203
 
204 204
     }//end key()
205 205
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      */
212 212
     public function next()
213 213
     {
214
-        next($this->files);
214
+        next( $this->files );
215 215
 
216 216
     }//end next()
217 217
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      */
224 224
     public function valid()
225 225
     {
226
-        if (current($this->files) === false) {
226
+        if ( current( $this->files ) === false ) {
227 227
             return false;
228 228
         }
229 229
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -64,8 +64,7 @@  discard block
 block discarded – undo
64 64
      *
65 65
      * @return void
66 66
      */
67
-    public function __construct(Config $config, Ruleset $ruleset)
68
-    {
67
+    public function __construct(Config $config, Ruleset $ruleset) {
69 68
         $this->ruleset = $ruleset;
70 69
         $this->config  = $config;
71 70
 
@@ -108,8 +107,7 @@  discard block
 block discarded – undo
108 107
      *
109 108
      * @return void
110 109
      */
111
-    public function addFile($path, $file=null)
112
-    {
110
+    public function addFile($path, $file=null) {
113 111
         // No filtering is done for STDIN when the filename
114 112
         // has not been specified.
115 113
         if ($path === 'STDIN') {
@@ -137,8 +135,7 @@  discard block
 block discarded – undo
137 135
      *
138 136
      * @return string
139 137
      */
140
-    private function getFilterClass()
141
-    {
138
+    private function getFilterClass() {
142 139
         $filterType = $this->config->filter;
143 140
 
144 141
         if ($filterType === null) {
@@ -168,8 +165,7 @@  discard block
 block discarded – undo
168 165
      *
169 166
      * @return void
170 167
      */
171
-    public function rewind()
172
-    {
168
+    public function rewind() {
173 169
         reset($this->files);
174 170
 
175 171
     }//end rewind()
@@ -180,8 +176,7 @@  discard block
 block discarded – undo
180 176
      *
181 177
      * @return \PHP_CodeSniffer\Files\File
182 178
      */
183
-    public function current()
184
-    {
179
+    public function current() {
185 180
         $path = key($this->files);
186 181
         if ($this->files[$path] === null) {
187 182
             $this->files[$path] = new LocalFile($path, $this->ruleset, $this->config);
@@ -197,8 +192,7 @@  discard block
 block discarded – undo
197 192
      *
198 193
      * @return void
199 194
      */
200
-    public function key()
201
-    {
195
+    public function key() {
202 196
         return key($this->files);
203 197
 
204 198
     }//end key()
@@ -209,8 +203,7 @@  discard block
 block discarded – undo
209 203
      *
210 204
      * @return void
211 205
      */
212
-    public function next()
213
-    {
206
+    public function next() {
214 207
         next($this->files);
215 208
 
216 209
     }//end next()
@@ -221,8 +214,7 @@  discard block
 block discarded – undo
221 214
      *
222 215
      * @return boolean
223 216
      */
224
-    public function valid()
225
-    {
217
+    public function valid() {
226 218
         if (current($this->files) === false) {
227 219
             return false;
228 220
         }
@@ -237,8 +229,7 @@  discard block
 block discarded – undo
237 229
      *
238 230
      * @return integer
239 231
      */
240
-    public function count()
241
-    {
232
+    public function count() {
242 233
         return $this->numFiles;
243 234
 
244 235
     }//end count()
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Fixer.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
     /**
343 343
      * Start recording actions for a changeset.
344 344
      *
345
-     * @return void
345
+     * @return false|null
346 346
      */
347 347
     public function beginChangeset()
348 348
     {
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
     /**
370 370
      * Stop recording actions for a changeset, and apply logged changes.
371 371
      *
372
-     * @return boolean
372
+     * @return false|null
373 373
      */
374 374
     public function endChangeset()
375 375
     {
Please login to merge, or discard this patch.
Indentation   +700 added lines, -700 removed lines patch added patch discarded remove patch
@@ -18,706 +18,706 @@
 block discarded – undo
18 18
 class Fixer
19 19
 {
20 20
 
21
-    /**
22
-     * Is the fixer enabled and fixing a file?
23
-     *
24
-     * Sniffs should check this value to ensure they are not
25
-     * doing extra processing to prepare for a fix when fixing is
26
-     * not required.
27
-     *
28
-     * @var boolean
29
-     */
30
-    public $enabled = false;
31
-
32
-    /**
33
-     * The number of times we have looped over a file.
34
-     *
35
-     * @var integer
36
-     */
37
-    public $loops = 0;
38
-
39
-    /**
40
-     * The file being fixed.
41
-     *
42
-     * @var \PHP_CodeSniffer\Files\File
43
-     */
44
-    private $currentFile = null;
45
-
46
-    /**
47
-     * The list of tokens that make up the file contents.
48
-     *
49
-     * This is a simplified list which just contains the token content and nothing
50
-     * else. This is the array that is updated as fixes are made, not the file's
51
-     * token array. Imploding this array will give you the file content back.
52
-     *
53
-     * @var array<int, string>
54
-     */
55
-    private $tokens = [];
56
-
57
-    /**
58
-     * A list of tokens that have already been fixed.
59
-     *
60
-     * We don't allow the same token to be fixed more than once each time
61
-     * through a file as this can easily cause conflicts between sniffs.
62
-     *
63
-     * @var int[]
64
-     */
65
-    private $fixedTokens = [];
66
-
67
-    /**
68
-     * The last value of each fixed token.
69
-     *
70
-     * If a token is being "fixed" back to its last value, the fix is
71
-     * probably conflicting with another.
72
-     *
73
-     * @var array<int, string>
74
-     */
75
-    private $oldTokenValues = [];
76
-
77
-    /**
78
-     * A list of tokens that have been fixed during a changeset.
79
-     *
80
-     * All changes in changeset must be able to be applied, or else
81
-     * the entire changeset is rejected.
82
-     *
83
-     * @var array
84
-     */
85
-    private $changeset = [];
86
-
87
-    /**
88
-     * Is there an open changeset.
89
-     *
90
-     * @var boolean
91
-     */
92
-    private $inChangeset = false;
93
-
94
-    /**
95
-     * Is the current fixing loop in conflict?
96
-     *
97
-     * @var boolean
98
-     */
99
-    private $inConflict = false;
100
-
101
-    /**
102
-     * The number of fixes that have been performed.
103
-     *
104
-     * @var integer
105
-     */
106
-    private $numFixes = 0;
107
-
108
-
109
-    /**
110
-     * Starts fixing a new file.
111
-     *
112
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being fixed.
113
-     *
114
-     * @return void
115
-     */
116
-    public function startFile(File $phpcsFile)
117
-    {
118
-        $this->currentFile = $phpcsFile;
119
-        $this->numFixes    = 0;
120
-        $this->fixedTokens = [];
121
-
122
-        $tokens       = $phpcsFile->getTokens();
123
-        $this->tokens = [];
124
-        foreach ($tokens as $index => $token) {
125
-            if (isset($token['orig_content']) === true) {
126
-                $this->tokens[$index] = $token['orig_content'];
127
-            } else {
128
-                $this->tokens[$index] = $token['content'];
129
-            }
130
-        }
131
-
132
-    }//end startFile()
133
-
134
-
135
-    /**
136
-     * Attempt to fix the file by processing it until no fixes are made.
137
-     *
138
-     * @return boolean
139
-     */
140
-    public function fixFile()
141
-    {
142
-        $fixable = $this->currentFile->getFixableCount();
143
-        if ($fixable === 0) {
144
-            // Nothing to fix.
145
-            return false;
146
-        }
147
-
148
-        $this->enabled = true;
149
-
150
-        $this->loops = 0;
151
-        while ($this->loops < 50) {
152
-            ob_start();
153
-
154
-            // Only needed once file content has changed.
155
-            $contents = $this->getContents();
156
-
157
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
158
-                @ob_end_clean();
159
-                echo '---START FILE CONTENT---'.PHP_EOL;
160
-                $lines = explode($this->currentFile->eolChar, $contents);
161
-                $max   = strlen(count($lines));
162
-                foreach ($lines as $lineNum => $line) {
163
-                    $lineNum++;
164
-                    echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT).'|'.$line.PHP_EOL;
165
-                }
166
-
167
-                echo '--- END FILE CONTENT ---'.PHP_EOL;
168
-                ob_start();
169
-            }
170
-
171
-            $this->inConflict = false;
172
-            $this->currentFile->ruleset->populateTokenListeners();
173
-            $this->currentFile->setContent($contents);
174
-            $this->currentFile->process();
175
-            ob_end_clean();
176
-
177
-            $this->loops++;
178
-
179
-            if (PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0) {
180
-                echo "\r".str_repeat(' ', 80)."\r";
181
-                echo "\t=> Fixing file: $this->numFixes/$fixable violations remaining [made $this->loops pass";
182
-                if ($this->loops > 1) {
183
-                    echo 'es';
184
-                }
185
-
186
-                echo ']... ';
187
-            }
188
-
189
-            if ($this->numFixes === 0 && $this->inConflict === false) {
190
-                // Nothing left to do.
191
-                break;
192
-            } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
193
-                echo "\t* fixed $this->numFixes violations, starting loop ".($this->loops + 1).' *'.PHP_EOL;
194
-            }
195
-        }//end while
196
-
197
-        $this->enabled = false;
198
-
199
-        if ($this->numFixes > 0) {
200
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
201
-                if (ob_get_level() > 0) {
202
-                    ob_end_clean();
203
-                }
204
-
205
-                echo "\t*** Reached maximum number of loops with $this->numFixes violations left unfixed ***".PHP_EOL;
206
-                ob_start();
207
-            }
208
-
209
-            return false;
210
-        }
211
-
212
-        return true;
213
-
214
-    }//end fixFile()
215
-
216
-
217
-    /**
218
-     * Generates a text diff of the original file and the new content.
219
-     *
220
-     * @param string  $filePath Optional file path to diff the file against.
221
-     *                          If not specified, the original version of the
222
-     *                          file will be used.
223
-     * @param boolean $colors   Print colored output or not.
224
-     *
225
-     * @return string
226
-     */
227
-    public function generateDiff($filePath=null, $colors=true)
228
-    {
229
-        if ($filePath === null) {
230
-            $filePath = $this->currentFile->getFilename();
231
-        }
232
-
233
-        $cwd = getcwd().DIRECTORY_SEPARATOR;
234
-        if (strpos($filePath, $cwd) === 0) {
235
-            $filename = substr($filePath, strlen($cwd));
236
-        } else {
237
-            $filename = $filePath;
238
-        }
239
-
240
-        $contents = $this->getContents();
241
-
242
-        $tempName  = tempnam(sys_get_temp_dir(), 'phpcs-fixer');
243
-        $fixedFile = fopen($tempName, 'w');
244
-        fwrite($fixedFile, $contents);
245
-
246
-        // We must use something like shell_exec() because whitespace at the end
247
-        // of lines is critical to diff files.
248
-        $filename = escapeshellarg($filename);
249
-        $cmd      = "diff -u -L$filename -LPHP_CodeSniffer $filename \"$tempName\"";
250
-
251
-        $diff = shell_exec($cmd);
252
-
253
-        fclose($fixedFile);
254
-        if (is_file($tempName) === true) {
255
-            unlink($tempName);
256
-        }
257
-
258
-        if ($colors === false) {
259
-            return $diff;
260
-        }
261
-
262
-        $diffLines = explode(PHP_EOL, $diff);
263
-        if (count($diffLines) === 1) {
264
-            // Seems to be required for cygwin.
265
-            $diffLines = explode("\n", $diff);
266
-        }
267
-
268
-        $diff = [];
269
-        foreach ($diffLines as $line) {
270
-            if (isset($line[0]) === true) {
271
-                switch ($line[0]) {
272
-                case '-':
273
-                    $diff[] = "\033[31m$line\033[0m";
274
-                    break;
275
-                case '+':
276
-                    $diff[] = "\033[32m$line\033[0m";
277
-                    break;
278
-                default:
279
-                    $diff[] = $line;
280
-                }
281
-            }
282
-        }
283
-
284
-        $diff = implode(PHP_EOL, $diff);
285
-
286
-        return $diff;
287
-
288
-    }//end generateDiff()
289
-
290
-
291
-    /**
292
-     * Get a count of fixes that have been performed on the file.
293
-     *
294
-     * This value is reset every time a new file is started, or an existing
295
-     * file is restarted.
296
-     *
297
-     * @return int
298
-     */
299
-    public function getFixCount()
300
-    {
301
-        return $this->numFixes;
302
-
303
-    }//end getFixCount()
304
-
305
-
306
-    /**
307
-     * Get the current content of the file, as a string.
308
-     *
309
-     * @return string
310
-     */
311
-    public function getContents()
312
-    {
313
-        $contents = implode($this->tokens);
314
-        return $contents;
315
-
316
-    }//end getContents()
317
-
318
-
319
-    /**
320
-     * Get the current fixed content of a token.
321
-     *
322
-     * This function takes changesets into account so should be used
323
-     * instead of directly accessing the token array.
324
-     *
325
-     * @param int $stackPtr The position of the token in the token stack.
326
-     *
327
-     * @return string
328
-     */
329
-    public function getTokenContent($stackPtr)
330
-    {
331
-        if ($this->inChangeset === true
332
-            && isset($this->changeset[$stackPtr]) === true
333
-        ) {
334
-            return $this->changeset[$stackPtr];
335
-        } else {
336
-            return $this->tokens[$stackPtr];
337
-        }
338
-
339
-    }//end getTokenContent()
340
-
341
-
342
-    /**
343
-     * Start recording actions for a changeset.
344
-     *
345
-     * @return void
346
-     */
347
-    public function beginChangeset()
348
-    {
349
-        if ($this->inConflict === true) {
350
-            return false;
351
-        }
352
-
353
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
354
-            $bt    = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
355
-            $sniff = $bt[1]['class'];
356
-            $line  = $bt[0]['line'];
357
-
358
-            @ob_end_clean();
359
-            echo "\t=> Changeset started by $sniff (line $line)".PHP_EOL;
360
-            ob_start();
361
-        }
362
-
363
-        $this->changeset   = [];
364
-        $this->inChangeset = true;
365
-
366
-    }//end beginChangeset()
367
-
368
-
369
-    /**
370
-     * Stop recording actions for a changeset, and apply logged changes.
371
-     *
372
-     * @return boolean
373
-     */
374
-    public function endChangeset()
375
-    {
376
-        if ($this->inConflict === true) {
377
-            return false;
378
-        }
379
-
380
-        $this->inChangeset = false;
381
-
382
-        $success = true;
383
-        $applied = [];
384
-        foreach ($this->changeset as $stackPtr => $content) {
385
-            $success = $this->replaceToken($stackPtr, $content);
386
-            if ($success === false) {
387
-                break;
388
-            } else {
389
-                $applied[] = $stackPtr;
390
-            }
391
-        }
392
-
393
-        if ($success === false) {
394
-            // Rolling back all changes.
395
-            foreach ($applied as $stackPtr) {
396
-                $this->revertToken($stackPtr);
397
-            }
398
-
399
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
400
-                @ob_end_clean();
401
-                echo "\t=> Changeset failed to apply".PHP_EOL;
402
-                ob_start();
403
-            }
404
-        } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
405
-            $fixes = count($this->changeset);
406
-            @ob_end_clean();
407
-            echo "\t=> Changeset ended: $fixes changes applied".PHP_EOL;
408
-            ob_start();
409
-        }
410
-
411
-        $this->changeset = [];
412
-
413
-    }//end endChangeset()
414
-
415
-
416
-    /**
417
-     * Stop recording actions for a changeset, and discard logged changes.
418
-     *
419
-     * @return void
420
-     */
421
-    public function rollbackChangeset()
422
-    {
423
-        $this->inChangeset = false;
424
-        $this->inConflict  = false;
425
-
426
-        if (empty($this->changeset) === false) {
427
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
428
-                $bt = debug_backtrace();
429
-                if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
430
-                    $sniff = $bt[2]['class'];
431
-                    $line  = $bt[1]['line'];
432
-                } else {
433
-                    $sniff = $bt[1]['class'];
434
-                    $line  = $bt[0]['line'];
435
-                }
436
-
437
-                $numChanges = count($this->changeset);
438
-
439
-                @ob_end_clean();
440
-                echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)".PHP_EOL;
441
-                echo "\t=> Changeset rolled back".PHP_EOL;
442
-                ob_start();
443
-            }
444
-
445
-            $this->changeset = [];
446
-        }//end if
447
-
448
-    }//end rollbackChangeset()
449
-
450
-
451
-    /**
452
-     * Replace the entire contents of a token.
453
-     *
454
-     * @param int    $stackPtr The position of the token in the token stack.
455
-     * @param string $content  The new content of the token.
456
-     *
457
-     * @return bool If the change was accepted.
458
-     */
459
-    public function replaceToken($stackPtr, $content)
460
-    {
461
-        if ($this->inConflict === true) {
462
-            return false;
463
-        }
464
-
465
-        if ($this->inChangeset === false
466
-            && isset($this->fixedTokens[$stackPtr]) === true
467
-        ) {
468
-            $indent = "\t";
469
-            if (empty($this->changeset) === false) {
470
-                $indent .= "\t";
471
-            }
472
-
473
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
474
-                @ob_end_clean();
475
-                echo "$indent* token $stackPtr has already been modified, skipping *".PHP_EOL;
476
-                ob_start();
477
-            }
478
-
479
-            return false;
480
-        }
481
-
482
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
483
-            $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
484
-            if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
485
-                $sniff = $bt[2]['class'];
486
-                $line  = $bt[1]['line'];
487
-            } else {
488
-                $sniff = $bt[1]['class'];
489
-                $line  = $bt[0]['line'];
490
-            }
491
-
492
-            $tokens     = $this->currentFile->getTokens();
493
-            $type       = $tokens[$stackPtr]['type'];
494
-            $oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
495
-            $newContent = Common::prepareForOutput($content);
496
-            if (trim($this->tokens[$stackPtr]) === '' && isset($this->tokens[($stackPtr + 1)]) === true) {
497
-                // Add some context for whitespace only changes.
498
-                $append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
499
-                $oldContent .= $append;
500
-                $newContent .= $append;
501
-            }
502
-        }//end if
503
-
504
-        if ($this->inChangeset === true) {
505
-            $this->changeset[$stackPtr] = $content;
506
-
507
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
508
-                @ob_end_clean();
509
-                echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
510
-                ob_start();
511
-            }
512
-
513
-            return true;
514
-        }
515
-
516
-        if (isset($this->oldTokenValues[$stackPtr]) === false) {
517
-            $this->oldTokenValues[$stackPtr] = [
518
-                'curr' => $content,
519
-                'prev' => $this->tokens[$stackPtr],
520
-                'loop' => $this->loops,
521
-            ];
522
-        } else {
523
-            if ($this->oldTokenValues[$stackPtr]['prev'] === $content
524
-                && $this->oldTokenValues[$stackPtr]['loop'] === ($this->loops - 1)
525
-            ) {
526
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
527
-                    $indent = "\t";
528
-                    if (empty($this->changeset) === false) {
529
-                        $indent .= "\t";
530
-                    }
531
-
532
-                    $loop = $this->oldTokenValues[$stackPtr]['loop'];
533
-
534
-                    @ob_end_clean();
535
-                    echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL;
536
-                    echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****".PHP_EOL;
537
-                }
538
-
539
-                if ($this->oldTokenValues[$stackPtr]['loop'] >= ($this->loops - 1)) {
540
-                    $this->inConflict = true;
541
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
542
-                        echo "$indent**** ignoring all changes until next loop ****".PHP_EOL;
543
-                    }
544
-                }
545
-
546
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
547
-                    ob_start();
548
-                }
549
-
550
-                return false;
551
-            }//end if
552
-
553
-            $this->oldTokenValues[$stackPtr]['prev'] = $this->oldTokenValues[$stackPtr]['curr'];
554
-            $this->oldTokenValues[$stackPtr]['curr'] = $content;
555
-            $this->oldTokenValues[$stackPtr]['loop'] = $this->loops;
556
-        }//end if
557
-
558
-        $this->fixedTokens[$stackPtr] = $this->tokens[$stackPtr];
559
-        $this->tokens[$stackPtr]      = $content;
560
-        $this->numFixes++;
561
-
562
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
563
-            $indent = "\t";
564
-            if (empty($this->changeset) === false) {
565
-                $indent .= "\tA: ";
566
-            }
567
-
568
-            if (ob_get_level() > 0) {
569
-                ob_end_clean();
570
-            }
571
-
572
-            echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
573
-            ob_start();
574
-        }
575
-
576
-        return true;
577
-
578
-    }//end replaceToken()
579
-
580
-
581
-    /**
582
-     * Reverts the previous fix made to a token.
583
-     *
584
-     * @param int $stackPtr The position of the token in the token stack.
585
-     *
586
-     * @return bool If a change was reverted.
587
-     */
588
-    public function revertToken($stackPtr)
589
-    {
590
-        if (isset($this->fixedTokens[$stackPtr]) === false) {
591
-            return false;
592
-        }
593
-
594
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
595
-            $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
596
-            if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
597
-                $sniff = $bt[2]['class'];
598
-                $line  = $bt[1]['line'];
599
-            } else {
600
-                $sniff = $bt[1]['class'];
601
-                $line  = $bt[0]['line'];
602
-            }
603
-
604
-            $tokens     = $this->currentFile->getTokens();
605
-            $type       = $tokens[$stackPtr]['type'];
606
-            $oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
607
-            $newContent = Common::prepareForOutput($this->fixedTokens[$stackPtr]);
608
-            if (trim($this->tokens[$stackPtr]) === '' && isset($tokens[($stackPtr + 1)]) === true) {
609
-                // Add some context for whitespace only changes.
610
-                $append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
611
-                $oldContent .= $append;
612
-                $newContent .= $append;
613
-            }
614
-        }//end if
615
-
616
-        $this->tokens[$stackPtr] = $this->fixedTokens[$stackPtr];
617
-        unset($this->fixedTokens[$stackPtr]);
618
-        $this->numFixes--;
619
-
620
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
621
-            $indent = "\t";
622
-            if (empty($this->changeset) === false) {
623
-                $indent .= "\tR: ";
624
-            }
625
-
626
-            @ob_end_clean();
627
-            echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
628
-            ob_start();
629
-        }
630
-
631
-        return true;
632
-
633
-    }//end revertToken()
634
-
635
-
636
-    /**
637
-     * Replace the content of a token with a part of its current content.
638
-     *
639
-     * @param int $stackPtr The position of the token in the token stack.
640
-     * @param int $start    The first character to keep.
641
-     * @param int $length   The number of characters to keep. If NULL, the content of
642
-     *                      the token from $start to the end of the content is kept.
643
-     *
644
-     * @return bool If the change was accepted.
645
-     */
646
-    public function substrToken($stackPtr, $start, $length=null)
647
-    {
648
-        $current = $this->getTokenContent($stackPtr);
649
-
650
-        if ($length === null) {
651
-            $newContent = substr($current, $start);
652
-        } else {
653
-            $newContent = substr($current, $start, $length);
654
-        }
655
-
656
-        return $this->replaceToken($stackPtr, $newContent);
657
-
658
-    }//end substrToken()
659
-
660
-
661
-    /**
662
-     * Adds a newline to end of a token's content.
663
-     *
664
-     * @param int $stackPtr The position of the token in the token stack.
665
-     *
666
-     * @return bool If the change was accepted.
667
-     */
668
-    public function addNewline($stackPtr)
669
-    {
670
-        $current = $this->getTokenContent($stackPtr);
671
-        return $this->replaceToken($stackPtr, $current.$this->currentFile->eolChar);
672
-
673
-    }//end addNewline()
674
-
675
-
676
-    /**
677
-     * Adds a newline to the start of a token's content.
678
-     *
679
-     * @param int $stackPtr The position of the token in the token stack.
680
-     *
681
-     * @return bool If the change was accepted.
682
-     */
683
-    public function addNewlineBefore($stackPtr)
684
-    {
685
-        $current = $this->getTokenContent($stackPtr);
686
-        return $this->replaceToken($stackPtr, $this->currentFile->eolChar.$current);
687
-
688
-    }//end addNewlineBefore()
689
-
690
-
691
-    /**
692
-     * Adds content to the end of a token's current content.
693
-     *
694
-     * @param int    $stackPtr The position of the token in the token stack.
695
-     * @param string $content  The content to add.
696
-     *
697
-     * @return bool If the change was accepted.
698
-     */
699
-    public function addContent($stackPtr, $content)
700
-    {
701
-        $current = $this->getTokenContent($stackPtr);
702
-        return $this->replaceToken($stackPtr, $current.$content);
703
-
704
-    }//end addContent()
705
-
706
-
707
-    /**
708
-     * Adds content to the start of a token's current content.
709
-     *
710
-     * @param int    $stackPtr The position of the token in the token stack.
711
-     * @param string $content  The content to add.
712
-     *
713
-     * @return bool If the change was accepted.
714
-     */
715
-    public function addContentBefore($stackPtr, $content)
716
-    {
717
-        $current = $this->getTokenContent($stackPtr);
718
-        return $this->replaceToken($stackPtr, $content.$current);
719
-
720
-    }//end addContentBefore()
21
+	/**
22
+	 * Is the fixer enabled and fixing a file?
23
+	 *
24
+	 * Sniffs should check this value to ensure they are not
25
+	 * doing extra processing to prepare for a fix when fixing is
26
+	 * not required.
27
+	 *
28
+	 * @var boolean
29
+	 */
30
+	public $enabled = false;
31
+
32
+	/**
33
+	 * The number of times we have looped over a file.
34
+	 *
35
+	 * @var integer
36
+	 */
37
+	public $loops = 0;
38
+
39
+	/**
40
+	 * The file being fixed.
41
+	 *
42
+	 * @var \PHP_CodeSniffer\Files\File
43
+	 */
44
+	private $currentFile = null;
45
+
46
+	/**
47
+	 * The list of tokens that make up the file contents.
48
+	 *
49
+	 * This is a simplified list which just contains the token content and nothing
50
+	 * else. This is the array that is updated as fixes are made, not the file's
51
+	 * token array. Imploding this array will give you the file content back.
52
+	 *
53
+	 * @var array<int, string>
54
+	 */
55
+	private $tokens = [];
56
+
57
+	/**
58
+	 * A list of tokens that have already been fixed.
59
+	 *
60
+	 * We don't allow the same token to be fixed more than once each time
61
+	 * through a file as this can easily cause conflicts between sniffs.
62
+	 *
63
+	 * @var int[]
64
+	 */
65
+	private $fixedTokens = [];
66
+
67
+	/**
68
+	 * The last value of each fixed token.
69
+	 *
70
+	 * If a token is being "fixed" back to its last value, the fix is
71
+	 * probably conflicting with another.
72
+	 *
73
+	 * @var array<int, string>
74
+	 */
75
+	private $oldTokenValues = [];
76
+
77
+	/**
78
+	 * A list of tokens that have been fixed during a changeset.
79
+	 *
80
+	 * All changes in changeset must be able to be applied, or else
81
+	 * the entire changeset is rejected.
82
+	 *
83
+	 * @var array
84
+	 */
85
+	private $changeset = [];
86
+
87
+	/**
88
+	 * Is there an open changeset.
89
+	 *
90
+	 * @var boolean
91
+	 */
92
+	private $inChangeset = false;
93
+
94
+	/**
95
+	 * Is the current fixing loop in conflict?
96
+	 *
97
+	 * @var boolean
98
+	 */
99
+	private $inConflict = false;
100
+
101
+	/**
102
+	 * The number of fixes that have been performed.
103
+	 *
104
+	 * @var integer
105
+	 */
106
+	private $numFixes = 0;
107
+
108
+
109
+	/**
110
+	 * Starts fixing a new file.
111
+	 *
112
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being fixed.
113
+	 *
114
+	 * @return void
115
+	 */
116
+	public function startFile(File $phpcsFile)
117
+	{
118
+		$this->currentFile = $phpcsFile;
119
+		$this->numFixes    = 0;
120
+		$this->fixedTokens = [];
121
+
122
+		$tokens       = $phpcsFile->getTokens();
123
+		$this->tokens = [];
124
+		foreach ($tokens as $index => $token) {
125
+			if (isset($token['orig_content']) === true) {
126
+				$this->tokens[$index] = $token['orig_content'];
127
+			} else {
128
+				$this->tokens[$index] = $token['content'];
129
+			}
130
+		}
131
+
132
+	}//end startFile()
133
+
134
+
135
+	/**
136
+	 * Attempt to fix the file by processing it until no fixes are made.
137
+	 *
138
+	 * @return boolean
139
+	 */
140
+	public function fixFile()
141
+	{
142
+		$fixable = $this->currentFile->getFixableCount();
143
+		if ($fixable === 0) {
144
+			// Nothing to fix.
145
+			return false;
146
+		}
147
+
148
+		$this->enabled = true;
149
+
150
+		$this->loops = 0;
151
+		while ($this->loops < 50) {
152
+			ob_start();
153
+
154
+			// Only needed once file content has changed.
155
+			$contents = $this->getContents();
156
+
157
+			if (PHP_CODESNIFFER_VERBOSITY > 2) {
158
+				@ob_end_clean();
159
+				echo '---START FILE CONTENT---'.PHP_EOL;
160
+				$lines = explode($this->currentFile->eolChar, $contents);
161
+				$max   = strlen(count($lines));
162
+				foreach ($lines as $lineNum => $line) {
163
+					$lineNum++;
164
+					echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT).'|'.$line.PHP_EOL;
165
+				}
166
+
167
+				echo '--- END FILE CONTENT ---'.PHP_EOL;
168
+				ob_start();
169
+			}
170
+
171
+			$this->inConflict = false;
172
+			$this->currentFile->ruleset->populateTokenListeners();
173
+			$this->currentFile->setContent($contents);
174
+			$this->currentFile->process();
175
+			ob_end_clean();
176
+
177
+			$this->loops++;
178
+
179
+			if (PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0) {
180
+				echo "\r".str_repeat(' ', 80)."\r";
181
+				echo "\t=> Fixing file: $this->numFixes/$fixable violations remaining [made $this->loops pass";
182
+				if ($this->loops > 1) {
183
+					echo 'es';
184
+				}
185
+
186
+				echo ']... ';
187
+			}
188
+
189
+			if ($this->numFixes === 0 && $this->inConflict === false) {
190
+				// Nothing left to do.
191
+				break;
192
+			} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
193
+				echo "\t* fixed $this->numFixes violations, starting loop ".($this->loops + 1).' *'.PHP_EOL;
194
+			}
195
+		}//end while
196
+
197
+		$this->enabled = false;
198
+
199
+		if ($this->numFixes > 0) {
200
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
201
+				if (ob_get_level() > 0) {
202
+					ob_end_clean();
203
+				}
204
+
205
+				echo "\t*** Reached maximum number of loops with $this->numFixes violations left unfixed ***".PHP_EOL;
206
+				ob_start();
207
+			}
208
+
209
+			return false;
210
+		}
211
+
212
+		return true;
213
+
214
+	}//end fixFile()
215
+
216
+
217
+	/**
218
+	 * Generates a text diff of the original file and the new content.
219
+	 *
220
+	 * @param string  $filePath Optional file path to diff the file against.
221
+	 *                          If not specified, the original version of the
222
+	 *                          file will be used.
223
+	 * @param boolean $colors   Print colored output or not.
224
+	 *
225
+	 * @return string
226
+	 */
227
+	public function generateDiff($filePath=null, $colors=true)
228
+	{
229
+		if ($filePath === null) {
230
+			$filePath = $this->currentFile->getFilename();
231
+		}
232
+
233
+		$cwd = getcwd().DIRECTORY_SEPARATOR;
234
+		if (strpos($filePath, $cwd) === 0) {
235
+			$filename = substr($filePath, strlen($cwd));
236
+		} else {
237
+			$filename = $filePath;
238
+		}
239
+
240
+		$contents = $this->getContents();
241
+
242
+		$tempName  = tempnam(sys_get_temp_dir(), 'phpcs-fixer');
243
+		$fixedFile = fopen($tempName, 'w');
244
+		fwrite($fixedFile, $contents);
245
+
246
+		// We must use something like shell_exec() because whitespace at the end
247
+		// of lines is critical to diff files.
248
+		$filename = escapeshellarg($filename);
249
+		$cmd      = "diff -u -L$filename -LPHP_CodeSniffer $filename \"$tempName\"";
250
+
251
+		$diff = shell_exec($cmd);
252
+
253
+		fclose($fixedFile);
254
+		if (is_file($tempName) === true) {
255
+			unlink($tempName);
256
+		}
257
+
258
+		if ($colors === false) {
259
+			return $diff;
260
+		}
261
+
262
+		$diffLines = explode(PHP_EOL, $diff);
263
+		if (count($diffLines) === 1) {
264
+			// Seems to be required for cygwin.
265
+			$diffLines = explode("\n", $diff);
266
+		}
267
+
268
+		$diff = [];
269
+		foreach ($diffLines as $line) {
270
+			if (isset($line[0]) === true) {
271
+				switch ($line[0]) {
272
+				case '-':
273
+					$diff[] = "\033[31m$line\033[0m";
274
+					break;
275
+				case '+':
276
+					$diff[] = "\033[32m$line\033[0m";
277
+					break;
278
+				default:
279
+					$diff[] = $line;
280
+				}
281
+			}
282
+		}
283
+
284
+		$diff = implode(PHP_EOL, $diff);
285
+
286
+		return $diff;
287
+
288
+	}//end generateDiff()
289
+
290
+
291
+	/**
292
+	 * Get a count of fixes that have been performed on the file.
293
+	 *
294
+	 * This value is reset every time a new file is started, or an existing
295
+	 * file is restarted.
296
+	 *
297
+	 * @return int
298
+	 */
299
+	public function getFixCount()
300
+	{
301
+		return $this->numFixes;
302
+
303
+	}//end getFixCount()
304
+
305
+
306
+	/**
307
+	 * Get the current content of the file, as a string.
308
+	 *
309
+	 * @return string
310
+	 */
311
+	public function getContents()
312
+	{
313
+		$contents = implode($this->tokens);
314
+		return $contents;
315
+
316
+	}//end getContents()
317
+
318
+
319
+	/**
320
+	 * Get the current fixed content of a token.
321
+	 *
322
+	 * This function takes changesets into account so should be used
323
+	 * instead of directly accessing the token array.
324
+	 *
325
+	 * @param int $stackPtr The position of the token in the token stack.
326
+	 *
327
+	 * @return string
328
+	 */
329
+	public function getTokenContent($stackPtr)
330
+	{
331
+		if ($this->inChangeset === true
332
+			&& isset($this->changeset[$stackPtr]) === true
333
+		) {
334
+			return $this->changeset[$stackPtr];
335
+		} else {
336
+			return $this->tokens[$stackPtr];
337
+		}
338
+
339
+	}//end getTokenContent()
340
+
341
+
342
+	/**
343
+	 * Start recording actions for a changeset.
344
+	 *
345
+	 * @return void
346
+	 */
347
+	public function beginChangeset()
348
+	{
349
+		if ($this->inConflict === true) {
350
+			return false;
351
+		}
352
+
353
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
354
+			$bt    = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
355
+			$sniff = $bt[1]['class'];
356
+			$line  = $bt[0]['line'];
357
+
358
+			@ob_end_clean();
359
+			echo "\t=> Changeset started by $sniff (line $line)".PHP_EOL;
360
+			ob_start();
361
+		}
362
+
363
+		$this->changeset   = [];
364
+		$this->inChangeset = true;
365
+
366
+	}//end beginChangeset()
367
+
368
+
369
+	/**
370
+	 * Stop recording actions for a changeset, and apply logged changes.
371
+	 *
372
+	 * @return boolean
373
+	 */
374
+	public function endChangeset()
375
+	{
376
+		if ($this->inConflict === true) {
377
+			return false;
378
+		}
379
+
380
+		$this->inChangeset = false;
381
+
382
+		$success = true;
383
+		$applied = [];
384
+		foreach ($this->changeset as $stackPtr => $content) {
385
+			$success = $this->replaceToken($stackPtr, $content);
386
+			if ($success === false) {
387
+				break;
388
+			} else {
389
+				$applied[] = $stackPtr;
390
+			}
391
+		}
392
+
393
+		if ($success === false) {
394
+			// Rolling back all changes.
395
+			foreach ($applied as $stackPtr) {
396
+				$this->revertToken($stackPtr);
397
+			}
398
+
399
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
400
+				@ob_end_clean();
401
+				echo "\t=> Changeset failed to apply".PHP_EOL;
402
+				ob_start();
403
+			}
404
+		} else if (PHP_CODESNIFFER_VERBOSITY > 1) {
405
+			$fixes = count($this->changeset);
406
+			@ob_end_clean();
407
+			echo "\t=> Changeset ended: $fixes changes applied".PHP_EOL;
408
+			ob_start();
409
+		}
410
+
411
+		$this->changeset = [];
412
+
413
+	}//end endChangeset()
414
+
415
+
416
+	/**
417
+	 * Stop recording actions for a changeset, and discard logged changes.
418
+	 *
419
+	 * @return void
420
+	 */
421
+	public function rollbackChangeset()
422
+	{
423
+		$this->inChangeset = false;
424
+		$this->inConflict  = false;
425
+
426
+		if (empty($this->changeset) === false) {
427
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
428
+				$bt = debug_backtrace();
429
+				if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
430
+					$sniff = $bt[2]['class'];
431
+					$line  = $bt[1]['line'];
432
+				} else {
433
+					$sniff = $bt[1]['class'];
434
+					$line  = $bt[0]['line'];
435
+				}
436
+
437
+				$numChanges = count($this->changeset);
438
+
439
+				@ob_end_clean();
440
+				echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)".PHP_EOL;
441
+				echo "\t=> Changeset rolled back".PHP_EOL;
442
+				ob_start();
443
+			}
444
+
445
+			$this->changeset = [];
446
+		}//end if
447
+
448
+	}//end rollbackChangeset()
449
+
450
+
451
+	/**
452
+	 * Replace the entire contents of a token.
453
+	 *
454
+	 * @param int    $stackPtr The position of the token in the token stack.
455
+	 * @param string $content  The new content of the token.
456
+	 *
457
+	 * @return bool If the change was accepted.
458
+	 */
459
+	public function replaceToken($stackPtr, $content)
460
+	{
461
+		if ($this->inConflict === true) {
462
+			return false;
463
+		}
464
+
465
+		if ($this->inChangeset === false
466
+			&& isset($this->fixedTokens[$stackPtr]) === true
467
+		) {
468
+			$indent = "\t";
469
+			if (empty($this->changeset) === false) {
470
+				$indent .= "\t";
471
+			}
472
+
473
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
474
+				@ob_end_clean();
475
+				echo "$indent* token $stackPtr has already been modified, skipping *".PHP_EOL;
476
+				ob_start();
477
+			}
478
+
479
+			return false;
480
+		}
481
+
482
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
483
+			$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
484
+			if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
485
+				$sniff = $bt[2]['class'];
486
+				$line  = $bt[1]['line'];
487
+			} else {
488
+				$sniff = $bt[1]['class'];
489
+				$line  = $bt[0]['line'];
490
+			}
491
+
492
+			$tokens     = $this->currentFile->getTokens();
493
+			$type       = $tokens[$stackPtr]['type'];
494
+			$oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
495
+			$newContent = Common::prepareForOutput($content);
496
+			if (trim($this->tokens[$stackPtr]) === '' && isset($this->tokens[($stackPtr + 1)]) === true) {
497
+				// Add some context for whitespace only changes.
498
+				$append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
499
+				$oldContent .= $append;
500
+				$newContent .= $append;
501
+			}
502
+		}//end if
503
+
504
+		if ($this->inChangeset === true) {
505
+			$this->changeset[$stackPtr] = $content;
506
+
507
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
508
+				@ob_end_clean();
509
+				echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
510
+				ob_start();
511
+			}
512
+
513
+			return true;
514
+		}
515
+
516
+		if (isset($this->oldTokenValues[$stackPtr]) === false) {
517
+			$this->oldTokenValues[$stackPtr] = [
518
+				'curr' => $content,
519
+				'prev' => $this->tokens[$stackPtr],
520
+				'loop' => $this->loops,
521
+			];
522
+		} else {
523
+			if ($this->oldTokenValues[$stackPtr]['prev'] === $content
524
+				&& $this->oldTokenValues[$stackPtr]['loop'] === ($this->loops - 1)
525
+			) {
526
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
527
+					$indent = "\t";
528
+					if (empty($this->changeset) === false) {
529
+						$indent .= "\t";
530
+					}
531
+
532
+					$loop = $this->oldTokenValues[$stackPtr]['loop'];
533
+
534
+					@ob_end_clean();
535
+					echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL;
536
+					echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****".PHP_EOL;
537
+				}
538
+
539
+				if ($this->oldTokenValues[$stackPtr]['loop'] >= ($this->loops - 1)) {
540
+					$this->inConflict = true;
541
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
542
+						echo "$indent**** ignoring all changes until next loop ****".PHP_EOL;
543
+					}
544
+				}
545
+
546
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
547
+					ob_start();
548
+				}
549
+
550
+				return false;
551
+			}//end if
552
+
553
+			$this->oldTokenValues[$stackPtr]['prev'] = $this->oldTokenValues[$stackPtr]['curr'];
554
+			$this->oldTokenValues[$stackPtr]['curr'] = $content;
555
+			$this->oldTokenValues[$stackPtr]['loop'] = $this->loops;
556
+		}//end if
557
+
558
+		$this->fixedTokens[$stackPtr] = $this->tokens[$stackPtr];
559
+		$this->tokens[$stackPtr]      = $content;
560
+		$this->numFixes++;
561
+
562
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
563
+			$indent = "\t";
564
+			if (empty($this->changeset) === false) {
565
+				$indent .= "\tA: ";
566
+			}
567
+
568
+			if (ob_get_level() > 0) {
569
+				ob_end_clean();
570
+			}
571
+
572
+			echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
573
+			ob_start();
574
+		}
575
+
576
+		return true;
577
+
578
+	}//end replaceToken()
579
+
580
+
581
+	/**
582
+	 * Reverts the previous fix made to a token.
583
+	 *
584
+	 * @param int $stackPtr The position of the token in the token stack.
585
+	 *
586
+	 * @return bool If a change was reverted.
587
+	 */
588
+	public function revertToken($stackPtr)
589
+	{
590
+		if (isset($this->fixedTokens[$stackPtr]) === false) {
591
+			return false;
592
+		}
593
+
594
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
595
+			$bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
596
+			if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
597
+				$sniff = $bt[2]['class'];
598
+				$line  = $bt[1]['line'];
599
+			} else {
600
+				$sniff = $bt[1]['class'];
601
+				$line  = $bt[0]['line'];
602
+			}
603
+
604
+			$tokens     = $this->currentFile->getTokens();
605
+			$type       = $tokens[$stackPtr]['type'];
606
+			$oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
607
+			$newContent = Common::prepareForOutput($this->fixedTokens[$stackPtr]);
608
+			if (trim($this->tokens[$stackPtr]) === '' && isset($tokens[($stackPtr + 1)]) === true) {
609
+				// Add some context for whitespace only changes.
610
+				$append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
611
+				$oldContent .= $append;
612
+				$newContent .= $append;
613
+			}
614
+		}//end if
615
+
616
+		$this->tokens[$stackPtr] = $this->fixedTokens[$stackPtr];
617
+		unset($this->fixedTokens[$stackPtr]);
618
+		$this->numFixes--;
619
+
620
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
621
+			$indent = "\t";
622
+			if (empty($this->changeset) === false) {
623
+				$indent .= "\tR: ";
624
+			}
625
+
626
+			@ob_end_clean();
627
+			echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
628
+			ob_start();
629
+		}
630
+
631
+		return true;
632
+
633
+	}//end revertToken()
634
+
635
+
636
+	/**
637
+	 * Replace the content of a token with a part of its current content.
638
+	 *
639
+	 * @param int $stackPtr The position of the token in the token stack.
640
+	 * @param int $start    The first character to keep.
641
+	 * @param int $length   The number of characters to keep. If NULL, the content of
642
+	 *                      the token from $start to the end of the content is kept.
643
+	 *
644
+	 * @return bool If the change was accepted.
645
+	 */
646
+	public function substrToken($stackPtr, $start, $length=null)
647
+	{
648
+		$current = $this->getTokenContent($stackPtr);
649
+
650
+		if ($length === null) {
651
+			$newContent = substr($current, $start);
652
+		} else {
653
+			$newContent = substr($current, $start, $length);
654
+		}
655
+
656
+		return $this->replaceToken($stackPtr, $newContent);
657
+
658
+	}//end substrToken()
659
+
660
+
661
+	/**
662
+	 * Adds a newline to end of a token's content.
663
+	 *
664
+	 * @param int $stackPtr The position of the token in the token stack.
665
+	 *
666
+	 * @return bool If the change was accepted.
667
+	 */
668
+	public function addNewline($stackPtr)
669
+	{
670
+		$current = $this->getTokenContent($stackPtr);
671
+		return $this->replaceToken($stackPtr, $current.$this->currentFile->eolChar);
672
+
673
+	}//end addNewline()
674
+
675
+
676
+	/**
677
+	 * Adds a newline to the start of a token's content.
678
+	 *
679
+	 * @param int $stackPtr The position of the token in the token stack.
680
+	 *
681
+	 * @return bool If the change was accepted.
682
+	 */
683
+	public function addNewlineBefore($stackPtr)
684
+	{
685
+		$current = $this->getTokenContent($stackPtr);
686
+		return $this->replaceToken($stackPtr, $this->currentFile->eolChar.$current);
687
+
688
+	}//end addNewlineBefore()
689
+
690
+
691
+	/**
692
+	 * Adds content to the end of a token's current content.
693
+	 *
694
+	 * @param int    $stackPtr The position of the token in the token stack.
695
+	 * @param string $content  The content to add.
696
+	 *
697
+	 * @return bool If the change was accepted.
698
+	 */
699
+	public function addContent($stackPtr, $content)
700
+	{
701
+		$current = $this->getTokenContent($stackPtr);
702
+		return $this->replaceToken($stackPtr, $current.$content);
703
+
704
+	}//end addContent()
705
+
706
+
707
+	/**
708
+	 * Adds content to the start of a token's current content.
709
+	 *
710
+	 * @param int    $stackPtr The position of the token in the token stack.
711
+	 * @param string $content  The content to add.
712
+	 *
713
+	 * @return bool If the change was accepted.
714
+	 */
715
+	public function addContentBefore($stackPtr, $content)
716
+	{
717
+		$current = $this->getTokenContent($stackPtr);
718
+		return $this->replaceToken($stackPtr, $content.$current);
719
+
720
+	}//end addContentBefore()
721 721
 
722 722
 
723 723
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -269,14 +269,14 @@
 block discarded – undo
269 269
         foreach ($diffLines as $line) {
270 270
             if (isset($line[0]) === true) {
271 271
                 switch ($line[0]) {
272
-                case '-':
273
-                    $diff[] = "\033[31m$line\033[0m";
274
-                    break;
275
-                case '+':
276
-                    $diff[] = "\033[32m$line\033[0m";
277
-                    break;
278
-                default:
279
-                    $diff[] = $line;
272
+                	case '-':
273
+                    	$diff[] = "\033[31m$line\033[0m";
274
+                    	break;
275
+                	case '+':
276
+                    	$diff[] = "\033[32m$line\033[0m";
277
+                    	break;
278
+                	default:
279
+                    	$diff[] = $line;
280 280
                 }
281 281
             }
282 282
         }
Please login to merge, or discard this patch.
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @var array<int, string>
54 54
      */
55
-    private $tokens = [];
55
+    private $tokens = [ ];
56 56
 
57 57
     /**
58 58
      * A list of tokens that have already been fixed.
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
      *
63 63
      * @var int[]
64 64
      */
65
-    private $fixedTokens = [];
65
+    private $fixedTokens = [ ];
66 66
 
67 67
     /**
68 68
      * The last value of each fixed token.
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @var array<int, string>
74 74
      */
75
-    private $oldTokenValues = [];
75
+    private $oldTokenValues = [ ];
76 76
 
77 77
     /**
78 78
      * A list of tokens that have been fixed during a changeset.
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @var array
84 84
      */
85
-    private $changeset = [];
85
+    private $changeset = [ ];
86 86
 
87 87
     /**
88 88
      * Is there an open changeset.
@@ -113,19 +113,19 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @return void
115 115
      */
116
-    public function startFile(File $phpcsFile)
116
+    public function startFile( File $phpcsFile )
117 117
     {
118 118
         $this->currentFile = $phpcsFile;
119 119
         $this->numFixes    = 0;
120
-        $this->fixedTokens = [];
120
+        $this->fixedTokens = [ ];
121 121
 
122 122
         $tokens       = $phpcsFile->getTokens();
123
-        $this->tokens = [];
124
-        foreach ($tokens as $index => $token) {
125
-            if (isset($token['orig_content']) === true) {
126
-                $this->tokens[$index] = $token['orig_content'];
123
+        $this->tokens = [ ];
124
+        foreach ( $tokens as $index => $token ) {
125
+            if ( isset( $token[ 'orig_content' ] ) === true ) {
126
+                $this->tokens[ $index ] = $token[ 'orig_content' ];
127 127
             } else {
128
-                $this->tokens[$index] = $token['content'];
128
+                $this->tokens[ $index ] = $token[ 'content' ];
129 129
             }
130 130
         }
131 131
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
     public function fixFile()
141 141
     {
142 142
         $fixable = $this->currentFile->getFixableCount();
143
-        if ($fixable === 0) {
143
+        if ( $fixable === 0 ) {
144 144
             // Nothing to fix.
145 145
             return false;
146 146
         }
@@ -148,61 +148,61 @@  discard block
 block discarded – undo
148 148
         $this->enabled = true;
149 149
 
150 150
         $this->loops = 0;
151
-        while ($this->loops < 50) {
151
+        while ( $this->loops < 50 ) {
152 152
             ob_start();
153 153
 
154 154
             // Only needed once file content has changed.
155 155
             $contents = $this->getContents();
156 156
 
157
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
157
+            if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
158 158
                 @ob_end_clean();
159
-                echo '---START FILE CONTENT---'.PHP_EOL;
160
-                $lines = explode($this->currentFile->eolChar, $contents);
161
-                $max   = strlen(count($lines));
162
-                foreach ($lines as $lineNum => $line) {
159
+                echo '---START FILE CONTENT---' . PHP_EOL;
160
+                $lines = explode( $this->currentFile->eolChar, $contents );
161
+                $max   = strlen( count( $lines ) );
162
+                foreach ( $lines as $lineNum => $line ) {
163 163
                     $lineNum++;
164
-                    echo str_pad($lineNum, $max, ' ', STR_PAD_LEFT).'|'.$line.PHP_EOL;
164
+                    echo str_pad( $lineNum, $max, ' ', STR_PAD_LEFT ) . '|' . $line . PHP_EOL;
165 165
                 }
166 166
 
167
-                echo '--- END FILE CONTENT ---'.PHP_EOL;
167
+                echo '--- END FILE CONTENT ---' . PHP_EOL;
168 168
                 ob_start();
169 169
             }
170 170
 
171 171
             $this->inConflict = false;
172 172
             $this->currentFile->ruleset->populateTokenListeners();
173
-            $this->currentFile->setContent($contents);
173
+            $this->currentFile->setContent( $contents );
174 174
             $this->currentFile->process();
175 175
             ob_end_clean();
176 176
 
177 177
             $this->loops++;
178 178
 
179
-            if (PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0) {
180
-                echo "\r".str_repeat(' ', 80)."\r";
179
+            if ( PHP_CODESNIFFER_CBF === true && PHP_CODESNIFFER_VERBOSITY > 0 ) {
180
+                echo "\r" . str_repeat( ' ', 80 ) . "\r";
181 181
                 echo "\t=> Fixing file: $this->numFixes/$fixable violations remaining [made $this->loops pass";
182
-                if ($this->loops > 1) {
182
+                if ( $this->loops > 1 ) {
183 183
                     echo 'es';
184 184
                 }
185 185
 
186 186
                 echo ']... ';
187 187
             }
188 188
 
189
-            if ($this->numFixes === 0 && $this->inConflict === false) {
189
+            if ( $this->numFixes === 0 && $this->inConflict === false ) {
190 190
                 // Nothing left to do.
191 191
                 break;
192
-            } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
193
-                echo "\t* fixed $this->numFixes violations, starting loop ".($this->loops + 1).' *'.PHP_EOL;
192
+            } else if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
193
+                echo "\t* fixed $this->numFixes violations, starting loop " . ( $this->loops + 1 ) . ' *' . PHP_EOL;
194 194
             }
195 195
         }//end while
196 196
 
197 197
         $this->enabled = false;
198 198
 
199
-        if ($this->numFixes > 0) {
200
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
201
-                if (ob_get_level() > 0) {
199
+        if ( $this->numFixes > 0 ) {
200
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
201
+                if ( ob_get_level() > 0 ) {
202 202
                     ob_end_clean();
203 203
                 }
204 204
 
205
-                echo "\t*** Reached maximum number of loops with $this->numFixes violations left unfixed ***".PHP_EOL;
205
+                echo "\t*** Reached maximum number of loops with $this->numFixes violations left unfixed ***" . PHP_EOL;
206 206
                 ob_start();
207 207
             }
208 208
 
@@ -224,64 +224,64 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return string
226 226
      */
227
-    public function generateDiff($filePath=null, $colors=true)
227
+    public function generateDiff( $filePath = null, $colors = true )
228 228
     {
229
-        if ($filePath === null) {
229
+        if ( $filePath === null ) {
230 230
             $filePath = $this->currentFile->getFilename();
231 231
         }
232 232
 
233
-        $cwd = getcwd().DIRECTORY_SEPARATOR;
234
-        if (strpos($filePath, $cwd) === 0) {
235
-            $filename = substr($filePath, strlen($cwd));
233
+        $cwd = getcwd() . DIRECTORY_SEPARATOR;
234
+        if ( strpos( $filePath, $cwd ) === 0 ) {
235
+            $filename = substr( $filePath, strlen( $cwd ) );
236 236
         } else {
237 237
             $filename = $filePath;
238 238
         }
239 239
 
240 240
         $contents = $this->getContents();
241 241
 
242
-        $tempName  = tempnam(sys_get_temp_dir(), 'phpcs-fixer');
243
-        $fixedFile = fopen($tempName, 'w');
244
-        fwrite($fixedFile, $contents);
242
+        $tempName  = tempnam( sys_get_temp_dir(), 'phpcs-fixer' );
243
+        $fixedFile = fopen( $tempName, 'w' );
244
+        fwrite( $fixedFile, $contents );
245 245
 
246 246
         // We must use something like shell_exec() because whitespace at the end
247 247
         // of lines is critical to diff files.
248
-        $filename = escapeshellarg($filename);
248
+        $filename = escapeshellarg( $filename );
249 249
         $cmd      = "diff -u -L$filename -LPHP_CodeSniffer $filename \"$tempName\"";
250 250
 
251
-        $diff = shell_exec($cmd);
251
+        $diff = shell_exec( $cmd );
252 252
 
253
-        fclose($fixedFile);
254
-        if (is_file($tempName) === true) {
255
-            unlink($tempName);
253
+        fclose( $fixedFile );
254
+        if ( is_file( $tempName ) === true ) {
255
+            unlink( $tempName );
256 256
         }
257 257
 
258
-        if ($colors === false) {
258
+        if ( $colors === false ) {
259 259
             return $diff;
260 260
         }
261 261
 
262
-        $diffLines = explode(PHP_EOL, $diff);
263
-        if (count($diffLines) === 1) {
262
+        $diffLines = explode( PHP_EOL, $diff );
263
+        if ( count( $diffLines ) === 1 ) {
264 264
             // Seems to be required for cygwin.
265
-            $diffLines = explode("\n", $diff);
265
+            $diffLines = explode( "\n", $diff );
266 266
         }
267 267
 
268
-        $diff = [];
269
-        foreach ($diffLines as $line) {
270
-            if (isset($line[0]) === true) {
271
-                switch ($line[0]) {
268
+        $diff = [ ];
269
+        foreach ( $diffLines as $line ) {
270
+            if ( isset( $line[ 0 ] ) === true ) {
271
+                switch ( $line[ 0 ] ) {
272 272
                 case '-':
273
-                    $diff[] = "\033[31m$line\033[0m";
273
+                    $diff[ ] = "\033[31m$line\033[0m";
274 274
                     break;
275 275
                 case '+':
276
-                    $diff[] = "\033[32m$line\033[0m";
276
+                    $diff[ ] = "\033[32m$line\033[0m";
277 277
                     break;
278 278
                 default:
279
-                    $diff[] = $line;
279
+                    $diff[ ] = $line;
280 280
                 }
281 281
             }
282 282
         }
283 283
 
284
-        $diff = implode(PHP_EOL, $diff);
284
+        $diff = implode( PHP_EOL, $diff );
285 285
 
286 286
         return $diff;
287 287
 
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public function getContents()
312 312
     {
313
-        $contents = implode($this->tokens);
313
+        $contents = implode( $this->tokens );
314 314
         return $contents;
315 315
 
316 316
     }//end getContents()
@@ -326,14 +326,14 @@  discard block
 block discarded – undo
326 326
      *
327 327
      * @return string
328 328
      */
329
-    public function getTokenContent($stackPtr)
329
+    public function getTokenContent( $stackPtr )
330 330
     {
331
-        if ($this->inChangeset === true
332
-            && isset($this->changeset[$stackPtr]) === true
331
+        if ( $this->inChangeset === true
332
+            && isset( $this->changeset[ $stackPtr ] ) === true
333 333
         ) {
334
-            return $this->changeset[$stackPtr];
334
+            return $this->changeset[ $stackPtr ];
335 335
         } else {
336
-            return $this->tokens[$stackPtr];
336
+            return $this->tokens[ $stackPtr ];
337 337
         }
338 338
 
339 339
     }//end getTokenContent()
@@ -346,21 +346,21 @@  discard block
 block discarded – undo
346 346
      */
347 347
     public function beginChangeset()
348 348
     {
349
-        if ($this->inConflict === true) {
349
+        if ( $this->inConflict === true ) {
350 350
             return false;
351 351
         }
352 352
 
353
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
354
-            $bt    = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
355
-            $sniff = $bt[1]['class'];
356
-            $line  = $bt[0]['line'];
353
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
354
+            $bt    = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
355
+            $sniff = $bt[ 1 ][ 'class' ];
356
+            $line  = $bt[ 0 ][ 'line' ];
357 357
 
358 358
             @ob_end_clean();
359
-            echo "\t=> Changeset started by $sniff (line $line)".PHP_EOL;
359
+            echo "\t=> Changeset started by $sniff (line $line)" . PHP_EOL;
360 360
             ob_start();
361 361
         }
362 362
 
363
-        $this->changeset   = [];
363
+        $this->changeset   = [ ];
364 364
         $this->inChangeset = true;
365 365
 
366 366
     }//end beginChangeset()
@@ -373,42 +373,42 @@  discard block
 block discarded – undo
373 373
      */
374 374
     public function endChangeset()
375 375
     {
376
-        if ($this->inConflict === true) {
376
+        if ( $this->inConflict === true ) {
377 377
             return false;
378 378
         }
379 379
 
380 380
         $this->inChangeset = false;
381 381
 
382 382
         $success = true;
383
-        $applied = [];
384
-        foreach ($this->changeset as $stackPtr => $content) {
385
-            $success = $this->replaceToken($stackPtr, $content);
386
-            if ($success === false) {
383
+        $applied = [ ];
384
+        foreach ( $this->changeset as $stackPtr => $content ) {
385
+            $success = $this->replaceToken( $stackPtr, $content );
386
+            if ( $success === false ) {
387 387
                 break;
388 388
             } else {
389
-                $applied[] = $stackPtr;
389
+                $applied[ ] = $stackPtr;
390 390
             }
391 391
         }
392 392
 
393
-        if ($success === false) {
393
+        if ( $success === false ) {
394 394
             // Rolling back all changes.
395
-            foreach ($applied as $stackPtr) {
396
-                $this->revertToken($stackPtr);
395
+            foreach ( $applied as $stackPtr ) {
396
+                $this->revertToken( $stackPtr );
397 397
             }
398 398
 
399
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
399
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
400 400
                 @ob_end_clean();
401
-                echo "\t=> Changeset failed to apply".PHP_EOL;
401
+                echo "\t=> Changeset failed to apply" . PHP_EOL;
402 402
                 ob_start();
403 403
             }
404
-        } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
405
-            $fixes = count($this->changeset);
404
+        } else if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
405
+            $fixes = count( $this->changeset );
406 406
             @ob_end_clean();
407
-            echo "\t=> Changeset ended: $fixes changes applied".PHP_EOL;
407
+            echo "\t=> Changeset ended: $fixes changes applied" . PHP_EOL;
408 408
             ob_start();
409 409
         }
410 410
 
411
-        $this->changeset = [];
411
+        $this->changeset = [ ];
412 412
 
413 413
     }//end endChangeset()
414 414
 
@@ -423,26 +423,26 @@  discard block
 block discarded – undo
423 423
         $this->inChangeset = false;
424 424
         $this->inConflict  = false;
425 425
 
426
-        if (empty($this->changeset) === false) {
427
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
426
+        if ( empty( $this->changeset ) === false ) {
427
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
428 428
                 $bt = debug_backtrace();
429
-                if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
430
-                    $sniff = $bt[2]['class'];
431
-                    $line  = $bt[1]['line'];
429
+                if ( $bt[ 1 ][ 'class' ] === 'PHP_CodeSniffer\Fixer' ) {
430
+                    $sniff = $bt[ 2 ][ 'class' ];
431
+                    $line  = $bt[ 1 ][ 'line' ];
432 432
                 } else {
433
-                    $sniff = $bt[1]['class'];
434
-                    $line  = $bt[0]['line'];
433
+                    $sniff = $bt[ 1 ][ 'class' ];
434
+                    $line  = $bt[ 0 ][ 'line' ];
435 435
                 }
436 436
 
437
-                $numChanges = count($this->changeset);
437
+                $numChanges = count( $this->changeset );
438 438
 
439 439
                 @ob_end_clean();
440
-                echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)".PHP_EOL;
441
-                echo "\t=> Changeset rolled back".PHP_EOL;
440
+                echo "\t\tR: $sniff (line $line) rolled back the changeset ($numChanges changes)" . PHP_EOL;
441
+                echo "\t=> Changeset rolled back" . PHP_EOL;
442 442
                 ob_start();
443 443
             }
444 444
 
445
-            $this->changeset = [];
445
+            $this->changeset = [ ];
446 446
         }//end if
447 447
 
448 448
     }//end rollbackChangeset()
@@ -456,120 +456,120 @@  discard block
 block discarded – undo
456 456
      *
457 457
      * @return bool If the change was accepted.
458 458
      */
459
-    public function replaceToken($stackPtr, $content)
459
+    public function replaceToken( $stackPtr, $content )
460 460
     {
461
-        if ($this->inConflict === true) {
461
+        if ( $this->inConflict === true ) {
462 462
             return false;
463 463
         }
464 464
 
465
-        if ($this->inChangeset === false
466
-            && isset($this->fixedTokens[$stackPtr]) === true
465
+        if ( $this->inChangeset === false
466
+            && isset( $this->fixedTokens[ $stackPtr ] ) === true
467 467
         ) {
468 468
             $indent = "\t";
469
-            if (empty($this->changeset) === false) {
469
+            if ( empty( $this->changeset ) === false ) {
470 470
                 $indent .= "\t";
471 471
             }
472 472
 
473
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
473
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
474 474
                 @ob_end_clean();
475
-                echo "$indent* token $stackPtr has already been modified, skipping *".PHP_EOL;
475
+                echo "$indent* token $stackPtr has already been modified, skipping *" . PHP_EOL;
476 476
                 ob_start();
477 477
             }
478 478
 
479 479
             return false;
480 480
         }
481 481
 
482
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
483
-            $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
484
-            if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
485
-                $sniff = $bt[2]['class'];
486
-                $line  = $bt[1]['line'];
482
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
483
+            $bt = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
484
+            if ( $bt[ 1 ][ 'class' ] === 'PHP_CodeSniffer\Fixer' ) {
485
+                $sniff = $bt[ 2 ][ 'class' ];
486
+                $line  = $bt[ 1 ][ 'line' ];
487 487
             } else {
488
-                $sniff = $bt[1]['class'];
489
-                $line  = $bt[0]['line'];
488
+                $sniff = $bt[ 1 ][ 'class' ];
489
+                $line  = $bt[ 0 ][ 'line' ];
490 490
             }
491 491
 
492 492
             $tokens     = $this->currentFile->getTokens();
493
-            $type       = $tokens[$stackPtr]['type'];
494
-            $oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
495
-            $newContent = Common::prepareForOutput($content);
496
-            if (trim($this->tokens[$stackPtr]) === '' && isset($this->tokens[($stackPtr + 1)]) === true) {
493
+            $type       = $tokens[ $stackPtr ][ 'type' ];
494
+            $oldContent = Common::prepareForOutput( $this->tokens[ $stackPtr ] );
495
+            $newContent = Common::prepareForOutput( $content );
496
+            if ( trim( $this->tokens[ $stackPtr ] ) === '' && isset( $this->tokens[ ( $stackPtr + 1 ) ] ) === true ) {
497 497
                 // Add some context for whitespace only changes.
498
-                $append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
498
+                $append      = Common::prepareForOutput( $this->tokens[ ( $stackPtr + 1 ) ] );
499 499
                 $oldContent .= $append;
500 500
                 $newContent .= $append;
501 501
             }
502 502
         }//end if
503 503
 
504
-        if ($this->inChangeset === true) {
505
-            $this->changeset[$stackPtr] = $content;
504
+        if ( $this->inChangeset === true ) {
505
+            $this->changeset[ $stackPtr ] = $content;
506 506
 
507
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
507
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
508 508
                 @ob_end_clean();
509
-                echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
509
+                echo "\t\tQ: $sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"" . PHP_EOL;
510 510
                 ob_start();
511 511
             }
512 512
 
513 513
             return true;
514 514
         }
515 515
 
516
-        if (isset($this->oldTokenValues[$stackPtr]) === false) {
517
-            $this->oldTokenValues[$stackPtr] = [
516
+        if ( isset( $this->oldTokenValues[ $stackPtr ] ) === false ) {
517
+            $this->oldTokenValues[ $stackPtr ] = [
518 518
                 'curr' => $content,
519
-                'prev' => $this->tokens[$stackPtr],
519
+                'prev' => $this->tokens[ $stackPtr ],
520 520
                 'loop' => $this->loops,
521 521
             ];
522 522
         } else {
523
-            if ($this->oldTokenValues[$stackPtr]['prev'] === $content
524
-                && $this->oldTokenValues[$stackPtr]['loop'] === ($this->loops - 1)
523
+            if ( $this->oldTokenValues[ $stackPtr ][ 'prev' ] === $content
524
+                && $this->oldTokenValues[ $stackPtr ][ 'loop' ] === ( $this->loops - 1 )
525 525
             ) {
526
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
526
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
527 527
                     $indent = "\t";
528
-                    if (empty($this->changeset) === false) {
528
+                    if ( empty( $this->changeset ) === false ) {
529 529
                         $indent .= "\t";
530 530
                     }
531 531
 
532
-                    $loop = $this->oldTokenValues[$stackPtr]['loop'];
532
+                    $loop = $this->oldTokenValues[ $stackPtr ][ 'loop' ];
533 533
 
534 534
                     @ob_end_clean();
535
-                    echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****".PHP_EOL;
536
-                    echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****".PHP_EOL;
535
+                    echo "$indent**** $sniff (line $line) has possible conflict with another sniff on loop $loop; caused by the following change ****" . PHP_EOL;
536
+                    echo "$indent**** replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\" ****" . PHP_EOL;
537 537
                 }
538 538
 
539
-                if ($this->oldTokenValues[$stackPtr]['loop'] >= ($this->loops - 1)) {
539
+                if ( $this->oldTokenValues[ $stackPtr ][ 'loop' ] >= ( $this->loops - 1 ) ) {
540 540
                     $this->inConflict = true;
541
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
542
-                        echo "$indent**** ignoring all changes until next loop ****".PHP_EOL;
541
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
542
+                        echo "$indent**** ignoring all changes until next loop ****" . PHP_EOL;
543 543
                     }
544 544
                 }
545 545
 
546
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
546
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
547 547
                     ob_start();
548 548
                 }
549 549
 
550 550
                 return false;
551 551
             }//end if
552 552
 
553
-            $this->oldTokenValues[$stackPtr]['prev'] = $this->oldTokenValues[$stackPtr]['curr'];
554
-            $this->oldTokenValues[$stackPtr]['curr'] = $content;
555
-            $this->oldTokenValues[$stackPtr]['loop'] = $this->loops;
553
+            $this->oldTokenValues[ $stackPtr ][ 'prev' ] = $this->oldTokenValues[ $stackPtr ][ 'curr' ];
554
+            $this->oldTokenValues[ $stackPtr ][ 'curr' ] = $content;
555
+            $this->oldTokenValues[ $stackPtr ][ 'loop' ] = $this->loops;
556 556
         }//end if
557 557
 
558
-        $this->fixedTokens[$stackPtr] = $this->tokens[$stackPtr];
559
-        $this->tokens[$stackPtr]      = $content;
558
+        $this->fixedTokens[ $stackPtr ] = $this->tokens[ $stackPtr ];
559
+        $this->tokens[ $stackPtr ]      = $content;
560 560
         $this->numFixes++;
561 561
 
562
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
562
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
563 563
             $indent = "\t";
564
-            if (empty($this->changeset) === false) {
564
+            if ( empty( $this->changeset ) === false ) {
565 565
                 $indent .= "\tA: ";
566 566
             }
567 567
 
568
-            if (ob_get_level() > 0) {
568
+            if ( ob_get_level() > 0 ) {
569 569
                 ob_end_clean();
570 570
             }
571 571
 
572
-            echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
572
+            echo "$indent$sniff (line $line) replaced token $stackPtr ($type) \"$oldContent\" => \"$newContent\"" . PHP_EOL;
573 573
             ob_start();
574 574
         }
575 575
 
@@ -585,46 +585,46 @@  discard block
 block discarded – undo
585 585
      *
586 586
      * @return bool If a change was reverted.
587 587
      */
588
-    public function revertToken($stackPtr)
588
+    public function revertToken( $stackPtr )
589 589
     {
590
-        if (isset($this->fixedTokens[$stackPtr]) === false) {
590
+        if ( isset( $this->fixedTokens[ $stackPtr ] ) === false ) {
591 591
             return false;
592 592
         }
593 593
 
594
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
595
-            $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
596
-            if ($bt[1]['class'] === 'PHP_CodeSniffer\Fixer') {
597
-                $sniff = $bt[2]['class'];
598
-                $line  = $bt[1]['line'];
594
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
595
+            $bt = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS );
596
+            if ( $bt[ 1 ][ 'class' ] === 'PHP_CodeSniffer\Fixer' ) {
597
+                $sniff = $bt[ 2 ][ 'class' ];
598
+                $line  = $bt[ 1 ][ 'line' ];
599 599
             } else {
600
-                $sniff = $bt[1]['class'];
601
-                $line  = $bt[0]['line'];
600
+                $sniff = $bt[ 1 ][ 'class' ];
601
+                $line  = $bt[ 0 ][ 'line' ];
602 602
             }
603 603
 
604 604
             $tokens     = $this->currentFile->getTokens();
605
-            $type       = $tokens[$stackPtr]['type'];
606
-            $oldContent = Common::prepareForOutput($this->tokens[$stackPtr]);
607
-            $newContent = Common::prepareForOutput($this->fixedTokens[$stackPtr]);
608
-            if (trim($this->tokens[$stackPtr]) === '' && isset($tokens[($stackPtr + 1)]) === true) {
605
+            $type       = $tokens[ $stackPtr ][ 'type' ];
606
+            $oldContent = Common::prepareForOutput( $this->tokens[ $stackPtr ] );
607
+            $newContent = Common::prepareForOutput( $this->fixedTokens[ $stackPtr ] );
608
+            if ( trim( $this->tokens[ $stackPtr ] ) === '' && isset( $tokens[ ( $stackPtr + 1 ) ] ) === true ) {
609 609
                 // Add some context for whitespace only changes.
610
-                $append      = Common::prepareForOutput($this->tokens[($stackPtr + 1)]);
610
+                $append      = Common::prepareForOutput( $this->tokens[ ( $stackPtr + 1 ) ] );
611 611
                 $oldContent .= $append;
612 612
                 $newContent .= $append;
613 613
             }
614 614
         }//end if
615 615
 
616
-        $this->tokens[$stackPtr] = $this->fixedTokens[$stackPtr];
617
-        unset($this->fixedTokens[$stackPtr]);
616
+        $this->tokens[ $stackPtr ] = $this->fixedTokens[ $stackPtr ];
617
+        unset( $this->fixedTokens[ $stackPtr ] );
618 618
         $this->numFixes--;
619 619
 
620
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
620
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
621 621
             $indent = "\t";
622
-            if (empty($this->changeset) === false) {
622
+            if ( empty( $this->changeset ) === false ) {
623 623
                 $indent .= "\tR: ";
624 624
             }
625 625
 
626 626
             @ob_end_clean();
627
-            echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"".PHP_EOL;
627
+            echo "$indent$sniff (line $line) reverted token $stackPtr ($type) \"$oldContent\" => \"$newContent\"" . PHP_EOL;
628 628
             ob_start();
629 629
         }
630 630
 
@@ -643,17 +643,17 @@  discard block
 block discarded – undo
643 643
      *
644 644
      * @return bool If the change was accepted.
645 645
      */
646
-    public function substrToken($stackPtr, $start, $length=null)
646
+    public function substrToken( $stackPtr, $start, $length = null )
647 647
     {
648
-        $current = $this->getTokenContent($stackPtr);
648
+        $current = $this->getTokenContent( $stackPtr );
649 649
 
650
-        if ($length === null) {
651
-            $newContent = substr($current, $start);
650
+        if ( $length === null ) {
651
+            $newContent = substr( $current, $start );
652 652
         } else {
653
-            $newContent = substr($current, $start, $length);
653
+            $newContent = substr( $current, $start, $length );
654 654
         }
655 655
 
656
-        return $this->replaceToken($stackPtr, $newContent);
656
+        return $this->replaceToken( $stackPtr, $newContent );
657 657
 
658 658
     }//end substrToken()
659 659
 
@@ -665,10 +665,10 @@  discard block
 block discarded – undo
665 665
      *
666 666
      * @return bool If the change was accepted.
667 667
      */
668
-    public function addNewline($stackPtr)
668
+    public function addNewline( $stackPtr )
669 669
     {
670
-        $current = $this->getTokenContent($stackPtr);
671
-        return $this->replaceToken($stackPtr, $current.$this->currentFile->eolChar);
670
+        $current = $this->getTokenContent( $stackPtr );
671
+        return $this->replaceToken( $stackPtr, $current . $this->currentFile->eolChar );
672 672
 
673 673
     }//end addNewline()
674 674
 
@@ -680,10 +680,10 @@  discard block
 block discarded – undo
680 680
      *
681 681
      * @return bool If the change was accepted.
682 682
      */
683
-    public function addNewlineBefore($stackPtr)
683
+    public function addNewlineBefore( $stackPtr )
684 684
     {
685
-        $current = $this->getTokenContent($stackPtr);
686
-        return $this->replaceToken($stackPtr, $this->currentFile->eolChar.$current);
685
+        $current = $this->getTokenContent( $stackPtr );
686
+        return $this->replaceToken( $stackPtr, $this->currentFile->eolChar . $current );
687 687
 
688 688
     }//end addNewlineBefore()
689 689
 
@@ -696,10 +696,10 @@  discard block
 block discarded – undo
696 696
      *
697 697
      * @return bool If the change was accepted.
698 698
      */
699
-    public function addContent($stackPtr, $content)
699
+    public function addContent( $stackPtr, $content )
700 700
     {
701
-        $current = $this->getTokenContent($stackPtr);
702
-        return $this->replaceToken($stackPtr, $current.$content);
701
+        $current = $this->getTokenContent( $stackPtr );
702
+        return $this->replaceToken( $stackPtr, $current . $content );
703 703
 
704 704
     }//end addContent()
705 705
 
@@ -712,10 +712,10 @@  discard block
 block discarded – undo
712 712
      *
713 713
      * @return bool If the change was accepted.
714 714
      */
715
-    public function addContentBefore($stackPtr, $content)
715
+    public function addContentBefore( $stackPtr, $content )
716 716
     {
717
-        $current = $this->getTokenContent($stackPtr);
718
-        return $this->replaceToken($stackPtr, $content.$current);
717
+        $current = $this->getTokenContent( $stackPtr );
718
+        return $this->replaceToken( $stackPtr, $content . $current );
719 719
 
720 720
     }//end addContentBefore()
721 721
 
Please login to merge, or discard this patch.
Braces   +17 added lines, -34 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@  discard block
 block discarded – undo
15 15
 use PHP_CodeSniffer\Files\File;
16 16
 use PHP_CodeSniffer\Util\Common;
17 17
 
18
-class Fixer
19
-{
18
+class Fixer {
20 19
 
21 20
     /**
22 21
      * Is the fixer enabled and fixing a file?
@@ -113,8 +112,7 @@  discard block
 block discarded – undo
113 112
      *
114 113
      * @return void
115 114
      */
116
-    public function startFile(File $phpcsFile)
117
-    {
115
+    public function startFile(File $phpcsFile) {
118 116
         $this->currentFile = $phpcsFile;
119 117
         $this->numFixes    = 0;
120 118
         $this->fixedTokens = [];
@@ -137,8 +135,7 @@  discard block
 block discarded – undo
137 135
      *
138 136
      * @return boolean
139 137
      */
140
-    public function fixFile()
141
-    {
138
+    public function fixFile() {
142 139
         $fixable = $this->currentFile->getFixableCount();
143 140
         if ($fixable === 0) {
144 141
             // Nothing to fix.
@@ -224,8 +221,7 @@  discard block
 block discarded – undo
224 221
      *
225 222
      * @return string
226 223
      */
227
-    public function generateDiff($filePath=null, $colors=true)
228
-    {
224
+    public function generateDiff($filePath=null, $colors=true) {
229 225
         if ($filePath === null) {
230 226
             $filePath = $this->currentFile->getFilename();
231 227
         }
@@ -296,8 +292,7 @@  discard block
 block discarded – undo
296 292
      *
297 293
      * @return int
298 294
      */
299
-    public function getFixCount()
300
-    {
295
+    public function getFixCount() {
301 296
         return $this->numFixes;
302 297
 
303 298
     }//end getFixCount()
@@ -308,8 +303,7 @@  discard block
 block discarded – undo
308 303
      *
309 304
      * @return string
310 305
      */
311
-    public function getContents()
312
-    {
306
+    public function getContents() {
313 307
         $contents = implode($this->tokens);
314 308
         return $contents;
315 309
 
@@ -326,8 +320,7 @@  discard block
 block discarded – undo
326 320
      *
327 321
      * @return string
328 322
      */
329
-    public function getTokenContent($stackPtr)
330
-    {
323
+    public function getTokenContent($stackPtr) {
331 324
         if ($this->inChangeset === true
332 325
             && isset($this->changeset[$stackPtr]) === true
333 326
         ) {
@@ -344,8 +337,7 @@  discard block
 block discarded – undo
344 337
      *
345 338
      * @return void
346 339
      */
347
-    public function beginChangeset()
348
-    {
340
+    public function beginChangeset() {
349 341
         if ($this->inConflict === true) {
350 342
             return false;
351 343
         }
@@ -371,8 +363,7 @@  discard block
 block discarded – undo
371 363
      *
372 364
      * @return boolean
373 365
      */
374
-    public function endChangeset()
375
-    {
366
+    public function endChangeset() {
376 367
         if ($this->inConflict === true) {
377 368
             return false;
378 369
         }
@@ -418,8 +409,7 @@  discard block
 block discarded – undo
418 409
      *
419 410
      * @return void
420 411
      */
421
-    public function rollbackChangeset()
422
-    {
412
+    public function rollbackChangeset() {
423 413
         $this->inChangeset = false;
424 414
         $this->inConflict  = false;
425 415
 
@@ -456,8 +446,7 @@  discard block
 block discarded – undo
456 446
      *
457 447
      * @return bool If the change was accepted.
458 448
      */
459
-    public function replaceToken($stackPtr, $content)
460
-    {
449
+    public function replaceToken($stackPtr, $content) {
461 450
         if ($this->inConflict === true) {
462 451
             return false;
463 452
         }
@@ -585,8 +574,7 @@  discard block
 block discarded – undo
585 574
      *
586 575
      * @return bool If a change was reverted.
587 576
      */
588
-    public function revertToken($stackPtr)
589
-    {
577
+    public function revertToken($stackPtr) {
590 578
         if (isset($this->fixedTokens[$stackPtr]) === false) {
591 579
             return false;
592 580
         }
@@ -643,8 +631,7 @@  discard block
 block discarded – undo
643 631
      *
644 632
      * @return bool If the change was accepted.
645 633
      */
646
-    public function substrToken($stackPtr, $start, $length=null)
647
-    {
634
+    public function substrToken($stackPtr, $start, $length=null) {
648 635
         $current = $this->getTokenContent($stackPtr);
649 636
 
650 637
         if ($length === null) {
@@ -665,8 +652,7 @@  discard block
 block discarded – undo
665 652
      *
666 653
      * @return bool If the change was accepted.
667 654
      */
668
-    public function addNewline($stackPtr)
669
-    {
655
+    public function addNewline($stackPtr) {
670 656
         $current = $this->getTokenContent($stackPtr);
671 657
         return $this->replaceToken($stackPtr, $current.$this->currentFile->eolChar);
672 658
 
@@ -680,8 +666,7 @@  discard block
 block discarded – undo
680 666
      *
681 667
      * @return bool If the change was accepted.
682 668
      */
683
-    public function addNewlineBefore($stackPtr)
684
-    {
669
+    public function addNewlineBefore($stackPtr) {
685 670
         $current = $this->getTokenContent($stackPtr);
686 671
         return $this->replaceToken($stackPtr, $this->currentFile->eolChar.$current);
687 672
 
@@ -696,8 +681,7 @@  discard block
 block discarded – undo
696 681
      *
697 682
      * @return bool If the change was accepted.
698 683
      */
699
-    public function addContent($stackPtr, $content)
700
-    {
684
+    public function addContent($stackPtr, $content) {
701 685
         $current = $this->getTokenContent($stackPtr);
702 686
         return $this->replaceToken($stackPtr, $current.$content);
703 687
 
@@ -712,8 +696,7 @@  discard block
 block discarded – undo
712 696
      *
713 697
      * @return bool If the change was accepted.
714 698
      */
715
-    public function addContentBefore($stackPtr, $content)
716
-    {
699
+    public function addContentBefore($stackPtr, $content) {
717 700
         $current = $this->getTokenContent($stackPtr);
718 701
         return $this->replaceToken($stackPtr, $content.$current);
719 702
 
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Reports/Cbf.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
      * its data should be counted in the grand totals.
30 30
      *
31 31
      * @param array                 $report      Prepared report data.
32
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
32
+     * @param File $phpcsFile   The file being reported on.
33 33
      * @param bool                  $showSources Show sources?
34 34
      * @param int                   $width       Maximum allowed line width.
35 35
      *
Please login to merge, or discard this patch.
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -21,229 +21,229 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * Generate a partial report for a single processed file.
26
-     *
27
-     * Function should return TRUE if it printed or stored data about the file
28
-     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
29
-     * its data should be counted in the grand totals.
30
-     *
31
-     * @param array                 $report      Prepared report data.
32
-     * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
33
-     * @param bool                  $showSources Show sources?
34
-     * @param int                   $width       Maximum allowed line width.
35
-     *
36
-     * @return bool
37
-     */
38
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
39
-    {
40
-        $errors = $phpcsFile->getFixableCount();
41
-        if ($errors !== 0) {
42
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
43
-                ob_end_clean();
44
-                $startTime = microtime(true);
45
-                echo "\t=> Fixing file: $errors/$errors violations remaining";
46
-            }
47
-
48
-            $fixed = $phpcsFile->fixer->fixFile();
49
-        }
50
-
51
-        if ($phpcsFile->config->stdin === true) {
52
-            // Replacing STDIN, so output current file to STDOUT
53
-            // even if nothing was fixed. Exit here because we
54
-            // can't process any more than 1 file in this setup.
55
-            $fixedContent = $phpcsFile->fixer->getContents();
56
-            throw new DeepExitException($fixedContent, 1);
57
-        }
58
-
59
-        if ($errors === 0) {
60
-            return false;
61
-        }
62
-
63
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
64
-            if ($fixed === false) {
65
-                echo 'ERROR';
66
-            } else {
67
-                echo 'DONE';
68
-            }
69
-
70
-            $timeTaken = ((microtime(true) - $startTime) * 1000);
71
-            if ($timeTaken < 1000) {
72
-                $timeTaken = round($timeTaken);
73
-                echo " in {$timeTaken}ms".PHP_EOL;
74
-            } else {
75
-                $timeTaken = round(($timeTaken / 1000), 2);
76
-                echo " in $timeTaken secs".PHP_EOL;
77
-            }
78
-        }
79
-
80
-        if ($fixed === true) {
81
-            // The filename in the report may be truncated due to a basepath setting
82
-            // but we are using it for writing here and not display,
83
-            // so find the correct path if basepath is in use.
84
-            $newFilename = $report['filename'].$phpcsFile->config->suffix;
85
-            if ($phpcsFile->config->basepath !== null) {
86
-                $newFilename = $phpcsFile->config->basepath.DIRECTORY_SEPARATOR.$newFilename;
87
-            }
88
-
89
-            $newContent = $phpcsFile->fixer->getContents();
90
-            file_put_contents($newFilename, $newContent);
91
-
92
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
93
-                if ($newFilename === $report['filename']) {
94
-                    echo "\t=> File was overwritten".PHP_EOL;
95
-                } else {
96
-                    echo "\t=> Fixed file written to ".basename($newFilename).PHP_EOL;
97
-                }
98
-            }
99
-        }
100
-
101
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
102
-            ob_start();
103
-        }
104
-
105
-        $errorCount   = $phpcsFile->getErrorCount();
106
-        $warningCount = $phpcsFile->getWarningCount();
107
-        $fixableCount = $phpcsFile->getFixableCount();
108
-        $fixedCount   = ($errors - $fixableCount);
109
-        echo $report['filename'].">>$errorCount>>$warningCount>>$fixableCount>>$fixedCount".PHP_EOL;
110
-
111
-        return $fixed;
112
-
113
-    }//end generateFileReport()
114
-
115
-
116
-    /**
117
-     * Prints a summary of fixed files.
118
-     *
119
-     * @param string $cachedData    Any partial report data that was returned from
120
-     *                              generateFileReport during the run.
121
-     * @param int    $totalFiles    Total number of files processed during the run.
122
-     * @param int    $totalErrors   Total number of errors found during the run.
123
-     * @param int    $totalWarnings Total number of warnings found during the run.
124
-     * @param int    $totalFixable  Total number of problems that can be fixed.
125
-     * @param bool   $showSources   Show sources?
126
-     * @param int    $width         Maximum allowed line width.
127
-     * @param bool   $interactive   Are we running in interactive mode?
128
-     * @param bool   $toScreen      Is the report being printed to screen?
129
-     *
130
-     * @return void
131
-     */
132
-    public function generate(
133
-        $cachedData,
134
-        $totalFiles,
135
-        $totalErrors,
136
-        $totalWarnings,
137
-        $totalFixable,
138
-        $showSources=false,
139
-        $width=80,
140
-        $interactive=false,
141
-        $toScreen=true
142
-    ) {
143
-        $lines = explode(PHP_EOL, $cachedData);
144
-        array_pop($lines);
145
-
146
-        if (empty($lines) === true) {
147
-            echo PHP_EOL.'No fixable errors were found'.PHP_EOL;
148
-            return;
149
-        }
150
-
151
-        $reportFiles = [];
152
-        $maxLength   = 0;
153
-        $totalFixed  = 0;
154
-        $failures    = 0;
155
-
156
-        foreach ($lines as $line) {
157
-            $parts   = explode('>>', $line);
158
-            $fileLen = strlen($parts[0]);
159
-            $reportFiles[$parts[0]] = [
160
-                'errors'   => $parts[1],
161
-                'warnings' => $parts[2],
162
-                'fixable'  => $parts[3],
163
-                'fixed'    => $parts[4],
164
-                'strlen'   => $fileLen,
165
-            ];
166
-
167
-            $maxLength = max($maxLength, $fileLen);
168
-
169
-            $totalFixed += $parts[4];
170
-
171
-            if ($parts[3] > 0) {
172
-                $failures++;
173
-            }
174
-        }
175
-
176
-        $width = min($width, ($maxLength + 21));
177
-        $width = max($width, 70);
178
-
179
-        echo PHP_EOL."\033[1m".'PHPCBF RESULT SUMMARY'."\033[0m".PHP_EOL;
180
-        echo str_repeat('-', $width).PHP_EOL;
181
-        echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'FIXED  REMAINING'."\033[0m".PHP_EOL;
182
-        echo str_repeat('-', $width).PHP_EOL;
183
-
184
-        foreach ($reportFiles as $file => $data) {
185
-            $padding = ($width - 18 - $data['strlen']);
186
-            if ($padding < 0) {
187
-                $file    = '...'.substr($file, (($padding * -1) + 3));
188
-                $padding = 0;
189
-            }
190
-
191
-            echo $file.str_repeat(' ', $padding).'  ';
192
-
193
-            if ($data['fixable'] > 0) {
194
-                echo "\033[31mFAILED TO FIX\033[0m".PHP_EOL;
195
-                continue;
196
-            }
197
-
198
-            $remaining = ($data['errors'] + $data['warnings']);
199
-
200
-            if ($data['fixed'] !== 0) {
201
-                echo $data['fixed'];
202
-                echo str_repeat(' ', (7 - strlen((string) $data['fixed'])));
203
-            } else {
204
-                echo '0      ';
205
-            }
206
-
207
-            if ($remaining !== 0) {
208
-                echo $remaining;
209
-            } else {
210
-                echo '0';
211
-            }
212
-
213
-            echo PHP_EOL;
214
-        }//end foreach
215
-
216
-        echo str_repeat('-', $width).PHP_EOL;
217
-        echo "\033[1mA TOTAL OF $totalFixed ERROR";
218
-        if ($totalFixed !== 1) {
219
-            echo 'S';
220
-        }
221
-
222
-        $numFiles = count($reportFiles);
223
-        echo ' WERE FIXED IN '.$numFiles.' FILE';
224
-        if ($numFiles !== 1) {
225
-            echo 'S';
226
-        }
227
-
228
-        echo "\033[0m";
229
-
230
-        if ($failures > 0) {
231
-            echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
232
-            echo "\033[1mPHPCBF FAILED TO FIX $failures FILE";
233
-            if ($failures !== 1) {
234
-                echo 'S';
235
-            }
236
-
237
-            echo "\033[0m";
238
-        }
239
-
240
-        echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
241
-
242
-        if ($toScreen === true && $interactive === false) {
243
-            Util\Timing::printRunTime();
244
-        }
245
-
246
-    }//end generate()
24
+	/**
25
+	 * Generate a partial report for a single processed file.
26
+	 *
27
+	 * Function should return TRUE if it printed or stored data about the file
28
+	 * and FALSE if it ignored the file. Returning TRUE indicates that the file and
29
+	 * its data should be counted in the grand totals.
30
+	 *
31
+	 * @param array                 $report      Prepared report data.
32
+	 * @param \PHP_CodeSniffer\File $phpcsFile   The file being reported on.
33
+	 * @param bool                  $showSources Show sources?
34
+	 * @param int                   $width       Maximum allowed line width.
35
+	 *
36
+	 * @return bool
37
+	 */
38
+	public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
39
+	{
40
+		$errors = $phpcsFile->getFixableCount();
41
+		if ($errors !== 0) {
42
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
43
+				ob_end_clean();
44
+				$startTime = microtime(true);
45
+				echo "\t=> Fixing file: $errors/$errors violations remaining";
46
+			}
47
+
48
+			$fixed = $phpcsFile->fixer->fixFile();
49
+		}
50
+
51
+		if ($phpcsFile->config->stdin === true) {
52
+			// Replacing STDIN, so output current file to STDOUT
53
+			// even if nothing was fixed. Exit here because we
54
+			// can't process any more than 1 file in this setup.
55
+			$fixedContent = $phpcsFile->fixer->getContents();
56
+			throw new DeepExitException($fixedContent, 1);
57
+		}
58
+
59
+		if ($errors === 0) {
60
+			return false;
61
+		}
62
+
63
+		if (PHP_CODESNIFFER_VERBOSITY > 0) {
64
+			if ($fixed === false) {
65
+				echo 'ERROR';
66
+			} else {
67
+				echo 'DONE';
68
+			}
69
+
70
+			$timeTaken = ((microtime(true) - $startTime) * 1000);
71
+			if ($timeTaken < 1000) {
72
+				$timeTaken = round($timeTaken);
73
+				echo " in {$timeTaken}ms".PHP_EOL;
74
+			} else {
75
+				$timeTaken = round(($timeTaken / 1000), 2);
76
+				echo " in $timeTaken secs".PHP_EOL;
77
+			}
78
+		}
79
+
80
+		if ($fixed === true) {
81
+			// The filename in the report may be truncated due to a basepath setting
82
+			// but we are using it for writing here and not display,
83
+			// so find the correct path if basepath is in use.
84
+			$newFilename = $report['filename'].$phpcsFile->config->suffix;
85
+			if ($phpcsFile->config->basepath !== null) {
86
+				$newFilename = $phpcsFile->config->basepath.DIRECTORY_SEPARATOR.$newFilename;
87
+			}
88
+
89
+			$newContent = $phpcsFile->fixer->getContents();
90
+			file_put_contents($newFilename, $newContent);
91
+
92
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
93
+				if ($newFilename === $report['filename']) {
94
+					echo "\t=> File was overwritten".PHP_EOL;
95
+				} else {
96
+					echo "\t=> Fixed file written to ".basename($newFilename).PHP_EOL;
97
+				}
98
+			}
99
+		}
100
+
101
+		if (PHP_CODESNIFFER_VERBOSITY > 0) {
102
+			ob_start();
103
+		}
104
+
105
+		$errorCount   = $phpcsFile->getErrorCount();
106
+		$warningCount = $phpcsFile->getWarningCount();
107
+		$fixableCount = $phpcsFile->getFixableCount();
108
+		$fixedCount   = ($errors - $fixableCount);
109
+		echo $report['filename'].">>$errorCount>>$warningCount>>$fixableCount>>$fixedCount".PHP_EOL;
110
+
111
+		return $fixed;
112
+
113
+	}//end generateFileReport()
114
+
115
+
116
+	/**
117
+	 * Prints a summary of fixed files.
118
+	 *
119
+	 * @param string $cachedData    Any partial report data that was returned from
120
+	 *                              generateFileReport during the run.
121
+	 * @param int    $totalFiles    Total number of files processed during the run.
122
+	 * @param int    $totalErrors   Total number of errors found during the run.
123
+	 * @param int    $totalWarnings Total number of warnings found during the run.
124
+	 * @param int    $totalFixable  Total number of problems that can be fixed.
125
+	 * @param bool   $showSources   Show sources?
126
+	 * @param int    $width         Maximum allowed line width.
127
+	 * @param bool   $interactive   Are we running in interactive mode?
128
+	 * @param bool   $toScreen      Is the report being printed to screen?
129
+	 *
130
+	 * @return void
131
+	 */
132
+	public function generate(
133
+		$cachedData,
134
+		$totalFiles,
135
+		$totalErrors,
136
+		$totalWarnings,
137
+		$totalFixable,
138
+		$showSources=false,
139
+		$width=80,
140
+		$interactive=false,
141
+		$toScreen=true
142
+	) {
143
+		$lines = explode(PHP_EOL, $cachedData);
144
+		array_pop($lines);
145
+
146
+		if (empty($lines) === true) {
147
+			echo PHP_EOL.'No fixable errors were found'.PHP_EOL;
148
+			return;
149
+		}
150
+
151
+		$reportFiles = [];
152
+		$maxLength   = 0;
153
+		$totalFixed  = 0;
154
+		$failures    = 0;
155
+
156
+		foreach ($lines as $line) {
157
+			$parts   = explode('>>', $line);
158
+			$fileLen = strlen($parts[0]);
159
+			$reportFiles[$parts[0]] = [
160
+				'errors'   => $parts[1],
161
+				'warnings' => $parts[2],
162
+				'fixable'  => $parts[3],
163
+				'fixed'    => $parts[4],
164
+				'strlen'   => $fileLen,
165
+			];
166
+
167
+			$maxLength = max($maxLength, $fileLen);
168
+
169
+			$totalFixed += $parts[4];
170
+
171
+			if ($parts[3] > 0) {
172
+				$failures++;
173
+			}
174
+		}
175
+
176
+		$width = min($width, ($maxLength + 21));
177
+		$width = max($width, 70);
178
+
179
+		echo PHP_EOL."\033[1m".'PHPCBF RESULT SUMMARY'."\033[0m".PHP_EOL;
180
+		echo str_repeat('-', $width).PHP_EOL;
181
+		echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'FIXED  REMAINING'."\033[0m".PHP_EOL;
182
+		echo str_repeat('-', $width).PHP_EOL;
183
+
184
+		foreach ($reportFiles as $file => $data) {
185
+			$padding = ($width - 18 - $data['strlen']);
186
+			if ($padding < 0) {
187
+				$file    = '...'.substr($file, (($padding * -1) + 3));
188
+				$padding = 0;
189
+			}
190
+
191
+			echo $file.str_repeat(' ', $padding).'  ';
192
+
193
+			if ($data['fixable'] > 0) {
194
+				echo "\033[31mFAILED TO FIX\033[0m".PHP_EOL;
195
+				continue;
196
+			}
197
+
198
+			$remaining = ($data['errors'] + $data['warnings']);
199
+
200
+			if ($data['fixed'] !== 0) {
201
+				echo $data['fixed'];
202
+				echo str_repeat(' ', (7 - strlen((string) $data['fixed'])));
203
+			} else {
204
+				echo '0      ';
205
+			}
206
+
207
+			if ($remaining !== 0) {
208
+				echo $remaining;
209
+			} else {
210
+				echo '0';
211
+			}
212
+
213
+			echo PHP_EOL;
214
+		}//end foreach
215
+
216
+		echo str_repeat('-', $width).PHP_EOL;
217
+		echo "\033[1mA TOTAL OF $totalFixed ERROR";
218
+		if ($totalFixed !== 1) {
219
+			echo 'S';
220
+		}
221
+
222
+		$numFiles = count($reportFiles);
223
+		echo ' WERE FIXED IN '.$numFiles.' FILE';
224
+		if ($numFiles !== 1) {
225
+			echo 'S';
226
+		}
227
+
228
+		echo "\033[0m";
229
+
230
+		if ($failures > 0) {
231
+			echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
232
+			echo "\033[1mPHPCBF FAILED TO FIX $failures FILE";
233
+			if ($failures !== 1) {
234
+				echo 'S';
235
+			}
236
+
237
+			echo "\033[0m";
238
+		}
239
+
240
+		echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
241
+
242
+		if ($toScreen === true && $interactive === false) {
243
+			Util\Timing::printRunTime();
244
+		}
245
+
246
+	}//end generate()
247 247
 
248 248
 
249 249
 }//end class
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -35,78 +35,78 @@  discard block
 block discarded – undo
35 35
      *
36 36
      * @return bool
37 37
      */
38
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
38
+    public function generateFileReport( $report, File $phpcsFile, $showSources = false, $width = 80 )
39 39
     {
40 40
         $errors = $phpcsFile->getFixableCount();
41
-        if ($errors !== 0) {
42
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
41
+        if ( $errors !== 0 ) {
42
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
43 43
                 ob_end_clean();
44
-                $startTime = microtime(true);
44
+                $startTime = microtime( true );
45 45
                 echo "\t=> Fixing file: $errors/$errors violations remaining";
46 46
             }
47 47
 
48 48
             $fixed = $phpcsFile->fixer->fixFile();
49 49
         }
50 50
 
51
-        if ($phpcsFile->config->stdin === true) {
51
+        if ( $phpcsFile->config->stdin === true ) {
52 52
             // Replacing STDIN, so output current file to STDOUT
53 53
             // even if nothing was fixed. Exit here because we
54 54
             // can't process any more than 1 file in this setup.
55 55
             $fixedContent = $phpcsFile->fixer->getContents();
56
-            throw new DeepExitException($fixedContent, 1);
56
+            throw new DeepExitException( $fixedContent, 1 );
57 57
         }
58 58
 
59
-        if ($errors === 0) {
59
+        if ( $errors === 0 ) {
60 60
             return false;
61 61
         }
62 62
 
63
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
64
-            if ($fixed === false) {
63
+        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
64
+            if ( $fixed === false ) {
65 65
                 echo 'ERROR';
66 66
             } else {
67 67
                 echo 'DONE';
68 68
             }
69 69
 
70
-            $timeTaken = ((microtime(true) - $startTime) * 1000);
71
-            if ($timeTaken < 1000) {
72
-                $timeTaken = round($timeTaken);
73
-                echo " in {$timeTaken}ms".PHP_EOL;
70
+            $timeTaken = ( ( microtime( true ) - $startTime ) * 1000 );
71
+            if ( $timeTaken < 1000 ) {
72
+                $timeTaken = round( $timeTaken );
73
+                echo " in {$timeTaken}ms" . PHP_EOL;
74 74
             } else {
75
-                $timeTaken = round(($timeTaken / 1000), 2);
76
-                echo " in $timeTaken secs".PHP_EOL;
75
+                $timeTaken = round( ( $timeTaken / 1000 ), 2 );
76
+                echo " in $timeTaken secs" . PHP_EOL;
77 77
             }
78 78
         }
79 79
 
80
-        if ($fixed === true) {
80
+        if ( $fixed === true ) {
81 81
             // The filename in the report may be truncated due to a basepath setting
82 82
             // but we are using it for writing here and not display,
83 83
             // so find the correct path if basepath is in use.
84
-            $newFilename = $report['filename'].$phpcsFile->config->suffix;
85
-            if ($phpcsFile->config->basepath !== null) {
86
-                $newFilename = $phpcsFile->config->basepath.DIRECTORY_SEPARATOR.$newFilename;
84
+            $newFilename = $report[ 'filename' ] . $phpcsFile->config->suffix;
85
+            if ( $phpcsFile->config->basepath !== null ) {
86
+                $newFilename = $phpcsFile->config->basepath . DIRECTORY_SEPARATOR . $newFilename;
87 87
             }
88 88
 
89 89
             $newContent = $phpcsFile->fixer->getContents();
90
-            file_put_contents($newFilename, $newContent);
90
+            file_put_contents( $newFilename, $newContent );
91 91
 
92
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
93
-                if ($newFilename === $report['filename']) {
94
-                    echo "\t=> File was overwritten".PHP_EOL;
92
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
93
+                if ( $newFilename === $report[ 'filename' ] ) {
94
+                    echo "\t=> File was overwritten" . PHP_EOL;
95 95
                 } else {
96
-                    echo "\t=> Fixed file written to ".basename($newFilename).PHP_EOL;
96
+                    echo "\t=> Fixed file written to " . basename( $newFilename ) . PHP_EOL;
97 97
                 }
98 98
             }
99 99
         }
100 100
 
101
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
101
+        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
102 102
             ob_start();
103 103
         }
104 104
 
105 105
         $errorCount   = $phpcsFile->getErrorCount();
106 106
         $warningCount = $phpcsFile->getWarningCount();
107 107
         $fixableCount = $phpcsFile->getFixableCount();
108
-        $fixedCount   = ($errors - $fixableCount);
109
-        echo $report['filename'].">>$errorCount>>$warningCount>>$fixableCount>>$fixedCount".PHP_EOL;
108
+        $fixedCount   = ( $errors - $fixableCount );
109
+        echo $report[ 'filename' ] . ">>$errorCount>>$warningCount>>$fixableCount>>$fixedCount" . PHP_EOL;
110 110
 
111 111
         return $fixed;
112 112
 
@@ -135,76 +135,76 @@  discard block
 block discarded – undo
135 135
         $totalErrors,
136 136
         $totalWarnings,
137 137
         $totalFixable,
138
-        $showSources=false,
139
-        $width=80,
140
-        $interactive=false,
141
-        $toScreen=true
138
+        $showSources = false,
139
+        $width = 80,
140
+        $interactive = false,
141
+        $toScreen = true
142 142
     ) {
143
-        $lines = explode(PHP_EOL, $cachedData);
144
-        array_pop($lines);
143
+        $lines = explode( PHP_EOL, $cachedData );
144
+        array_pop( $lines );
145 145
 
146
-        if (empty($lines) === true) {
147
-            echo PHP_EOL.'No fixable errors were found'.PHP_EOL;
146
+        if ( empty( $lines ) === true ) {
147
+            echo PHP_EOL . 'No fixable errors were found' . PHP_EOL;
148 148
             return;
149 149
         }
150 150
 
151
-        $reportFiles = [];
151
+        $reportFiles = [ ];
152 152
         $maxLength   = 0;
153 153
         $totalFixed  = 0;
154 154
         $failures    = 0;
155 155
 
156
-        foreach ($lines as $line) {
157
-            $parts   = explode('>>', $line);
158
-            $fileLen = strlen($parts[0]);
159
-            $reportFiles[$parts[0]] = [
160
-                'errors'   => $parts[1],
161
-                'warnings' => $parts[2],
162
-                'fixable'  => $parts[3],
163
-                'fixed'    => $parts[4],
156
+        foreach ( $lines as $line ) {
157
+            $parts   = explode( '>>', $line );
158
+            $fileLen = strlen( $parts[ 0 ] );
159
+            $reportFiles[ $parts[ 0 ] ] = [
160
+                'errors'   => $parts[ 1 ],
161
+                'warnings' => $parts[ 2 ],
162
+                'fixable'  => $parts[ 3 ],
163
+                'fixed'    => $parts[ 4 ],
164 164
                 'strlen'   => $fileLen,
165 165
             ];
166 166
 
167
-            $maxLength = max($maxLength, $fileLen);
167
+            $maxLength = max( $maxLength, $fileLen );
168 168
 
169
-            $totalFixed += $parts[4];
169
+            $totalFixed += $parts[ 4 ];
170 170
 
171
-            if ($parts[3] > 0) {
171
+            if ( $parts[ 3 ] > 0 ) {
172 172
                 $failures++;
173 173
             }
174 174
         }
175 175
 
176
-        $width = min($width, ($maxLength + 21));
177
-        $width = max($width, 70);
176
+        $width = min( $width, ( $maxLength + 21 ) );
177
+        $width = max( $width, 70 );
178 178
 
179
-        echo PHP_EOL."\033[1m".'PHPCBF RESULT SUMMARY'."\033[0m".PHP_EOL;
180
-        echo str_repeat('-', $width).PHP_EOL;
181
-        echo "\033[1m".'FILE'.str_repeat(' ', ($width - 20)).'FIXED  REMAINING'."\033[0m".PHP_EOL;
182
-        echo str_repeat('-', $width).PHP_EOL;
179
+        echo PHP_EOL . "\033[1m" . 'PHPCBF RESULT SUMMARY' . "\033[0m" . PHP_EOL;
180
+        echo str_repeat( '-', $width ) . PHP_EOL;
181
+        echo "\033[1m" . 'FILE' . str_repeat( ' ', ( $width - 20 ) ) . 'FIXED  REMAINING' . "\033[0m" . PHP_EOL;
182
+        echo str_repeat( '-', $width ) . PHP_EOL;
183 183
 
184
-        foreach ($reportFiles as $file => $data) {
185
-            $padding = ($width - 18 - $data['strlen']);
186
-            if ($padding < 0) {
187
-                $file    = '...'.substr($file, (($padding * -1) + 3));
184
+        foreach ( $reportFiles as $file => $data ) {
185
+            $padding = ( $width - 18 - $data[ 'strlen' ] );
186
+            if ( $padding < 0 ) {
187
+                $file    = '...' . substr( $file, ( ( $padding * -1 ) + 3 ) );
188 188
                 $padding = 0;
189 189
             }
190 190
 
191
-            echo $file.str_repeat(' ', $padding).'  ';
191
+            echo $file . str_repeat( ' ', $padding ) . '  ';
192 192
 
193
-            if ($data['fixable'] > 0) {
194
-                echo "\033[31mFAILED TO FIX\033[0m".PHP_EOL;
193
+            if ( $data[ 'fixable' ] > 0 ) {
194
+                echo "\033[31mFAILED TO FIX\033[0m" . PHP_EOL;
195 195
                 continue;
196 196
             }
197 197
 
198
-            $remaining = ($data['errors'] + $data['warnings']);
198
+            $remaining = ( $data[ 'errors' ] + $data[ 'warnings' ] );
199 199
 
200
-            if ($data['fixed'] !== 0) {
201
-                echo $data['fixed'];
202
-                echo str_repeat(' ', (7 - strlen((string) $data['fixed'])));
200
+            if ( $data[ 'fixed' ] !== 0 ) {
201
+                echo $data[ 'fixed' ];
202
+                echo str_repeat( ' ', ( 7 - strlen( (string)$data[ 'fixed' ] ) ) );
203 203
             } else {
204 204
                 echo '0      ';
205 205
             }
206 206
 
207
-            if ($remaining !== 0) {
207
+            if ( $remaining !== 0 ) {
208 208
                 echo $remaining;
209 209
             } else {
210 210
                 echo '0';
@@ -213,33 +213,33 @@  discard block
 block discarded – undo
213 213
             echo PHP_EOL;
214 214
         }//end foreach
215 215
 
216
-        echo str_repeat('-', $width).PHP_EOL;
216
+        echo str_repeat( '-', $width ) . PHP_EOL;
217 217
         echo "\033[1mA TOTAL OF $totalFixed ERROR";
218
-        if ($totalFixed !== 1) {
218
+        if ( $totalFixed !== 1 ) {
219 219
             echo 'S';
220 220
         }
221 221
 
222
-        $numFiles = count($reportFiles);
223
-        echo ' WERE FIXED IN '.$numFiles.' FILE';
224
-        if ($numFiles !== 1) {
222
+        $numFiles = count( $reportFiles );
223
+        echo ' WERE FIXED IN ' . $numFiles . ' FILE';
224
+        if ( $numFiles !== 1 ) {
225 225
             echo 'S';
226 226
         }
227 227
 
228 228
         echo "\033[0m";
229 229
 
230
-        if ($failures > 0) {
231
-            echo PHP_EOL.str_repeat('-', $width).PHP_EOL;
230
+        if ( $failures > 0 ) {
231
+            echo PHP_EOL . str_repeat( '-', $width ) . PHP_EOL;
232 232
             echo "\033[1mPHPCBF FAILED TO FIX $failures FILE";
233
-            if ($failures !== 1) {
233
+            if ( $failures !== 1 ) {
234 234
                 echo 'S';
235 235
             }
236 236
 
237 237
             echo "\033[0m";
238 238
         }
239 239
 
240
-        echo PHP_EOL.str_repeat('-', $width).PHP_EOL.PHP_EOL;
240
+        echo PHP_EOL . str_repeat( '-', $width ) . PHP_EOL . PHP_EOL;
241 241
 
242
-        if ($toScreen === true && $interactive === false) {
242
+        if ( $toScreen === true && $interactive === false ) {
243 243
             Util\Timing::printRunTime();
244 244
         }
245 245
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
 use PHP_CodeSniffer\Files\File;
18 18
 use PHP_CodeSniffer\Util;
19 19
 
20
-class Cbf implements Report
21
-{
20
+class Cbf implements Report {
22 21
 
23 22
 
24 23
     /**
@@ -35,8 +34,7 @@  discard block
 block discarded – undo
35 34
      *
36 35
      * @return bool
37 36
      */
38
-    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
39
-    {
37
+    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80) {
40 38
         $errors = $phpcsFile->getFixableCount();
41 39
         if ($errors !== 0) {
42 40
             if (PHP_CODESNIFFER_VERBOSITY > 0) {
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Runner.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
      * @param string $file    The path of the file that raised the error.
594 594
      * @param int    $line    The line number the error was raised at.
595 595
      *
596
-     * @return void
596
+     * @return boolean
597 597
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
598 598
      */
599 599
     public function handleErrors($code, $message, $file, $line)
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
      *
709 709
      * @param array $childProcs An array of child processes to wait for.
710 710
      *
711
-     * @return void
711
+     * @return boolean
712 712
      */
713 713
     private function processChildProcs($childProcs)
714 714
     {
Please login to merge, or discard this patch.
Indentation   +853 added lines, -853 removed lines patch added patch discarded remove patch
@@ -24,863 +24,863 @@
 block discarded – undo
24 24
 class Runner
25 25
 {
26 26
 
27
-    /**
28
-     * The config data for the run.
29
-     *
30
-     * @var \PHP_CodeSniffer\Config
31
-     */
32
-    public $config = null;
33
-
34
-    /**
35
-     * The ruleset used for the run.
36
-     *
37
-     * @var \PHP_CodeSniffer\Ruleset
38
-     */
39
-    public $ruleset = null;
40
-
41
-    /**
42
-     * The reporter used for generating reports after the run.
43
-     *
44
-     * @var \PHP_CodeSniffer\Reporter
45
-     */
46
-    public $reporter = null;
47
-
48
-
49
-    /**
50
-     * Run the PHPCS script.
51
-     *
52
-     * @return array
53
-     */
54
-    public function runPHPCS()
55
-    {
56
-        try {
57
-            Util\Timing::startTiming();
58
-            Runner::checkRequirements();
59
-
60
-            if (defined('PHP_CODESNIFFER_CBF') === false) {
61
-                define('PHP_CODESNIFFER_CBF', false);
62
-            }
63
-
64
-            // Creating the Config object populates it with all required settings
65
-            // based on the CLI arguments provided to the script and any config
66
-            // values the user has set.
67
-            $this->config = new Config();
68
-
69
-            // Init the run and load the rulesets to set additional config vars.
70
-            $this->init();
71
-
72
-            // Print a list of sniffs in each of the supplied standards.
73
-            // We fudge the config here so that each standard is explained in isolation.
74
-            if ($this->config->explain === true) {
75
-                $standards = $this->config->standards;
76
-                foreach ($standards as $standard) {
77
-                    $this->config->standards = [$standard];
78
-                    $ruleset = new Ruleset($this->config);
79
-                    $ruleset->explain();
80
-                }
81
-
82
-                return 0;
83
-            }
84
-
85
-            // Generate documentation for each of the supplied standards.
86
-            if ($this->config->generator !== null) {
87
-                $standards = $this->config->standards;
88
-                foreach ($standards as $standard) {
89
-                    $this->config->standards = [$standard];
90
-                    $ruleset   = new Ruleset($this->config);
91
-                    $class     = 'PHP_CodeSniffer\Generators\\'.$this->config->generator;
92
-                    $generator = new $class($ruleset);
93
-                    $generator->generate();
94
-                }
95
-
96
-                return 0;
97
-            }
98
-
99
-            // Other report formats don't really make sense in interactive mode
100
-            // so we hard-code the full report here and when outputting.
101
-            // We also ensure parallel processing is off because we need to do one file at a time.
102
-            if ($this->config->interactive === true) {
103
-                $this->config->reports      = ['full' => null];
104
-                $this->config->parallel     = 1;
105
-                $this->config->showProgress = false;
106
-            }
107
-
108
-            // Disable caching if we are processing STDIN as we can't be 100%
109
-            // sure where the file came from or if it will change in the future.
110
-            if ($this->config->stdin === true) {
111
-                $this->config->cache = false;
112
-            }
113
-
114
-            $numErrors = $this->run();
115
-
116
-            // Print all the reports for this run.
117
-            $toScreen = $this->reporter->printReports();
118
-
119
-            // Only print timer output if no reports were
120
-            // printed to the screen so we don't put additional output
121
-            // in something like an XML report. If we are printing to screen,
122
-            // the report types would have already worked out who should
123
-            // print the timer info.
124
-            if ($this->config->interactive === false
125
-                && ($toScreen === false
126
-                || (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true))
127
-            ) {
128
-                Util\Timing::printRunTime();
129
-            }
130
-        } catch (DeepExitException $e) {
131
-            echo $e->getMessage();
132
-            return $e->getCode();
133
-        }//end try
134
-
135
-        if ($numErrors === 0) {
136
-            // No errors found.
137
-            return 0;
138
-        } else if ($this->reporter->totalFixable === 0) {
139
-            // Errors found, but none of them can be fixed by PHPCBF.
140
-            return 1;
141
-        } else {
142
-            // Errors found, and some can be fixed by PHPCBF.
143
-            return 2;
144
-        }
145
-
146
-    }//end runPHPCS()
147
-
148
-
149
-    /**
150
-     * Run the PHPCBF script.
151
-     *
152
-     * @return array
153
-     */
154
-    public function runPHPCBF()
155
-    {
156
-        if (defined('PHP_CODESNIFFER_CBF') === false) {
157
-            define('PHP_CODESNIFFER_CBF', true);
158
-        }
159
-
160
-        try {
161
-            Util\Timing::startTiming();
162
-            Runner::checkRequirements();
163
-
164
-            // Creating the Config object populates it with all required settings
165
-            // based on the CLI arguments provided to the script and any config
166
-            // values the user has set.
167
-            $this->config = new Config();
168
-
169
-            // When processing STDIN, we can't output anything to the screen
170
-            // or it will end up mixed in with the file output.
171
-            if ($this->config->stdin === true) {
172
-                $this->config->verbosity = 0;
173
-            }
174
-
175
-            // Init the run and load the rulesets to set additional config vars.
176
-            $this->init();
177
-
178
-            // When processing STDIN, we only process one file at a time and
179
-            // we don't process all the way through, so we can't use the parallel
180
-            // running system.
181
-            if ($this->config->stdin === true) {
182
-                $this->config->parallel = 1;
183
-            }
184
-
185
-            // Override some of the command line settings that might break the fixes.
186
-            $this->config->generator    = null;
187
-            $this->config->explain      = false;
188
-            $this->config->interactive  = false;
189
-            $this->config->cache        = false;
190
-            $this->config->showSources  = false;
191
-            $this->config->recordErrors = false;
192
-            $this->config->reportFile   = null;
193
-            $this->config->reports      = ['cbf' => null];
194
-
195
-            // If a standard tries to set command line arguments itself, some
196
-            // may be blocked because PHPCBF is running, so stop the script
197
-            // dying if any are found.
198
-            $this->config->dieOnUnknownArg = false;
199
-
200
-            $this->run();
201
-            $this->reporter->printReports();
202
-
203
-            echo PHP_EOL;
204
-            Util\Timing::printRunTime();
205
-        } catch (DeepExitException $e) {
206
-            echo $e->getMessage();
207
-            return $e->getCode();
208
-        }//end try
209
-
210
-        if ($this->reporter->totalFixed === 0) {
211
-            // Nothing was fixed by PHPCBF.
212
-            if ($this->reporter->totalFixable === 0) {
213
-                // Nothing found that could be fixed.
214
-                return 0;
215
-            } else {
216
-                // Something failed to fix.
217
-                return 2;
218
-            }
219
-        }
220
-
221
-        if ($this->reporter->totalFixable === 0) {
222
-            // PHPCBF fixed all fixable errors.
223
-            return 1;
224
-        }
225
-
226
-        // PHPCBF fixed some fixable errors, but others failed to fix.
227
-        return 2;
228
-
229
-    }//end runPHPCBF()
230
-
231
-
232
-    /**
233
-     * Exits if the minimum requirements of PHP_CodeSniffer are not met.
234
-     *
235
-     * @return array
236
-     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
237
-     */
238
-    public function checkRequirements()
239
-    {
240
-        // Check the PHP version.
241
-        if (PHP_VERSION_ID < 50400) {
242
-            $error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
243
-            throw new DeepExitException($error, 3);
244
-        }
245
-
246
-        $requiredExtensions = [
247
-            'tokenizer',
248
-            'xmlwriter',
249
-            'SimpleXML',
250
-        ];
251
-        $missingExtensions  = [];
252
-
253
-        foreach ($requiredExtensions as $extension) {
254
-            if (extension_loaded($extension) === false) {
255
-                $missingExtensions[] = $extension;
256
-            }
257
-        }
258
-
259
-        if (empty($missingExtensions) === false) {
260
-            $last      = array_pop($requiredExtensions);
261
-            $required  = implode(', ', $requiredExtensions);
262
-            $required .= ' and '.$last;
263
-
264
-            if (count($missingExtensions) === 1) {
265
-                $missing = $missingExtensions[0];
266
-            } else {
267
-                $last     = array_pop($missingExtensions);
268
-                $missing  = implode(', ', $missingExtensions);
269
-                $missing .= ' and '.$last;
270
-            }
271
-
272
-            $error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.'.PHP_EOL;
273
-            $error = sprintf($error, $required, $missing);
274
-            throw new DeepExitException($error, 3);
275
-        }
276
-
277
-    }//end checkRequirements()
278
-
279
-
280
-    /**
281
-     * Init the rulesets and other high-level settings.
282
-     *
283
-     * @return void
284
-     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
285
-     */
286
-    public function init()
287
-    {
288
-        if (defined('PHP_CODESNIFFER_CBF') === false) {
289
-            define('PHP_CODESNIFFER_CBF', false);
290
-        }
291
-
292
-        // Ensure this option is enabled or else line endings will not always
293
-        // be detected properly for files created on a Mac with the /r line ending.
294
-        ini_set('auto_detect_line_endings', true);
295
-
296
-        // Disable the PCRE JIT as this caused issues with parallel running.
297
-        ini_set('pcre.jit', false);
298
-
299
-        // Check that the standards are valid.
300
-        foreach ($this->config->standards as $standard) {
301
-            if (Util\Standards::isInstalledStandard($standard) === false) {
302
-                // They didn't select a valid coding standard, so help them
303
-                // out by letting them know which standards are installed.
304
-                $error = 'ERROR: the "'.$standard.'" coding standard is not installed. ';
305
-                ob_start();
306
-                Util\Standards::printInstalledStandards();
307
-                $error .= ob_get_contents();
308
-                ob_end_clean();
309
-                throw new DeepExitException($error, 3);
310
-            }
311
-        }
312
-
313
-        // Saves passing the Config object into other objects that only need
314
-        // the verbosity flag for debug output.
315
-        if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
316
-            define('PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity);
317
-        }
318
-
319
-        // Create this class so it is autoloaded and sets up a bunch
320
-        // of PHP_CodeSniffer-specific token type constants.
321
-        $tokens = new Util\Tokens();
322
-
323
-        // Allow autoloading of custom files inside installed standards.
324
-        $installedStandards = Standards::getInstalledStandardDetails();
325
-        foreach ($installedStandards as $name => $details) {
326
-            Autoload::addSearchPath($details['path'], $details['namespace']);
327
-        }
328
-
329
-        // The ruleset contains all the information about how the files
330
-        // should be checked and/or fixed.
331
-        try {
332
-            $this->ruleset = new Ruleset($this->config);
333
-        } catch (RuntimeException $e) {
334
-            $error  = 'ERROR: '.$e->getMessage().PHP_EOL.PHP_EOL;
335
-            $error .= $this->config->printShortUsage(true);
336
-            throw new DeepExitException($error, 3);
337
-        }
338
-
339
-    }//end init()
340
-
341
-
342
-    /**
343
-     * Performs the run.
344
-     *
345
-     * @return int The number of errors and warnings found.
346
-     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
347
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
348
-     */
349
-    private function run()
350
-    {
351
-        // The class that manages all reporters for the run.
352
-        $this->reporter = new Reporter($this->config);
353
-
354
-        // Include bootstrap files.
355
-        foreach ($this->config->bootstrap as $bootstrap) {
356
-            include $bootstrap;
357
-        }
358
-
359
-        if ($this->config->stdin === true) {
360
-            $fileContents = $this->config->stdinContent;
361
-            if ($fileContents === null) {
362
-                $handle = fopen('php://stdin', 'r');
363
-                stream_set_blocking($handle, true);
364
-                $fileContents = stream_get_contents($handle);
365
-                fclose($handle);
366
-            }
367
-
368
-            $todo  = new FileList($this->config, $this->ruleset);
369
-            $dummy = new DummyFile($fileContents, $this->ruleset, $this->config);
370
-            $todo->addFile($dummy->path, $dummy);
371
-        } else {
372
-            if (empty($this->config->files) === true) {
373
-                $error  = 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
374
-                $error .= $this->config->printShortUsage(true);
375
-                throw new DeepExitException($error, 3);
376
-            }
377
-
378
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
379
-                echo 'Creating file list... ';
380
-            }
381
-
382
-            $todo = new FileList($this->config, $this->ruleset);
383
-
384
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
385
-                $numFiles = count($todo);
386
-                echo "DONE ($numFiles files in queue)".PHP_EOL;
387
-            }
388
-
389
-            if ($this->config->cache === true) {
390
-                if (PHP_CODESNIFFER_VERBOSITY > 0) {
391
-                    echo 'Loading cache... ';
392
-                }
393
-
394
-                Cache::load($this->ruleset, $this->config);
395
-
396
-                if (PHP_CODESNIFFER_VERBOSITY > 0) {
397
-                    $size = Cache::getSize();
398
-                    echo "DONE ($size files in cache)".PHP_EOL;
399
-                }
400
-            }
401
-        }//end if
402
-
403
-        // Turn all sniff errors into exceptions.
404
-        set_error_handler([$this, 'handleErrors']);
405
-
406
-        // If verbosity is too high, turn off parallelism so the
407
-        // debug output is clean.
408
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
409
-            $this->config->parallel = 1;
410
-        }
411
-
412
-        // If the PCNTL extension isn't installed, we can't fork.
413
-        if (function_exists('pcntl_fork') === false) {
414
-            $this->config->parallel = 1;
415
-        }
416
-
417
-        $lastDir  = '';
418
-        $numFiles = count($todo);
419
-
420
-        if ($this->config->parallel === 1) {
421
-            // Running normally.
422
-            $numProcessed = 0;
423
-            foreach ($todo as $path => $file) {
424
-                if ($file->ignored === false) {
425
-                    $currDir = dirname($path);
426
-                    if ($lastDir !== $currDir) {
427
-                        if (PHP_CODESNIFFER_VERBOSITY > 0) {
428
-                            echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
429
-                        }
430
-
431
-                        $lastDir = $currDir;
432
-                    }
433
-
434
-                    $this->processFile($file);
435
-                } else if (PHP_CODESNIFFER_VERBOSITY > 0) {
436
-                    echo 'Skipping '.basename($file->path).PHP_EOL;
437
-                }
438
-
439
-                $numProcessed++;
440
-                $this->printProgress($file, $numFiles, $numProcessed);
441
-            }
442
-        } else {
443
-            // Batching and forking.
444
-            $childProcs  = [];
445
-            $numPerBatch = ceil($numFiles / $this->config->parallel);
446
-
447
-            for ($batch = 0; $batch < $this->config->parallel; $batch++) {
448
-                $startAt = ($batch * $numPerBatch);
449
-                if ($startAt >= $numFiles) {
450
-                    break;
451
-                }
452
-
453
-                $endAt = ($startAt + $numPerBatch);
454
-                if ($endAt > $numFiles) {
455
-                    $endAt = $numFiles;
456
-                }
457
-
458
-                $childOutFilename = tempnam(sys_get_temp_dir(), 'phpcs-child');
459
-                $pid = pcntl_fork();
460
-                if ($pid === -1) {
461
-                    throw new RuntimeException('Failed to create child process');
462
-                } else if ($pid !== 0) {
463
-                    $childProcs[] = [
464
-                        'pid' => $pid,
465
-                        'out' => $childOutFilename,
466
-                    ];
467
-                } else {
468
-                    // Move forward to the start of the batch.
469
-                    $todo->rewind();
470
-                    for ($i = 0; $i < $startAt; $i++) {
471
-                        $todo->next();
472
-                    }
473
-
474
-                    // Reset the reporter to make sure only figures from this
475
-                    // file batch are recorded.
476
-                    $this->reporter->totalFiles    = 0;
477
-                    $this->reporter->totalErrors   = 0;
478
-                    $this->reporter->totalWarnings = 0;
479
-                    $this->reporter->totalFixable  = 0;
480
-                    $this->reporter->totalFixed    = 0;
481
-
482
-                    // Process the files.
483
-                    $pathsProcessed = [];
484
-                    ob_start();
485
-                    for ($i = $startAt; $i < $endAt; $i++) {
486
-                        $path = $todo->key();
487
-                        $file = $todo->current();
488
-
489
-                        if ($file->ignored === true) {
490
-                            continue;
491
-                        }
492
-
493
-                        $currDir = dirname($path);
494
-                        if ($lastDir !== $currDir) {
495
-                            if (PHP_CODESNIFFER_VERBOSITY > 0) {
496
-                                echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
497
-                            }
498
-
499
-                            $lastDir = $currDir;
500
-                        }
501
-
502
-                        $this->processFile($file);
503
-
504
-                        $pathsProcessed[] = $path;
505
-                        $todo->next();
506
-                    }//end for
507
-
508
-                    $debugOutput = ob_get_contents();
509
-                    ob_end_clean();
510
-
511
-                    // Write information about the run to the filesystem
512
-                    // so it can be picked up by the main process.
513
-                    $childOutput = [
514
-                        'totalFiles'    => $this->reporter->totalFiles,
515
-                        'totalErrors'   => $this->reporter->totalErrors,
516
-                        'totalWarnings' => $this->reporter->totalWarnings,
517
-                        'totalFixable'  => $this->reporter->totalFixable,
518
-                        'totalFixed'    => $this->reporter->totalFixed,
519
-                    ];
520
-
521
-                    $output  = '<'.'?php'."\n".' $childOutput = ';
522
-                    $output .= var_export($childOutput, true);
523
-                    $output .= ";\n\$debugOutput = ";
524
-                    $output .= var_export($debugOutput, true);
525
-
526
-                    if ($this->config->cache === true) {
527
-                        $childCache = [];
528
-                        foreach ($pathsProcessed as $path) {
529
-                            $childCache[$path] = Cache::get($path);
530
-                        }
531
-
532
-                        $output .= ";\n\$childCache = ";
533
-                        $output .= var_export($childCache, true);
534
-                    }
535
-
536
-                    $output .= ";\n?".'>';
537
-                    file_put_contents($childOutFilename, $output);
538
-                    exit($pid);
539
-                }//end if
540
-            }//end for
541
-
542
-            $success = $this->processChildProcs($childProcs);
543
-            if ($success === false) {
544
-                throw new RuntimeException('One or more child processes failed to run');
545
-            }
546
-        }//end if
547
-
548
-        restore_error_handler();
549
-
550
-        if (PHP_CODESNIFFER_VERBOSITY === 0
551
-            && $this->config->interactive === false
552
-            && $this->config->showProgress === true
553
-        ) {
554
-            echo PHP_EOL.PHP_EOL;
555
-        }
556
-
557
-        if ($this->config->cache === true) {
558
-            Cache::save();
559
-        }
560
-
561
-        $ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit');
562
-        $ignoreErrors   = Config::getConfigData('ignore_errors_on_exit');
563
-
564
-        $return = ($this->reporter->totalErrors + $this->reporter->totalWarnings);
565
-        if ($ignoreErrors !== null) {
566
-            $ignoreErrors = (bool) $ignoreErrors;
567
-            if ($ignoreErrors === true) {
568
-                $return -= $this->reporter->totalErrors;
569
-            }
570
-        }
571
-
572
-        if ($ignoreWarnings !== null) {
573
-            $ignoreWarnings = (bool) $ignoreWarnings;
574
-            if ($ignoreWarnings === true) {
575
-                $return -= $this->reporter->totalWarnings;
576
-            }
577
-        }
578
-
579
-        return $return;
580
-
581
-    }//end run()
582
-
583
-
584
-    /**
585
-     * Converts all PHP errors into exceptions.
586
-     *
587
-     * This method forces a sniff to stop processing if it is not
588
-     * able to handle a specific piece of code, instead of continuing
589
-     * and potentially getting into a loop.
590
-     *
591
-     * @param int    $code    The level of error raised.
592
-     * @param string $message The error message.
593
-     * @param string $file    The path of the file that raised the error.
594
-     * @param int    $line    The line number the error was raised at.
595
-     *
596
-     * @return void
597
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
598
-     */
599
-    public function handleErrors($code, $message, $file, $line)
600
-    {
601
-        if ((error_reporting() & $code) === 0) {
602
-            // This type of error is being muted.
603
-            return true;
604
-        }
605
-
606
-        throw new RuntimeException("$message in $file on line $line");
607
-
608
-    }//end handleErrors()
609
-
610
-
611
-    /**
612
-     * Processes a single file, including checking and fixing.
613
-     *
614
-     * @param \PHP_CodeSniffer\Files\File $file The file to be processed.
615
-     *
616
-     * @return void
617
-     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
618
-     */
619
-    public function processFile($file)
620
-    {
621
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
622
-            $startTime = microtime(true);
623
-            echo 'Processing '.basename($file->path).' ';
624
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
625
-                echo PHP_EOL;
626
-            }
627
-        }
628
-
629
-        try {
630
-            $file->process();
631
-
632
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
633
-                $timeTaken = ((microtime(true) - $startTime) * 1000);
634
-                if ($timeTaken < 1000) {
635
-                    $timeTaken = round($timeTaken);
636
-                    echo "DONE in {$timeTaken}ms";
637
-                } else {
638
-                    $timeTaken = round(($timeTaken / 1000), 2);
639
-                    echo "DONE in $timeTaken secs";
640
-                }
641
-
642
-                if (PHP_CODESNIFFER_CBF === true) {
643
-                    $errors = $file->getFixableCount();
644
-                    echo " ($errors fixable violations)".PHP_EOL;
645
-                } else {
646
-                    $errors   = $file->getErrorCount();
647
-                    $warnings = $file->getWarningCount();
648
-                    echo " ($errors errors, $warnings warnings)".PHP_EOL;
649
-                }
650
-            }
651
-        } catch (\Exception $e) {
652
-            $error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
653
-            $file->addErrorOnLine($error, 1, 'Internal.Exception');
654
-        }//end try
655
-
656
-        $this->reporter->cacheFileReport($file, $this->config);
657
-
658
-        if ($this->config->interactive === true) {
659
-            /*
27
+	/**
28
+	 * The config data for the run.
29
+	 *
30
+	 * @var \PHP_CodeSniffer\Config
31
+	 */
32
+	public $config = null;
33
+
34
+	/**
35
+	 * The ruleset used for the run.
36
+	 *
37
+	 * @var \PHP_CodeSniffer\Ruleset
38
+	 */
39
+	public $ruleset = null;
40
+
41
+	/**
42
+	 * The reporter used for generating reports after the run.
43
+	 *
44
+	 * @var \PHP_CodeSniffer\Reporter
45
+	 */
46
+	public $reporter = null;
47
+
48
+
49
+	/**
50
+	 * Run the PHPCS script.
51
+	 *
52
+	 * @return array
53
+	 */
54
+	public function runPHPCS()
55
+	{
56
+		try {
57
+			Util\Timing::startTiming();
58
+			Runner::checkRequirements();
59
+
60
+			if (defined('PHP_CODESNIFFER_CBF') === false) {
61
+				define('PHP_CODESNIFFER_CBF', false);
62
+			}
63
+
64
+			// Creating the Config object populates it with all required settings
65
+			// based on the CLI arguments provided to the script and any config
66
+			// values the user has set.
67
+			$this->config = new Config();
68
+
69
+			// Init the run and load the rulesets to set additional config vars.
70
+			$this->init();
71
+
72
+			// Print a list of sniffs in each of the supplied standards.
73
+			// We fudge the config here so that each standard is explained in isolation.
74
+			if ($this->config->explain === true) {
75
+				$standards = $this->config->standards;
76
+				foreach ($standards as $standard) {
77
+					$this->config->standards = [$standard];
78
+					$ruleset = new Ruleset($this->config);
79
+					$ruleset->explain();
80
+				}
81
+
82
+				return 0;
83
+			}
84
+
85
+			// Generate documentation for each of the supplied standards.
86
+			if ($this->config->generator !== null) {
87
+				$standards = $this->config->standards;
88
+				foreach ($standards as $standard) {
89
+					$this->config->standards = [$standard];
90
+					$ruleset   = new Ruleset($this->config);
91
+					$class     = 'PHP_CodeSniffer\Generators\\'.$this->config->generator;
92
+					$generator = new $class($ruleset);
93
+					$generator->generate();
94
+				}
95
+
96
+				return 0;
97
+			}
98
+
99
+			// Other report formats don't really make sense in interactive mode
100
+			// so we hard-code the full report here and when outputting.
101
+			// We also ensure parallel processing is off because we need to do one file at a time.
102
+			if ($this->config->interactive === true) {
103
+				$this->config->reports      = ['full' => null];
104
+				$this->config->parallel     = 1;
105
+				$this->config->showProgress = false;
106
+			}
107
+
108
+			// Disable caching if we are processing STDIN as we can't be 100%
109
+			// sure where the file came from or if it will change in the future.
110
+			if ($this->config->stdin === true) {
111
+				$this->config->cache = false;
112
+			}
113
+
114
+			$numErrors = $this->run();
115
+
116
+			// Print all the reports for this run.
117
+			$toScreen = $this->reporter->printReports();
118
+
119
+			// Only print timer output if no reports were
120
+			// printed to the screen so we don't put additional output
121
+			// in something like an XML report. If we are printing to screen,
122
+			// the report types would have already worked out who should
123
+			// print the timer info.
124
+			if ($this->config->interactive === false
125
+				&& ($toScreen === false
126
+				|| (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true))
127
+			) {
128
+				Util\Timing::printRunTime();
129
+			}
130
+		} catch (DeepExitException $e) {
131
+			echo $e->getMessage();
132
+			return $e->getCode();
133
+		}//end try
134
+
135
+		if ($numErrors === 0) {
136
+			// No errors found.
137
+			return 0;
138
+		} else if ($this->reporter->totalFixable === 0) {
139
+			// Errors found, but none of them can be fixed by PHPCBF.
140
+			return 1;
141
+		} else {
142
+			// Errors found, and some can be fixed by PHPCBF.
143
+			return 2;
144
+		}
145
+
146
+	}//end runPHPCS()
147
+
148
+
149
+	/**
150
+	 * Run the PHPCBF script.
151
+	 *
152
+	 * @return array
153
+	 */
154
+	public function runPHPCBF()
155
+	{
156
+		if (defined('PHP_CODESNIFFER_CBF') === false) {
157
+			define('PHP_CODESNIFFER_CBF', true);
158
+		}
159
+
160
+		try {
161
+			Util\Timing::startTiming();
162
+			Runner::checkRequirements();
163
+
164
+			// Creating the Config object populates it with all required settings
165
+			// based on the CLI arguments provided to the script and any config
166
+			// values the user has set.
167
+			$this->config = new Config();
168
+
169
+			// When processing STDIN, we can't output anything to the screen
170
+			// or it will end up mixed in with the file output.
171
+			if ($this->config->stdin === true) {
172
+				$this->config->verbosity = 0;
173
+			}
174
+
175
+			// Init the run and load the rulesets to set additional config vars.
176
+			$this->init();
177
+
178
+			// When processing STDIN, we only process one file at a time and
179
+			// we don't process all the way through, so we can't use the parallel
180
+			// running system.
181
+			if ($this->config->stdin === true) {
182
+				$this->config->parallel = 1;
183
+			}
184
+
185
+			// Override some of the command line settings that might break the fixes.
186
+			$this->config->generator    = null;
187
+			$this->config->explain      = false;
188
+			$this->config->interactive  = false;
189
+			$this->config->cache        = false;
190
+			$this->config->showSources  = false;
191
+			$this->config->recordErrors = false;
192
+			$this->config->reportFile   = null;
193
+			$this->config->reports      = ['cbf' => null];
194
+
195
+			// If a standard tries to set command line arguments itself, some
196
+			// may be blocked because PHPCBF is running, so stop the script
197
+			// dying if any are found.
198
+			$this->config->dieOnUnknownArg = false;
199
+
200
+			$this->run();
201
+			$this->reporter->printReports();
202
+
203
+			echo PHP_EOL;
204
+			Util\Timing::printRunTime();
205
+		} catch (DeepExitException $e) {
206
+			echo $e->getMessage();
207
+			return $e->getCode();
208
+		}//end try
209
+
210
+		if ($this->reporter->totalFixed === 0) {
211
+			// Nothing was fixed by PHPCBF.
212
+			if ($this->reporter->totalFixable === 0) {
213
+				// Nothing found that could be fixed.
214
+				return 0;
215
+			} else {
216
+				// Something failed to fix.
217
+				return 2;
218
+			}
219
+		}
220
+
221
+		if ($this->reporter->totalFixable === 0) {
222
+			// PHPCBF fixed all fixable errors.
223
+			return 1;
224
+		}
225
+
226
+		// PHPCBF fixed some fixable errors, but others failed to fix.
227
+		return 2;
228
+
229
+	}//end runPHPCBF()
230
+
231
+
232
+	/**
233
+	 * Exits if the minimum requirements of PHP_CodeSniffer are not met.
234
+	 *
235
+	 * @return array
236
+	 * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
237
+	 */
238
+	public function checkRequirements()
239
+	{
240
+		// Check the PHP version.
241
+		if (PHP_VERSION_ID < 50400) {
242
+			$error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
243
+			throw new DeepExitException($error, 3);
244
+		}
245
+
246
+		$requiredExtensions = [
247
+			'tokenizer',
248
+			'xmlwriter',
249
+			'SimpleXML',
250
+		];
251
+		$missingExtensions  = [];
252
+
253
+		foreach ($requiredExtensions as $extension) {
254
+			if (extension_loaded($extension) === false) {
255
+				$missingExtensions[] = $extension;
256
+			}
257
+		}
258
+
259
+		if (empty($missingExtensions) === false) {
260
+			$last      = array_pop($requiredExtensions);
261
+			$required  = implode(', ', $requiredExtensions);
262
+			$required .= ' and '.$last;
263
+
264
+			if (count($missingExtensions) === 1) {
265
+				$missing = $missingExtensions[0];
266
+			} else {
267
+				$last     = array_pop($missingExtensions);
268
+				$missing  = implode(', ', $missingExtensions);
269
+				$missing .= ' and '.$last;
270
+			}
271
+
272
+			$error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.'.PHP_EOL;
273
+			$error = sprintf($error, $required, $missing);
274
+			throw new DeepExitException($error, 3);
275
+		}
276
+
277
+	}//end checkRequirements()
278
+
279
+
280
+	/**
281
+	 * Init the rulesets and other high-level settings.
282
+	 *
283
+	 * @return void
284
+	 * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
285
+	 */
286
+	public function init()
287
+	{
288
+		if (defined('PHP_CODESNIFFER_CBF') === false) {
289
+			define('PHP_CODESNIFFER_CBF', false);
290
+		}
291
+
292
+		// Ensure this option is enabled or else line endings will not always
293
+		// be detected properly for files created on a Mac with the /r line ending.
294
+		ini_set('auto_detect_line_endings', true);
295
+
296
+		// Disable the PCRE JIT as this caused issues with parallel running.
297
+		ini_set('pcre.jit', false);
298
+
299
+		// Check that the standards are valid.
300
+		foreach ($this->config->standards as $standard) {
301
+			if (Util\Standards::isInstalledStandard($standard) === false) {
302
+				// They didn't select a valid coding standard, so help them
303
+				// out by letting them know which standards are installed.
304
+				$error = 'ERROR: the "'.$standard.'" coding standard is not installed. ';
305
+				ob_start();
306
+				Util\Standards::printInstalledStandards();
307
+				$error .= ob_get_contents();
308
+				ob_end_clean();
309
+				throw new DeepExitException($error, 3);
310
+			}
311
+		}
312
+
313
+		// Saves passing the Config object into other objects that only need
314
+		// the verbosity flag for debug output.
315
+		if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
316
+			define('PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity);
317
+		}
318
+
319
+		// Create this class so it is autoloaded and sets up a bunch
320
+		// of PHP_CodeSniffer-specific token type constants.
321
+		$tokens = new Util\Tokens();
322
+
323
+		// Allow autoloading of custom files inside installed standards.
324
+		$installedStandards = Standards::getInstalledStandardDetails();
325
+		foreach ($installedStandards as $name => $details) {
326
+			Autoload::addSearchPath($details['path'], $details['namespace']);
327
+		}
328
+
329
+		// The ruleset contains all the information about how the files
330
+		// should be checked and/or fixed.
331
+		try {
332
+			$this->ruleset = new Ruleset($this->config);
333
+		} catch (RuntimeException $e) {
334
+			$error  = 'ERROR: '.$e->getMessage().PHP_EOL.PHP_EOL;
335
+			$error .= $this->config->printShortUsage(true);
336
+			throw new DeepExitException($error, 3);
337
+		}
338
+
339
+	}//end init()
340
+
341
+
342
+	/**
343
+	 * Performs the run.
344
+	 *
345
+	 * @return int The number of errors and warnings found.
346
+	 * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
347
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
348
+	 */
349
+	private function run()
350
+	{
351
+		// The class that manages all reporters for the run.
352
+		$this->reporter = new Reporter($this->config);
353
+
354
+		// Include bootstrap files.
355
+		foreach ($this->config->bootstrap as $bootstrap) {
356
+			include $bootstrap;
357
+		}
358
+
359
+		if ($this->config->stdin === true) {
360
+			$fileContents = $this->config->stdinContent;
361
+			if ($fileContents === null) {
362
+				$handle = fopen('php://stdin', 'r');
363
+				stream_set_blocking($handle, true);
364
+				$fileContents = stream_get_contents($handle);
365
+				fclose($handle);
366
+			}
367
+
368
+			$todo  = new FileList($this->config, $this->ruleset);
369
+			$dummy = new DummyFile($fileContents, $this->ruleset, $this->config);
370
+			$todo->addFile($dummy->path, $dummy);
371
+		} else {
372
+			if (empty($this->config->files) === true) {
373
+				$error  = 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
374
+				$error .= $this->config->printShortUsage(true);
375
+				throw new DeepExitException($error, 3);
376
+			}
377
+
378
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
379
+				echo 'Creating file list... ';
380
+			}
381
+
382
+			$todo = new FileList($this->config, $this->ruleset);
383
+
384
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
385
+				$numFiles = count($todo);
386
+				echo "DONE ($numFiles files in queue)".PHP_EOL;
387
+			}
388
+
389
+			if ($this->config->cache === true) {
390
+				if (PHP_CODESNIFFER_VERBOSITY > 0) {
391
+					echo 'Loading cache... ';
392
+				}
393
+
394
+				Cache::load($this->ruleset, $this->config);
395
+
396
+				if (PHP_CODESNIFFER_VERBOSITY > 0) {
397
+					$size = Cache::getSize();
398
+					echo "DONE ($size files in cache)".PHP_EOL;
399
+				}
400
+			}
401
+		}//end if
402
+
403
+		// Turn all sniff errors into exceptions.
404
+		set_error_handler([$this, 'handleErrors']);
405
+
406
+		// If verbosity is too high, turn off parallelism so the
407
+		// debug output is clean.
408
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
409
+			$this->config->parallel = 1;
410
+		}
411
+
412
+		// If the PCNTL extension isn't installed, we can't fork.
413
+		if (function_exists('pcntl_fork') === false) {
414
+			$this->config->parallel = 1;
415
+		}
416
+
417
+		$lastDir  = '';
418
+		$numFiles = count($todo);
419
+
420
+		if ($this->config->parallel === 1) {
421
+			// Running normally.
422
+			$numProcessed = 0;
423
+			foreach ($todo as $path => $file) {
424
+				if ($file->ignored === false) {
425
+					$currDir = dirname($path);
426
+					if ($lastDir !== $currDir) {
427
+						if (PHP_CODESNIFFER_VERBOSITY > 0) {
428
+							echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
429
+						}
430
+
431
+						$lastDir = $currDir;
432
+					}
433
+
434
+					$this->processFile($file);
435
+				} else if (PHP_CODESNIFFER_VERBOSITY > 0) {
436
+					echo 'Skipping '.basename($file->path).PHP_EOL;
437
+				}
438
+
439
+				$numProcessed++;
440
+				$this->printProgress($file, $numFiles, $numProcessed);
441
+			}
442
+		} else {
443
+			// Batching and forking.
444
+			$childProcs  = [];
445
+			$numPerBatch = ceil($numFiles / $this->config->parallel);
446
+
447
+			for ($batch = 0; $batch < $this->config->parallel; $batch++) {
448
+				$startAt = ($batch * $numPerBatch);
449
+				if ($startAt >= $numFiles) {
450
+					break;
451
+				}
452
+
453
+				$endAt = ($startAt + $numPerBatch);
454
+				if ($endAt > $numFiles) {
455
+					$endAt = $numFiles;
456
+				}
457
+
458
+				$childOutFilename = tempnam(sys_get_temp_dir(), 'phpcs-child');
459
+				$pid = pcntl_fork();
460
+				if ($pid === -1) {
461
+					throw new RuntimeException('Failed to create child process');
462
+				} else if ($pid !== 0) {
463
+					$childProcs[] = [
464
+						'pid' => $pid,
465
+						'out' => $childOutFilename,
466
+					];
467
+				} else {
468
+					// Move forward to the start of the batch.
469
+					$todo->rewind();
470
+					for ($i = 0; $i < $startAt; $i++) {
471
+						$todo->next();
472
+					}
473
+
474
+					// Reset the reporter to make sure only figures from this
475
+					// file batch are recorded.
476
+					$this->reporter->totalFiles    = 0;
477
+					$this->reporter->totalErrors   = 0;
478
+					$this->reporter->totalWarnings = 0;
479
+					$this->reporter->totalFixable  = 0;
480
+					$this->reporter->totalFixed    = 0;
481
+
482
+					// Process the files.
483
+					$pathsProcessed = [];
484
+					ob_start();
485
+					for ($i = $startAt; $i < $endAt; $i++) {
486
+						$path = $todo->key();
487
+						$file = $todo->current();
488
+
489
+						if ($file->ignored === true) {
490
+							continue;
491
+						}
492
+
493
+						$currDir = dirname($path);
494
+						if ($lastDir !== $currDir) {
495
+							if (PHP_CODESNIFFER_VERBOSITY > 0) {
496
+								echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
497
+							}
498
+
499
+							$lastDir = $currDir;
500
+						}
501
+
502
+						$this->processFile($file);
503
+
504
+						$pathsProcessed[] = $path;
505
+						$todo->next();
506
+					}//end for
507
+
508
+					$debugOutput = ob_get_contents();
509
+					ob_end_clean();
510
+
511
+					// Write information about the run to the filesystem
512
+					// so it can be picked up by the main process.
513
+					$childOutput = [
514
+						'totalFiles'    => $this->reporter->totalFiles,
515
+						'totalErrors'   => $this->reporter->totalErrors,
516
+						'totalWarnings' => $this->reporter->totalWarnings,
517
+						'totalFixable'  => $this->reporter->totalFixable,
518
+						'totalFixed'    => $this->reporter->totalFixed,
519
+					];
520
+
521
+					$output  = '<'.'?php'."\n".' $childOutput = ';
522
+					$output .= var_export($childOutput, true);
523
+					$output .= ";\n\$debugOutput = ";
524
+					$output .= var_export($debugOutput, true);
525
+
526
+					if ($this->config->cache === true) {
527
+						$childCache = [];
528
+						foreach ($pathsProcessed as $path) {
529
+							$childCache[$path] = Cache::get($path);
530
+						}
531
+
532
+						$output .= ";\n\$childCache = ";
533
+						$output .= var_export($childCache, true);
534
+					}
535
+
536
+					$output .= ";\n?".'>';
537
+					file_put_contents($childOutFilename, $output);
538
+					exit($pid);
539
+				}//end if
540
+			}//end for
541
+
542
+			$success = $this->processChildProcs($childProcs);
543
+			if ($success === false) {
544
+				throw new RuntimeException('One or more child processes failed to run');
545
+			}
546
+		}//end if
547
+
548
+		restore_error_handler();
549
+
550
+		if (PHP_CODESNIFFER_VERBOSITY === 0
551
+			&& $this->config->interactive === false
552
+			&& $this->config->showProgress === true
553
+		) {
554
+			echo PHP_EOL.PHP_EOL;
555
+		}
556
+
557
+		if ($this->config->cache === true) {
558
+			Cache::save();
559
+		}
560
+
561
+		$ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit');
562
+		$ignoreErrors   = Config::getConfigData('ignore_errors_on_exit');
563
+
564
+		$return = ($this->reporter->totalErrors + $this->reporter->totalWarnings);
565
+		if ($ignoreErrors !== null) {
566
+			$ignoreErrors = (bool) $ignoreErrors;
567
+			if ($ignoreErrors === true) {
568
+				$return -= $this->reporter->totalErrors;
569
+			}
570
+		}
571
+
572
+		if ($ignoreWarnings !== null) {
573
+			$ignoreWarnings = (bool) $ignoreWarnings;
574
+			if ($ignoreWarnings === true) {
575
+				$return -= $this->reporter->totalWarnings;
576
+			}
577
+		}
578
+
579
+		return $return;
580
+
581
+	}//end run()
582
+
583
+
584
+	/**
585
+	 * Converts all PHP errors into exceptions.
586
+	 *
587
+	 * This method forces a sniff to stop processing if it is not
588
+	 * able to handle a specific piece of code, instead of continuing
589
+	 * and potentially getting into a loop.
590
+	 *
591
+	 * @param int    $code    The level of error raised.
592
+	 * @param string $message The error message.
593
+	 * @param string $file    The path of the file that raised the error.
594
+	 * @param int    $line    The line number the error was raised at.
595
+	 *
596
+	 * @return void
597
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
598
+	 */
599
+	public function handleErrors($code, $message, $file, $line)
600
+	{
601
+		if ((error_reporting() & $code) === 0) {
602
+			// This type of error is being muted.
603
+			return true;
604
+		}
605
+
606
+		throw new RuntimeException("$message in $file on line $line");
607
+
608
+	}//end handleErrors()
609
+
610
+
611
+	/**
612
+	 * Processes a single file, including checking and fixing.
613
+	 *
614
+	 * @param \PHP_CodeSniffer\Files\File $file The file to be processed.
615
+	 *
616
+	 * @return void
617
+	 * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
618
+	 */
619
+	public function processFile($file)
620
+	{
621
+		if (PHP_CODESNIFFER_VERBOSITY > 0) {
622
+			$startTime = microtime(true);
623
+			echo 'Processing '.basename($file->path).' ';
624
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
625
+				echo PHP_EOL;
626
+			}
627
+		}
628
+
629
+		try {
630
+			$file->process();
631
+
632
+			if (PHP_CODESNIFFER_VERBOSITY > 0) {
633
+				$timeTaken = ((microtime(true) - $startTime) * 1000);
634
+				if ($timeTaken < 1000) {
635
+					$timeTaken = round($timeTaken);
636
+					echo "DONE in {$timeTaken}ms";
637
+				} else {
638
+					$timeTaken = round(($timeTaken / 1000), 2);
639
+					echo "DONE in $timeTaken secs";
640
+				}
641
+
642
+				if (PHP_CODESNIFFER_CBF === true) {
643
+					$errors = $file->getFixableCount();
644
+					echo " ($errors fixable violations)".PHP_EOL;
645
+				} else {
646
+					$errors   = $file->getErrorCount();
647
+					$warnings = $file->getWarningCount();
648
+					echo " ($errors errors, $warnings warnings)".PHP_EOL;
649
+				}
650
+			}
651
+		} catch (\Exception $e) {
652
+			$error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
653
+			$file->addErrorOnLine($error, 1, 'Internal.Exception');
654
+		}//end try
655
+
656
+		$this->reporter->cacheFileReport($file, $this->config);
657
+
658
+		if ($this->config->interactive === true) {
659
+			/*
660 660
                 Running interactively.
661 661
                 Print the error report for the current file and then wait for user input.
662 662
             */
663 663
 
664
-            // Get current violations and then clear the list to make sure
665
-            // we only print violations for a single file each time.
666
-            $numErrors = null;
667
-            while ($numErrors !== 0) {
668
-                $numErrors = ($file->getErrorCount() + $file->getWarningCount());
669
-                if ($numErrors === 0) {
670
-                    continue;
671
-                }
672
-
673
-                $this->reporter->printReport('full');
674
-
675
-                echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
676
-                $input = fgets(STDIN);
677
-                $input = trim($input);
678
-
679
-                switch ($input) {
680
-                case 's':
681
-                    break(2);
682
-                case 'q':
683
-                    throw new DeepExitException('', 0);
684
-                default:
685
-                    // Repopulate the sniffs because some of them save their state
686
-                    // and only clear it when the file changes, but we are rechecking
687
-                    // the same file.
688
-                    $file->ruleset->populateTokenListeners();
689
-                    $file->reloadContent();
690
-                    $file->process();
691
-                    $this->reporter->cacheFileReport($file, $this->config);
692
-                    break;
693
-                }
694
-            }//end while
695
-        }//end if
696
-
697
-        // Clean up the file to save (a lot of) memory.
698
-        $file->cleanUp();
699
-
700
-    }//end processFile()
701
-
702
-
703
-    /**
704
-     * Waits for child processes to complete and cleans up after them.
705
-     *
706
-     * The reporting information returned by each child process is merged
707
-     * into the main reporter class.
708
-     *
709
-     * @param array $childProcs An array of child processes to wait for.
710
-     *
711
-     * @return void
712
-     */
713
-    private function processChildProcs($childProcs)
714
-    {
715
-        $numProcessed = 0;
716
-        $totalBatches = count($childProcs);
717
-
718
-        $success = true;
719
-
720
-        while (count($childProcs) > 0) {
721
-            foreach ($childProcs as $key => $procData) {
722
-                $res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
723
-                if ($res === $procData['pid']) {
724
-                    if (file_exists($procData['out']) === true) {
725
-                        include $procData['out'];
726
-
727
-                        unlink($procData['out']);
728
-                        unset($childProcs[$key]);
729
-
730
-                        $numProcessed++;
731
-
732
-                        if (isset($childOutput) === false) {
733
-                            // The child process died, so the run has failed.
734
-                            $file = new DummyFile(null, $this->ruleset, $this->config);
735
-                            $file->setErrorCounts(1, 0, 0, 0);
736
-                            $this->printProgress($file, $totalBatches, $numProcessed);
737
-                            $success = false;
738
-                            continue;
739
-                        }
740
-
741
-                        $this->reporter->totalFiles    += $childOutput['totalFiles'];
742
-                        $this->reporter->totalErrors   += $childOutput['totalErrors'];
743
-                        $this->reporter->totalWarnings += $childOutput['totalWarnings'];
744
-                        $this->reporter->totalFixable  += $childOutput['totalFixable'];
745
-                        $this->reporter->totalFixed    += $childOutput['totalFixed'];
746
-
747
-                        if (isset($debugOutput) === true) {
748
-                            echo $debugOutput;
749
-                        }
750
-
751
-                        if (isset($childCache) === true) {
752
-                            foreach ($childCache as $path => $cache) {
753
-                                Cache::set($path, $cache);
754
-                            }
755
-                        }
756
-
757
-                        // Fake a processed file so we can print progress output for the batch.
758
-                        $file = new DummyFile(null, $this->ruleset, $this->config);
759
-                        $file->setErrorCounts(
760
-                            $childOutput['totalErrors'],
761
-                            $childOutput['totalWarnings'],
762
-                            $childOutput['totalFixable'],
763
-                            $childOutput['totalFixed']
764
-                        );
765
-                        $this->printProgress($file, $totalBatches, $numProcessed);
766
-                    }//end if
767
-                }//end if
768
-            }//end foreach
769
-        }//end while
770
-
771
-        return $success;
772
-
773
-    }//end processChildProcs()
774
-
775
-
776
-    /**
777
-     * Print progress information for a single processed file.
778
-     *
779
-     * @param \PHP_CodeSniffer\Files\File $file         The file that was processed.
780
-     * @param int                         $numFiles     The total number of files to process.
781
-     * @param int                         $numProcessed The number of files that have been processed,
782
-     *                                                  including this one.
783
-     *
784
-     * @return void
785
-     */
786
-    public function printProgress(File $file, $numFiles, $numProcessed)
787
-    {
788
-        if (PHP_CODESNIFFER_VERBOSITY > 0
789
-            || $this->config->showProgress === false
790
-        ) {
791
-            return;
792
-        }
793
-
794
-        // Show progress information.
795
-        if ($file->ignored === true) {
796
-            echo 'S';
797
-        } else {
798
-            $errors   = $file->getErrorCount();
799
-            $warnings = $file->getWarningCount();
800
-            $fixable  = $file->getFixableCount();
801
-            $fixed    = $file->getFixedCount();
802
-
803
-            if (PHP_CODESNIFFER_CBF === true) {
804
-                // Files with fixed errors or warnings are F (green).
805
-                // Files with unfixable errors or warnings are E (red).
806
-                // Files with no errors or warnings are . (black).
807
-                if ($fixable > 0) {
808
-                    if ($this->config->colors === true) {
809
-                        echo "\033[31m";
810
-                    }
811
-
812
-                    echo 'E';
813
-
814
-                    if ($this->config->colors === true) {
815
-                        echo "\033[0m";
816
-                    }
817
-                } else if ($fixed > 0) {
818
-                    if ($this->config->colors === true) {
819
-                        echo "\033[32m";
820
-                    }
821
-
822
-                    echo 'F';
823
-
824
-                    if ($this->config->colors === true) {
825
-                        echo "\033[0m";
826
-                    }
827
-                } else {
828
-                    echo '.';
829
-                }//end if
830
-            } else {
831
-                // Files with errors are E (red).
832
-                // Files with fixable errors are E (green).
833
-                // Files with warnings are W (yellow).
834
-                // Files with fixable warnings are W (green).
835
-                // Files with no errors or warnings are . (black).
836
-                if ($errors > 0) {
837
-                    if ($this->config->colors === true) {
838
-                        if ($fixable > 0) {
839
-                            echo "\033[32m";
840
-                        } else {
841
-                            echo "\033[31m";
842
-                        }
843
-                    }
844
-
845
-                    echo 'E';
846
-
847
-                    if ($this->config->colors === true) {
848
-                        echo "\033[0m";
849
-                    }
850
-                } else if ($warnings > 0) {
851
-                    if ($this->config->colors === true) {
852
-                        if ($fixable > 0) {
853
-                            echo "\033[32m";
854
-                        } else {
855
-                            echo "\033[33m";
856
-                        }
857
-                    }
858
-
859
-                    echo 'W';
860
-
861
-                    if ($this->config->colors === true) {
862
-                        echo "\033[0m";
863
-                    }
864
-                } else {
865
-                    echo '.';
866
-                }//end if
867
-            }//end if
868
-        }//end if
869
-
870
-        $numPerLine = 60;
871
-        if ($numProcessed !== $numFiles && ($numProcessed % $numPerLine) !== 0) {
872
-            return;
873
-        }
874
-
875
-        $percent = round(($numProcessed / $numFiles) * 100);
876
-        $padding = (strlen($numFiles) - strlen($numProcessed));
877
-        if ($numProcessed === $numFiles && $numFiles > $numPerLine) {
878
-            $padding += ($numPerLine - ($numFiles - (floor($numFiles / $numPerLine) * $numPerLine)));
879
-        }
880
-
881
-        echo str_repeat(' ', $padding)." $numProcessed / $numFiles ($percent%)".PHP_EOL;
882
-
883
-    }//end printProgress()
664
+			// Get current violations and then clear the list to make sure
665
+			// we only print violations for a single file each time.
666
+			$numErrors = null;
667
+			while ($numErrors !== 0) {
668
+				$numErrors = ($file->getErrorCount() + $file->getWarningCount());
669
+				if ($numErrors === 0) {
670
+					continue;
671
+				}
672
+
673
+				$this->reporter->printReport('full');
674
+
675
+				echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
676
+				$input = fgets(STDIN);
677
+				$input = trim($input);
678
+
679
+				switch ($input) {
680
+				case 's':
681
+					break(2);
682
+				case 'q':
683
+					throw new DeepExitException('', 0);
684
+				default:
685
+					// Repopulate the sniffs because some of them save their state
686
+					// and only clear it when the file changes, but we are rechecking
687
+					// the same file.
688
+					$file->ruleset->populateTokenListeners();
689
+					$file->reloadContent();
690
+					$file->process();
691
+					$this->reporter->cacheFileReport($file, $this->config);
692
+					break;
693
+				}
694
+			}//end while
695
+		}//end if
696
+
697
+		// Clean up the file to save (a lot of) memory.
698
+		$file->cleanUp();
699
+
700
+	}//end processFile()
701
+
702
+
703
+	/**
704
+	 * Waits for child processes to complete and cleans up after them.
705
+	 *
706
+	 * The reporting information returned by each child process is merged
707
+	 * into the main reporter class.
708
+	 *
709
+	 * @param array $childProcs An array of child processes to wait for.
710
+	 *
711
+	 * @return void
712
+	 */
713
+	private function processChildProcs($childProcs)
714
+	{
715
+		$numProcessed = 0;
716
+		$totalBatches = count($childProcs);
717
+
718
+		$success = true;
719
+
720
+		while (count($childProcs) > 0) {
721
+			foreach ($childProcs as $key => $procData) {
722
+				$res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
723
+				if ($res === $procData['pid']) {
724
+					if (file_exists($procData['out']) === true) {
725
+						include $procData['out'];
726
+
727
+						unlink($procData['out']);
728
+						unset($childProcs[$key]);
729
+
730
+						$numProcessed++;
731
+
732
+						if (isset($childOutput) === false) {
733
+							// The child process died, so the run has failed.
734
+							$file = new DummyFile(null, $this->ruleset, $this->config);
735
+							$file->setErrorCounts(1, 0, 0, 0);
736
+							$this->printProgress($file, $totalBatches, $numProcessed);
737
+							$success = false;
738
+							continue;
739
+						}
740
+
741
+						$this->reporter->totalFiles    += $childOutput['totalFiles'];
742
+						$this->reporter->totalErrors   += $childOutput['totalErrors'];
743
+						$this->reporter->totalWarnings += $childOutput['totalWarnings'];
744
+						$this->reporter->totalFixable  += $childOutput['totalFixable'];
745
+						$this->reporter->totalFixed    += $childOutput['totalFixed'];
746
+
747
+						if (isset($debugOutput) === true) {
748
+							echo $debugOutput;
749
+						}
750
+
751
+						if (isset($childCache) === true) {
752
+							foreach ($childCache as $path => $cache) {
753
+								Cache::set($path, $cache);
754
+							}
755
+						}
756
+
757
+						// Fake a processed file so we can print progress output for the batch.
758
+						$file = new DummyFile(null, $this->ruleset, $this->config);
759
+						$file->setErrorCounts(
760
+							$childOutput['totalErrors'],
761
+							$childOutput['totalWarnings'],
762
+							$childOutput['totalFixable'],
763
+							$childOutput['totalFixed']
764
+						);
765
+						$this->printProgress($file, $totalBatches, $numProcessed);
766
+					}//end if
767
+				}//end if
768
+			}//end foreach
769
+		}//end while
770
+
771
+		return $success;
772
+
773
+	}//end processChildProcs()
774
+
775
+
776
+	/**
777
+	 * Print progress information for a single processed file.
778
+	 *
779
+	 * @param \PHP_CodeSniffer\Files\File $file         The file that was processed.
780
+	 * @param int                         $numFiles     The total number of files to process.
781
+	 * @param int                         $numProcessed The number of files that have been processed,
782
+	 *                                                  including this one.
783
+	 *
784
+	 * @return void
785
+	 */
786
+	public function printProgress(File $file, $numFiles, $numProcessed)
787
+	{
788
+		if (PHP_CODESNIFFER_VERBOSITY > 0
789
+			|| $this->config->showProgress === false
790
+		) {
791
+			return;
792
+		}
793
+
794
+		// Show progress information.
795
+		if ($file->ignored === true) {
796
+			echo 'S';
797
+		} else {
798
+			$errors   = $file->getErrorCount();
799
+			$warnings = $file->getWarningCount();
800
+			$fixable  = $file->getFixableCount();
801
+			$fixed    = $file->getFixedCount();
802
+
803
+			if (PHP_CODESNIFFER_CBF === true) {
804
+				// Files with fixed errors or warnings are F (green).
805
+				// Files with unfixable errors or warnings are E (red).
806
+				// Files with no errors or warnings are . (black).
807
+				if ($fixable > 0) {
808
+					if ($this->config->colors === true) {
809
+						echo "\033[31m";
810
+					}
811
+
812
+					echo 'E';
813
+
814
+					if ($this->config->colors === true) {
815
+						echo "\033[0m";
816
+					}
817
+				} else if ($fixed > 0) {
818
+					if ($this->config->colors === true) {
819
+						echo "\033[32m";
820
+					}
821
+
822
+					echo 'F';
823
+
824
+					if ($this->config->colors === true) {
825
+						echo "\033[0m";
826
+					}
827
+				} else {
828
+					echo '.';
829
+				}//end if
830
+			} else {
831
+				// Files with errors are E (red).
832
+				// Files with fixable errors are E (green).
833
+				// Files with warnings are W (yellow).
834
+				// Files with fixable warnings are W (green).
835
+				// Files with no errors or warnings are . (black).
836
+				if ($errors > 0) {
837
+					if ($this->config->colors === true) {
838
+						if ($fixable > 0) {
839
+							echo "\033[32m";
840
+						} else {
841
+							echo "\033[31m";
842
+						}
843
+					}
844
+
845
+					echo 'E';
846
+
847
+					if ($this->config->colors === true) {
848
+						echo "\033[0m";
849
+					}
850
+				} else if ($warnings > 0) {
851
+					if ($this->config->colors === true) {
852
+						if ($fixable > 0) {
853
+							echo "\033[32m";
854
+						} else {
855
+							echo "\033[33m";
856
+						}
857
+					}
858
+
859
+					echo 'W';
860
+
861
+					if ($this->config->colors === true) {
862
+						echo "\033[0m";
863
+					}
864
+				} else {
865
+					echo '.';
866
+				}//end if
867
+			}//end if
868
+		}//end if
869
+
870
+		$numPerLine = 60;
871
+		if ($numProcessed !== $numFiles && ($numProcessed % $numPerLine) !== 0) {
872
+			return;
873
+		}
874
+
875
+		$percent = round(($numProcessed / $numFiles) * 100);
876
+		$padding = (strlen($numFiles) - strlen($numProcessed));
877
+		if ($numProcessed === $numFiles && $numFiles > $numPerLine) {
878
+			$padding += ($numPerLine - ($numFiles - (floor($numFiles / $numPerLine) * $numPerLine)));
879
+		}
880
+
881
+		echo str_repeat(' ', $padding)." $numProcessed / $numFiles ($percent%)".PHP_EOL;
882
+
883
+	}//end printProgress()
884 884
 
885 885
 
886 886
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -677,19 +677,19 @@
 block discarded – undo
677 677
                 $input = trim($input);
678 678
 
679 679
                 switch ($input) {
680
-                case 's':
681
-                    break(2);
682
-                case 'q':
683
-                    throw new DeepExitException('', 0);
684
-                default:
685
-                    // Repopulate the sniffs because some of them save their state
686
-                    // and only clear it when the file changes, but we are rechecking
687
-                    // the same file.
688
-                    $file->ruleset->populateTokenListeners();
689
-                    $file->reloadContent();
690
-                    $file->process();
691
-                    $this->reporter->cacheFileReport($file, $this->config);
692
-                    break;
680
+                	case 's':
681
+                    	break(2);
682
+                	case 'q':
683
+                    	throw new DeepExitException('', 0);
684
+                	default:
685
+                    	// Repopulate the sniffs because some of them save their state
686
+                    	// and only clear it when the file changes, but we are rechecking
687
+                    	// the same file.
688
+                    	$file->ruleset->populateTokenListeners();
689
+                    	$file->reloadContent();
690
+                    	$file->process();
691
+                    	$this->reporter->cacheFileReport($file, $this->config);
692
+                    	break;
693 693
                 }
694 694
             }//end while
695 695
         }//end if
Please login to merge, or discard this patch.
Spacing   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             Util\Timing::startTiming();
58 58
             Runner::checkRequirements();
59 59
 
60
-            if (defined('PHP_CODESNIFFER_CBF') === false) {
61
-                define('PHP_CODESNIFFER_CBF', false);
60
+            if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) {
61
+                define( 'PHP_CODESNIFFER_CBF', false );
62 62
             }
63 63
 
64 64
             // Creating the Config object populates it with all required settings
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 
72 72
             // Print a list of sniffs in each of the supplied standards.
73 73
             // We fudge the config here so that each standard is explained in isolation.
74
-            if ($this->config->explain === true) {
74
+            if ( $this->config->explain === true ) {
75 75
                 $standards = $this->config->standards;
76
-                foreach ($standards as $standard) {
77
-                    $this->config->standards = [$standard];
78
-                    $ruleset = new Ruleset($this->config);
76
+                foreach ( $standards as $standard ) {
77
+                    $this->config->standards = [ $standard ];
78
+                    $ruleset = new Ruleset( $this->config );
79 79
                     $ruleset->explain();
80 80
                 }
81 81
 
@@ -83,13 +83,13 @@  discard block
 block discarded – undo
83 83
             }
84 84
 
85 85
             // Generate documentation for each of the supplied standards.
86
-            if ($this->config->generator !== null) {
86
+            if ( $this->config->generator !== null ) {
87 87
                 $standards = $this->config->standards;
88
-                foreach ($standards as $standard) {
89
-                    $this->config->standards = [$standard];
90
-                    $ruleset   = new Ruleset($this->config);
91
-                    $class     = 'PHP_CodeSniffer\Generators\\'.$this->config->generator;
92
-                    $generator = new $class($ruleset);
88
+                foreach ( $standards as $standard ) {
89
+                    $this->config->standards = [ $standard ];
90
+                    $ruleset   = new Ruleset( $this->config );
91
+                    $class     = 'PHP_CodeSniffer\Generators\\' . $this->config->generator;
92
+                    $generator = new $class( $ruleset );
93 93
                     $generator->generate();
94 94
                 }
95 95
 
@@ -99,15 +99,15 @@  discard block
 block discarded – undo
99 99
             // Other report formats don't really make sense in interactive mode
100 100
             // so we hard-code the full report here and when outputting.
101 101
             // We also ensure parallel processing is off because we need to do one file at a time.
102
-            if ($this->config->interactive === true) {
103
-                $this->config->reports      = ['full' => null];
102
+            if ( $this->config->interactive === true ) {
103
+                $this->config->reports      = [ 'full' => null ];
104 104
                 $this->config->parallel     = 1;
105 105
                 $this->config->showProgress = false;
106 106
             }
107 107
 
108 108
             // Disable caching if we are processing STDIN as we can't be 100%
109 109
             // sure where the file came from or if it will change in the future.
110
-            if ($this->config->stdin === true) {
110
+            if ( $this->config->stdin === true ) {
111 111
                 $this->config->cache = false;
112 112
             }
113 113
 
@@ -121,21 +121,21 @@  discard block
 block discarded – undo
121 121
             // in something like an XML report. If we are printing to screen,
122 122
             // the report types would have already worked out who should
123 123
             // print the timer info.
124
-            if ($this->config->interactive === false
125
-                && ($toScreen === false
126
-                || (($this->reporter->totalErrors + $this->reporter->totalWarnings) === 0 && $this->config->showProgress === true))
124
+            if ( $this->config->interactive === false
125
+                && ( $toScreen === false
126
+                || ( ( $this->reporter->totalErrors + $this->reporter->totalWarnings ) === 0 && $this->config->showProgress === true ) )
127 127
             ) {
128 128
                 Util\Timing::printRunTime();
129 129
             }
130
-        } catch (DeepExitException $e) {
130
+        } catch ( DeepExitException $e ) {
131 131
             echo $e->getMessage();
132 132
             return $e->getCode();
133 133
         }//end try
134 134
 
135
-        if ($numErrors === 0) {
135
+        if ( $numErrors === 0 ) {
136 136
             // No errors found.
137 137
             return 0;
138
-        } else if ($this->reporter->totalFixable === 0) {
138
+        } else if ( $this->reporter->totalFixable === 0 ) {
139 139
             // Errors found, but none of them can be fixed by PHPCBF.
140 140
             return 1;
141 141
         } else {
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function runPHPCBF()
155 155
     {
156
-        if (defined('PHP_CODESNIFFER_CBF') === false) {
157
-            define('PHP_CODESNIFFER_CBF', true);
156
+        if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) {
157
+            define( 'PHP_CODESNIFFER_CBF', true );
158 158
         }
159 159
 
160 160
         try {
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 
169 169
             // When processing STDIN, we can't output anything to the screen
170 170
             // or it will end up mixed in with the file output.
171
-            if ($this->config->stdin === true) {
171
+            if ( $this->config->stdin === true ) {
172 172
                 $this->config->verbosity = 0;
173 173
             }
174 174
 
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
             // When processing STDIN, we only process one file at a time and
179 179
             // we don't process all the way through, so we can't use the parallel
180 180
             // running system.
181
-            if ($this->config->stdin === true) {
181
+            if ( $this->config->stdin === true ) {
182 182
                 $this->config->parallel = 1;
183 183
             }
184 184
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
             $this->config->showSources  = false;
191 191
             $this->config->recordErrors = false;
192 192
             $this->config->reportFile   = null;
193
-            $this->config->reports      = ['cbf' => null];
193
+            $this->config->reports      = [ 'cbf' => null ];
194 194
 
195 195
             // If a standard tries to set command line arguments itself, some
196 196
             // may be blocked because PHPCBF is running, so stop the script
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 
203 203
             echo PHP_EOL;
204 204
             Util\Timing::printRunTime();
205
-        } catch (DeepExitException $e) {
205
+        } catch ( DeepExitException $e ) {
206 206
             echo $e->getMessage();
207 207
             return $e->getCode();
208 208
         }//end try
209 209
 
210
-        if ($this->reporter->totalFixed === 0) {
210
+        if ( $this->reporter->totalFixed === 0 ) {
211 211
             // Nothing was fixed by PHPCBF.
212
-            if ($this->reporter->totalFixable === 0) {
212
+            if ( $this->reporter->totalFixable === 0 ) {
213 213
                 // Nothing found that could be fixed.
214 214
                 return 0;
215 215
             } else {
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
             }
219 219
         }
220 220
 
221
-        if ($this->reporter->totalFixable === 0) {
221
+        if ( $this->reporter->totalFixable === 0 ) {
222 222
             // PHPCBF fixed all fixable errors.
223 223
             return 1;
224 224
         }
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
     public function checkRequirements()
239 239
     {
240 240
         // Check the PHP version.
241
-        if (PHP_VERSION_ID < 50400) {
242
-            $error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
243
-            throw new DeepExitException($error, 3);
241
+        if ( PHP_VERSION_ID < 50400 ) {
242
+            $error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.' . PHP_EOL;
243
+            throw new DeepExitException( $error, 3 );
244 244
         }
245 245
 
246 246
         $requiredExtensions = [
@@ -248,30 +248,30 @@  discard block
 block discarded – undo
248 248
             'xmlwriter',
249 249
             'SimpleXML',
250 250
         ];
251
-        $missingExtensions  = [];
251
+        $missingExtensions = [ ];
252 252
 
253
-        foreach ($requiredExtensions as $extension) {
254
-            if (extension_loaded($extension) === false) {
255
-                $missingExtensions[] = $extension;
253
+        foreach ( $requiredExtensions as $extension ) {
254
+            if ( extension_loaded( $extension ) === false ) {
255
+                $missingExtensions[ ] = $extension;
256 256
             }
257 257
         }
258 258
 
259
-        if (empty($missingExtensions) === false) {
260
-            $last      = array_pop($requiredExtensions);
261
-            $required  = implode(', ', $requiredExtensions);
262
-            $required .= ' and '.$last;
259
+        if ( empty( $missingExtensions ) === false ) {
260
+            $last      = array_pop( $requiredExtensions );
261
+            $required  = implode( ', ', $requiredExtensions );
262
+            $required .= ' and ' . $last;
263 263
 
264
-            if (count($missingExtensions) === 1) {
265
-                $missing = $missingExtensions[0];
264
+            if ( count( $missingExtensions ) === 1 ) {
265
+                $missing = $missingExtensions[ 0 ];
266 266
             } else {
267
-                $last     = array_pop($missingExtensions);
268
-                $missing  = implode(', ', $missingExtensions);
269
-                $missing .= ' and '.$last;
267
+                $last     = array_pop( $missingExtensions );
268
+                $missing  = implode( ', ', $missingExtensions );
269
+                $missing .= ' and ' . $last;
270 270
             }
271 271
 
272
-            $error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.'.PHP_EOL;
273
-            $error = sprintf($error, $required, $missing);
274
-            throw new DeepExitException($error, 3);
272
+            $error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.' . PHP_EOL;
273
+            $error = sprintf( $error, $required, $missing );
274
+            throw new DeepExitException( $error, 3 );
275 275
         }
276 276
 
277 277
     }//end checkRequirements()
@@ -285,35 +285,35 @@  discard block
 block discarded – undo
285 285
      */
286 286
     public function init()
287 287
     {
288
-        if (defined('PHP_CODESNIFFER_CBF') === false) {
289
-            define('PHP_CODESNIFFER_CBF', false);
288
+        if ( defined( 'PHP_CODESNIFFER_CBF' ) === false ) {
289
+            define( 'PHP_CODESNIFFER_CBF', false );
290 290
         }
291 291
 
292 292
         // Ensure this option is enabled or else line endings will not always
293 293
         // be detected properly for files created on a Mac with the /r line ending.
294
-        ini_set('auto_detect_line_endings', true);
294
+        ini_set( 'auto_detect_line_endings', true );
295 295
 
296 296
         // Disable the PCRE JIT as this caused issues with parallel running.
297
-        ini_set('pcre.jit', false);
297
+        ini_set( 'pcre.jit', false );
298 298
 
299 299
         // Check that the standards are valid.
300
-        foreach ($this->config->standards as $standard) {
301
-            if (Util\Standards::isInstalledStandard($standard) === false) {
300
+        foreach ( $this->config->standards as $standard ) {
301
+            if ( Util\Standards::isInstalledStandard( $standard ) === false ) {
302 302
                 // They didn't select a valid coding standard, so help them
303 303
                 // out by letting them know which standards are installed.
304
-                $error = 'ERROR: the "'.$standard.'" coding standard is not installed. ';
304
+                $error = 'ERROR: the "' . $standard . '" coding standard is not installed. ';
305 305
                 ob_start();
306 306
                 Util\Standards::printInstalledStandards();
307 307
                 $error .= ob_get_contents();
308 308
                 ob_end_clean();
309
-                throw new DeepExitException($error, 3);
309
+                throw new DeepExitException( $error, 3 );
310 310
             }
311 311
         }
312 312
 
313 313
         // Saves passing the Config object into other objects that only need
314 314
         // the verbosity flag for debug output.
315
-        if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
316
-            define('PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity);
315
+        if ( defined( 'PHP_CODESNIFFER_VERBOSITY' ) === false ) {
316
+            define( 'PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity );
317 317
         }
318 318
 
319 319
         // Create this class so it is autoloaded and sets up a bunch
@@ -322,18 +322,18 @@  discard block
 block discarded – undo
322 322
 
323 323
         // Allow autoloading of custom files inside installed standards.
324 324
         $installedStandards = Standards::getInstalledStandardDetails();
325
-        foreach ($installedStandards as $name => $details) {
326
-            Autoload::addSearchPath($details['path'], $details['namespace']);
325
+        foreach ( $installedStandards as $name => $details ) {
326
+            Autoload::addSearchPath( $details[ 'path' ], $details[ 'namespace' ] );
327 327
         }
328 328
 
329 329
         // The ruleset contains all the information about how the files
330 330
         // should be checked and/or fixed.
331 331
         try {
332
-            $this->ruleset = new Ruleset($this->config);
333
-        } catch (RuntimeException $e) {
334
-            $error  = 'ERROR: '.$e->getMessage().PHP_EOL.PHP_EOL;
335
-            $error .= $this->config->printShortUsage(true);
336
-            throw new DeepExitException($error, 3);
332
+            $this->ruleset = new Ruleset( $this->config );
333
+        } catch ( RuntimeException $e ) {
334
+            $error  = 'ERROR: ' . $e->getMessage() . PHP_EOL . PHP_EOL;
335
+            $error .= $this->config->printShortUsage( true );
336
+            throw new DeepExitException( $error, 3 );
337 337
         }
338 338
 
339 339
     }//end init()
@@ -349,125 +349,125 @@  discard block
 block discarded – undo
349 349
     private function run()
350 350
     {
351 351
         // The class that manages all reporters for the run.
352
-        $this->reporter = new Reporter($this->config);
352
+        $this->reporter = new Reporter( $this->config );
353 353
 
354 354
         // Include bootstrap files.
355
-        foreach ($this->config->bootstrap as $bootstrap) {
355
+        foreach ( $this->config->bootstrap as $bootstrap ) {
356 356
             include $bootstrap;
357 357
         }
358 358
 
359
-        if ($this->config->stdin === true) {
359
+        if ( $this->config->stdin === true ) {
360 360
             $fileContents = $this->config->stdinContent;
361
-            if ($fileContents === null) {
362
-                $handle = fopen('php://stdin', 'r');
363
-                stream_set_blocking($handle, true);
364
-                $fileContents = stream_get_contents($handle);
365
-                fclose($handle);
361
+            if ( $fileContents === null ) {
362
+                $handle = fopen( 'php://stdin', 'r' );
363
+                stream_set_blocking( $handle, true );
364
+                $fileContents = stream_get_contents( $handle );
365
+                fclose( $handle );
366 366
             }
367 367
 
368
-            $todo  = new FileList($this->config, $this->ruleset);
369
-            $dummy = new DummyFile($fileContents, $this->ruleset, $this->config);
370
-            $todo->addFile($dummy->path, $dummy);
368
+            $todo  = new FileList( $this->config, $this->ruleset );
369
+            $dummy = new DummyFile( $fileContents, $this->ruleset, $this->config );
370
+            $todo->addFile( $dummy->path, $dummy );
371 371
         } else {
372
-            if (empty($this->config->files) === true) {
373
-                $error  = 'ERROR: You must supply at least one file or directory to process.'.PHP_EOL.PHP_EOL;
374
-                $error .= $this->config->printShortUsage(true);
375
-                throw new DeepExitException($error, 3);
372
+            if ( empty( $this->config->files ) === true ) {
373
+                $error  = 'ERROR: You must supply at least one file or directory to process.' . PHP_EOL . PHP_EOL;
374
+                $error .= $this->config->printShortUsage( true );
375
+                throw new DeepExitException( $error, 3 );
376 376
             }
377 377
 
378
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
378
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
379 379
                 echo 'Creating file list... ';
380 380
             }
381 381
 
382
-            $todo = new FileList($this->config, $this->ruleset);
382
+            $todo = new FileList( $this->config, $this->ruleset );
383 383
 
384
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
385
-                $numFiles = count($todo);
386
-                echo "DONE ($numFiles files in queue)".PHP_EOL;
384
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
385
+                $numFiles = count( $todo );
386
+                echo "DONE ($numFiles files in queue)" . PHP_EOL;
387 387
             }
388 388
 
389
-            if ($this->config->cache === true) {
390
-                if (PHP_CODESNIFFER_VERBOSITY > 0) {
389
+            if ( $this->config->cache === true ) {
390
+                if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
391 391
                     echo 'Loading cache... ';
392 392
                 }
393 393
 
394
-                Cache::load($this->ruleset, $this->config);
394
+                Cache::load( $this->ruleset, $this->config );
395 395
 
396
-                if (PHP_CODESNIFFER_VERBOSITY > 0) {
396
+                if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
397 397
                     $size = Cache::getSize();
398
-                    echo "DONE ($size files in cache)".PHP_EOL;
398
+                    echo "DONE ($size files in cache)" . PHP_EOL;
399 399
                 }
400 400
             }
401 401
         }//end if
402 402
 
403 403
         // Turn all sniff errors into exceptions.
404
-        set_error_handler([$this, 'handleErrors']);
404
+        set_error_handler( [ $this, 'handleErrors' ] );
405 405
 
406 406
         // If verbosity is too high, turn off parallelism so the
407 407
         // debug output is clean.
408
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
408
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
409 409
             $this->config->parallel = 1;
410 410
         }
411 411
 
412 412
         // If the PCNTL extension isn't installed, we can't fork.
413
-        if (function_exists('pcntl_fork') === false) {
413
+        if ( function_exists( 'pcntl_fork' ) === false ) {
414 414
             $this->config->parallel = 1;
415 415
         }
416 416
 
417 417
         $lastDir  = '';
418
-        $numFiles = count($todo);
418
+        $numFiles = count( $todo );
419 419
 
420
-        if ($this->config->parallel === 1) {
420
+        if ( $this->config->parallel === 1 ) {
421 421
             // Running normally.
422 422
             $numProcessed = 0;
423
-            foreach ($todo as $path => $file) {
424
-                if ($file->ignored === false) {
425
-                    $currDir = dirname($path);
426
-                    if ($lastDir !== $currDir) {
427
-                        if (PHP_CODESNIFFER_VERBOSITY > 0) {
428
-                            echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
423
+            foreach ( $todo as $path => $file ) {
424
+                if ( $file->ignored === false ) {
425
+                    $currDir = dirname( $path );
426
+                    if ( $lastDir !== $currDir ) {
427
+                        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
428
+                            echo 'Changing into directory ' . Common::stripBasepath( $currDir, $this->config->basepath ) . PHP_EOL;
429 429
                         }
430 430
 
431 431
                         $lastDir = $currDir;
432 432
                     }
433 433
 
434
-                    $this->processFile($file);
435
-                } else if (PHP_CODESNIFFER_VERBOSITY > 0) {
436
-                    echo 'Skipping '.basename($file->path).PHP_EOL;
434
+                    $this->processFile( $file );
435
+                } else if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
436
+                    echo 'Skipping ' . basename( $file->path ) . PHP_EOL;
437 437
                 }
438 438
 
439 439
                 $numProcessed++;
440
-                $this->printProgress($file, $numFiles, $numProcessed);
440
+                $this->printProgress( $file, $numFiles, $numProcessed );
441 441
             }
442 442
         } else {
443 443
             // Batching and forking.
444
-            $childProcs  = [];
445
-            $numPerBatch = ceil($numFiles / $this->config->parallel);
444
+            $childProcs  = [ ];
445
+            $numPerBatch = ceil( $numFiles / $this->config->parallel );
446 446
 
447
-            for ($batch = 0; $batch < $this->config->parallel; $batch++) {
448
-                $startAt = ($batch * $numPerBatch);
449
-                if ($startAt >= $numFiles) {
447
+            for ( $batch = 0; $batch < $this->config->parallel; $batch++ ) {
448
+                $startAt = ( $batch * $numPerBatch );
449
+                if ( $startAt >= $numFiles ) {
450 450
                     break;
451 451
                 }
452 452
 
453
-                $endAt = ($startAt + $numPerBatch);
454
-                if ($endAt > $numFiles) {
453
+                $endAt = ( $startAt + $numPerBatch );
454
+                if ( $endAt > $numFiles ) {
455 455
                     $endAt = $numFiles;
456 456
                 }
457 457
 
458
-                $childOutFilename = tempnam(sys_get_temp_dir(), 'phpcs-child');
458
+                $childOutFilename = tempnam( sys_get_temp_dir(), 'phpcs-child' );
459 459
                 $pid = pcntl_fork();
460
-                if ($pid === -1) {
461
-                    throw new RuntimeException('Failed to create child process');
462
-                } else if ($pid !== 0) {
463
-                    $childProcs[] = [
460
+                if ( $pid === -1 ) {
461
+                    throw new RuntimeException( 'Failed to create child process' );
462
+                } else if ( $pid !== 0 ) {
463
+                    $childProcs[ ] = [
464 464
                         'pid' => $pid,
465 465
                         'out' => $childOutFilename,
466 466
                     ];
467 467
                 } else {
468 468
                     // Move forward to the start of the batch.
469 469
                     $todo->rewind();
470
-                    for ($i = 0; $i < $startAt; $i++) {
470
+                    for ( $i = 0; $i < $startAt; $i++ ) {
471 471
                         $todo->next();
472 472
                     }
473 473
 
@@ -480,28 +480,28 @@  discard block
 block discarded – undo
480 480
                     $this->reporter->totalFixed    = 0;
481 481
 
482 482
                     // Process the files.
483
-                    $pathsProcessed = [];
483
+                    $pathsProcessed = [ ];
484 484
                     ob_start();
485
-                    for ($i = $startAt; $i < $endAt; $i++) {
485
+                    for ( $i = $startAt; $i < $endAt; $i++ ) {
486 486
                         $path = $todo->key();
487 487
                         $file = $todo->current();
488 488
 
489
-                        if ($file->ignored === true) {
489
+                        if ( $file->ignored === true ) {
490 490
                             continue;
491 491
                         }
492 492
 
493
-                        $currDir = dirname($path);
494
-                        if ($lastDir !== $currDir) {
495
-                            if (PHP_CODESNIFFER_VERBOSITY > 0) {
496
-                                echo 'Changing into directory '.Common::stripBasepath($currDir, $this->config->basepath).PHP_EOL;
493
+                        $currDir = dirname( $path );
494
+                        if ( $lastDir !== $currDir ) {
495
+                            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
496
+                                echo 'Changing into directory ' . Common::stripBasepath( $currDir, $this->config->basepath ) . PHP_EOL;
497 497
                             }
498 498
 
499 499
                             $lastDir = $currDir;
500 500
                         }
501 501
 
502
-                        $this->processFile($file);
502
+                        $this->processFile( $file );
503 503
 
504
-                        $pathsProcessed[] = $path;
504
+                        $pathsProcessed[ ] = $path;
505 505
                         $todo->next();
506 506
                     }//end for
507 507
 
@@ -518,60 +518,60 @@  discard block
 block discarded – undo
518 518
                         'totalFixed'    => $this->reporter->totalFixed,
519 519
                     ];
520 520
 
521
-                    $output  = '<'.'?php'."\n".' $childOutput = ';
522
-                    $output .= var_export($childOutput, true);
521
+                    $output  = '<' . '?php' . "\n" . ' $childOutput = ';
522
+                    $output .= var_export( $childOutput, true );
523 523
                     $output .= ";\n\$debugOutput = ";
524
-                    $output .= var_export($debugOutput, true);
524
+                    $output .= var_export( $debugOutput, true );
525 525
 
526
-                    if ($this->config->cache === true) {
527
-                        $childCache = [];
528
-                        foreach ($pathsProcessed as $path) {
529
-                            $childCache[$path] = Cache::get($path);
526
+                    if ( $this->config->cache === true ) {
527
+                        $childCache = [ ];
528
+                        foreach ( $pathsProcessed as $path ) {
529
+                            $childCache[ $path ] = Cache::get( $path );
530 530
                         }
531 531
 
532 532
                         $output .= ";\n\$childCache = ";
533
-                        $output .= var_export($childCache, true);
533
+                        $output .= var_export( $childCache, true );
534 534
                     }
535 535
 
536
-                    $output .= ";\n?".'>';
537
-                    file_put_contents($childOutFilename, $output);
538
-                    exit($pid);
536
+                    $output .= ";\n?" . '>';
537
+                    file_put_contents( $childOutFilename, $output );
538
+                    exit( $pid );
539 539
                 }//end if
540 540
             }//end for
541 541
 
542
-            $success = $this->processChildProcs($childProcs);
543
-            if ($success === false) {
544
-                throw new RuntimeException('One or more child processes failed to run');
542
+            $success = $this->processChildProcs( $childProcs );
543
+            if ( $success === false ) {
544
+                throw new RuntimeException( 'One or more child processes failed to run' );
545 545
             }
546 546
         }//end if
547 547
 
548 548
         restore_error_handler();
549 549
 
550
-        if (PHP_CODESNIFFER_VERBOSITY === 0
550
+        if ( PHP_CODESNIFFER_VERBOSITY === 0
551 551
             && $this->config->interactive === false
552 552
             && $this->config->showProgress === true
553 553
         ) {
554
-            echo PHP_EOL.PHP_EOL;
554
+            echo PHP_EOL . PHP_EOL;
555 555
         }
556 556
 
557
-        if ($this->config->cache === true) {
557
+        if ( $this->config->cache === true ) {
558 558
             Cache::save();
559 559
         }
560 560
 
561
-        $ignoreWarnings = Config::getConfigData('ignore_warnings_on_exit');
562
-        $ignoreErrors   = Config::getConfigData('ignore_errors_on_exit');
561
+        $ignoreWarnings = Config::getConfigData( 'ignore_warnings_on_exit' );
562
+        $ignoreErrors   = Config::getConfigData( 'ignore_errors_on_exit' );
563 563
 
564
-        $return = ($this->reporter->totalErrors + $this->reporter->totalWarnings);
565
-        if ($ignoreErrors !== null) {
566
-            $ignoreErrors = (bool) $ignoreErrors;
567
-            if ($ignoreErrors === true) {
564
+        $return = ( $this->reporter->totalErrors + $this->reporter->totalWarnings );
565
+        if ( $ignoreErrors !== null ) {
566
+            $ignoreErrors = (bool)$ignoreErrors;
567
+            if ( $ignoreErrors === true ) {
568 568
                 $return -= $this->reporter->totalErrors;
569 569
             }
570 570
         }
571 571
 
572
-        if ($ignoreWarnings !== null) {
573
-            $ignoreWarnings = (bool) $ignoreWarnings;
574
-            if ($ignoreWarnings === true) {
572
+        if ( $ignoreWarnings !== null ) {
573
+            $ignoreWarnings = (bool)$ignoreWarnings;
574
+            if ( $ignoreWarnings === true ) {
575 575
                 $return -= $this->reporter->totalWarnings;
576 576
             }
577 577
         }
@@ -596,14 +596,14 @@  discard block
 block discarded – undo
596 596
      * @return void
597 597
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
598 598
      */
599
-    public function handleErrors($code, $message, $file, $line)
599
+    public function handleErrors( $code, $message, $file, $line )
600 600
     {
601
-        if ((error_reporting() & $code) === 0) {
601
+        if ( ( error_reporting() & $code ) === 0 ) {
602 602
             // This type of error is being muted.
603 603
             return true;
604 604
         }
605 605
 
606
-        throw new RuntimeException("$message in $file on line $line");
606
+        throw new RuntimeException( "$message in $file on line $line" );
607 607
 
608 608
     }//end handleErrors()
609 609
 
@@ -616,12 +616,12 @@  discard block
 block discarded – undo
616 616
      * @return void
617 617
      * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
618 618
      */
619
-    public function processFile($file)
619
+    public function processFile( $file )
620 620
     {
621
-        if (PHP_CODESNIFFER_VERBOSITY > 0) {
622
-            $startTime = microtime(true);
623
-            echo 'Processing '.basename($file->path).' ';
624
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
621
+        if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
622
+            $startTime = microtime( true );
623
+            echo 'Processing ' . basename( $file->path ) . ' ';
624
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
625 625
                 echo PHP_EOL;
626 626
             }
627 627
         }
@@ -629,33 +629,33 @@  discard block
 block discarded – undo
629 629
         try {
630 630
             $file->process();
631 631
 
632
-            if (PHP_CODESNIFFER_VERBOSITY > 0) {
633
-                $timeTaken = ((microtime(true) - $startTime) * 1000);
634
-                if ($timeTaken < 1000) {
635
-                    $timeTaken = round($timeTaken);
632
+            if ( PHP_CODESNIFFER_VERBOSITY > 0 ) {
633
+                $timeTaken = ( ( microtime( true ) - $startTime ) * 1000 );
634
+                if ( $timeTaken < 1000 ) {
635
+                    $timeTaken = round( $timeTaken );
636 636
                     echo "DONE in {$timeTaken}ms";
637 637
                 } else {
638
-                    $timeTaken = round(($timeTaken / 1000), 2);
638
+                    $timeTaken = round( ( $timeTaken / 1000 ), 2 );
639 639
                     echo "DONE in $timeTaken secs";
640 640
                 }
641 641
 
642
-                if (PHP_CODESNIFFER_CBF === true) {
642
+                if ( PHP_CODESNIFFER_CBF === true ) {
643 643
                     $errors = $file->getFixableCount();
644
-                    echo " ($errors fixable violations)".PHP_EOL;
644
+                    echo " ($errors fixable violations)" . PHP_EOL;
645 645
                 } else {
646 646
                     $errors   = $file->getErrorCount();
647 647
                     $warnings = $file->getWarningCount();
648
-                    echo " ($errors errors, $warnings warnings)".PHP_EOL;
648
+                    echo " ($errors errors, $warnings warnings)" . PHP_EOL;
649 649
                 }
650 650
             }
651
-        } catch (\Exception $e) {
652
-            $error = 'An error occurred during processing; checking has been aborted. The error message was: '.$e->getMessage();
653
-            $file->addErrorOnLine($error, 1, 'Internal.Exception');
651
+        } catch ( \Exception $e ) {
652
+            $error = 'An error occurred during processing; checking has been aborted. The error message was: ' . $e->getMessage();
653
+            $file->addErrorOnLine( $error, 1, 'Internal.Exception' );
654 654
         }//end try
655 655
 
656
-        $this->reporter->cacheFileReport($file, $this->config);
656
+        $this->reporter->cacheFileReport( $file, $this->config );
657 657
 
658
-        if ($this->config->interactive === true) {
658
+        if ( $this->config->interactive === true ) {
659 659
             /*
660 660
                 Running interactively.
661 661
                 Print the error report for the current file and then wait for user input.
@@ -664,23 +664,23 @@  discard block
 block discarded – undo
664 664
             // Get current violations and then clear the list to make sure
665 665
             // we only print violations for a single file each time.
666 666
             $numErrors = null;
667
-            while ($numErrors !== 0) {
668
-                $numErrors = ($file->getErrorCount() + $file->getWarningCount());
669
-                if ($numErrors === 0) {
667
+            while ( $numErrors !== 0 ) {
668
+                $numErrors = ( $file->getErrorCount() + $file->getWarningCount() );
669
+                if ( $numErrors === 0 ) {
670 670
                     continue;
671 671
                 }
672 672
 
673
-                $this->reporter->printReport('full');
673
+                $this->reporter->printReport( 'full' );
674 674
 
675 675
                 echo '<ENTER> to recheck, [s] to skip or [q] to quit : ';
676
-                $input = fgets(STDIN);
677
-                $input = trim($input);
676
+                $input = fgets( STDIN );
677
+                $input = trim( $input );
678 678
 
679
-                switch ($input) {
679
+                switch ( $input ) {
680 680
                 case 's':
681
-                    break(2);
681
+                    break( 2 );
682 682
                 case 'q':
683
-                    throw new DeepExitException('', 0);
683
+                    throw new DeepExitException( '', 0 );
684 684
                 default:
685 685
                     // Repopulate the sniffs because some of them save their state
686 686
                     // and only clear it when the file changes, but we are rechecking
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
                     $file->ruleset->populateTokenListeners();
689 689
                     $file->reloadContent();
690 690
                     $file->process();
691
-                    $this->reporter->cacheFileReport($file, $this->config);
691
+                    $this->reporter->cacheFileReport( $file, $this->config );
692 692
                     break;
693 693
                 }
694 694
             }//end while
@@ -710,59 +710,59 @@  discard block
 block discarded – undo
710 710
      *
711 711
      * @return void
712 712
      */
713
-    private function processChildProcs($childProcs)
713
+    private function processChildProcs( $childProcs )
714 714
     {
715 715
         $numProcessed = 0;
716
-        $totalBatches = count($childProcs);
716
+        $totalBatches = count( $childProcs );
717 717
 
718 718
         $success = true;
719 719
 
720
-        while (count($childProcs) > 0) {
721
-            foreach ($childProcs as $key => $procData) {
722
-                $res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
723
-                if ($res === $procData['pid']) {
724
-                    if (file_exists($procData['out']) === true) {
725
-                        include $procData['out'];
720
+        while ( count( $childProcs ) > 0 ) {
721
+            foreach ( $childProcs as $key => $procData ) {
722
+                $res = pcntl_waitpid( $procData[ 'pid' ], $status, WNOHANG );
723
+                if ( $res === $procData[ 'pid' ] ) {
724
+                    if ( file_exists( $procData[ 'out' ] ) === true ) {
725
+                        include $procData[ 'out' ];
726 726
 
727
-                        unlink($procData['out']);
728
-                        unset($childProcs[$key]);
727
+                        unlink( $procData[ 'out' ] );
728
+                        unset( $childProcs[ $key ] );
729 729
 
730 730
                         $numProcessed++;
731 731
 
732
-                        if (isset($childOutput) === false) {
732
+                        if ( isset( $childOutput ) === false ) {
733 733
                             // The child process died, so the run has failed.
734
-                            $file = new DummyFile(null, $this->ruleset, $this->config);
735
-                            $file->setErrorCounts(1, 0, 0, 0);
736
-                            $this->printProgress($file, $totalBatches, $numProcessed);
734
+                            $file = new DummyFile( null, $this->ruleset, $this->config );
735
+                            $file->setErrorCounts( 1, 0, 0, 0 );
736
+                            $this->printProgress( $file, $totalBatches, $numProcessed );
737 737
                             $success = false;
738 738
                             continue;
739 739
                         }
740 740
 
741
-                        $this->reporter->totalFiles    += $childOutput['totalFiles'];
742
-                        $this->reporter->totalErrors   += $childOutput['totalErrors'];
743
-                        $this->reporter->totalWarnings += $childOutput['totalWarnings'];
744
-                        $this->reporter->totalFixable  += $childOutput['totalFixable'];
745
-                        $this->reporter->totalFixed    += $childOutput['totalFixed'];
741
+                        $this->reporter->totalFiles    += $childOutput[ 'totalFiles' ];
742
+                        $this->reporter->totalErrors   += $childOutput[ 'totalErrors' ];
743
+                        $this->reporter->totalWarnings += $childOutput[ 'totalWarnings' ];
744
+                        $this->reporter->totalFixable  += $childOutput[ 'totalFixable' ];
745
+                        $this->reporter->totalFixed    += $childOutput[ 'totalFixed' ];
746 746
 
747
-                        if (isset($debugOutput) === true) {
747
+                        if ( isset( $debugOutput ) === true ) {
748 748
                             echo $debugOutput;
749 749
                         }
750 750
 
751
-                        if (isset($childCache) === true) {
752
-                            foreach ($childCache as $path => $cache) {
753
-                                Cache::set($path, $cache);
751
+                        if ( isset( $childCache ) === true ) {
752
+                            foreach ( $childCache as $path => $cache ) {
753
+                                Cache::set( $path, $cache );
754 754
                             }
755 755
                         }
756 756
 
757 757
                         // Fake a processed file so we can print progress output for the batch.
758
-                        $file = new DummyFile(null, $this->ruleset, $this->config);
758
+                        $file = new DummyFile( null, $this->ruleset, $this->config );
759 759
                         $file->setErrorCounts(
760
-                            $childOutput['totalErrors'],
761
-                            $childOutput['totalWarnings'],
762
-                            $childOutput['totalFixable'],
763
-                            $childOutput['totalFixed']
760
+                            $childOutput[ 'totalErrors' ],
761
+                            $childOutput[ 'totalWarnings' ],
762
+                            $childOutput[ 'totalFixable' ],
763
+                            $childOutput[ 'totalFixed' ]
764 764
                         );
765
-                        $this->printProgress($file, $totalBatches, $numProcessed);
765
+                        $this->printProgress( $file, $totalBatches, $numProcessed );
766 766
                     }//end if
767 767
                 }//end if
768 768
             }//end foreach
@@ -783,16 +783,16 @@  discard block
 block discarded – undo
783 783
      *
784 784
      * @return void
785 785
      */
786
-    public function printProgress(File $file, $numFiles, $numProcessed)
786
+    public function printProgress( File $file, $numFiles, $numProcessed )
787 787
     {
788
-        if (PHP_CODESNIFFER_VERBOSITY > 0
788
+        if ( PHP_CODESNIFFER_VERBOSITY > 0
789 789
             || $this->config->showProgress === false
790 790
         ) {
791 791
             return;
792 792
         }
793 793
 
794 794
         // Show progress information.
795
-        if ($file->ignored === true) {
795
+        if ( $file->ignored === true ) {
796 796
             echo 'S';
797 797
         } else {
798 798
             $errors   = $file->getErrorCount();
@@ -800,28 +800,28 @@  discard block
 block discarded – undo
800 800
             $fixable  = $file->getFixableCount();
801 801
             $fixed    = $file->getFixedCount();
802 802
 
803
-            if (PHP_CODESNIFFER_CBF === true) {
803
+            if ( PHP_CODESNIFFER_CBF === true ) {
804 804
                 // Files with fixed errors or warnings are F (green).
805 805
                 // Files with unfixable errors or warnings are E (red).
806 806
                 // Files with no errors or warnings are . (black).
807
-                if ($fixable > 0) {
808
-                    if ($this->config->colors === true) {
807
+                if ( $fixable > 0 ) {
808
+                    if ( $this->config->colors === true ) {
809 809
                         echo "\033[31m";
810 810
                     }
811 811
 
812 812
                     echo 'E';
813 813
 
814
-                    if ($this->config->colors === true) {
814
+                    if ( $this->config->colors === true ) {
815 815
                         echo "\033[0m";
816 816
                     }
817
-                } else if ($fixed > 0) {
818
-                    if ($this->config->colors === true) {
817
+                } else if ( $fixed > 0 ) {
818
+                    if ( $this->config->colors === true ) {
819 819
                         echo "\033[32m";
820 820
                     }
821 821
 
822 822
                     echo 'F';
823 823
 
824
-                    if ($this->config->colors === true) {
824
+                    if ( $this->config->colors === true ) {
825 825
                         echo "\033[0m";
826 826
                     }
827 827
                 } else {
@@ -833,9 +833,9 @@  discard block
 block discarded – undo
833 833
                 // Files with warnings are W (yellow).
834 834
                 // Files with fixable warnings are W (green).
835 835
                 // Files with no errors or warnings are . (black).
836
-                if ($errors > 0) {
837
-                    if ($this->config->colors === true) {
838
-                        if ($fixable > 0) {
836
+                if ( $errors > 0 ) {
837
+                    if ( $this->config->colors === true ) {
838
+                        if ( $fixable > 0 ) {
839 839
                             echo "\033[32m";
840 840
                         } else {
841 841
                             echo "\033[31m";
@@ -844,12 +844,12 @@  discard block
 block discarded – undo
844 844
 
845 845
                     echo 'E';
846 846
 
847
-                    if ($this->config->colors === true) {
847
+                    if ( $this->config->colors === true ) {
848 848
                         echo "\033[0m";
849 849
                     }
850
-                } else if ($warnings > 0) {
851
-                    if ($this->config->colors === true) {
852
-                        if ($fixable > 0) {
850
+                } else if ( $warnings > 0 ) {
851
+                    if ( $this->config->colors === true ) {
852
+                        if ( $fixable > 0 ) {
853 853
                             echo "\033[32m";
854 854
                         } else {
855 855
                             echo "\033[33m";
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 
859 859
                     echo 'W';
860 860
 
861
-                    if ($this->config->colors === true) {
861
+                    if ( $this->config->colors === true ) {
862 862
                         echo "\033[0m";
863 863
                     }
864 864
                 } else {
@@ -868,17 +868,17 @@  discard block
 block discarded – undo
868 868
         }//end if
869 869
 
870 870
         $numPerLine = 60;
871
-        if ($numProcessed !== $numFiles && ($numProcessed % $numPerLine) !== 0) {
871
+        if ( $numProcessed !== $numFiles && ( $numProcessed % $numPerLine ) !== 0 ) {
872 872
             return;
873 873
         }
874 874
 
875
-        $percent = round(($numProcessed / $numFiles) * 100);
876
-        $padding = (strlen($numFiles) - strlen($numProcessed));
877
-        if ($numProcessed === $numFiles && $numFiles > $numPerLine) {
878
-            $padding += ($numPerLine - ($numFiles - (floor($numFiles / $numPerLine) * $numPerLine)));
875
+        $percent = round( ( $numProcessed / $numFiles ) * 100 );
876
+        $padding = ( strlen( $numFiles ) - strlen( $numProcessed ) );
877
+        if ( $numProcessed === $numFiles && $numFiles > $numPerLine ) {
878
+            $padding += ( $numPerLine - ( $numFiles - ( floor( $numFiles / $numPerLine ) * $numPerLine ) ) );
879 879
         }
880 880
 
881
-        echo str_repeat(' ', $padding)." $numProcessed / $numFiles ($percent%)".PHP_EOL;
881
+        echo str_repeat( ' ', $padding ) . " $numProcessed / $numFiles ($percent%)" . PHP_EOL;
882 882
 
883 883
     }//end printProgress()
884 884
 
Please login to merge, or discard this patch.
Braces   +10 added lines, -20 removed lines patch added patch discarded remove patch
@@ -21,8 +21,7 @@  discard block
 block discarded – undo
21 21
 use PHP_CodeSniffer\Exceptions\RuntimeException;
22 22
 use PHP_CodeSniffer\Exceptions\DeepExitException;
23 23
 
24
-class Runner
25
-{
24
+class Runner {
26 25
 
27 26
     /**
28 27
      * The config data for the run.
@@ -51,8 +50,7 @@  discard block
 block discarded – undo
51 50
      *
52 51
      * @return array
53 52
      */
54
-    public function runPHPCS()
55
-    {
53
+    public function runPHPCS() {
56 54
         try {
57 55
             Util\Timing::startTiming();
58 56
             Runner::checkRequirements();
@@ -151,8 +149,7 @@  discard block
 block discarded – undo
151 149
      *
152 150
      * @return array
153 151
      */
154
-    public function runPHPCBF()
155
-    {
152
+    public function runPHPCBF() {
156 153
         if (defined('PHP_CODESNIFFER_CBF') === false) {
157 154
             define('PHP_CODESNIFFER_CBF', true);
158 155
         }
@@ -235,8 +232,7 @@  discard block
 block discarded – undo
235 232
      * @return array
236 233
      * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
237 234
      */
238
-    public function checkRequirements()
239
-    {
235
+    public function checkRequirements() {
240 236
         // Check the PHP version.
241 237
         if (PHP_VERSION_ID < 50400) {
242 238
             $error = 'ERROR: PHP_CodeSniffer requires PHP version 5.4.0 or greater.'.PHP_EOL;
@@ -283,8 +279,7 @@  discard block
 block discarded – undo
283 279
      * @return void
284 280
      * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
285 281
      */
286
-    public function init()
287
-    {
282
+    public function init() {
288 283
         if (defined('PHP_CODESNIFFER_CBF') === false) {
289 284
             define('PHP_CODESNIFFER_CBF', false);
290 285
         }
@@ -346,8 +341,7 @@  discard block
 block discarded – undo
346 341
      * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
347 342
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
348 343
      */
349
-    private function run()
350
-    {
344
+    private function run() {
351 345
         // The class that manages all reporters for the run.
352 346
         $this->reporter = new Reporter($this->config);
353 347
 
@@ -596,8 +590,7 @@  discard block
 block discarded – undo
596 590
      * @return void
597 591
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
598 592
      */
599
-    public function handleErrors($code, $message, $file, $line)
600
-    {
593
+    public function handleErrors($code, $message, $file, $line) {
601 594
         if ((error_reporting() & $code) === 0) {
602 595
             // This type of error is being muted.
603 596
             return true;
@@ -616,8 +609,7 @@  discard block
 block discarded – undo
616 609
      * @return void
617 610
      * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
618 611
      */
619
-    public function processFile($file)
620
-    {
612
+    public function processFile($file) {
621 613
         if (PHP_CODESNIFFER_VERBOSITY > 0) {
622 614
             $startTime = microtime(true);
623 615
             echo 'Processing '.basename($file->path).' ';
@@ -710,8 +702,7 @@  discard block
 block discarded – undo
710 702
      *
711 703
      * @return void
712 704
      */
713
-    private function processChildProcs($childProcs)
714
-    {
705
+    private function processChildProcs($childProcs) {
715 706
         $numProcessed = 0;
716 707
         $totalBatches = count($childProcs);
717 708
 
@@ -783,8 +774,7 @@  discard block
 block discarded – undo
783 774
      *
784 775
      * @return void
785 776
      */
786
-    public function printProgress(File $file, $numFiles, $numProcessed)
787
-    {
777
+    public function printProgress(File $file, $numFiles, $numProcessed) {
788 778
         if (PHP_CODESNIFFER_VERBOSITY > 0
789 779
             || $this->config->showProgress === false
790 780
         ) {
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@
 block discarded – undo
39 39
     /**
40 40
      * Registers the tokens that this sniff wants to listen for.
41 41
      *
42
-     * @return int[]
42
+     * @return integer[]
43 43
      */
44 44
     public function register()
45 45
     {
Please login to merge, or discard this patch.
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -36,99 +36,99 @@
 block discarded – undo
36 36
 {
37 37
 
38 38
 
39
-    /**
40
-     * Registers the tokens that this sniff wants to listen for.
41
-     *
42
-     * @return int[]
43
-     */
44
-    public function register()
45
-    {
46
-        return [T_FOR];
47
-
48
-    }//end register()
49
-
50
-
51
-    /**
52
-     * Processes this test, when one of its tokens is encountered.
53
-     *
54
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
55
-     * @param int                         $stackPtr  The position of the current token
56
-     *                                               in the stack passed in $tokens.
57
-     *
58
-     * @return void
59
-     */
60
-    public function process(File $phpcsFile, $stackPtr)
61
-    {
62
-        $tokens = $phpcsFile->getTokens();
63
-        $token  = $tokens[$stackPtr];
64
-
65
-        // Skip for-loop without body.
66
-        if (isset($token['scope_opener']) === false) {
67
-            return;
68
-        }
69
-
70
-        // Find incrementors for outer loop.
71
-        $outer = $this->findIncrementers($tokens, $token);
72
-
73
-        // Skip if empty.
74
-        if (count($outer) === 0) {
75
-            return;
76
-        }
77
-
78
-        // Find nested for loops.
79
-        $start = ++$token['scope_opener'];
80
-        $end   = --$token['scope_closer'];
81
-
82
-        for (; $start <= $end; ++$start) {
83
-            if ($tokens[$start]['code'] !== T_FOR) {
84
-                continue;
85
-            }
86
-
87
-            $inner = $this->findIncrementers($tokens, $tokens[$start]);
88
-            $diff  = array_intersect($outer, $inner);
89
-
90
-            if (count($diff) !== 0) {
91
-                $error = 'Loop incrementor (%s) jumbling with inner loop';
92
-                $data  = [join(', ', $diff)];
93
-                $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
94
-            }
95
-        }
96
-
97
-    }//end process()
98
-
99
-
100
-    /**
101
-     * Get all used variables in the incrementer part of a for statement.
102
-     *
103
-     * @param array(integer=>array) $tokens Array with all code sniffer tokens.
104
-     * @param array(string=>mixed)  $token  Current for loop token
105
-     *
106
-     * @return string[] List of all found incrementer variables.
107
-     */
108
-    protected function findIncrementers(array $tokens, array $token)
109
-    {
110
-        // Skip invalid statement.
111
-        if (isset($token['parenthesis_opener']) === false) {
112
-            return [];
113
-        }
114
-
115
-        $start = ++$token['parenthesis_opener'];
116
-        $end   = --$token['parenthesis_closer'];
117
-
118
-        $incrementers = [];
119
-        $semicolons   = 0;
120
-        for ($next = $start; $next <= $end; ++$next) {
121
-            $code = $tokens[$next]['code'];
122
-            if ($code === T_SEMICOLON) {
123
-                ++$semicolons;
124
-            } else if ($semicolons === 2 && $code === T_VARIABLE) {
125
-                $incrementers[] = $tokens[$next]['content'];
126
-            }
127
-        }
128
-
129
-        return $incrementers;
130
-
131
-    }//end findIncrementers()
39
+	/**
40
+	 * Registers the tokens that this sniff wants to listen for.
41
+	 *
42
+	 * @return int[]
43
+	 */
44
+	public function register()
45
+	{
46
+		return [T_FOR];
47
+
48
+	}//end register()
49
+
50
+
51
+	/**
52
+	 * Processes this test, when one of its tokens is encountered.
53
+	 *
54
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
55
+	 * @param int                         $stackPtr  The position of the current token
56
+	 *                                               in the stack passed in $tokens.
57
+	 *
58
+	 * @return void
59
+	 */
60
+	public function process(File $phpcsFile, $stackPtr)
61
+	{
62
+		$tokens = $phpcsFile->getTokens();
63
+		$token  = $tokens[$stackPtr];
64
+
65
+		// Skip for-loop without body.
66
+		if (isset($token['scope_opener']) === false) {
67
+			return;
68
+		}
69
+
70
+		// Find incrementors for outer loop.
71
+		$outer = $this->findIncrementers($tokens, $token);
72
+
73
+		// Skip if empty.
74
+		if (count($outer) === 0) {
75
+			return;
76
+		}
77
+
78
+		// Find nested for loops.
79
+		$start = ++$token['scope_opener'];
80
+		$end   = --$token['scope_closer'];
81
+
82
+		for (; $start <= $end; ++$start) {
83
+			if ($tokens[$start]['code'] !== T_FOR) {
84
+				continue;
85
+			}
86
+
87
+			$inner = $this->findIncrementers($tokens, $tokens[$start]);
88
+			$diff  = array_intersect($outer, $inner);
89
+
90
+			if (count($diff) !== 0) {
91
+				$error = 'Loop incrementor (%s) jumbling with inner loop';
92
+				$data  = [join(', ', $diff)];
93
+				$phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
94
+			}
95
+		}
96
+
97
+	}//end process()
98
+
99
+
100
+	/**
101
+	 * Get all used variables in the incrementer part of a for statement.
102
+	 *
103
+	 * @param array(integer=>array) $tokens Array with all code sniffer tokens.
104
+	 * @param array(string=>mixed)  $token  Current for loop token
105
+	 *
106
+	 * @return string[] List of all found incrementer variables.
107
+	 */
108
+	protected function findIncrementers(array $tokens, array $token)
109
+	{
110
+		// Skip invalid statement.
111
+		if (isset($token['parenthesis_opener']) === false) {
112
+			return [];
113
+		}
114
+
115
+		$start = ++$token['parenthesis_opener'];
116
+		$end   = --$token['parenthesis_closer'];
117
+
118
+		$incrementers = [];
119
+		$semicolons   = 0;
120
+		for ($next = $start; $next <= $end; ++$next) {
121
+			$code = $tokens[$next]['code'];
122
+			if ($code === T_SEMICOLON) {
123
+				++$semicolons;
124
+			} else if ($semicolons === 2 && $code === T_VARIABLE) {
125
+				$incrementers[] = $tokens[$next]['content'];
126
+			}
127
+		}
128
+
129
+		return $incrementers;
130
+
131
+	}//end findIncrementers()
132 132
 
133 133
 
134 134
 }//end class
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function register()
45 45
     {
46
-        return [T_FOR];
46
+        return [ T_FOR ];
47 47
 
48 48
     }//end register()
49 49
 
@@ -57,40 +57,40 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @return void
59 59
      */
60
-    public function process(File $phpcsFile, $stackPtr)
60
+    public function process( File $phpcsFile, $stackPtr )
61 61
     {
62 62
         $tokens = $phpcsFile->getTokens();
63
-        $token  = $tokens[$stackPtr];
63
+        $token  = $tokens[ $stackPtr ];
64 64
 
65 65
         // Skip for-loop without body.
66
-        if (isset($token['scope_opener']) === false) {
66
+        if ( isset( $token[ 'scope_opener' ] ) === false ) {
67 67
             return;
68 68
         }
69 69
 
70 70
         // Find incrementors for outer loop.
71
-        $outer = $this->findIncrementers($tokens, $token);
71
+        $outer = $this->findIncrementers( $tokens, $token );
72 72
 
73 73
         // Skip if empty.
74
-        if (count($outer) === 0) {
74
+        if ( count( $outer ) === 0 ) {
75 75
             return;
76 76
         }
77 77
 
78 78
         // Find nested for loops.
79
-        $start = ++$token['scope_opener'];
80
-        $end   = --$token['scope_closer'];
79
+        $start = ++$token[ 'scope_opener' ];
80
+        $end   = --$token[ 'scope_closer' ];
81 81
 
82
-        for (; $start <= $end; ++$start) {
83
-            if ($tokens[$start]['code'] !== T_FOR) {
82
+        for ( ; $start <= $end; ++$start ) {
83
+            if ( $tokens[ $start ][ 'code' ] !== T_FOR ) {
84 84
                 continue;
85 85
             }
86 86
 
87
-            $inner = $this->findIncrementers($tokens, $tokens[$start]);
88
-            $diff  = array_intersect($outer, $inner);
87
+            $inner = $this->findIncrementers( $tokens, $tokens[ $start ] );
88
+            $diff  = array_intersect( $outer, $inner );
89 89
 
90
-            if (count($diff) !== 0) {
90
+            if ( count( $diff ) !== 0 ) {
91 91
                 $error = 'Loop incrementor (%s) jumbling with inner loop';
92
-                $data  = [join(', ', $diff)];
93
-                $phpcsFile->addWarning($error, $stackPtr, 'Found', $data);
92
+                $data  = [ join( ', ', $diff ) ];
93
+                $phpcsFile->addWarning( $error, $stackPtr, 'Found', $data );
94 94
             }
95 95
         }
96 96
 
@@ -105,24 +105,24 @@  discard block
 block discarded – undo
105 105
      *
106 106
      * @return string[] List of all found incrementer variables.
107 107
      */
108
-    protected function findIncrementers(array $tokens, array $token)
108
+    protected function findIncrementers( array $tokens, array $token )
109 109
     {
110 110
         // Skip invalid statement.
111
-        if (isset($token['parenthesis_opener']) === false) {
112
-            return [];
111
+        if ( isset( $token[ 'parenthesis_opener' ] ) === false ) {
112
+            return [ ];
113 113
         }
114 114
 
115
-        $start = ++$token['parenthesis_opener'];
116
-        $end   = --$token['parenthesis_closer'];
115
+        $start = ++$token[ 'parenthesis_opener' ];
116
+        $end   = --$token[ 'parenthesis_closer' ];
117 117
 
118
-        $incrementers = [];
118
+        $incrementers = [ ];
119 119
         $semicolons   = 0;
120
-        for ($next = $start; $next <= $end; ++$next) {
121
-            $code = $tokens[$next]['code'];
122
-            if ($code === T_SEMICOLON) {
120
+        for ( $next = $start; $next <= $end; ++$next ) {
121
+            $code = $tokens[ $next ][ 'code' ];
122
+            if ( $code === T_SEMICOLON ) {
123 123
                 ++$semicolons;
124
-            } else if ($semicolons === 2 && $code === T_VARIABLE) {
125
-                $incrementers[] = $tokens[$next]['content'];
124
+            } else if ( $semicolons === 2 && $code === T_VARIABLE ) {
125
+                $incrementers[ ] = $tokens[ $next ][ 'content' ];
126 126
             }
127 127
         }
128 128
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,8 +32,7 @@  discard block
 block discarded – undo
32 32
 use PHP_CodeSniffer\Sniffs\Sniff;
33 33
 use PHP_CodeSniffer\Files\File;
34 34
 
35
-class JumbledIncrementerSniff implements Sniff
36
-{
35
+class JumbledIncrementerSniff implements Sniff {
37 36
 
38 37
 
39 38
     /**
@@ -41,8 +40,7 @@  discard block
 block discarded – undo
41 40
      *
42 41
      * @return int[]
43 42
      */
44
-    public function register()
45
-    {
43
+    public function register() {
46 44
         return [T_FOR];
47 45
 
48 46
     }//end register()
@@ -57,8 +55,7 @@  discard block
 block discarded – undo
57 55
      *
58 56
      * @return void
59 57
      */
60
-    public function process(File $phpcsFile, $stackPtr)
61
-    {
58
+    public function process(File $phpcsFile, $stackPtr) {
62 59
         $tokens = $phpcsFile->getTokens();
63 60
         $token  = $tokens[$stackPtr];
64 61
 
@@ -105,8 +102,7 @@  discard block
 block discarded – undo
105 102
      *
106 103
      * @return string[] List of all found incrementer variables.
107 104
      */
108
-    protected function findIncrementers(array $tokens, array $token)
109
-    {
105
+    protected function findIncrementers(array $tokens, array $token) {
110 106
         // Skip invalid statement.
111 107
         if (isset($token['parenthesis_opener']) === false) {
112 108
             return [];
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/WhiteSpace/DisallowSpaceIndentSniff.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     /**
38 38
      * Returns an array of tokens this test wants to listen for.
39 39
      *
40
-     * @return array
40
+     * @return integer[]
41 41
      */
42 42
     public function register()
43 43
     {
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
      * @param int                         $stackPtr  The position of the current token in
54 54
      *                                               the stack passed in $tokens.
55 55
      *
56
-     * @return void
56
+     * @return integer
57 57
      */
58 58
     public function process(File $phpcsFile, $stackPtr)
59 59
     {
Please login to merge, or discard this patch.
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -15,203 +15,203 @@
 block discarded – undo
15 15
 class DisallowSpaceIndentSniff implements Sniff
16 16
 {
17 17
 
18
-    /**
19
-     * A list of tokenizers this sniff supports.
20
-     *
21
-     * @var array
22
-     */
23
-    public $supportedTokenizers = [
24
-        'PHP',
25
-        'JS',
26
-        'CSS',
27
-    ];
28
-
29
-    /**
30
-     * The --tab-width CLI value that is being used.
31
-     *
32
-     * @var integer
33
-     */
34
-    private $tabWidth = null;
35
-
36
-
37
-    /**
38
-     * Returns an array of tokens this test wants to listen for.
39
-     *
40
-     * @return array
41
-     */
42
-    public function register()
43
-    {
44
-        return [T_OPEN_TAG];
45
-
46
-    }//end register()
47
-
48
-
49
-    /**
50
-     * Processes this test, when one of its tokens is encountered.
51
-     *
52
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
53
-     * @param int                         $stackPtr  The position of the current token in
54
-     *                                               the stack passed in $tokens.
55
-     *
56
-     * @return void
57
-     */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
60
-        $tabsReplaced = false;
61
-        if ($this->tabWidth === null) {
62
-            if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
63
-                // We have no idea how wide tabs are, so assume 4 spaces for fixing.
64
-                // It shouldn't really matter because indent checks elsewhere in the
65
-                // standard should fix things up.
66
-                $this->tabWidth = 4;
67
-            } else {
68
-                $this->tabWidth = $phpcsFile->config->tabWidth;
69
-                $tabsReplaced   = true;
70
-            }
71
-        }
72
-
73
-        $checkTokens = [
74
-            T_WHITESPACE             => true,
75
-            T_INLINE_HTML            => true,
76
-            T_DOC_COMMENT_WHITESPACE => true,
77
-            T_COMMENT                => true,
78
-        ];
79
-
80
-        $eolLen = strlen($phpcsFile->eolChar);
81
-
82
-        $tokens = $phpcsFile->getTokens();
83
-        for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
84
-            if ($tokens[$i]['column'] !== 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
85
-                continue;
86
-            }
87
-
88
-            // If the tokenizer hasn't replaced tabs with spaces, we need to do it manually.
89
-            $token = $tokens[$i];
90
-            if ($tabsReplaced === false) {
91
-                $phpcsFile->tokenizer->replaceTabsInToken($token, ' ', ' ', $this->tabWidth);
92
-                if (strpos($token['content'], $phpcsFile->eolChar) !== false) {
93
-                    // Newline chars are not counted in the token length.
94
-                    $token['length'] -= $eolLen;
95
-                }
96
-            }
97
-
98
-            if (isset($tokens[$i]['orig_content']) === true) {
99
-                $content = $tokens[$i]['orig_content'];
100
-            } else {
101
-                $content = $tokens[$i]['content'];
102
-            }
103
-
104
-            $expectedIndentSize = $token['length'];
105
-
106
-            $recordMetrics = true;
107
-
108
-            // If this is an inline HTML token or a subsequent line of a multi-line comment,
109
-            // split the content into indentation whitespace and the actual HTML/text.
110
-            $nonWhitespace = '';
111
-            if (($tokens[$i]['code'] === T_INLINE_HTML
112
-                || $tokens[$i]['code'] === T_COMMENT)
113
-                && preg_match('`^(\s*)(\S.*)`s', $content, $matches) > 0
114
-            ) {
115
-                if (isset($matches[1]) === true) {
116
-                    $content = $matches[1];
117
-
118
-                    // Tabs are not replaced in content, so the "length" is wrong.
119
-                    $matches[1]         = str_replace("\t", str_repeat(' ', $this->tabWidth), $matches[1]);
120
-                    $expectedIndentSize = strlen($matches[1]);
121
-                }
122
-
123
-                if (isset($matches[2]) === true) {
124
-                    $nonWhitespace = $matches[2];
125
-                }
126
-            } else if (isset($tokens[($i + 1)]) === true
127
-                && $tokens[$i]['line'] < $tokens[($i + 1)]['line']
128
-            ) {
129
-                // There is no content after this whitespace except for a newline.
130
-                $content       = rtrim($content, "\r\n");
131
-                $nonWhitespace = $phpcsFile->eolChar;
132
-
133
-                // Don't record metrics for empty lines.
134
-                $recordMetrics = false;
135
-            }//end if
136
-
137
-            $foundSpaces = substr_count($content, ' ');
138
-            $foundTabs   = substr_count($content, "\t");
139
-
140
-            if ($foundSpaces === 0 && $foundTabs === 0) {
141
-                // Empty line.
142
-                continue;
143
-            }
144
-
145
-            if ($foundSpaces === 0 && $foundTabs > 0) {
146
-                // All ok, nothing to do.
147
-                if ($recordMetrics === true) {
148
-                    $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
149
-                }
150
-
151
-                continue;
152
-            }
153
-
154
-            if (($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE
155
-                || $tokens[$i]['code'] === T_COMMENT)
156
-                && $content === ' '
157
-            ) {
158
-                // Ignore all non-indented comments, especially for recording metrics.
159
-                continue;
160
-            }
161
-
162
-            // OK, by now we know there will be spaces.
163
-            // We just don't know yet whether they need to be replaced or
164
-            // are precision indentation, nor whether they are correctly
165
-            // placed at the end of the whitespace.
166
-            $tabAfterSpaces = strpos($content, "\t", strpos($content, ' '));
167
-
168
-            // Calculate the expected tabs and spaces.
169
-            $expectedTabs   = (int) floor($expectedIndentSize / $this->tabWidth);
170
-            $expectedSpaces = ($expectedIndentSize % $this->tabWidth);
171
-
172
-            if ($foundTabs === 0) {
173
-                if ($recordMetrics === true) {
174
-                    $phpcsFile->recordMetric($i, 'Line indent', 'spaces');
175
-                }
176
-
177
-                if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
178
-                    // Ignore: precision indentation.
179
-                    continue;
180
-                }
181
-            } else {
182
-                if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
183
-                    // Precision indentation.
184
-                    if ($recordMetrics === true) {
185
-                        if ($tabAfterSpaces !== false) {
186
-                            $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
187
-                        } else {
188
-                            $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
189
-                        }
190
-                    }
191
-
192
-                    if ($tabAfterSpaces === false) {
193
-                        // Ignore: precision indentation is already at the
194
-                        // end of the whitespace.
195
-                        continue;
196
-                    }
197
-                } else if ($recordMetrics === true) {
198
-                    $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
199
-                }
200
-            }//end if
201
-
202
-            $error = 'Tabs must be used to indent lines; spaces are not allowed';
203
-            $fix   = $phpcsFile->addFixableError($error, $i, 'SpacesUsed');
204
-            if ($fix === true) {
205
-                $padding  = str_repeat("\t", $expectedTabs);
206
-                $padding .= str_repeat(' ', $expectedSpaces);
207
-                $phpcsFile->fixer->replaceToken($i, $padding.$nonWhitespace);
208
-            }
209
-        }//end for
210
-
211
-        // Ignore the rest of the file.
212
-        return ($phpcsFile->numTokens + 1);
213
-
214
-    }//end process()
18
+	/**
19
+	 * A list of tokenizers this sniff supports.
20
+	 *
21
+	 * @var array
22
+	 */
23
+	public $supportedTokenizers = [
24
+		'PHP',
25
+		'JS',
26
+		'CSS',
27
+	];
28
+
29
+	/**
30
+	 * The --tab-width CLI value that is being used.
31
+	 *
32
+	 * @var integer
33
+	 */
34
+	private $tabWidth = null;
35
+
36
+
37
+	/**
38
+	 * Returns an array of tokens this test wants to listen for.
39
+	 *
40
+	 * @return array
41
+	 */
42
+	public function register()
43
+	{
44
+		return [T_OPEN_TAG];
45
+
46
+	}//end register()
47
+
48
+
49
+	/**
50
+	 * Processes this test, when one of its tokens is encountered.
51
+	 *
52
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
53
+	 * @param int                         $stackPtr  The position of the current token in
54
+	 *                                               the stack passed in $tokens.
55
+	 *
56
+	 * @return void
57
+	 */
58
+	public function process(File $phpcsFile, $stackPtr)
59
+	{
60
+		$tabsReplaced = false;
61
+		if ($this->tabWidth === null) {
62
+			if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
63
+				// We have no idea how wide tabs are, so assume 4 spaces for fixing.
64
+				// It shouldn't really matter because indent checks elsewhere in the
65
+				// standard should fix things up.
66
+				$this->tabWidth = 4;
67
+			} else {
68
+				$this->tabWidth = $phpcsFile->config->tabWidth;
69
+				$tabsReplaced   = true;
70
+			}
71
+		}
72
+
73
+		$checkTokens = [
74
+			T_WHITESPACE             => true,
75
+			T_INLINE_HTML            => true,
76
+			T_DOC_COMMENT_WHITESPACE => true,
77
+			T_COMMENT                => true,
78
+		];
79
+
80
+		$eolLen = strlen($phpcsFile->eolChar);
81
+
82
+		$tokens = $phpcsFile->getTokens();
83
+		for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
84
+			if ($tokens[$i]['column'] !== 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
85
+				continue;
86
+			}
87
+
88
+			// If the tokenizer hasn't replaced tabs with spaces, we need to do it manually.
89
+			$token = $tokens[$i];
90
+			if ($tabsReplaced === false) {
91
+				$phpcsFile->tokenizer->replaceTabsInToken($token, ' ', ' ', $this->tabWidth);
92
+				if (strpos($token['content'], $phpcsFile->eolChar) !== false) {
93
+					// Newline chars are not counted in the token length.
94
+					$token['length'] -= $eolLen;
95
+				}
96
+			}
97
+
98
+			if (isset($tokens[$i]['orig_content']) === true) {
99
+				$content = $tokens[$i]['orig_content'];
100
+			} else {
101
+				$content = $tokens[$i]['content'];
102
+			}
103
+
104
+			$expectedIndentSize = $token['length'];
105
+
106
+			$recordMetrics = true;
107
+
108
+			// If this is an inline HTML token or a subsequent line of a multi-line comment,
109
+			// split the content into indentation whitespace and the actual HTML/text.
110
+			$nonWhitespace = '';
111
+			if (($tokens[$i]['code'] === T_INLINE_HTML
112
+				|| $tokens[$i]['code'] === T_COMMENT)
113
+				&& preg_match('`^(\s*)(\S.*)`s', $content, $matches) > 0
114
+			) {
115
+				if (isset($matches[1]) === true) {
116
+					$content = $matches[1];
117
+
118
+					// Tabs are not replaced in content, so the "length" is wrong.
119
+					$matches[1]         = str_replace("\t", str_repeat(' ', $this->tabWidth), $matches[1]);
120
+					$expectedIndentSize = strlen($matches[1]);
121
+				}
122
+
123
+				if (isset($matches[2]) === true) {
124
+					$nonWhitespace = $matches[2];
125
+				}
126
+			} else if (isset($tokens[($i + 1)]) === true
127
+				&& $tokens[$i]['line'] < $tokens[($i + 1)]['line']
128
+			) {
129
+				// There is no content after this whitespace except for a newline.
130
+				$content       = rtrim($content, "\r\n");
131
+				$nonWhitespace = $phpcsFile->eolChar;
132
+
133
+				// Don't record metrics for empty lines.
134
+				$recordMetrics = false;
135
+			}//end if
136
+
137
+			$foundSpaces = substr_count($content, ' ');
138
+			$foundTabs   = substr_count($content, "\t");
139
+
140
+			if ($foundSpaces === 0 && $foundTabs === 0) {
141
+				// Empty line.
142
+				continue;
143
+			}
144
+
145
+			if ($foundSpaces === 0 && $foundTabs > 0) {
146
+				// All ok, nothing to do.
147
+				if ($recordMetrics === true) {
148
+					$phpcsFile->recordMetric($i, 'Line indent', 'tabs');
149
+				}
150
+
151
+				continue;
152
+			}
153
+
154
+			if (($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE
155
+				|| $tokens[$i]['code'] === T_COMMENT)
156
+				&& $content === ' '
157
+			) {
158
+				// Ignore all non-indented comments, especially for recording metrics.
159
+				continue;
160
+			}
161
+
162
+			// OK, by now we know there will be spaces.
163
+			// We just don't know yet whether they need to be replaced or
164
+			// are precision indentation, nor whether they are correctly
165
+			// placed at the end of the whitespace.
166
+			$tabAfterSpaces = strpos($content, "\t", strpos($content, ' '));
167
+
168
+			// Calculate the expected tabs and spaces.
169
+			$expectedTabs   = (int) floor($expectedIndentSize / $this->tabWidth);
170
+			$expectedSpaces = ($expectedIndentSize % $this->tabWidth);
171
+
172
+			if ($foundTabs === 0) {
173
+				if ($recordMetrics === true) {
174
+					$phpcsFile->recordMetric($i, 'Line indent', 'spaces');
175
+				}
176
+
177
+				if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
178
+					// Ignore: precision indentation.
179
+					continue;
180
+				}
181
+			} else {
182
+				if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
183
+					// Precision indentation.
184
+					if ($recordMetrics === true) {
185
+						if ($tabAfterSpaces !== false) {
186
+							$phpcsFile->recordMetric($i, 'Line indent', 'mixed');
187
+						} else {
188
+							$phpcsFile->recordMetric($i, 'Line indent', 'tabs');
189
+						}
190
+					}
191
+
192
+					if ($tabAfterSpaces === false) {
193
+						// Ignore: precision indentation is already at the
194
+						// end of the whitespace.
195
+						continue;
196
+					}
197
+				} else if ($recordMetrics === true) {
198
+					$phpcsFile->recordMetric($i, 'Line indent', 'mixed');
199
+				}
200
+			}//end if
201
+
202
+			$error = 'Tabs must be used to indent lines; spaces are not allowed';
203
+			$fix   = $phpcsFile->addFixableError($error, $i, 'SpacesUsed');
204
+			if ($fix === true) {
205
+				$padding  = str_repeat("\t", $expectedTabs);
206
+				$padding .= str_repeat(' ', $expectedSpaces);
207
+				$phpcsFile->fixer->replaceToken($i, $padding.$nonWhitespace);
208
+			}
209
+		}//end for
210
+
211
+		// Ignore the rest of the file.
212
+		return ($phpcsFile->numTokens + 1);
213
+
214
+	}//end process()
215 215
 
216 216
 
217 217
 }//end class
Please login to merge, or discard this patch.
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
      */
42 42
     public function register()
43 43
     {
44
-        return [T_OPEN_TAG];
44
+        return [ T_OPEN_TAG ];
45 45
 
46 46
     }//end register()
47 47
 
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return void
57 57
      */
58
-    public function process(File $phpcsFile, $stackPtr)
58
+    public function process( File $phpcsFile, $stackPtr )
59 59
     {
60 60
         $tabsReplaced = false;
61
-        if ($this->tabWidth === null) {
62
-            if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
61
+        if ( $this->tabWidth === null ) {
62
+            if ( isset( $phpcsFile->config->tabWidth ) === false || $phpcsFile->config->tabWidth === 0 ) {
63 63
                 // We have no idea how wide tabs are, so assume 4 spaces for fixing.
64 64
                 // It shouldn't really matter because indent checks elsewhere in the
65 65
                 // standard should fix things up.
@@ -77,82 +77,82 @@  discard block
 block discarded – undo
77 77
             T_COMMENT                => true,
78 78
         ];
79 79
 
80
-        $eolLen = strlen($phpcsFile->eolChar);
80
+        $eolLen = strlen( $phpcsFile->eolChar );
81 81
 
82 82
         $tokens = $phpcsFile->getTokens();
83
-        for ($i = 0; $i < $phpcsFile->numTokens; $i++) {
84
-            if ($tokens[$i]['column'] !== 1 || isset($checkTokens[$tokens[$i]['code']]) === false) {
83
+        for ( $i = 0; $i < $phpcsFile->numTokens; $i++ ) {
84
+            if ( $tokens[ $i ][ 'column' ] !== 1 || isset( $checkTokens[ $tokens[ $i ][ 'code' ] ] ) === false ) {
85 85
                 continue;
86 86
             }
87 87
 
88 88
             // If the tokenizer hasn't replaced tabs with spaces, we need to do it manually.
89
-            $token = $tokens[$i];
90
-            if ($tabsReplaced === false) {
91
-                $phpcsFile->tokenizer->replaceTabsInToken($token, ' ', ' ', $this->tabWidth);
92
-                if (strpos($token['content'], $phpcsFile->eolChar) !== false) {
89
+            $token = $tokens[ $i ];
90
+            if ( $tabsReplaced === false ) {
91
+                $phpcsFile->tokenizer->replaceTabsInToken( $token, ' ', ' ', $this->tabWidth );
92
+                if ( strpos( $token[ 'content' ], $phpcsFile->eolChar ) !== false ) {
93 93
                     // Newline chars are not counted in the token length.
94
-                    $token['length'] -= $eolLen;
94
+                    $token[ 'length' ] -= $eolLen;
95 95
                 }
96 96
             }
97 97
 
98
-            if (isset($tokens[$i]['orig_content']) === true) {
99
-                $content = $tokens[$i]['orig_content'];
98
+            if ( isset( $tokens[ $i ][ 'orig_content' ] ) === true ) {
99
+                $content = $tokens[ $i ][ 'orig_content' ];
100 100
             } else {
101
-                $content = $tokens[$i]['content'];
101
+                $content = $tokens[ $i ][ 'content' ];
102 102
             }
103 103
 
104
-            $expectedIndentSize = $token['length'];
104
+            $expectedIndentSize = $token[ 'length' ];
105 105
 
106 106
             $recordMetrics = true;
107 107
 
108 108
             // If this is an inline HTML token or a subsequent line of a multi-line comment,
109 109
             // split the content into indentation whitespace and the actual HTML/text.
110 110
             $nonWhitespace = '';
111
-            if (($tokens[$i]['code'] === T_INLINE_HTML
112
-                || $tokens[$i]['code'] === T_COMMENT)
113
-                && preg_match('`^(\s*)(\S.*)`s', $content, $matches) > 0
111
+            if ( ( $tokens[ $i ][ 'code' ] === T_INLINE_HTML
112
+                || $tokens[ $i ][ 'code' ] === T_COMMENT )
113
+                && preg_match( '`^(\s*)(\S.*)`s', $content, $matches ) > 0
114 114
             ) {
115
-                if (isset($matches[1]) === true) {
116
-                    $content = $matches[1];
115
+                if ( isset( $matches[ 1 ] ) === true ) {
116
+                    $content = $matches[ 1 ];
117 117
 
118 118
                     // Tabs are not replaced in content, so the "length" is wrong.
119
-                    $matches[1]         = str_replace("\t", str_repeat(' ', $this->tabWidth), $matches[1]);
120
-                    $expectedIndentSize = strlen($matches[1]);
119
+                    $matches[ 1 ]         = str_replace( "\t", str_repeat( ' ', $this->tabWidth ), $matches[ 1 ] );
120
+                    $expectedIndentSize = strlen( $matches[ 1 ] );
121 121
                 }
122 122
 
123
-                if (isset($matches[2]) === true) {
124
-                    $nonWhitespace = $matches[2];
123
+                if ( isset( $matches[ 2 ] ) === true ) {
124
+                    $nonWhitespace = $matches[ 2 ];
125 125
                 }
126
-            } else if (isset($tokens[($i + 1)]) === true
127
-                && $tokens[$i]['line'] < $tokens[($i + 1)]['line']
126
+            } else if ( isset( $tokens[ ( $i + 1 ) ] ) === true
127
+                && $tokens[ $i ][ 'line' ] < $tokens[ ( $i + 1 ) ][ 'line' ]
128 128
             ) {
129 129
                 // There is no content after this whitespace except for a newline.
130
-                $content       = rtrim($content, "\r\n");
130
+                $content       = rtrim( $content, "\r\n" );
131 131
                 $nonWhitespace = $phpcsFile->eolChar;
132 132
 
133 133
                 // Don't record metrics for empty lines.
134 134
                 $recordMetrics = false;
135 135
             }//end if
136 136
 
137
-            $foundSpaces = substr_count($content, ' ');
138
-            $foundTabs   = substr_count($content, "\t");
137
+            $foundSpaces = substr_count( $content, ' ' );
138
+            $foundTabs   = substr_count( $content, "\t" );
139 139
 
140
-            if ($foundSpaces === 0 && $foundTabs === 0) {
140
+            if ( $foundSpaces === 0 && $foundTabs === 0 ) {
141 141
                 // Empty line.
142 142
                 continue;
143 143
             }
144 144
 
145
-            if ($foundSpaces === 0 && $foundTabs > 0) {
145
+            if ( $foundSpaces === 0 && $foundTabs > 0 ) {
146 146
                 // All ok, nothing to do.
147
-                if ($recordMetrics === true) {
148
-                    $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
147
+                if ( $recordMetrics === true ) {
148
+                    $phpcsFile->recordMetric( $i, 'Line indent', 'tabs' );
149 149
                 }
150 150
 
151 151
                 continue;
152 152
             }
153 153
 
154
-            if (($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE
155
-                || $tokens[$i]['code'] === T_COMMENT)
154
+            if ( ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_WHITESPACE
155
+                || $tokens[ $i ][ 'code' ] === T_COMMENT )
156 156
                 && $content === ' '
157 157
             ) {
158 158
                 // Ignore all non-indented comments, especially for recording metrics.
@@ -163,53 +163,53 @@  discard block
 block discarded – undo
163 163
             // We just don't know yet whether they need to be replaced or
164 164
             // are precision indentation, nor whether they are correctly
165 165
             // placed at the end of the whitespace.
166
-            $tabAfterSpaces = strpos($content, "\t", strpos($content, ' '));
166
+            $tabAfterSpaces = strpos( $content, "\t", strpos( $content, ' ' ) );
167 167
 
168 168
             // Calculate the expected tabs and spaces.
169
-            $expectedTabs   = (int) floor($expectedIndentSize / $this->tabWidth);
170
-            $expectedSpaces = ($expectedIndentSize % $this->tabWidth);
169
+            $expectedTabs   = (int)floor( $expectedIndentSize / $this->tabWidth );
170
+            $expectedSpaces = ( $expectedIndentSize % $this->tabWidth );
171 171
 
172
-            if ($foundTabs === 0) {
173
-                if ($recordMetrics === true) {
174
-                    $phpcsFile->recordMetric($i, 'Line indent', 'spaces');
172
+            if ( $foundTabs === 0 ) {
173
+                if ( $recordMetrics === true ) {
174
+                    $phpcsFile->recordMetric( $i, 'Line indent', 'spaces' );
175 175
                 }
176 176
 
177
-                if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
177
+                if ( $foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces ) {
178 178
                     // Ignore: precision indentation.
179 179
                     continue;
180 180
                 }
181 181
             } else {
182
-                if ($foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces) {
182
+                if ( $foundTabs === $expectedTabs && $foundSpaces === $expectedSpaces ) {
183 183
                     // Precision indentation.
184
-                    if ($recordMetrics === true) {
185
-                        if ($tabAfterSpaces !== false) {
186
-                            $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
184
+                    if ( $recordMetrics === true ) {
185
+                        if ( $tabAfterSpaces !== false ) {
186
+                            $phpcsFile->recordMetric( $i, 'Line indent', 'mixed' );
187 187
                         } else {
188
-                            $phpcsFile->recordMetric($i, 'Line indent', 'tabs');
188
+                            $phpcsFile->recordMetric( $i, 'Line indent', 'tabs' );
189 189
                         }
190 190
                     }
191 191
 
192
-                    if ($tabAfterSpaces === false) {
192
+                    if ( $tabAfterSpaces === false ) {
193 193
                         // Ignore: precision indentation is already at the
194 194
                         // end of the whitespace.
195 195
                         continue;
196 196
                     }
197
-                } else if ($recordMetrics === true) {
198
-                    $phpcsFile->recordMetric($i, 'Line indent', 'mixed');
197
+                } else if ( $recordMetrics === true ) {
198
+                    $phpcsFile->recordMetric( $i, 'Line indent', 'mixed' );
199 199
                 }
200 200
             }//end if
201 201
 
202 202
             $error = 'Tabs must be used to indent lines; spaces are not allowed';
203
-            $fix   = $phpcsFile->addFixableError($error, $i, 'SpacesUsed');
204
-            if ($fix === true) {
205
-                $padding  = str_repeat("\t", $expectedTabs);
206
-                $padding .= str_repeat(' ', $expectedSpaces);
207
-                $phpcsFile->fixer->replaceToken($i, $padding.$nonWhitespace);
203
+            $fix   = $phpcsFile->addFixableError( $error, $i, 'SpacesUsed' );
204
+            if ( $fix === true ) {
205
+                $padding  = str_repeat( "\t", $expectedTabs );
206
+                $padding .= str_repeat( ' ', $expectedSpaces );
207
+                $phpcsFile->fixer->replaceToken( $i, $padding . $nonWhitespace );
208 208
             }
209 209
         }//end for
210 210
 
211 211
         // Ignore the rest of the file.
212
-        return ($phpcsFile->numTokens + 1);
212
+        return ( $phpcsFile->numTokens + 1 );
213 213
 
214 214
     }//end process()
215 215
 
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,8 +12,7 @@  discard block
 block discarded – undo
12 12
 use PHP_CodeSniffer\Sniffs\Sniff;
13 13
 use PHP_CodeSniffer\Files\File;
14 14
 
15
-class DisallowSpaceIndentSniff implements Sniff
16
-{
15
+class DisallowSpaceIndentSniff implements Sniff {
17 16
 
18 17
     /**
19 18
      * A list of tokenizers this sniff supports.
@@ -39,8 +38,7 @@  discard block
 block discarded – undo
39 38
      *
40 39
      * @return array
41 40
      */
42
-    public function register()
43
-    {
41
+    public function register() {
44 42
         return [T_OPEN_TAG];
45 43
 
46 44
     }//end register()
@@ -55,8 +53,7 @@  discard block
 block discarded – undo
55 53
      *
56 54
      * @return void
57 55
      */
58
-    public function process(File $phpcsFile, $stackPtr)
59
-    {
56
+    public function process(File $phpcsFile, $stackPtr) {
60 57
         $tabsReplaced = false;
61 58
         if ($this->tabWidth === null) {
62 59
             if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
Please login to merge, or discard this patch.
src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php 5 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     /**
103 103
      * Returns an array of tokens this test wants to listen for.
104 104
      *
105
-     * @return array
105
+     * @return integer[]
106 106
      */
107 107
     public function register()
108 108
     {
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
      * @param int                         $stackPtr  The position of the current token
123 123
      *                                               in the stack passed in $tokens.
124 124
      *
125
-     * @return void
125
+     * @return integer
126 126
      */
127 127
     public function process(File $phpcsFile, $stackPtr)
128 128
     {
Please login to merge, or discard this patch.
Indentation   +1441 added lines, -1441 removed lines patch added patch discarded remove patch
@@ -17,904 +17,904 @@  discard block
 block discarded – undo
17 17
 class ScopeIndentSniff implements Sniff
18 18
 {
19 19
 
20
-    /**
21
-     * A list of tokenizers this sniff supports.
22
-     *
23
-     * @var array
24
-     */
25
-    public $supportedTokenizers = [
26
-        'PHP',
27
-        'JS',
28
-    ];
29
-
30
-    /**
31
-     * The number of spaces code should be indented.
32
-     *
33
-     * @var integer
34
-     */
35
-    public $indent = 4;
36
-
37
-    /**
38
-     * Does the indent need to be exactly right?
39
-     *
40
-     * If TRUE, indent needs to be exactly $indent spaces. If FALSE,
41
-     * indent needs to be at least $indent spaces (but can be more).
42
-     *
43
-     * @var boolean
44
-     */
45
-    public $exact = false;
46
-
47
-    /**
48
-     * Should tabs be used for indenting?
49
-     *
50
-     * If TRUE, fixes will be made using tabs instead of spaces.
51
-     * The size of each tab is important, so it should be specified
52
-     * using the --tab-width CLI argument.
53
-     *
54
-     * @var boolean
55
-     */
56
-    public $tabIndent = false;
57
-
58
-    /**
59
-     * The --tab-width CLI value that is being used.
60
-     *
61
-     * @var integer
62
-     */
63
-    private $tabWidth = null;
64
-
65
-    /**
66
-     * List of tokens not needing to be checked for indentation.
67
-     *
68
-     * Useful to allow Sniffs based on this to easily ignore/skip some
69
-     * tokens from verification. For example, inline HTML sections
70
-     * or PHP open/close tags can escape from here and have their own
71
-     * rules elsewhere.
72
-     *
73
-     * @var int[]
74
-     */
75
-    public $ignoreIndentationTokens = [];
76
-
77
-    /**
78
-     * List of tokens not needing to be checked for indentation.
79
-     *
80
-     * This is a cached copy of the public version of this var, which
81
-     * can be set in a ruleset file, and some core ignored tokens.
82
-     *
83
-     * @var int[]
84
-     */
85
-    private $ignoreIndentation = [];
86
-
87
-    /**
88
-     * Any scope openers that should not cause an indent.
89
-     *
90
-     * @var int[]
91
-     */
92
-    protected $nonIndentingScopes = [];
93
-
94
-    /**
95
-     * Show debug output for this sniff.
96
-     *
97
-     * @var boolean
98
-     */
99
-    private $debug = false;
100
-
101
-
102
-    /**
103
-     * Returns an array of tokens this test wants to listen for.
104
-     *
105
-     * @return array
106
-     */
107
-    public function register()
108
-    {
109
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
110
-            $this->debug = false;
111
-        }
112
-
113
-        return [T_OPEN_TAG];
114
-
115
-    }//end register()
116
-
117
-
118
-    /**
119
-     * Processes this test, when one of its tokens is encountered.
120
-     *
121
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
122
-     * @param int                         $stackPtr  The position of the current token
123
-     *                                               in the stack passed in $tokens.
124
-     *
125
-     * @return void
126
-     */
127
-    public function process(File $phpcsFile, $stackPtr)
128
-    {
129
-        $debug = Config::getConfigData('scope_indent_debug');
130
-        if ($debug !== null) {
131
-            $this->debug = (bool) $debug;
132
-        }
133
-
134
-        if ($this->tabWidth === null) {
135
-            if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
136
-                // We have no idea how wide tabs are, so assume 4 spaces for fixing.
137
-                // It shouldn't really matter because indent checks elsewhere in the
138
-                // standard should fix things up.
139
-                $this->tabWidth = 4;
140
-            } else {
141
-                $this->tabWidth = $phpcsFile->config->tabWidth;
142
-            }
143
-        }
144
-
145
-        $lastOpenTag     = $stackPtr;
146
-        $lastCloseTag    = null;
147
-        $openScopes      = [];
148
-        $adjustments     = [];
149
-        $setIndents      = [];
150
-        $disableExactEnd = 0;
151
-
152
-        $tokens  = $phpcsFile->getTokens();
153
-        $first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
154
-        $trimmed = ltrim($tokens[$first]['content']);
155
-        if ($trimmed === '') {
156
-            $currentIndent = ($tokens[$stackPtr]['column'] - 1);
157
-        } else {
158
-            $currentIndent = (strlen($tokens[$first]['content']) - strlen($trimmed));
159
-        }
160
-
161
-        if ($this->debug === true) {
162
-            $line = $tokens[$stackPtr]['line'];
163
-            echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL;
164
-        }
165
-
166
-        if (empty($this->ignoreIndentation) === true) {
167
-            $this->ignoreIndentation = [T_INLINE_HTML => true];
168
-            foreach ($this->ignoreIndentationTokens as $token) {
169
-                if (is_int($token) === false) {
170
-                    if (defined($token) === false) {
171
-                        continue;
172
-                    }
173
-
174
-                    $token = constant($token);
175
-                }
176
-
177
-                $this->ignoreIndentation[$token] = true;
178
-            }
179
-        }//end if
180
-
181
-        $this->exact     = (bool) $this->exact;
182
-        $this->tabIndent = (bool) $this->tabIndent;
183
-
184
-        $checkAnnotations = $phpcsFile->config->annotations;
185
-
186
-        for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
187
-            if ($i === false) {
188
-                // Something has gone very wrong; maybe a parse error.
189
-                break;
190
-            }
191
-
192
-            if ($checkAnnotations === true
193
-                && $tokens[$i]['code'] === T_PHPCS_SET
194
-                && isset($tokens[$i]['sniffCode']) === true
195
-                && $tokens[$i]['sniffCode'] === 'Generic.WhiteSpace.ScopeIndent'
196
-                && $tokens[$i]['sniffProperty'] === 'exact'
197
-            ) {
198
-                $value = $tokens[$i]['sniffPropertyValue'];
199
-                if ($value === 'true') {
200
-                    $value = true;
201
-                } else if ($value === 'false') {
202
-                    $value = false;
203
-                } else {
204
-                    $value = (bool) $value;
205
-                }
206
-
207
-                $this->exact = $value;
208
-
209
-                if ($this->debug === true) {
210
-                    $line = $tokens[$i]['line'];
211
-                    if ($this->exact === true) {
212
-                        $value = 'true';
213
-                    } else {
214
-                        $value = 'false';
215
-                    }
216
-
217
-                    echo "* token $i on line $line set exact flag to $value *".PHP_EOL;
218
-                }
219
-            }//end if
220
-
221
-            $checkToken  = null;
222
-            $checkIndent = null;
223
-
224
-            /*
20
+	/**
21
+	 * A list of tokenizers this sniff supports.
22
+	 *
23
+	 * @var array
24
+	 */
25
+	public $supportedTokenizers = [
26
+		'PHP',
27
+		'JS',
28
+	];
29
+
30
+	/**
31
+	 * The number of spaces code should be indented.
32
+	 *
33
+	 * @var integer
34
+	 */
35
+	public $indent = 4;
36
+
37
+	/**
38
+	 * Does the indent need to be exactly right?
39
+	 *
40
+	 * If TRUE, indent needs to be exactly $indent spaces. If FALSE,
41
+	 * indent needs to be at least $indent spaces (but can be more).
42
+	 *
43
+	 * @var boolean
44
+	 */
45
+	public $exact = false;
46
+
47
+	/**
48
+	 * Should tabs be used for indenting?
49
+	 *
50
+	 * If TRUE, fixes will be made using tabs instead of spaces.
51
+	 * The size of each tab is important, so it should be specified
52
+	 * using the --tab-width CLI argument.
53
+	 *
54
+	 * @var boolean
55
+	 */
56
+	public $tabIndent = false;
57
+
58
+	/**
59
+	 * The --tab-width CLI value that is being used.
60
+	 *
61
+	 * @var integer
62
+	 */
63
+	private $tabWidth = null;
64
+
65
+	/**
66
+	 * List of tokens not needing to be checked for indentation.
67
+	 *
68
+	 * Useful to allow Sniffs based on this to easily ignore/skip some
69
+	 * tokens from verification. For example, inline HTML sections
70
+	 * or PHP open/close tags can escape from here and have their own
71
+	 * rules elsewhere.
72
+	 *
73
+	 * @var int[]
74
+	 */
75
+	public $ignoreIndentationTokens = [];
76
+
77
+	/**
78
+	 * List of tokens not needing to be checked for indentation.
79
+	 *
80
+	 * This is a cached copy of the public version of this var, which
81
+	 * can be set in a ruleset file, and some core ignored tokens.
82
+	 *
83
+	 * @var int[]
84
+	 */
85
+	private $ignoreIndentation = [];
86
+
87
+	/**
88
+	 * Any scope openers that should not cause an indent.
89
+	 *
90
+	 * @var int[]
91
+	 */
92
+	protected $nonIndentingScopes = [];
93
+
94
+	/**
95
+	 * Show debug output for this sniff.
96
+	 *
97
+	 * @var boolean
98
+	 */
99
+	private $debug = false;
100
+
101
+
102
+	/**
103
+	 * Returns an array of tokens this test wants to listen for.
104
+	 *
105
+	 * @return array
106
+	 */
107
+	public function register()
108
+	{
109
+		if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
110
+			$this->debug = false;
111
+		}
112
+
113
+		return [T_OPEN_TAG];
114
+
115
+	}//end register()
116
+
117
+
118
+	/**
119
+	 * Processes this test, when one of its tokens is encountered.
120
+	 *
121
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
122
+	 * @param int                         $stackPtr  The position of the current token
123
+	 *                                               in the stack passed in $tokens.
124
+	 *
125
+	 * @return void
126
+	 */
127
+	public function process(File $phpcsFile, $stackPtr)
128
+	{
129
+		$debug = Config::getConfigData('scope_indent_debug');
130
+		if ($debug !== null) {
131
+			$this->debug = (bool) $debug;
132
+		}
133
+
134
+		if ($this->tabWidth === null) {
135
+			if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
136
+				// We have no idea how wide tabs are, so assume 4 spaces for fixing.
137
+				// It shouldn't really matter because indent checks elsewhere in the
138
+				// standard should fix things up.
139
+				$this->tabWidth = 4;
140
+			} else {
141
+				$this->tabWidth = $phpcsFile->config->tabWidth;
142
+			}
143
+		}
144
+
145
+		$lastOpenTag     = $stackPtr;
146
+		$lastCloseTag    = null;
147
+		$openScopes      = [];
148
+		$adjustments     = [];
149
+		$setIndents      = [];
150
+		$disableExactEnd = 0;
151
+
152
+		$tokens  = $phpcsFile->getTokens();
153
+		$first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
154
+		$trimmed = ltrim($tokens[$first]['content']);
155
+		if ($trimmed === '') {
156
+			$currentIndent = ($tokens[$stackPtr]['column'] - 1);
157
+		} else {
158
+			$currentIndent = (strlen($tokens[$first]['content']) - strlen($trimmed));
159
+		}
160
+
161
+		if ($this->debug === true) {
162
+			$line = $tokens[$stackPtr]['line'];
163
+			echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL;
164
+		}
165
+
166
+		if (empty($this->ignoreIndentation) === true) {
167
+			$this->ignoreIndentation = [T_INLINE_HTML => true];
168
+			foreach ($this->ignoreIndentationTokens as $token) {
169
+				if (is_int($token) === false) {
170
+					if (defined($token) === false) {
171
+						continue;
172
+					}
173
+
174
+					$token = constant($token);
175
+				}
176
+
177
+				$this->ignoreIndentation[$token] = true;
178
+			}
179
+		}//end if
180
+
181
+		$this->exact     = (bool) $this->exact;
182
+		$this->tabIndent = (bool) $this->tabIndent;
183
+
184
+		$checkAnnotations = $phpcsFile->config->annotations;
185
+
186
+		for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
187
+			if ($i === false) {
188
+				// Something has gone very wrong; maybe a parse error.
189
+				break;
190
+			}
191
+
192
+			if ($checkAnnotations === true
193
+				&& $tokens[$i]['code'] === T_PHPCS_SET
194
+				&& isset($tokens[$i]['sniffCode']) === true
195
+				&& $tokens[$i]['sniffCode'] === 'Generic.WhiteSpace.ScopeIndent'
196
+				&& $tokens[$i]['sniffProperty'] === 'exact'
197
+			) {
198
+				$value = $tokens[$i]['sniffPropertyValue'];
199
+				if ($value === 'true') {
200
+					$value = true;
201
+				} else if ($value === 'false') {
202
+					$value = false;
203
+				} else {
204
+					$value = (bool) $value;
205
+				}
206
+
207
+				$this->exact = $value;
208
+
209
+				if ($this->debug === true) {
210
+					$line = $tokens[$i]['line'];
211
+					if ($this->exact === true) {
212
+						$value = 'true';
213
+					} else {
214
+						$value = 'false';
215
+					}
216
+
217
+					echo "* token $i on line $line set exact flag to $value *".PHP_EOL;
218
+				}
219
+			}//end if
220
+
221
+			$checkToken  = null;
222
+			$checkIndent = null;
223
+
224
+			/*
225 225
                 Don't check indents exactly between parenthesis or arrays as they
226 226
                 tend to have custom rules, such as with multi-line function calls
227 227
                 and control structure conditions.
228 228
             */
229 229
 
230
-            $exact = $this->exact;
231
-
232
-            if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
233
-                $disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
234
-            }
235
-
236
-            if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
237
-                && isset($tokens[$i]['parenthesis_closer']) === true
238
-            ) {
239
-                $disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
240
-            }
241
-
242
-            if ($exact === true && $i < $disableExactEnd) {
243
-                $exact = false;
244
-            }
245
-
246
-            // Detect line changes and figure out where the indent is.
247
-            if ($tokens[$i]['column'] === 1) {
248
-                $trimmed = ltrim($tokens[$i]['content']);
249
-                if ($trimmed === '') {
250
-                    if (isset($tokens[($i + 1)]) === true
251
-                        && $tokens[$i]['line'] === $tokens[($i + 1)]['line']
252
-                    ) {
253
-                        $checkToken  = ($i + 1);
254
-                        $tokenIndent = ($tokens[($i + 1)]['column'] - 1);
255
-                    }
256
-                } else {
257
-                    $checkToken  = $i;
258
-                    $tokenIndent = (strlen($tokens[$i]['content']) - strlen($trimmed));
259
-                }
260
-            }
261
-
262
-            // Closing parenthesis should just be indented to at least
263
-            // the same level as where they were opened (but can be more).
264
-            if (($checkToken !== null
265
-                && $tokens[$checkToken]['code'] === T_CLOSE_PARENTHESIS
266
-                && isset($tokens[$checkToken]['parenthesis_opener']) === true)
267
-                || ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS
268
-                && isset($tokens[$i]['parenthesis_opener']) === true)
269
-            ) {
270
-                if ($checkToken !== null) {
271
-                    $parenCloser = $checkToken;
272
-                } else {
273
-                    $parenCloser = $i;
274
-                }
275
-
276
-                if ($this->debug === true) {
277
-                    $line = $tokens[$i]['line'];
278
-                    echo "Closing parenthesis found on line $line".PHP_EOL;
279
-                }
280
-
281
-                $parenOpener = $tokens[$parenCloser]['parenthesis_opener'];
282
-                if ($tokens[$parenCloser]['line'] !== $tokens[$parenOpener]['line']) {
283
-                    $parens = 0;
284
-                    if (isset($tokens[$parenCloser]['nested_parenthesis']) === true
285
-                        && empty($tokens[$parenCloser]['nested_parenthesis']) === false
286
-                    ) {
287
-                        $parens = $tokens[$parenCloser]['nested_parenthesis'];
288
-                        end($parens);
289
-                        $parens = key($parens);
290
-                        if ($this->debug === true) {
291
-                            $line = $tokens[$parens]['line'];
292
-                            echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
293
-                        }
294
-                    }
295
-
296
-                    $condition = 0;
297
-                    if (isset($tokens[$parenCloser]['conditions']) === true
298
-                        && empty($tokens[$parenCloser]['conditions']) === false
299
-                        && (isset($tokens[$parenCloser]['parenthesis_owner']) === false
300
-                        || $parens > 0)
301
-                    ) {
302
-                        $condition = $tokens[$parenCloser]['conditions'];
303
-                        end($condition);
304
-                        $condition = key($condition);
305
-                        if ($this->debug === true) {
306
-                            $line = $tokens[$condition]['line'];
307
-                            $type = $tokens[$condition]['type'];
308
-                            echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
309
-                        }
310
-                    }
311
-
312
-                    if ($parens > $condition) {
313
-                        if ($this->debug === true) {
314
-                            echo "\t* using parenthesis *".PHP_EOL;
315
-                        }
316
-
317
-                        $parenOpener = $parens;
318
-                        $condition   = 0;
319
-                    } else if ($condition > 0) {
320
-                        if ($this->debug === true) {
321
-                            echo "\t* using condition *".PHP_EOL;
322
-                        }
323
-
324
-                        $parenOpener = $condition;
325
-                        $parens      = 0;
326
-                    }
327
-
328
-                    $exact = false;
329
-
330
-                    $lastOpenTagConditions = array_keys($tokens[$lastOpenTag]['conditions']);
331
-                    $lastOpenTagCondition  = array_pop($lastOpenTagConditions);
332
-
333
-                    if ($condition > 0 && $lastOpenTagCondition === $condition) {
334
-                        if ($this->debug === true) {
335
-                            echo "\t* open tag is inside condition; using open tag *".PHP_EOL;
336
-                        }
337
-
338
-                        $checkIndent = ($tokens[$lastOpenTag]['column'] - 1);
339
-                        if (isset($adjustments[$condition]) === true) {
340
-                            $checkIndent += $adjustments[$condition];
341
-                        }
342
-
343
-                        $currentIndent = $checkIndent;
344
-
345
-                        if ($this->debug === true) {
346
-                            $type = $tokens[$lastOpenTag]['type'];
347
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)".PHP_EOL;
348
-                        }
349
-                    } else if ($condition > 0
350
-                        && isset($tokens[$condition]['scope_opener']) === true
351
-                        && isset($setIndents[$tokens[$condition]['scope_opener']]) === true
352
-                    ) {
353
-                        $checkIndent = $setIndents[$tokens[$condition]['scope_opener']];
354
-                        if (isset($adjustments[$condition]) === true) {
355
-                            $checkIndent += $adjustments[$condition];
356
-                        }
357
-
358
-                        $currentIndent = $checkIndent;
359
-
360
-                        if ($this->debug === true) {
361
-                            $type = $tokens[$condition]['type'];
362
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)".PHP_EOL;
363
-                        }
364
-                    } else {
365
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parenOpener, true);
366
-
367
-                        $checkIndent = ($tokens[$first]['column'] - 1);
368
-                        if (isset($adjustments[$first]) === true) {
369
-                            $checkIndent += $adjustments[$first];
370
-                        }
371
-
372
-                        if ($this->debug === true) {
373
-                            $line = $tokens[$first]['line'];
374
-                            $type = $tokens[$first]['type'];
375
-                            echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
376
-                        }
377
-
378
-                        if ($first === $tokens[$parenCloser]['parenthesis_opener']
379
-                            && $tokens[($first - 1)]['line'] === $tokens[$first]['line']
380
-                        ) {
381
-                            // This is unlikely to be the start of the statement, so look
382
-                            // back further to find it.
383
-                            $first--;
384
-                            if ($this->debug === true) {
385
-                                $line = $tokens[$first]['line'];
386
-                                $type = $tokens[$first]['type'];
387
-                                echo "\t* first token is the parenthesis opener *".PHP_EOL;
388
-                                echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
389
-                            }
390
-                        }
391
-
392
-                        $prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
393
-                        if ($prev !== $first) {
394
-                            // This is not the start of the statement.
395
-                            if ($this->debug === true) {
396
-                                $line = $tokens[$prev]['line'];
397
-                                $type = $tokens[$prev]['type'];
398
-                                echo "\t* previous is $type on line $line *".PHP_EOL;
399
-                            }
400
-
401
-                            $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
402
-                            if ($first !== false) {
403
-                                $prev  = $phpcsFile->findStartOfStatement($first, T_COMMA);
404
-                                $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
405
-                            } else {
406
-                                $first = $prev;
407
-                            }
408
-
409
-                            if ($this->debug === true) {
410
-                                $line = $tokens[$first]['line'];
411
-                                $type = $tokens[$first]['type'];
412
-                                echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
413
-                            }
414
-                        }//end if
415
-
416
-                        if (isset($tokens[$first]['scope_closer']) === true
417
-                            && $tokens[$first]['scope_closer'] === $first
418
-                        ) {
419
-                            if ($this->debug === true) {
420
-                                echo "\t* first token is a scope closer *".PHP_EOL;
421
-                            }
422
-
423
-                            if (isset($tokens[$first]['scope_condition']) === true) {
424
-                                $scopeCloser = $first;
425
-                                $first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true);
426
-
427
-                                $currentIndent = ($tokens[$first]['column'] - 1);
428
-                                if (isset($adjustments[$first]) === true) {
429
-                                    $currentIndent += $adjustments[$first];
430
-                                }
431
-
432
-                                // Make sure it is divisible by our expected indent.
433
-                                if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) {
434
-                                    $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent);
435
-                                }
436
-
437
-                                $setIndents[$first] = $currentIndent;
438
-
439
-                                if ($this->debug === true) {
440
-                                    $type = $tokens[$first]['type'];
441
-                                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
442
-                                }
443
-                            }//end if
444
-                        } else {
445
-                            // Don't force current indent to be divisible because there could be custom
446
-                            // rules in place between parenthesis, such as with arrays.
447
-                            $currentIndent = ($tokens[$first]['column'] - 1);
448
-                            if (isset($adjustments[$first]) === true) {
449
-                                $currentIndent += $adjustments[$first];
450
-                            }
451
-
452
-                            $setIndents[$first] = $currentIndent;
453
-
454
-                            if ($this->debug === true) {
455
-                                $type = $tokens[$first]['type'];
456
-                                echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
457
-                            }
458
-                        }//end if
459
-                    }//end if
460
-                } else if ($this->debug === true) {
461
-                    echo "\t * ignoring single-line definition *".PHP_EOL;
462
-                }//end if
463
-            }//end if
464
-
465
-            // Closing short array bracket should just be indented to at least
466
-            // the same level as where it was opened (but can be more).
467
-            if ($tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
468
-                || ($checkToken !== null
469
-                && $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY)
470
-            ) {
471
-                if ($checkToken !== null) {
472
-                    $arrayCloser = $checkToken;
473
-                } else {
474
-                    $arrayCloser = $i;
475
-                }
476
-
477
-                if ($this->debug === true) {
478
-                    $line = $tokens[$arrayCloser]['line'];
479
-                    echo "Closing short array bracket found on line $line".PHP_EOL;
480
-                }
481
-
482
-                $arrayOpener = $tokens[$arrayCloser]['bracket_opener'];
483
-                if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) {
484
-                    $first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
485
-                    $checkIndent = ($tokens[$first]['column'] - 1);
486
-                    if (isset($adjustments[$first]) === true) {
487
-                        $checkIndent += $adjustments[$first];
488
-                    }
489
-
490
-                    $exact = false;
491
-
492
-                    if ($this->debug === true) {
493
-                        $line = $tokens[$first]['line'];
494
-                        $type = $tokens[$first]['type'];
495
-                        echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
496
-                    }
497
-
498
-                    if ($first === $tokens[$arrayCloser]['bracket_opener']) {
499
-                        // This is unlikely to be the start of the statement, so look
500
-                        // back further to find it.
501
-                        $first--;
502
-                    }
503
-
504
-                    $prev = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
505
-                    if ($prev !== $first) {
506
-                        // This is not the start of the statement.
507
-                        if ($this->debug === true) {
508
-                            $line = $tokens[$prev]['line'];
509
-                            $type = $tokens[$prev]['type'];
510
-                            echo "\t* previous is $type on line $line *".PHP_EOL;
511
-                        }
512
-
513
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
514
-                        $prev  = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
515
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
516
-                        if ($this->debug === true) {
517
-                            $line = $tokens[$first]['line'];
518
-                            $type = $tokens[$first]['type'];
519
-                            echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
520
-                        }
521
-                    } else if ($tokens[$first]['code'] === T_WHITESPACE) {
522
-                        $first = $phpcsFile->findNext(T_WHITESPACE, ($first + 1), null, true);
523
-                    }
524
-
525
-                    if (isset($tokens[$first]['scope_closer']) === true
526
-                        && $tokens[$first]['scope_closer'] === $first
527
-                    ) {
528
-                        // The first token is a scope closer and would have already
529
-                        // been processed and set the indent level correctly, so
530
-                        // don't adjust it again.
531
-                        if ($this->debug === true) {
532
-                            echo "\t* first token is a scope closer; ignoring closing short array bracket *".PHP_EOL;
533
-                        }
534
-
535
-                        if (isset($setIndents[$first]) === true) {
536
-                            $currentIndent = $setIndents[$first];
537
-                            if ($this->debug === true) {
538
-                                echo "\t=> indent reset to $currentIndent".PHP_EOL;
539
-                            }
540
-                        }
541
-                    } else {
542
-                        // Don't force current indent to be divisible because there could be custom
543
-                        // rules in place for arrays.
544
-                        $currentIndent = ($tokens[$first]['column'] - 1);
545
-                        if (isset($adjustments[$first]) === true) {
546
-                            $currentIndent += $adjustments[$first];
547
-                        }
548
-
549
-                        $setIndents[$first] = $currentIndent;
550
-
551
-                        if ($this->debug === true) {
552
-                            $type = $tokens[$first]['type'];
553
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
554
-                        }
555
-                    }//end if
556
-                } else if ($this->debug === true) {
557
-                    echo "\t * ignoring single-line definition *".PHP_EOL;
558
-                }//end if
559
-            }//end if
560
-
561
-            // Adjust lines within scopes while auto-fixing.
562
-            if ($checkToken !== null
563
-                && $exact === false
564
-                && (empty($tokens[$checkToken]['conditions']) === false
565
-                || (isset($tokens[$checkToken]['scope_opener']) === true
566
-                && $tokens[$checkToken]['scope_opener'] === $checkToken))
567
-            ) {
568
-                if (empty($tokens[$checkToken]['conditions']) === false) {
569
-                    $condition = $tokens[$checkToken]['conditions'];
570
-                    end($condition);
571
-                    $condition = key($condition);
572
-                } else {
573
-                    $condition = $tokens[$checkToken]['scope_condition'];
574
-                }
575
-
576
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
577
-
578
-                if (isset($adjustments[$first]) === true
579
-                    && (($adjustments[$first] < 0 && $tokenIndent > $currentIndent)
580
-                    || ($adjustments[$first] > 0 && $tokenIndent < $currentIndent))
581
-                ) {
582
-                    $length = ($tokenIndent + $adjustments[$first]);
583
-
584
-                    // When fixing, we're going to adjust the indent of this line
585
-                    // here automatically, so use this new padding value when
586
-                    // comparing the expected padding to the actual padding.
587
-                    if ($phpcsFile->fixer->enabled === true) {
588
-                        $tokenIndent = $length;
589
-                        $this->adjustIndent($phpcsFile, $checkToken, $length, $adjustments[$first]);
590
-                    }
591
-
592
-                    if ($this->debug === true) {
593
-                        $line = $tokens[$checkToken]['line'];
594
-                        $type = $tokens[$checkToken]['type'];
595
-                        echo "Indent adjusted to $length for $type on line $line".PHP_EOL;
596
-                    }
597
-
598
-                    $adjustments[$checkToken] = $adjustments[$first];
599
-
600
-                    if ($this->debug === true) {
601
-                        $line = $tokens[$checkToken]['line'];
602
-                        $type = $tokens[$checkToken]['type'];
603
-                        echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
604
-                    }
605
-                }//end if
606
-            }//end if
607
-
608
-            // Scope closers reset the required indent to the same level as the opening condition.
609
-            if (($checkToken !== null
610
-                && isset($openScopes[$checkToken]) === true
611
-                || (isset($tokens[$checkToken]['scope_condition']) === true
612
-                && isset($tokens[$checkToken]['scope_closer']) === true
613
-                && $tokens[$checkToken]['scope_closer'] === $checkToken
614
-                && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))
615
-                || ($checkToken === null
616
-                && isset($openScopes[$i]) === true
617
-                || (isset($tokens[$i]['scope_condition']) === true
618
-                && isset($tokens[$i]['scope_closer']) === true
619
-                && $tokens[$i]['scope_closer'] === $i
620
-                && $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line']))
621
-            ) {
622
-                if ($this->debug === true) {
623
-                    if ($checkToken === null) {
624
-                        $type = $tokens[$tokens[$i]['scope_condition']]['type'];
625
-                        $line = $tokens[$i]['line'];
626
-                    } else {
627
-                        $type = $tokens[$tokens[$checkToken]['scope_condition']]['type'];
628
-                        $line = $tokens[$checkToken]['line'];
629
-                    }
630
-
631
-                    echo "Close scope ($type) on line $line".PHP_EOL;
632
-                }
633
-
634
-                $scopeCloser = $checkToken;
635
-                if ($scopeCloser === null) {
636
-                    $scopeCloser = $i;
637
-                }
638
-
639
-                $conditionToken = array_pop($openScopes);
640
-                if ($this->debug === true) {
641
-                    $line = $tokens[$conditionToken]['line'];
642
-                    $type = $tokens[$conditionToken]['type'];
643
-                    echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
644
-                }
645
-
646
-                if (isset($tokens[$scopeCloser]['scope_condition']) === true) {
647
-                    $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $tokens[$scopeCloser]['scope_condition'], true);
648
-                    if ($this->debug === true) {
649
-                        $line = $tokens[$first]['line'];
650
-                        $type = $tokens[$first]['type'];
651
-                        echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
652
-                    }
653
-
654
-                    while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
655
-                        && $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
656
-                    ) {
657
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
658
-                        if ($this->debug === true) {
659
-                            $line = $tokens[$first]['line'];
660
-                            $type = $tokens[$first]['type'];
661
-                            echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
662
-                        }
663
-                    }
664
-
665
-                    $currentIndent = ($tokens[$first]['column'] - 1);
666
-                    if (isset($adjustments[$first]) === true) {
667
-                        $currentIndent += $adjustments[$first];
668
-                    }
669
-
670
-                    $setIndents[$scopeCloser] = $currentIndent;
671
-
672
-                    if ($this->debug === true) {
673
-                        $type = $tokens[$scopeCloser]['type'];
674
-                        echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)".PHP_EOL;
675
-                    }
676
-
677
-                    // We only check the indent of scope closers if they are
678
-                    // curly braces because other constructs tend to have different rules.
679
-                    if ($tokens[$scopeCloser]['code'] === T_CLOSE_CURLY_BRACKET) {
680
-                        $exact = true;
681
-                    } else {
682
-                        $checkToken = null;
683
-                    }
684
-                }//end if
685
-            }//end if
686
-
687
-            // Handle scope for JS object notation.
688
-            if ($phpcsFile->tokenizerType === 'JS'
689
-                && (($checkToken !== null
690
-                && $tokens[$checkToken]['code'] === T_CLOSE_OBJECT
691
-                && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['bracket_opener']]['line'])
692
-                || ($checkToken === null
693
-                && $tokens[$i]['code'] === T_CLOSE_OBJECT
694
-                && $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line']))
695
-            ) {
696
-                if ($this->debug === true) {
697
-                    $line = $tokens[$i]['line'];
698
-                    echo "Close JS object on line $line".PHP_EOL;
699
-                }
700
-
701
-                $scopeCloser = $checkToken;
702
-                if ($scopeCloser === null) {
703
-                    $scopeCloser = $i;
704
-                } else {
705
-                    $conditionToken = array_pop($openScopes);
706
-                    if ($this->debug === true) {
707
-                        $line = $tokens[$conditionToken]['line'];
708
-                        $type = $tokens[$conditionToken]['type'];
709
-                        echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
710
-                    }
711
-                }
712
-
713
-                $parens = 0;
714
-                if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true
715
-                    && empty($tokens[$scopeCloser]['nested_parenthesis']) === false
716
-                ) {
717
-                    $parens = $tokens[$scopeCloser]['nested_parenthesis'];
718
-                    end($parens);
719
-                    $parens = key($parens);
720
-                    if ($this->debug === true) {
721
-                        $line = $tokens[$parens]['line'];
722
-                        echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
723
-                    }
724
-                }
725
-
726
-                $condition = 0;
727
-                if (isset($tokens[$scopeCloser]['conditions']) === true
728
-                    && empty($tokens[$scopeCloser]['conditions']) === false
729
-                ) {
730
-                    $condition = $tokens[$scopeCloser]['conditions'];
731
-                    end($condition);
732
-                    $condition = key($condition);
733
-                    if ($this->debug === true) {
734
-                        $line = $tokens[$condition]['line'];
735
-                        $type = $tokens[$condition]['type'];
736
-                        echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
737
-                    }
738
-                }
739
-
740
-                if ($parens > $condition) {
741
-                    if ($this->debug === true) {
742
-                        echo "\t* using parenthesis *".PHP_EOL;
743
-                    }
744
-
745
-                    $first     = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true);
746
-                    $condition = 0;
747
-                } else if ($condition > 0) {
748
-                    if ($this->debug === true) {
749
-                        echo "\t* using condition *".PHP_EOL;
750
-                    }
751
-
752
-                    $first  = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
753
-                    $parens = 0;
754
-                } else {
755
-                    if ($this->debug === true) {
756
-                        $line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line'];
757
-                        echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL;
758
-                    }
759
-
760
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['bracket_opener'], true);
761
-                }//end if
762
-
763
-                $currentIndent = ($tokens[$first]['column'] - 1);
764
-                if (isset($adjustments[$first]) === true) {
765
-                    $currentIndent += $adjustments[$first];
766
-                }
767
-
768
-                if ($parens > 0 || $condition > 0) {
769
-                    $checkIndent = ($tokens[$first]['column'] - 1);
770
-                    if (isset($adjustments[$first]) === true) {
771
-                        $checkIndent += $adjustments[$first];
772
-                    }
773
-
774
-                    if ($condition > 0) {
775
-                        $checkIndent   += $this->indent;
776
-                        $currentIndent += $this->indent;
777
-                        $exact          = true;
778
-                    }
779
-                } else {
780
-                    $checkIndent = $currentIndent;
781
-                }
782
-
783
-                // Make sure it is divisible by our expected indent.
784
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
785
-                $checkIndent        = (int) (ceil($checkIndent / $this->indent) * $this->indent);
786
-                $setIndents[$first] = $currentIndent;
787
-
788
-                if ($this->debug === true) {
789
-                    $type = $tokens[$first]['type'];
790
-                    echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
791
-                }
792
-            }//end if
793
-
794
-            if ($checkToken !== null
795
-                && isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true
796
-                && in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes, true) === false
797
-                && isset($tokens[$checkToken]['scope_opener']) === true
798
-            ) {
799
-                $exact = true;
800
-
801
-                $lastOpener = null;
802
-                if (empty($openScopes) === false) {
803
-                    end($openScopes);
804
-                    $lastOpener = current($openScopes);
805
-                }
806
-
807
-                // A scope opener that shares a closer with another token (like multiple
808
-                // CASEs using the same BREAK) needs to reduce the indent level so its
809
-                // indent is checked correctly. It will then increase the indent again
810
-                // (as all openers do) after being checked.
811
-                if ($lastOpener !== null
812
-                    && isset($tokens[$lastOpener]['scope_closer']) === true
813
-                    && $tokens[$lastOpener]['level'] === $tokens[$checkToken]['level']
814
-                    && $tokens[$lastOpener]['scope_closer'] === $tokens[$checkToken]['scope_closer']
815
-                ) {
816
-                    $currentIndent          -= $this->indent;
817
-                    $setIndents[$lastOpener] = $currentIndent;
818
-                    if ($this->debug === true) {
819
-                        $line = $tokens[$i]['line'];
820
-                        $type = $tokens[$lastOpener]['type'];
821
-                        echo "Shared closer found on line $line".PHP_EOL;
822
-                        echo "\t=> indent set to $currentIndent by token $lastOpener ($type)".PHP_EOL;
823
-                    }
824
-                }
825
-
826
-                if ($tokens[$checkToken]['code'] === T_CLOSURE
827
-                    && $tokenIndent > $currentIndent
828
-                ) {
829
-                    // The opener is indented more than needed, which is fine.
830
-                    // But just check that it is divisible by our expected indent.
831
-                    $checkIndent = (int) (ceil($tokenIndent / $this->indent) * $this->indent);
832
-                    $exact       = false;
833
-
834
-                    if ($this->debug === true) {
835
-                        $line = $tokens[$i]['line'];
836
-                        echo "Closure found on line $line".PHP_EOL;
837
-                        echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent".PHP_EOL;
838
-                    }
839
-                }
840
-            }//end if
841
-
842
-            // Method prefix indentation has to be exact or else it will break
843
-            // the rest of the function declaration, and potentially future ones.
844
-            if ($checkToken !== null
845
-                && isset(Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true
846
-                && $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON
847
-            ) {
848
-                $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($checkToken + 1), null, true);
849
-                if ($next === false || $tokens[$next]['code'] !== T_CLOSURE) {
850
-                    if ($this->debug === true) {
851
-                        $line = $tokens[$checkToken]['line'];
852
-                        $type = $tokens[$checkToken]['type'];
853
-                        echo "\t* method prefix ($type) found on line $line; indent set to exact *".PHP_EOL;
854
-                    }
855
-
856
-                    $exact = true;
857
-                }
858
-            }
859
-
860
-            // JS property indentation has to be exact or else if will break
861
-            // things like function and object indentation.
862
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_PROPERTY) {
863
-                $exact = true;
864
-            }
865
-
866
-            // Open PHP tags needs to be indented to exact column positions
867
-            // so they don't cause problems with indent checks for the code
868
-            // within them, but they don't need to line up with the current indent
869
-            // in most cases.
870
-            if ($checkToken !== null
871
-                && ($tokens[$checkToken]['code'] === T_OPEN_TAG
872
-                || $tokens[$checkToken]['code'] === T_OPEN_TAG_WITH_ECHO)
873
-            ) {
874
-                $checkIndent = ($tokens[$checkToken]['column'] - 1);
875
-
876
-                // If we are re-opening a block that was closed in the same
877
-                // scope as us, then reset the indent back to what the scope opener
878
-                // set instead of using whatever indent this open tag has set.
879
-                if (empty($tokens[$checkToken]['conditions']) === false) {
880
-                    $close = $phpcsFile->findPrevious(T_CLOSE_TAG, ($checkToken - 1));
881
-                    if ($close !== false
882
-                        && $tokens[$checkToken]['conditions'] === $tokens[$close]['conditions']
883
-                    ) {
884
-                        $conditions    = array_keys($tokens[$checkToken]['conditions']);
885
-                        $lastCondition = array_pop($conditions);
886
-                        $lastOpener    = $tokens[$lastCondition]['scope_opener'];
887
-                        $lastCloser    = $tokens[$lastCondition]['scope_closer'];
888
-                        if ($tokens[$lastCloser]['line'] !== $tokens[$checkToken]['line']
889
-                            && isset($setIndents[$lastOpener]) === true
890
-                        ) {
891
-                            $checkIndent = $setIndents[$lastOpener];
892
-                        }
893
-                    }
894
-                }
895
-
896
-                $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
897
-            }//end if
898
-
899
-            // Close tags needs to be indented to exact column positions.
900
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_CLOSE_TAG) {
901
-                $exact       = true;
902
-                $checkIndent = $currentIndent;
903
-                $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
904
-            }
905
-
906
-            // Special case for ELSE statements that are not on the same
907
-            // line as the previous IF statements closing brace. They still need
908
-            // to have the same indent or it will break code after the block.
909
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_ELSE) {
910
-                $exact = true;
911
-            }
912
-
913
-            if ($checkIndent === null) {
914
-                $checkIndent = $currentIndent;
915
-            }
916
-
917
-            /*
230
+			$exact = $this->exact;
231
+
232
+			if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
233
+				$disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
234
+			}
235
+
236
+			if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
237
+				&& isset($tokens[$i]['parenthesis_closer']) === true
238
+			) {
239
+				$disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
240
+			}
241
+
242
+			if ($exact === true && $i < $disableExactEnd) {
243
+				$exact = false;
244
+			}
245
+
246
+			// Detect line changes and figure out where the indent is.
247
+			if ($tokens[$i]['column'] === 1) {
248
+				$trimmed = ltrim($tokens[$i]['content']);
249
+				if ($trimmed === '') {
250
+					if (isset($tokens[($i + 1)]) === true
251
+						&& $tokens[$i]['line'] === $tokens[($i + 1)]['line']
252
+					) {
253
+						$checkToken  = ($i + 1);
254
+						$tokenIndent = ($tokens[($i + 1)]['column'] - 1);
255
+					}
256
+				} else {
257
+					$checkToken  = $i;
258
+					$tokenIndent = (strlen($tokens[$i]['content']) - strlen($trimmed));
259
+				}
260
+			}
261
+
262
+			// Closing parenthesis should just be indented to at least
263
+			// the same level as where they were opened (but can be more).
264
+			if (($checkToken !== null
265
+				&& $tokens[$checkToken]['code'] === T_CLOSE_PARENTHESIS
266
+				&& isset($tokens[$checkToken]['parenthesis_opener']) === true)
267
+				|| ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS
268
+				&& isset($tokens[$i]['parenthesis_opener']) === true)
269
+			) {
270
+				if ($checkToken !== null) {
271
+					$parenCloser = $checkToken;
272
+				} else {
273
+					$parenCloser = $i;
274
+				}
275
+
276
+				if ($this->debug === true) {
277
+					$line = $tokens[$i]['line'];
278
+					echo "Closing parenthesis found on line $line".PHP_EOL;
279
+				}
280
+
281
+				$parenOpener = $tokens[$parenCloser]['parenthesis_opener'];
282
+				if ($tokens[$parenCloser]['line'] !== $tokens[$parenOpener]['line']) {
283
+					$parens = 0;
284
+					if (isset($tokens[$parenCloser]['nested_parenthesis']) === true
285
+						&& empty($tokens[$parenCloser]['nested_parenthesis']) === false
286
+					) {
287
+						$parens = $tokens[$parenCloser]['nested_parenthesis'];
288
+						end($parens);
289
+						$parens = key($parens);
290
+						if ($this->debug === true) {
291
+							$line = $tokens[$parens]['line'];
292
+							echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
293
+						}
294
+					}
295
+
296
+					$condition = 0;
297
+					if (isset($tokens[$parenCloser]['conditions']) === true
298
+						&& empty($tokens[$parenCloser]['conditions']) === false
299
+						&& (isset($tokens[$parenCloser]['parenthesis_owner']) === false
300
+						|| $parens > 0)
301
+					) {
302
+						$condition = $tokens[$parenCloser]['conditions'];
303
+						end($condition);
304
+						$condition = key($condition);
305
+						if ($this->debug === true) {
306
+							$line = $tokens[$condition]['line'];
307
+							$type = $tokens[$condition]['type'];
308
+							echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
309
+						}
310
+					}
311
+
312
+					if ($parens > $condition) {
313
+						if ($this->debug === true) {
314
+							echo "\t* using parenthesis *".PHP_EOL;
315
+						}
316
+
317
+						$parenOpener = $parens;
318
+						$condition   = 0;
319
+					} else if ($condition > 0) {
320
+						if ($this->debug === true) {
321
+							echo "\t* using condition *".PHP_EOL;
322
+						}
323
+
324
+						$parenOpener = $condition;
325
+						$parens      = 0;
326
+					}
327
+
328
+					$exact = false;
329
+
330
+					$lastOpenTagConditions = array_keys($tokens[$lastOpenTag]['conditions']);
331
+					$lastOpenTagCondition  = array_pop($lastOpenTagConditions);
332
+
333
+					if ($condition > 0 && $lastOpenTagCondition === $condition) {
334
+						if ($this->debug === true) {
335
+							echo "\t* open tag is inside condition; using open tag *".PHP_EOL;
336
+						}
337
+
338
+						$checkIndent = ($tokens[$lastOpenTag]['column'] - 1);
339
+						if (isset($adjustments[$condition]) === true) {
340
+							$checkIndent += $adjustments[$condition];
341
+						}
342
+
343
+						$currentIndent = $checkIndent;
344
+
345
+						if ($this->debug === true) {
346
+							$type = $tokens[$lastOpenTag]['type'];
347
+							echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)".PHP_EOL;
348
+						}
349
+					} else if ($condition > 0
350
+						&& isset($tokens[$condition]['scope_opener']) === true
351
+						&& isset($setIndents[$tokens[$condition]['scope_opener']]) === true
352
+					) {
353
+						$checkIndent = $setIndents[$tokens[$condition]['scope_opener']];
354
+						if (isset($adjustments[$condition]) === true) {
355
+							$checkIndent += $adjustments[$condition];
356
+						}
357
+
358
+						$currentIndent = $checkIndent;
359
+
360
+						if ($this->debug === true) {
361
+							$type = $tokens[$condition]['type'];
362
+							echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)".PHP_EOL;
363
+						}
364
+					} else {
365
+						$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parenOpener, true);
366
+
367
+						$checkIndent = ($tokens[$first]['column'] - 1);
368
+						if (isset($adjustments[$first]) === true) {
369
+							$checkIndent += $adjustments[$first];
370
+						}
371
+
372
+						if ($this->debug === true) {
373
+							$line = $tokens[$first]['line'];
374
+							$type = $tokens[$first]['type'];
375
+							echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
376
+						}
377
+
378
+						if ($first === $tokens[$parenCloser]['parenthesis_opener']
379
+							&& $tokens[($first - 1)]['line'] === $tokens[$first]['line']
380
+						) {
381
+							// This is unlikely to be the start of the statement, so look
382
+							// back further to find it.
383
+							$first--;
384
+							if ($this->debug === true) {
385
+								$line = $tokens[$first]['line'];
386
+								$type = $tokens[$first]['type'];
387
+								echo "\t* first token is the parenthesis opener *".PHP_EOL;
388
+								echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
389
+							}
390
+						}
391
+
392
+						$prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
393
+						if ($prev !== $first) {
394
+							// This is not the start of the statement.
395
+							if ($this->debug === true) {
396
+								$line = $tokens[$prev]['line'];
397
+								$type = $tokens[$prev]['type'];
398
+								echo "\t* previous is $type on line $line *".PHP_EOL;
399
+							}
400
+
401
+							$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
402
+							if ($first !== false) {
403
+								$prev  = $phpcsFile->findStartOfStatement($first, T_COMMA);
404
+								$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
405
+							} else {
406
+								$first = $prev;
407
+							}
408
+
409
+							if ($this->debug === true) {
410
+								$line = $tokens[$first]['line'];
411
+								$type = $tokens[$first]['type'];
412
+								echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
413
+							}
414
+						}//end if
415
+
416
+						if (isset($tokens[$first]['scope_closer']) === true
417
+							&& $tokens[$first]['scope_closer'] === $first
418
+						) {
419
+							if ($this->debug === true) {
420
+								echo "\t* first token is a scope closer *".PHP_EOL;
421
+							}
422
+
423
+							if (isset($tokens[$first]['scope_condition']) === true) {
424
+								$scopeCloser = $first;
425
+								$first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true);
426
+
427
+								$currentIndent = ($tokens[$first]['column'] - 1);
428
+								if (isset($adjustments[$first]) === true) {
429
+									$currentIndent += $adjustments[$first];
430
+								}
431
+
432
+								// Make sure it is divisible by our expected indent.
433
+								if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) {
434
+									$currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent);
435
+								}
436
+
437
+								$setIndents[$first] = $currentIndent;
438
+
439
+								if ($this->debug === true) {
440
+									$type = $tokens[$first]['type'];
441
+									echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
442
+								}
443
+							}//end if
444
+						} else {
445
+							// Don't force current indent to be divisible because there could be custom
446
+							// rules in place between parenthesis, such as with arrays.
447
+							$currentIndent = ($tokens[$first]['column'] - 1);
448
+							if (isset($adjustments[$first]) === true) {
449
+								$currentIndent += $adjustments[$first];
450
+							}
451
+
452
+							$setIndents[$first] = $currentIndent;
453
+
454
+							if ($this->debug === true) {
455
+								$type = $tokens[$first]['type'];
456
+								echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
457
+							}
458
+						}//end if
459
+					}//end if
460
+				} else if ($this->debug === true) {
461
+					echo "\t * ignoring single-line definition *".PHP_EOL;
462
+				}//end if
463
+			}//end if
464
+
465
+			// Closing short array bracket should just be indented to at least
466
+			// the same level as where it was opened (but can be more).
467
+			if ($tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
468
+				|| ($checkToken !== null
469
+				&& $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY)
470
+			) {
471
+				if ($checkToken !== null) {
472
+					$arrayCloser = $checkToken;
473
+				} else {
474
+					$arrayCloser = $i;
475
+				}
476
+
477
+				if ($this->debug === true) {
478
+					$line = $tokens[$arrayCloser]['line'];
479
+					echo "Closing short array bracket found on line $line".PHP_EOL;
480
+				}
481
+
482
+				$arrayOpener = $tokens[$arrayCloser]['bracket_opener'];
483
+				if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) {
484
+					$first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
485
+					$checkIndent = ($tokens[$first]['column'] - 1);
486
+					if (isset($adjustments[$first]) === true) {
487
+						$checkIndent += $adjustments[$first];
488
+					}
489
+
490
+					$exact = false;
491
+
492
+					if ($this->debug === true) {
493
+						$line = $tokens[$first]['line'];
494
+						$type = $tokens[$first]['type'];
495
+						echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
496
+					}
497
+
498
+					if ($first === $tokens[$arrayCloser]['bracket_opener']) {
499
+						// This is unlikely to be the start of the statement, so look
500
+						// back further to find it.
501
+						$first--;
502
+					}
503
+
504
+					$prev = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
505
+					if ($prev !== $first) {
506
+						// This is not the start of the statement.
507
+						if ($this->debug === true) {
508
+							$line = $tokens[$prev]['line'];
509
+							$type = $tokens[$prev]['type'];
510
+							echo "\t* previous is $type on line $line *".PHP_EOL;
511
+						}
512
+
513
+						$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
514
+						$prev  = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
515
+						$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
516
+						if ($this->debug === true) {
517
+							$line = $tokens[$first]['line'];
518
+							$type = $tokens[$first]['type'];
519
+							echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
520
+						}
521
+					} else if ($tokens[$first]['code'] === T_WHITESPACE) {
522
+						$first = $phpcsFile->findNext(T_WHITESPACE, ($first + 1), null, true);
523
+					}
524
+
525
+					if (isset($tokens[$first]['scope_closer']) === true
526
+						&& $tokens[$first]['scope_closer'] === $first
527
+					) {
528
+						// The first token is a scope closer and would have already
529
+						// been processed and set the indent level correctly, so
530
+						// don't adjust it again.
531
+						if ($this->debug === true) {
532
+							echo "\t* first token is a scope closer; ignoring closing short array bracket *".PHP_EOL;
533
+						}
534
+
535
+						if (isset($setIndents[$first]) === true) {
536
+							$currentIndent = $setIndents[$first];
537
+							if ($this->debug === true) {
538
+								echo "\t=> indent reset to $currentIndent".PHP_EOL;
539
+							}
540
+						}
541
+					} else {
542
+						// Don't force current indent to be divisible because there could be custom
543
+						// rules in place for arrays.
544
+						$currentIndent = ($tokens[$first]['column'] - 1);
545
+						if (isset($adjustments[$first]) === true) {
546
+							$currentIndent += $adjustments[$first];
547
+						}
548
+
549
+						$setIndents[$first] = $currentIndent;
550
+
551
+						if ($this->debug === true) {
552
+							$type = $tokens[$first]['type'];
553
+							echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
554
+						}
555
+					}//end if
556
+				} else if ($this->debug === true) {
557
+					echo "\t * ignoring single-line definition *".PHP_EOL;
558
+				}//end if
559
+			}//end if
560
+
561
+			// Adjust lines within scopes while auto-fixing.
562
+			if ($checkToken !== null
563
+				&& $exact === false
564
+				&& (empty($tokens[$checkToken]['conditions']) === false
565
+				|| (isset($tokens[$checkToken]['scope_opener']) === true
566
+				&& $tokens[$checkToken]['scope_opener'] === $checkToken))
567
+			) {
568
+				if (empty($tokens[$checkToken]['conditions']) === false) {
569
+					$condition = $tokens[$checkToken]['conditions'];
570
+					end($condition);
571
+					$condition = key($condition);
572
+				} else {
573
+					$condition = $tokens[$checkToken]['scope_condition'];
574
+				}
575
+
576
+				$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
577
+
578
+				if (isset($adjustments[$first]) === true
579
+					&& (($adjustments[$first] < 0 && $tokenIndent > $currentIndent)
580
+					|| ($adjustments[$first] > 0 && $tokenIndent < $currentIndent))
581
+				) {
582
+					$length = ($tokenIndent + $adjustments[$first]);
583
+
584
+					// When fixing, we're going to adjust the indent of this line
585
+					// here automatically, so use this new padding value when
586
+					// comparing the expected padding to the actual padding.
587
+					if ($phpcsFile->fixer->enabled === true) {
588
+						$tokenIndent = $length;
589
+						$this->adjustIndent($phpcsFile, $checkToken, $length, $adjustments[$first]);
590
+					}
591
+
592
+					if ($this->debug === true) {
593
+						$line = $tokens[$checkToken]['line'];
594
+						$type = $tokens[$checkToken]['type'];
595
+						echo "Indent adjusted to $length for $type on line $line".PHP_EOL;
596
+					}
597
+
598
+					$adjustments[$checkToken] = $adjustments[$first];
599
+
600
+					if ($this->debug === true) {
601
+						$line = $tokens[$checkToken]['line'];
602
+						$type = $tokens[$checkToken]['type'];
603
+						echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
604
+					}
605
+				}//end if
606
+			}//end if
607
+
608
+			// Scope closers reset the required indent to the same level as the opening condition.
609
+			if (($checkToken !== null
610
+				&& isset($openScopes[$checkToken]) === true
611
+				|| (isset($tokens[$checkToken]['scope_condition']) === true
612
+				&& isset($tokens[$checkToken]['scope_closer']) === true
613
+				&& $tokens[$checkToken]['scope_closer'] === $checkToken
614
+				&& $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))
615
+				|| ($checkToken === null
616
+				&& isset($openScopes[$i]) === true
617
+				|| (isset($tokens[$i]['scope_condition']) === true
618
+				&& isset($tokens[$i]['scope_closer']) === true
619
+				&& $tokens[$i]['scope_closer'] === $i
620
+				&& $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line']))
621
+			) {
622
+				if ($this->debug === true) {
623
+					if ($checkToken === null) {
624
+						$type = $tokens[$tokens[$i]['scope_condition']]['type'];
625
+						$line = $tokens[$i]['line'];
626
+					} else {
627
+						$type = $tokens[$tokens[$checkToken]['scope_condition']]['type'];
628
+						$line = $tokens[$checkToken]['line'];
629
+					}
630
+
631
+					echo "Close scope ($type) on line $line".PHP_EOL;
632
+				}
633
+
634
+				$scopeCloser = $checkToken;
635
+				if ($scopeCloser === null) {
636
+					$scopeCloser = $i;
637
+				}
638
+
639
+				$conditionToken = array_pop($openScopes);
640
+				if ($this->debug === true) {
641
+					$line = $tokens[$conditionToken]['line'];
642
+					$type = $tokens[$conditionToken]['type'];
643
+					echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
644
+				}
645
+
646
+				if (isset($tokens[$scopeCloser]['scope_condition']) === true) {
647
+					$first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $tokens[$scopeCloser]['scope_condition'], true);
648
+					if ($this->debug === true) {
649
+						$line = $tokens[$first]['line'];
650
+						$type = $tokens[$first]['type'];
651
+						echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
652
+					}
653
+
654
+					while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
655
+						&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
656
+					) {
657
+						$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
658
+						if ($this->debug === true) {
659
+							$line = $tokens[$first]['line'];
660
+							$type = $tokens[$first]['type'];
661
+							echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
662
+						}
663
+					}
664
+
665
+					$currentIndent = ($tokens[$first]['column'] - 1);
666
+					if (isset($adjustments[$first]) === true) {
667
+						$currentIndent += $adjustments[$first];
668
+					}
669
+
670
+					$setIndents[$scopeCloser] = $currentIndent;
671
+
672
+					if ($this->debug === true) {
673
+						$type = $tokens[$scopeCloser]['type'];
674
+						echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)".PHP_EOL;
675
+					}
676
+
677
+					// We only check the indent of scope closers if they are
678
+					// curly braces because other constructs tend to have different rules.
679
+					if ($tokens[$scopeCloser]['code'] === T_CLOSE_CURLY_BRACKET) {
680
+						$exact = true;
681
+					} else {
682
+						$checkToken = null;
683
+					}
684
+				}//end if
685
+			}//end if
686
+
687
+			// Handle scope for JS object notation.
688
+			if ($phpcsFile->tokenizerType === 'JS'
689
+				&& (($checkToken !== null
690
+				&& $tokens[$checkToken]['code'] === T_CLOSE_OBJECT
691
+				&& $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['bracket_opener']]['line'])
692
+				|| ($checkToken === null
693
+				&& $tokens[$i]['code'] === T_CLOSE_OBJECT
694
+				&& $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line']))
695
+			) {
696
+				if ($this->debug === true) {
697
+					$line = $tokens[$i]['line'];
698
+					echo "Close JS object on line $line".PHP_EOL;
699
+				}
700
+
701
+				$scopeCloser = $checkToken;
702
+				if ($scopeCloser === null) {
703
+					$scopeCloser = $i;
704
+				} else {
705
+					$conditionToken = array_pop($openScopes);
706
+					if ($this->debug === true) {
707
+						$line = $tokens[$conditionToken]['line'];
708
+						$type = $tokens[$conditionToken]['type'];
709
+						echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
710
+					}
711
+				}
712
+
713
+				$parens = 0;
714
+				if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true
715
+					&& empty($tokens[$scopeCloser]['nested_parenthesis']) === false
716
+				) {
717
+					$parens = $tokens[$scopeCloser]['nested_parenthesis'];
718
+					end($parens);
719
+					$parens = key($parens);
720
+					if ($this->debug === true) {
721
+						$line = $tokens[$parens]['line'];
722
+						echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
723
+					}
724
+				}
725
+
726
+				$condition = 0;
727
+				if (isset($tokens[$scopeCloser]['conditions']) === true
728
+					&& empty($tokens[$scopeCloser]['conditions']) === false
729
+				) {
730
+					$condition = $tokens[$scopeCloser]['conditions'];
731
+					end($condition);
732
+					$condition = key($condition);
733
+					if ($this->debug === true) {
734
+						$line = $tokens[$condition]['line'];
735
+						$type = $tokens[$condition]['type'];
736
+						echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
737
+					}
738
+				}
739
+
740
+				if ($parens > $condition) {
741
+					if ($this->debug === true) {
742
+						echo "\t* using parenthesis *".PHP_EOL;
743
+					}
744
+
745
+					$first     = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true);
746
+					$condition = 0;
747
+				} else if ($condition > 0) {
748
+					if ($this->debug === true) {
749
+						echo "\t* using condition *".PHP_EOL;
750
+					}
751
+
752
+					$first  = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
753
+					$parens = 0;
754
+				} else {
755
+					if ($this->debug === true) {
756
+						$line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line'];
757
+						echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL;
758
+					}
759
+
760
+					$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['bracket_opener'], true);
761
+				}//end if
762
+
763
+				$currentIndent = ($tokens[$first]['column'] - 1);
764
+				if (isset($adjustments[$first]) === true) {
765
+					$currentIndent += $adjustments[$first];
766
+				}
767
+
768
+				if ($parens > 0 || $condition > 0) {
769
+					$checkIndent = ($tokens[$first]['column'] - 1);
770
+					if (isset($adjustments[$first]) === true) {
771
+						$checkIndent += $adjustments[$first];
772
+					}
773
+
774
+					if ($condition > 0) {
775
+						$checkIndent   += $this->indent;
776
+						$currentIndent += $this->indent;
777
+						$exact          = true;
778
+					}
779
+				} else {
780
+					$checkIndent = $currentIndent;
781
+				}
782
+
783
+				// Make sure it is divisible by our expected indent.
784
+				$currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
785
+				$checkIndent        = (int) (ceil($checkIndent / $this->indent) * $this->indent);
786
+				$setIndents[$first] = $currentIndent;
787
+
788
+				if ($this->debug === true) {
789
+					$type = $tokens[$first]['type'];
790
+					echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
791
+				}
792
+			}//end if
793
+
794
+			if ($checkToken !== null
795
+				&& isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true
796
+				&& in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes, true) === false
797
+				&& isset($tokens[$checkToken]['scope_opener']) === true
798
+			) {
799
+				$exact = true;
800
+
801
+				$lastOpener = null;
802
+				if (empty($openScopes) === false) {
803
+					end($openScopes);
804
+					$lastOpener = current($openScopes);
805
+				}
806
+
807
+				// A scope opener that shares a closer with another token (like multiple
808
+				// CASEs using the same BREAK) needs to reduce the indent level so its
809
+				// indent is checked correctly. It will then increase the indent again
810
+				// (as all openers do) after being checked.
811
+				if ($lastOpener !== null
812
+					&& isset($tokens[$lastOpener]['scope_closer']) === true
813
+					&& $tokens[$lastOpener]['level'] === $tokens[$checkToken]['level']
814
+					&& $tokens[$lastOpener]['scope_closer'] === $tokens[$checkToken]['scope_closer']
815
+				) {
816
+					$currentIndent          -= $this->indent;
817
+					$setIndents[$lastOpener] = $currentIndent;
818
+					if ($this->debug === true) {
819
+						$line = $tokens[$i]['line'];
820
+						$type = $tokens[$lastOpener]['type'];
821
+						echo "Shared closer found on line $line".PHP_EOL;
822
+						echo "\t=> indent set to $currentIndent by token $lastOpener ($type)".PHP_EOL;
823
+					}
824
+				}
825
+
826
+				if ($tokens[$checkToken]['code'] === T_CLOSURE
827
+					&& $tokenIndent > $currentIndent
828
+				) {
829
+					// The opener is indented more than needed, which is fine.
830
+					// But just check that it is divisible by our expected indent.
831
+					$checkIndent = (int) (ceil($tokenIndent / $this->indent) * $this->indent);
832
+					$exact       = false;
833
+
834
+					if ($this->debug === true) {
835
+						$line = $tokens[$i]['line'];
836
+						echo "Closure found on line $line".PHP_EOL;
837
+						echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent".PHP_EOL;
838
+					}
839
+				}
840
+			}//end if
841
+
842
+			// Method prefix indentation has to be exact or else it will break
843
+			// the rest of the function declaration, and potentially future ones.
844
+			if ($checkToken !== null
845
+				&& isset(Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true
846
+				&& $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON
847
+			) {
848
+				$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($checkToken + 1), null, true);
849
+				if ($next === false || $tokens[$next]['code'] !== T_CLOSURE) {
850
+					if ($this->debug === true) {
851
+						$line = $tokens[$checkToken]['line'];
852
+						$type = $tokens[$checkToken]['type'];
853
+						echo "\t* method prefix ($type) found on line $line; indent set to exact *".PHP_EOL;
854
+					}
855
+
856
+					$exact = true;
857
+				}
858
+			}
859
+
860
+			// JS property indentation has to be exact or else if will break
861
+			// things like function and object indentation.
862
+			if ($checkToken !== null && $tokens[$checkToken]['code'] === T_PROPERTY) {
863
+				$exact = true;
864
+			}
865
+
866
+			// Open PHP tags needs to be indented to exact column positions
867
+			// so they don't cause problems with indent checks for the code
868
+			// within them, but they don't need to line up with the current indent
869
+			// in most cases.
870
+			if ($checkToken !== null
871
+				&& ($tokens[$checkToken]['code'] === T_OPEN_TAG
872
+				|| $tokens[$checkToken]['code'] === T_OPEN_TAG_WITH_ECHO)
873
+			) {
874
+				$checkIndent = ($tokens[$checkToken]['column'] - 1);
875
+
876
+				// If we are re-opening a block that was closed in the same
877
+				// scope as us, then reset the indent back to what the scope opener
878
+				// set instead of using whatever indent this open tag has set.
879
+				if (empty($tokens[$checkToken]['conditions']) === false) {
880
+					$close = $phpcsFile->findPrevious(T_CLOSE_TAG, ($checkToken - 1));
881
+					if ($close !== false
882
+						&& $tokens[$checkToken]['conditions'] === $tokens[$close]['conditions']
883
+					) {
884
+						$conditions    = array_keys($tokens[$checkToken]['conditions']);
885
+						$lastCondition = array_pop($conditions);
886
+						$lastOpener    = $tokens[$lastCondition]['scope_opener'];
887
+						$lastCloser    = $tokens[$lastCondition]['scope_closer'];
888
+						if ($tokens[$lastCloser]['line'] !== $tokens[$checkToken]['line']
889
+							&& isset($setIndents[$lastOpener]) === true
890
+						) {
891
+							$checkIndent = $setIndents[$lastOpener];
892
+						}
893
+					}
894
+				}
895
+
896
+				$checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
897
+			}//end if
898
+
899
+			// Close tags needs to be indented to exact column positions.
900
+			if ($checkToken !== null && $tokens[$checkToken]['code'] === T_CLOSE_TAG) {
901
+				$exact       = true;
902
+				$checkIndent = $currentIndent;
903
+				$checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
904
+			}
905
+
906
+			// Special case for ELSE statements that are not on the same
907
+			// line as the previous IF statements closing brace. They still need
908
+			// to have the same indent or it will break code after the block.
909
+			if ($checkToken !== null && $tokens[$checkToken]['code'] === T_ELSE) {
910
+				$exact = true;
911
+			}
912
+
913
+			if ($checkIndent === null) {
914
+				$checkIndent = $currentIndent;
915
+			}
916
+
917
+			/*
918 918
                 The indent of the line is checked by the following IF block.
919 919
 
920 920
                 Up until now, we've just been figuring out what the indent
@@ -924,554 +924,554 @@  discard block
 block discarded – undo
924 924
                 the checking of future lines
925 925
             */
926 926
 
927
-            if ($checkToken !== null
928
-                && isset($this->ignoreIndentation[$tokens[$checkToken]['code']]) === false
929
-                && (($tokenIndent !== $checkIndent && $exact === true)
930
-                || ($tokenIndent < $checkIndent && $exact === false))
931
-            ) {
932
-                $type  = 'IncorrectExact';
933
-                $error = 'Line indented incorrectly; expected ';
934
-                if ($exact === false) {
935
-                    $error .= 'at least ';
936
-                    $type   = 'Incorrect';
937
-                }
938
-
939
-                if ($this->tabIndent === true) {
940
-                    $error .= '%s tabs, found %s';
941
-                    $data   = [
942
-                        floor($checkIndent / $this->tabWidth),
943
-                        floor($tokenIndent / $this->tabWidth),
944
-                    ];
945
-                } else {
946
-                    $error .= '%s spaces, found %s';
947
-                    $data   = [
948
-                        $checkIndent,
949
-                        $tokenIndent,
950
-                    ];
951
-                }
952
-
953
-                if ($this->debug === true) {
954
-                    $line    = $tokens[$checkToken]['line'];
955
-                    $message = vsprintf($error, $data);
956
-                    echo "[Line $line] $message".PHP_EOL;
957
-                }
958
-
959
-                // Assume the change would be applied and continue
960
-                // checking indents under this assumption. This gives more
961
-                // technically accurate error messages.
962
-                $adjustments[$checkToken] = ($checkIndent - $tokenIndent);
963
-
964
-                $fix = $phpcsFile->addFixableError($error, $checkToken, $type, $data);
965
-                if ($fix === true || $this->debug === true) {
966
-                    $accepted = $this->adjustIndent($phpcsFile, $checkToken, $checkIndent, ($checkIndent - $tokenIndent));
967
-
968
-                    if ($accepted === true && $this->debug === true) {
969
-                        $line = $tokens[$checkToken]['line'];
970
-                        $type = $tokens[$checkToken]['type'];
971
-                        echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
972
-                    }
973
-                }
974
-            }//end if
975
-
976
-            if ($checkToken !== null) {
977
-                $i = $checkToken;
978
-            }
979
-
980
-            // Completely skip here/now docs as the indent is a part of the
981
-            // content itself.
982
-            if ($tokens[$i]['code'] === T_START_HEREDOC
983
-                || $tokens[$i]['code'] === T_START_NOWDOC
984
-            ) {
985
-                $i = $phpcsFile->findNext([T_END_HEREDOC, T_END_NOWDOC], ($i + 1));
986
-                $i = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
987
-                continue;
988
-            }
989
-
990
-            // Completely skip multi-line strings as the indent is a part of the
991
-            // content itself.
992
-            if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING
993
-                || $tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING
994
-            ) {
995
-                $i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true);
996
-                $i--;
997
-                continue;
998
-            }
999
-
1000
-            // Completely skip doc comments as they tend to have complex
1001
-            // indentation rules.
1002
-            if ($tokens[$i]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1003
-                $i = $tokens[$i]['comment_closer'];
1004
-                continue;
1005
-            }
1006
-
1007
-            // Open tags reset the indent level.
1008
-            if ($tokens[$i]['code'] === T_OPEN_TAG
1009
-                || $tokens[$i]['code'] === T_OPEN_TAG_WITH_ECHO
1010
-            ) {
1011
-                if ($this->debug === true) {
1012
-                    $line = $tokens[$i]['line'];
1013
-                    echo "Open PHP tag found on line $line".PHP_EOL;
1014
-                }
1015
-
1016
-                if ($checkToken === null) {
1017
-                    $first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1018
-                    $currentIndent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
1019
-                } else {
1020
-                    $currentIndent = ($tokens[$i]['column'] - 1);
1021
-                }
1022
-
1023
-                $lastOpenTag = $i;
1024
-
1025
-                if (isset($adjustments[$i]) === true) {
1026
-                    $currentIndent += $adjustments[$i];
1027
-                }
1028
-
1029
-                // Make sure it is divisible by our expected indent.
1030
-                $currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1031
-                $setIndents[$i] = $currentIndent;
1032
-
1033
-                if ($this->debug === true) {
1034
-                    $type = $tokens[$i]['type'];
1035
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1036
-                }
1037
-
1038
-                continue;
1039
-            }//end if
1040
-
1041
-            // Close tags reset the indent level, unless they are closing a tag
1042
-            // opened on the same line.
1043
-            if ($tokens[$i]['code'] === T_CLOSE_TAG) {
1044
-                if ($this->debug === true) {
1045
-                    $line = $tokens[$i]['line'];
1046
-                    echo "Close PHP tag found on line $line".PHP_EOL;
1047
-                }
1048
-
1049
-                if ($tokens[$lastOpenTag]['line'] !== $tokens[$i]['line']) {
1050
-                    $currentIndent = ($tokens[$i]['column'] - 1);
1051
-                    $lastCloseTag  = $i;
1052
-                } else {
1053
-                    if ($lastCloseTag === null) {
1054
-                        $currentIndent = 0;
1055
-                    } else {
1056
-                        $currentIndent = ($tokens[$lastCloseTag]['column'] - 1);
1057
-                    }
1058
-                }
1059
-
1060
-                if (isset($adjustments[$i]) === true) {
1061
-                    $currentIndent += $adjustments[$i];
1062
-                }
1063
-
1064
-                // Make sure it is divisible by our expected indent.
1065
-                $currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1066
-                $setIndents[$i] = $currentIndent;
1067
-
1068
-                if ($this->debug === true) {
1069
-                    $type = $tokens[$i]['type'];
1070
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1071
-                }
1072
-
1073
-                continue;
1074
-            }//end if
1075
-
1076
-            // Anon classes and functions set the indent based on their own indent level.
1077
-            if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) {
1078
-                $closer = $tokens[$i]['scope_closer'];
1079
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1080
-                    if ($this->debug === true) {
1081
-                        $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1082
-                        $line = $tokens[$i]['line'];
1083
-                        echo "* ignoring single-line $type on line $line".PHP_EOL;
1084
-                    }
1085
-
1086
-                    $i = $closer;
1087
-                    continue;
1088
-                }
1089
-
1090
-                if ($this->debug === true) {
1091
-                    $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1092
-                    $line = $tokens[$i]['line'];
1093
-                    echo "Open $type on line $line".PHP_EOL;
1094
-                }
1095
-
1096
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1097
-                if ($this->debug === true) {
1098
-                    $line = $tokens[$first]['line'];
1099
-                    $type = $tokens[$first]['type'];
1100
-                    echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
1101
-                }
1102
-
1103
-                while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
1104
-                    && $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
1105
-                ) {
1106
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
1107
-                    if ($this->debug === true) {
1108
-                        $line = $tokens[$first]['line'];
1109
-                        $type = $tokens[$first]['type'];
1110
-                        echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
1111
-                    }
1112
-                }
1113
-
1114
-                $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1115
-                $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1116
-                if ($this->debug === true) {
1117
-                    $closerToken    = $tokens[$i]['scope_closer'];
1118
-                    $closerLine     = $tokens[$closerToken]['line'];
1119
-                    $closerType     = $tokens[$closerToken]['type'];
1120
-                    $conditionToken = $tokens[$i]['scope_condition'];
1121
-                    $conditionLine  = $tokens[$conditionToken]['line'];
1122
-                    $conditionType  = $tokens[$conditionToken]['type'];
1123
-                    echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1124
-                }
1125
-
1126
-                if (isset($adjustments[$first]) === true) {
1127
-                    $currentIndent += $adjustments[$first];
1128
-                }
1129
-
1130
-                // Make sure it is divisible by our expected indent.
1131
-                $currentIndent = (int) (floor($currentIndent / $this->indent) * $this->indent);
1132
-                $i = $tokens[$i]['scope_opener'];
1133
-                $setIndents[$i] = $currentIndent;
1134
-
1135
-                if ($this->debug === true) {
1136
-                    $type = $tokens[$i]['type'];
1137
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1138
-                }
1139
-
1140
-                continue;
1141
-            }//end if
1142
-
1143
-            // Scope openers increase the indent level.
1144
-            if (isset($tokens[$i]['scope_condition']) === true
1145
-                && isset($tokens[$i]['scope_opener']) === true
1146
-                && $tokens[$i]['scope_opener'] === $i
1147
-            ) {
1148
-                $closer = $tokens[$i]['scope_closer'];
1149
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1150
-                    if ($this->debug === true) {
1151
-                        $line = $tokens[$i]['line'];
1152
-                        $type = $tokens[$i]['type'];
1153
-                        echo "* ignoring single-line $type on line $line".PHP_EOL;
1154
-                    }
1155
-
1156
-                    $i = $closer;
1157
-                    continue;
1158
-                }
1159
-
1160
-                $condition = $tokens[$tokens[$i]['scope_condition']]['code'];
1161
-                if (isset(Tokens::$scopeOpeners[$condition]) === true
1162
-                    && in_array($condition, $this->nonIndentingScopes, true) === false
1163
-                ) {
1164
-                    if ($this->debug === true) {
1165
-                        $line = $tokens[$i]['line'];
1166
-                        $type = $tokens[$tokens[$i]['scope_condition']]['type'];
1167
-                        echo "Open scope ($type) on line $line".PHP_EOL;
1168
-                    }
1169
-
1170
-                    $currentIndent += $this->indent;
1171
-                    $setIndents[$i] = $currentIndent;
1172
-                    $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1173
-                    if ($this->debug === true) {
1174
-                        $closerToken    = $tokens[$i]['scope_closer'];
1175
-                        $closerLine     = $tokens[$closerToken]['line'];
1176
-                        $closerType     = $tokens[$closerToken]['type'];
1177
-                        $conditionToken = $tokens[$i]['scope_condition'];
1178
-                        $conditionLine  = $tokens[$conditionToken]['line'];
1179
-                        $conditionType  = $tokens[$conditionToken]['type'];
1180
-                        echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1181
-                    }
1182
-
1183
-                    if ($this->debug === true) {
1184
-                        $type = $tokens[$i]['type'];
1185
-                        echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1186
-                    }
1187
-
1188
-                    continue;
1189
-                }//end if
1190
-            }//end if
1191
-
1192
-            // JS objects set the indent level.
1193
-            if ($phpcsFile->tokenizerType === 'JS'
1194
-                && $tokens[$i]['code'] === T_OBJECT
1195
-            ) {
1196
-                $closer = $tokens[$i]['bracket_closer'];
1197
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1198
-                    if ($this->debug === true) {
1199
-                        $line = $tokens[$i]['line'];
1200
-                        echo "* ignoring single-line JS object on line $line".PHP_EOL;
1201
-                    }
1202
-
1203
-                    $i = $closer;
1204
-                    continue;
1205
-                }
1206
-
1207
-                if ($this->debug === true) {
1208
-                    $line = $tokens[$i]['line'];
1209
-                    echo "Open JS object on line $line".PHP_EOL;
1210
-                }
1211
-
1212
-                $first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1213
-                $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1214
-                if (isset($adjustments[$first]) === true) {
1215
-                    $currentIndent += $adjustments[$first];
1216
-                }
1217
-
1218
-                // Make sure it is divisible by our expected indent.
1219
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1220
-                $setIndents[$first] = $currentIndent;
1221
-
1222
-                if ($this->debug === true) {
1223
-                    $type = $tokens[$first]['type'];
1224
-                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1225
-                }
1226
-
1227
-                continue;
1228
-            }//end if
1229
-
1230
-            // Closing an anon class or function.
1231
-            if (isset($tokens[$i]['scope_condition']) === true
1232
-                && $tokens[$i]['scope_closer'] === $i
1233
-                && ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE
1234
-                || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS)
1235
-            ) {
1236
-                if ($this->debug === true) {
1237
-                    $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2)));
1238
-                    $line = $tokens[$i]['line'];
1239
-                    echo "Close $type on line $line".PHP_EOL;
1240
-                }
1241
-
1242
-                $prev = false;
1243
-
1244
-                $object = 0;
1245
-                if ($phpcsFile->tokenizerType === 'JS') {
1246
-                    $conditions = $tokens[$i]['conditions'];
1247
-                    krsort($conditions, SORT_NUMERIC);
1248
-                    foreach ($conditions as $token => $condition) {
1249
-                        if ($condition === T_OBJECT) {
1250
-                            $object = $token;
1251
-                            break;
1252
-                        }
1253
-                    }
1254
-
1255
-                    if ($this->debug === true && $object !== 0) {
1256
-                        $line = $tokens[$object]['line'];
1257
-                        echo "\t* token is inside JS object $object on line $line *".PHP_EOL;
1258
-                    }
1259
-                }
1260
-
1261
-                $parens = 0;
1262
-                if (isset($tokens[$i]['nested_parenthesis']) === true
1263
-                    && empty($tokens[$i]['nested_parenthesis']) === false
1264
-                ) {
1265
-                    $parens = $tokens[$i]['nested_parenthesis'];
1266
-                    end($parens);
1267
-                    $parens = key($parens);
1268
-                    if ($this->debug === true) {
1269
-                        $line = $tokens[$parens]['line'];
1270
-                        echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
1271
-                    }
1272
-                }
1273
-
1274
-                $condition = 0;
1275
-                if (isset($tokens[$i]['conditions']) === true
1276
-                    && empty($tokens[$i]['conditions']) === false
1277
-                ) {
1278
-                    $condition = $tokens[$i]['conditions'];
1279
-                    end($condition);
1280
-                    $condition = key($condition);
1281
-                    if ($this->debug === true) {
1282
-                        $line = $tokens[$condition]['line'];
1283
-                        $type = $tokens[$condition]['type'];
1284
-                        echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
1285
-                    }
1286
-                }
1287
-
1288
-                if ($parens > $object && $parens > $condition) {
1289
-                    if ($this->debug === true) {
1290
-                        echo "\t* using parenthesis *".PHP_EOL;
1291
-                    }
1292
-
1293
-                    $prev      = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parens - 1), null, true);
1294
-                    $object    = 0;
1295
-                    $condition = 0;
1296
-                } else if ($object > 0 && $object >= $condition) {
1297
-                    if ($this->debug === true) {
1298
-                        echo "\t* using object *".PHP_EOL;
1299
-                    }
1300
-
1301
-                    $prev      = $object;
1302
-                    $parens    = 0;
1303
-                    $condition = 0;
1304
-                } else if ($condition > 0) {
1305
-                    if ($this->debug === true) {
1306
-                        echo "\t* using condition *".PHP_EOL;
1307
-                    }
1308
-
1309
-                    $prev   = $condition;
1310
-                    $object = 0;
1311
-                    $parens = 0;
1312
-                }//end if
1313
-
1314
-                if ($prev === false) {
1315
-                    $prev = $phpcsFile->findPrevious([T_EQUAL, T_RETURN], ($tokens[$i]['scope_condition'] - 1), null, false, null, true);
1316
-                    if ($prev === false) {
1317
-                        $prev = $i;
1318
-                        if ($this->debug === true) {
1319
-                            echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *".PHP_EOL;
1320
-                        }
1321
-                    }
1322
-                }
1323
-
1324
-                if ($this->debug === true) {
1325
-                    $line = $tokens[$prev]['line'];
1326
-                    $type = $tokens[$prev]['type'];
1327
-                    echo "\t* previous token is $type on line $line *".PHP_EOL;
1328
-                }
1329
-
1330
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1331
-                if ($this->debug === true) {
1332
-                    $line = $tokens[$first]['line'];
1333
-                    $type = $tokens[$first]['type'];
1334
-                    echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
1335
-                }
1336
-
1337
-                $prev = $phpcsFile->findStartOfStatement($first);
1338
-                if ($prev !== $first) {
1339
-                    // This is not the start of the statement.
1340
-                    if ($this->debug === true) {
1341
-                        $line = $tokens[$prev]['line'];
1342
-                        $type = $tokens[$prev]['type'];
1343
-                        echo "\t* amended previous is $type on line $line *".PHP_EOL;
1344
-                    }
1345
-
1346
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1347
-                    if ($this->debug === true) {
1348
-                        $line = $tokens[$first]['line'];
1349
-                        $type = $tokens[$first]['type'];
1350
-                        echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
1351
-                    }
1352
-                }
1353
-
1354
-                $currentIndent = ($tokens[$first]['column'] - 1);
1355
-                if ($object > 0 || $condition > 0) {
1356
-                    $currentIndent += $this->indent;
1357
-                }
1358
-
1359
-                if (isset($tokens[$first]['scope_closer']) === true
1360
-                    && $tokens[$first]['scope_closer'] === $first
1361
-                ) {
1362
-                    if ($this->debug === true) {
1363
-                        echo "\t* first token is a scope closer *".PHP_EOL;
1364
-                    }
1365
-
1366
-                    if ($condition === 0 || $tokens[$condition]['scope_opener'] < $first) {
1367
-                        $currentIndent = $setIndents[$first];
1368
-                    } else if ($this->debug === true) {
1369
-                        echo "\t* ignoring scope closer *".PHP_EOL;
1370
-                    }
1371
-                }
1372
-
1373
-                // Make sure it is divisible by our expected indent.
1374
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1375
-                $setIndents[$first] = $currentIndent;
1376
-
1377
-                if ($this->debug === true) {
1378
-                    $type = $tokens[$first]['type'];
1379
-                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1380
-                }
1381
-            }//end if
1382
-        }//end for
1383
-
1384
-        // Don't process the rest of the file.
1385
-        return $phpcsFile->numTokens;
1386
-
1387
-    }//end process()
1388
-
1389
-
1390
-    /**
1391
-     * Processes this test, when one of its tokens is encountered.
1392
-     *
1393
-     * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
1394
-     * @param int                         $stackPtr  The position of the current token
1395
-     *                                               in the stack passed in $tokens.
1396
-     * @param int                         $length    The length of the new indent.
1397
-     * @param int                         $change    The difference in length between
1398
-     *                                               the old and new indent.
1399
-     *
1400
-     * @return bool
1401
-     */
1402
-    protected function adjustIndent(File $phpcsFile, $stackPtr, $length, $change)
1403
-    {
1404
-        $tokens = $phpcsFile->getTokens();
1405
-
1406
-        // We don't adjust indents outside of PHP.
1407
-        if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) {
1408
-            return false;
1409
-        }
1410
-
1411
-        $padding = '';
1412
-        if ($length > 0) {
1413
-            if ($this->tabIndent === true) {
1414
-                $numTabs = floor($length / $this->tabWidth);
1415
-                if ($numTabs > 0) {
1416
-                    $numSpaces = ($length - ($numTabs * $this->tabWidth));
1417
-                    $padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1418
-                }
1419
-            } else {
1420
-                $padding = str_repeat(' ', $length);
1421
-            }
1422
-        }
1423
-
1424
-        if ($tokens[$stackPtr]['column'] === 1) {
1425
-            $trimmed  = ltrim($tokens[$stackPtr]['content']);
1426
-            $accepted = $phpcsFile->fixer->replaceToken($stackPtr, $padding.$trimmed);
1427
-        } else {
1428
-            // Easier to just replace the entire indent.
1429
-            $accepted = $phpcsFile->fixer->replaceToken(($stackPtr - 1), $padding);
1430
-        }
1431
-
1432
-        if ($accepted === false) {
1433
-            return false;
1434
-        }
1435
-
1436
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1437
-            // We adjusted the start of a comment, so adjust the rest of it
1438
-            // as well so the alignment remains correct.
1439
-            for ($x = ($stackPtr + 1); $x < $tokens[$stackPtr]['comment_closer']; $x++) {
1440
-                if ($tokens[$x]['column'] !== 1) {
1441
-                    continue;
1442
-                }
1443
-
1444
-                $length = 0;
1445
-                if ($tokens[$x]['code'] === T_DOC_COMMENT_WHITESPACE) {
1446
-                    $length = $tokens[$x]['length'];
1447
-                }
1448
-
1449
-                $padding = ($length + $change);
1450
-                if ($padding > 0) {
1451
-                    if ($this->tabIndent === true) {
1452
-                        $numTabs   = floor($padding / $this->tabWidth);
1453
-                        $numSpaces = ($padding - ($numTabs * $this->tabWidth));
1454
-                        $padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1455
-                    } else {
1456
-                        $padding = str_repeat(' ', $padding);
1457
-                    }
1458
-                } else {
1459
-                    $padding = '';
1460
-                }
1461
-
1462
-                $phpcsFile->fixer->replaceToken($x, $padding);
1463
-                if ($this->debug === true) {
1464
-                    $length = strlen($padding);
1465
-                    $line   = $tokens[$x]['line'];
1466
-                    $type   = $tokens[$x]['type'];
1467
-                    echo "\t=> Indent adjusted to $length for $type on line $line".PHP_EOL;
1468
-                }
1469
-            }//end for
1470
-        }//end if
1471
-
1472
-        return true;
1473
-
1474
-    }//end adjustIndent()
927
+			if ($checkToken !== null
928
+				&& isset($this->ignoreIndentation[$tokens[$checkToken]['code']]) === false
929
+				&& (($tokenIndent !== $checkIndent && $exact === true)
930
+				|| ($tokenIndent < $checkIndent && $exact === false))
931
+			) {
932
+				$type  = 'IncorrectExact';
933
+				$error = 'Line indented incorrectly; expected ';
934
+				if ($exact === false) {
935
+					$error .= 'at least ';
936
+					$type   = 'Incorrect';
937
+				}
938
+
939
+				if ($this->tabIndent === true) {
940
+					$error .= '%s tabs, found %s';
941
+					$data   = [
942
+						floor($checkIndent / $this->tabWidth),
943
+						floor($tokenIndent / $this->tabWidth),
944
+					];
945
+				} else {
946
+					$error .= '%s spaces, found %s';
947
+					$data   = [
948
+						$checkIndent,
949
+						$tokenIndent,
950
+					];
951
+				}
952
+
953
+				if ($this->debug === true) {
954
+					$line    = $tokens[$checkToken]['line'];
955
+					$message = vsprintf($error, $data);
956
+					echo "[Line $line] $message".PHP_EOL;
957
+				}
958
+
959
+				// Assume the change would be applied and continue
960
+				// checking indents under this assumption. This gives more
961
+				// technically accurate error messages.
962
+				$adjustments[$checkToken] = ($checkIndent - $tokenIndent);
963
+
964
+				$fix = $phpcsFile->addFixableError($error, $checkToken, $type, $data);
965
+				if ($fix === true || $this->debug === true) {
966
+					$accepted = $this->adjustIndent($phpcsFile, $checkToken, $checkIndent, ($checkIndent - $tokenIndent));
967
+
968
+					if ($accepted === true && $this->debug === true) {
969
+						$line = $tokens[$checkToken]['line'];
970
+						$type = $tokens[$checkToken]['type'];
971
+						echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
972
+					}
973
+				}
974
+			}//end if
975
+
976
+			if ($checkToken !== null) {
977
+				$i = $checkToken;
978
+			}
979
+
980
+			// Completely skip here/now docs as the indent is a part of the
981
+			// content itself.
982
+			if ($tokens[$i]['code'] === T_START_HEREDOC
983
+				|| $tokens[$i]['code'] === T_START_NOWDOC
984
+			) {
985
+				$i = $phpcsFile->findNext([T_END_HEREDOC, T_END_NOWDOC], ($i + 1));
986
+				$i = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
987
+				continue;
988
+			}
989
+
990
+			// Completely skip multi-line strings as the indent is a part of the
991
+			// content itself.
992
+			if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING
993
+				|| $tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING
994
+			) {
995
+				$i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true);
996
+				$i--;
997
+				continue;
998
+			}
999
+
1000
+			// Completely skip doc comments as they tend to have complex
1001
+			// indentation rules.
1002
+			if ($tokens[$i]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1003
+				$i = $tokens[$i]['comment_closer'];
1004
+				continue;
1005
+			}
1006
+
1007
+			// Open tags reset the indent level.
1008
+			if ($tokens[$i]['code'] === T_OPEN_TAG
1009
+				|| $tokens[$i]['code'] === T_OPEN_TAG_WITH_ECHO
1010
+			) {
1011
+				if ($this->debug === true) {
1012
+					$line = $tokens[$i]['line'];
1013
+					echo "Open PHP tag found on line $line".PHP_EOL;
1014
+				}
1015
+
1016
+				if ($checkToken === null) {
1017
+					$first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1018
+					$currentIndent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
1019
+				} else {
1020
+					$currentIndent = ($tokens[$i]['column'] - 1);
1021
+				}
1022
+
1023
+				$lastOpenTag = $i;
1024
+
1025
+				if (isset($adjustments[$i]) === true) {
1026
+					$currentIndent += $adjustments[$i];
1027
+				}
1028
+
1029
+				// Make sure it is divisible by our expected indent.
1030
+				$currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1031
+				$setIndents[$i] = $currentIndent;
1032
+
1033
+				if ($this->debug === true) {
1034
+					$type = $tokens[$i]['type'];
1035
+					echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1036
+				}
1037
+
1038
+				continue;
1039
+			}//end if
1040
+
1041
+			// Close tags reset the indent level, unless they are closing a tag
1042
+			// opened on the same line.
1043
+			if ($tokens[$i]['code'] === T_CLOSE_TAG) {
1044
+				if ($this->debug === true) {
1045
+					$line = $tokens[$i]['line'];
1046
+					echo "Close PHP tag found on line $line".PHP_EOL;
1047
+				}
1048
+
1049
+				if ($tokens[$lastOpenTag]['line'] !== $tokens[$i]['line']) {
1050
+					$currentIndent = ($tokens[$i]['column'] - 1);
1051
+					$lastCloseTag  = $i;
1052
+				} else {
1053
+					if ($lastCloseTag === null) {
1054
+						$currentIndent = 0;
1055
+					} else {
1056
+						$currentIndent = ($tokens[$lastCloseTag]['column'] - 1);
1057
+					}
1058
+				}
1059
+
1060
+				if (isset($adjustments[$i]) === true) {
1061
+					$currentIndent += $adjustments[$i];
1062
+				}
1063
+
1064
+				// Make sure it is divisible by our expected indent.
1065
+				$currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1066
+				$setIndents[$i] = $currentIndent;
1067
+
1068
+				if ($this->debug === true) {
1069
+					$type = $tokens[$i]['type'];
1070
+					echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1071
+				}
1072
+
1073
+				continue;
1074
+			}//end if
1075
+
1076
+			// Anon classes and functions set the indent based on their own indent level.
1077
+			if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) {
1078
+				$closer = $tokens[$i]['scope_closer'];
1079
+				if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1080
+					if ($this->debug === true) {
1081
+						$type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1082
+						$line = $tokens[$i]['line'];
1083
+						echo "* ignoring single-line $type on line $line".PHP_EOL;
1084
+					}
1085
+
1086
+					$i = $closer;
1087
+					continue;
1088
+				}
1089
+
1090
+				if ($this->debug === true) {
1091
+					$type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1092
+					$line = $tokens[$i]['line'];
1093
+					echo "Open $type on line $line".PHP_EOL;
1094
+				}
1095
+
1096
+				$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1097
+				if ($this->debug === true) {
1098
+					$line = $tokens[$first]['line'];
1099
+					$type = $tokens[$first]['type'];
1100
+					echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
1101
+				}
1102
+
1103
+				while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
1104
+					&& $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
1105
+				) {
1106
+					$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
1107
+					if ($this->debug === true) {
1108
+						$line = $tokens[$first]['line'];
1109
+						$type = $tokens[$first]['type'];
1110
+						echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
1111
+					}
1112
+				}
1113
+
1114
+				$currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1115
+				$openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1116
+				if ($this->debug === true) {
1117
+					$closerToken    = $tokens[$i]['scope_closer'];
1118
+					$closerLine     = $tokens[$closerToken]['line'];
1119
+					$closerType     = $tokens[$closerToken]['type'];
1120
+					$conditionToken = $tokens[$i]['scope_condition'];
1121
+					$conditionLine  = $tokens[$conditionToken]['line'];
1122
+					$conditionType  = $tokens[$conditionToken]['type'];
1123
+					echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1124
+				}
1125
+
1126
+				if (isset($adjustments[$first]) === true) {
1127
+					$currentIndent += $adjustments[$first];
1128
+				}
1129
+
1130
+				// Make sure it is divisible by our expected indent.
1131
+				$currentIndent = (int) (floor($currentIndent / $this->indent) * $this->indent);
1132
+				$i = $tokens[$i]['scope_opener'];
1133
+				$setIndents[$i] = $currentIndent;
1134
+
1135
+				if ($this->debug === true) {
1136
+					$type = $tokens[$i]['type'];
1137
+					echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1138
+				}
1139
+
1140
+				continue;
1141
+			}//end if
1142
+
1143
+			// Scope openers increase the indent level.
1144
+			if (isset($tokens[$i]['scope_condition']) === true
1145
+				&& isset($tokens[$i]['scope_opener']) === true
1146
+				&& $tokens[$i]['scope_opener'] === $i
1147
+			) {
1148
+				$closer = $tokens[$i]['scope_closer'];
1149
+				if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1150
+					if ($this->debug === true) {
1151
+						$line = $tokens[$i]['line'];
1152
+						$type = $tokens[$i]['type'];
1153
+						echo "* ignoring single-line $type on line $line".PHP_EOL;
1154
+					}
1155
+
1156
+					$i = $closer;
1157
+					continue;
1158
+				}
1159
+
1160
+				$condition = $tokens[$tokens[$i]['scope_condition']]['code'];
1161
+				if (isset(Tokens::$scopeOpeners[$condition]) === true
1162
+					&& in_array($condition, $this->nonIndentingScopes, true) === false
1163
+				) {
1164
+					if ($this->debug === true) {
1165
+						$line = $tokens[$i]['line'];
1166
+						$type = $tokens[$tokens[$i]['scope_condition']]['type'];
1167
+						echo "Open scope ($type) on line $line".PHP_EOL;
1168
+					}
1169
+
1170
+					$currentIndent += $this->indent;
1171
+					$setIndents[$i] = $currentIndent;
1172
+					$openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1173
+					if ($this->debug === true) {
1174
+						$closerToken    = $tokens[$i]['scope_closer'];
1175
+						$closerLine     = $tokens[$closerToken]['line'];
1176
+						$closerType     = $tokens[$closerToken]['type'];
1177
+						$conditionToken = $tokens[$i]['scope_condition'];
1178
+						$conditionLine  = $tokens[$conditionToken]['line'];
1179
+						$conditionType  = $tokens[$conditionToken]['type'];
1180
+						echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1181
+					}
1182
+
1183
+					if ($this->debug === true) {
1184
+						$type = $tokens[$i]['type'];
1185
+						echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1186
+					}
1187
+
1188
+					continue;
1189
+				}//end if
1190
+			}//end if
1191
+
1192
+			// JS objects set the indent level.
1193
+			if ($phpcsFile->tokenizerType === 'JS'
1194
+				&& $tokens[$i]['code'] === T_OBJECT
1195
+			) {
1196
+				$closer = $tokens[$i]['bracket_closer'];
1197
+				if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1198
+					if ($this->debug === true) {
1199
+						$line = $tokens[$i]['line'];
1200
+						echo "* ignoring single-line JS object on line $line".PHP_EOL;
1201
+					}
1202
+
1203
+					$i = $closer;
1204
+					continue;
1205
+				}
1206
+
1207
+				if ($this->debug === true) {
1208
+					$line = $tokens[$i]['line'];
1209
+					echo "Open JS object on line $line".PHP_EOL;
1210
+				}
1211
+
1212
+				$first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1213
+				$currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1214
+				if (isset($adjustments[$first]) === true) {
1215
+					$currentIndent += $adjustments[$first];
1216
+				}
1217
+
1218
+				// Make sure it is divisible by our expected indent.
1219
+				$currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1220
+				$setIndents[$first] = $currentIndent;
1221
+
1222
+				if ($this->debug === true) {
1223
+					$type = $tokens[$first]['type'];
1224
+					echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1225
+				}
1226
+
1227
+				continue;
1228
+			}//end if
1229
+
1230
+			// Closing an anon class or function.
1231
+			if (isset($tokens[$i]['scope_condition']) === true
1232
+				&& $tokens[$i]['scope_closer'] === $i
1233
+				&& ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE
1234
+				|| $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS)
1235
+			) {
1236
+				if ($this->debug === true) {
1237
+					$type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2)));
1238
+					$line = $tokens[$i]['line'];
1239
+					echo "Close $type on line $line".PHP_EOL;
1240
+				}
1241
+
1242
+				$prev = false;
1243
+
1244
+				$object = 0;
1245
+				if ($phpcsFile->tokenizerType === 'JS') {
1246
+					$conditions = $tokens[$i]['conditions'];
1247
+					krsort($conditions, SORT_NUMERIC);
1248
+					foreach ($conditions as $token => $condition) {
1249
+						if ($condition === T_OBJECT) {
1250
+							$object = $token;
1251
+							break;
1252
+						}
1253
+					}
1254
+
1255
+					if ($this->debug === true && $object !== 0) {
1256
+						$line = $tokens[$object]['line'];
1257
+						echo "\t* token is inside JS object $object on line $line *".PHP_EOL;
1258
+					}
1259
+				}
1260
+
1261
+				$parens = 0;
1262
+				if (isset($tokens[$i]['nested_parenthesis']) === true
1263
+					&& empty($tokens[$i]['nested_parenthesis']) === false
1264
+				) {
1265
+					$parens = $tokens[$i]['nested_parenthesis'];
1266
+					end($parens);
1267
+					$parens = key($parens);
1268
+					if ($this->debug === true) {
1269
+						$line = $tokens[$parens]['line'];
1270
+						echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
1271
+					}
1272
+				}
1273
+
1274
+				$condition = 0;
1275
+				if (isset($tokens[$i]['conditions']) === true
1276
+					&& empty($tokens[$i]['conditions']) === false
1277
+				) {
1278
+					$condition = $tokens[$i]['conditions'];
1279
+					end($condition);
1280
+					$condition = key($condition);
1281
+					if ($this->debug === true) {
1282
+						$line = $tokens[$condition]['line'];
1283
+						$type = $tokens[$condition]['type'];
1284
+						echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
1285
+					}
1286
+				}
1287
+
1288
+				if ($parens > $object && $parens > $condition) {
1289
+					if ($this->debug === true) {
1290
+						echo "\t* using parenthesis *".PHP_EOL;
1291
+					}
1292
+
1293
+					$prev      = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parens - 1), null, true);
1294
+					$object    = 0;
1295
+					$condition = 0;
1296
+				} else if ($object > 0 && $object >= $condition) {
1297
+					if ($this->debug === true) {
1298
+						echo "\t* using object *".PHP_EOL;
1299
+					}
1300
+
1301
+					$prev      = $object;
1302
+					$parens    = 0;
1303
+					$condition = 0;
1304
+				} else if ($condition > 0) {
1305
+					if ($this->debug === true) {
1306
+						echo "\t* using condition *".PHP_EOL;
1307
+					}
1308
+
1309
+					$prev   = $condition;
1310
+					$object = 0;
1311
+					$parens = 0;
1312
+				}//end if
1313
+
1314
+				if ($prev === false) {
1315
+					$prev = $phpcsFile->findPrevious([T_EQUAL, T_RETURN], ($tokens[$i]['scope_condition'] - 1), null, false, null, true);
1316
+					if ($prev === false) {
1317
+						$prev = $i;
1318
+						if ($this->debug === true) {
1319
+							echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *".PHP_EOL;
1320
+						}
1321
+					}
1322
+				}
1323
+
1324
+				if ($this->debug === true) {
1325
+					$line = $tokens[$prev]['line'];
1326
+					$type = $tokens[$prev]['type'];
1327
+					echo "\t* previous token is $type on line $line *".PHP_EOL;
1328
+				}
1329
+
1330
+				$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1331
+				if ($this->debug === true) {
1332
+					$line = $tokens[$first]['line'];
1333
+					$type = $tokens[$first]['type'];
1334
+					echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
1335
+				}
1336
+
1337
+				$prev = $phpcsFile->findStartOfStatement($first);
1338
+				if ($prev !== $first) {
1339
+					// This is not the start of the statement.
1340
+					if ($this->debug === true) {
1341
+						$line = $tokens[$prev]['line'];
1342
+						$type = $tokens[$prev]['type'];
1343
+						echo "\t* amended previous is $type on line $line *".PHP_EOL;
1344
+					}
1345
+
1346
+					$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1347
+					if ($this->debug === true) {
1348
+						$line = $tokens[$first]['line'];
1349
+						$type = $tokens[$first]['type'];
1350
+						echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
1351
+					}
1352
+				}
1353
+
1354
+				$currentIndent = ($tokens[$first]['column'] - 1);
1355
+				if ($object > 0 || $condition > 0) {
1356
+					$currentIndent += $this->indent;
1357
+				}
1358
+
1359
+				if (isset($tokens[$first]['scope_closer']) === true
1360
+					&& $tokens[$first]['scope_closer'] === $first
1361
+				) {
1362
+					if ($this->debug === true) {
1363
+						echo "\t* first token is a scope closer *".PHP_EOL;
1364
+					}
1365
+
1366
+					if ($condition === 0 || $tokens[$condition]['scope_opener'] < $first) {
1367
+						$currentIndent = $setIndents[$first];
1368
+					} else if ($this->debug === true) {
1369
+						echo "\t* ignoring scope closer *".PHP_EOL;
1370
+					}
1371
+				}
1372
+
1373
+				// Make sure it is divisible by our expected indent.
1374
+				$currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1375
+				$setIndents[$first] = $currentIndent;
1376
+
1377
+				if ($this->debug === true) {
1378
+					$type = $tokens[$first]['type'];
1379
+					echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1380
+				}
1381
+			}//end if
1382
+		}//end for
1383
+
1384
+		// Don't process the rest of the file.
1385
+		return $phpcsFile->numTokens;
1386
+
1387
+	}//end process()
1388
+
1389
+
1390
+	/**
1391
+	 * Processes this test, when one of its tokens is encountered.
1392
+	 *
1393
+	 * @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
1394
+	 * @param int                         $stackPtr  The position of the current token
1395
+	 *                                               in the stack passed in $tokens.
1396
+	 * @param int                         $length    The length of the new indent.
1397
+	 * @param int                         $change    The difference in length between
1398
+	 *                                               the old and new indent.
1399
+	 *
1400
+	 * @return bool
1401
+	 */
1402
+	protected function adjustIndent(File $phpcsFile, $stackPtr, $length, $change)
1403
+	{
1404
+		$tokens = $phpcsFile->getTokens();
1405
+
1406
+		// We don't adjust indents outside of PHP.
1407
+		if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) {
1408
+			return false;
1409
+		}
1410
+
1411
+		$padding = '';
1412
+		if ($length > 0) {
1413
+			if ($this->tabIndent === true) {
1414
+				$numTabs = floor($length / $this->tabWidth);
1415
+				if ($numTabs > 0) {
1416
+					$numSpaces = ($length - ($numTabs * $this->tabWidth));
1417
+					$padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1418
+				}
1419
+			} else {
1420
+				$padding = str_repeat(' ', $length);
1421
+			}
1422
+		}
1423
+
1424
+		if ($tokens[$stackPtr]['column'] === 1) {
1425
+			$trimmed  = ltrim($tokens[$stackPtr]['content']);
1426
+			$accepted = $phpcsFile->fixer->replaceToken($stackPtr, $padding.$trimmed);
1427
+		} else {
1428
+			// Easier to just replace the entire indent.
1429
+			$accepted = $phpcsFile->fixer->replaceToken(($stackPtr - 1), $padding);
1430
+		}
1431
+
1432
+		if ($accepted === false) {
1433
+			return false;
1434
+		}
1435
+
1436
+		if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1437
+			// We adjusted the start of a comment, so adjust the rest of it
1438
+			// as well so the alignment remains correct.
1439
+			for ($x = ($stackPtr + 1); $x < $tokens[$stackPtr]['comment_closer']; $x++) {
1440
+				if ($tokens[$x]['column'] !== 1) {
1441
+					continue;
1442
+				}
1443
+
1444
+				$length = 0;
1445
+				if ($tokens[$x]['code'] === T_DOC_COMMENT_WHITESPACE) {
1446
+					$length = $tokens[$x]['length'];
1447
+				}
1448
+
1449
+				$padding = ($length + $change);
1450
+				if ($padding > 0) {
1451
+					if ($this->tabIndent === true) {
1452
+						$numTabs   = floor($padding / $this->tabWidth);
1453
+						$numSpaces = ($padding - ($numTabs * $this->tabWidth));
1454
+						$padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1455
+					} else {
1456
+						$padding = str_repeat(' ', $padding);
1457
+					}
1458
+				} else {
1459
+					$padding = '';
1460
+				}
1461
+
1462
+				$phpcsFile->fixer->replaceToken($x, $padding);
1463
+				if ($this->debug === true) {
1464
+					$length = strlen($padding);
1465
+					$line   = $tokens[$x]['line'];
1466
+					$type   = $tokens[$x]['type'];
1467
+					echo "\t=> Indent adjusted to $length for $type on line $line".PHP_EOL;
1468
+				}
1469
+			}//end for
1470
+		}//end if
1471
+
1472
+		return true;
1473
+
1474
+	}//end adjustIndent()
1475 1475
 
1476 1476
 
1477 1477
 }//end class
Please login to merge, or discard this patch.
Spacing   +667 added lines, -667 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @var int[]
74 74
      */
75
-    public $ignoreIndentationTokens = [];
75
+    public $ignoreIndentationTokens = [ ];
76 76
 
77 77
     /**
78 78
      * List of tokens not needing to be checked for indentation.
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @var int[]
84 84
      */
85
-    private $ignoreIndentation = [];
85
+    private $ignoreIndentation = [ ];
86 86
 
87 87
     /**
88 88
      * Any scope openers that should not cause an indent.
89 89
      *
90 90
      * @var int[]
91 91
      */
92
-    protected $nonIndentingScopes = [];
92
+    protected $nonIndentingScopes = [ ];
93 93
 
94 94
     /**
95 95
      * Show debug output for this sniff.
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function register()
108 108
     {
109
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
109
+        if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === true ) {
110 110
             $this->debug = false;
111 111
         }
112 112
 
113
-        return [T_OPEN_TAG];
113
+        return [ T_OPEN_TAG ];
114 114
 
115 115
     }//end register()
116 116
 
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
      *
125 125
      * @return void
126 126
      */
127
-    public function process(File $phpcsFile, $stackPtr)
127
+    public function process( File $phpcsFile, $stackPtr )
128 128
     {
129
-        $debug = Config::getConfigData('scope_indent_debug');
130
-        if ($debug !== null) {
131
-            $this->debug = (bool) $debug;
129
+        $debug = Config::getConfigData( 'scope_indent_debug' );
130
+        if ( $debug !== null ) {
131
+            $this->debug = (bool)$debug;
132 132
         }
133 133
 
134
-        if ($this->tabWidth === null) {
135
-            if (isset($phpcsFile->config->tabWidth) === false || $phpcsFile->config->tabWidth === 0) {
134
+        if ( $this->tabWidth === null ) {
135
+            if ( isset( $phpcsFile->config->tabWidth ) === false || $phpcsFile->config->tabWidth === 0 ) {
136 136
                 // We have no idea how wide tabs are, so assume 4 spaces for fixing.
137 137
                 // It shouldn't really matter because indent checks elsewhere in the
138 138
                 // standard should fix things up.
@@ -144,77 +144,77 @@  discard block
 block discarded – undo
144 144
 
145 145
         $lastOpenTag     = $stackPtr;
146 146
         $lastCloseTag    = null;
147
-        $openScopes      = [];
148
-        $adjustments     = [];
149
-        $setIndents      = [];
147
+        $openScopes      = [ ];
148
+        $adjustments     = [ ];
149
+        $setIndents      = [ ];
150 150
         $disableExactEnd = 0;
151 151
 
152 152
         $tokens  = $phpcsFile->getTokens();
153
-        $first   = $phpcsFile->findFirstOnLine(T_INLINE_HTML, $stackPtr);
154
-        $trimmed = ltrim($tokens[$first]['content']);
155
-        if ($trimmed === '') {
156
-            $currentIndent = ($tokens[$stackPtr]['column'] - 1);
153
+        $first   = $phpcsFile->findFirstOnLine( T_INLINE_HTML, $stackPtr );
154
+        $trimmed = ltrim( $tokens[ $first ][ 'content' ] );
155
+        if ( $trimmed === '' ) {
156
+            $currentIndent = ( $tokens[ $stackPtr ][ 'column' ] - 1 );
157 157
         } else {
158
-            $currentIndent = (strlen($tokens[$first]['content']) - strlen($trimmed));
158
+            $currentIndent = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( $trimmed ) );
159 159
         }
160 160
 
161
-        if ($this->debug === true) {
162
-            $line = $tokens[$stackPtr]['line'];
163
-            echo "Start with token $stackPtr on line $line with indent $currentIndent".PHP_EOL;
161
+        if ( $this->debug === true ) {
162
+            $line = $tokens[ $stackPtr ][ 'line' ];
163
+            echo "Start with token $stackPtr on line $line with indent $currentIndent" . PHP_EOL;
164 164
         }
165 165
 
166
-        if (empty($this->ignoreIndentation) === true) {
167
-            $this->ignoreIndentation = [T_INLINE_HTML => true];
168
-            foreach ($this->ignoreIndentationTokens as $token) {
169
-                if (is_int($token) === false) {
170
-                    if (defined($token) === false) {
166
+        if ( empty( $this->ignoreIndentation ) === true ) {
167
+            $this->ignoreIndentation = [ T_INLINE_HTML => true ];
168
+            foreach ( $this->ignoreIndentationTokens as $token ) {
169
+                if ( is_int( $token ) === false ) {
170
+                    if ( defined( $token ) === false ) {
171 171
                         continue;
172 172
                     }
173 173
 
174
-                    $token = constant($token);
174
+                    $token = constant( $token );
175 175
                 }
176 176
 
177
-                $this->ignoreIndentation[$token] = true;
177
+                $this->ignoreIndentation[ $token ] = true;
178 178
             }
179 179
         }//end if
180 180
 
181
-        $this->exact     = (bool) $this->exact;
182
-        $this->tabIndent = (bool) $this->tabIndent;
181
+        $this->exact     = (bool)$this->exact;
182
+        $this->tabIndent = (bool)$this->tabIndent;
183 183
 
184 184
         $checkAnnotations = $phpcsFile->config->annotations;
185 185
 
186
-        for ($i = ($stackPtr + 1); $i < $phpcsFile->numTokens; $i++) {
187
-            if ($i === false) {
186
+        for ( $i = ( $stackPtr + 1 ); $i < $phpcsFile->numTokens; $i++ ) {
187
+            if ( $i === false ) {
188 188
                 // Something has gone very wrong; maybe a parse error.
189 189
                 break;
190 190
             }
191 191
 
192
-            if ($checkAnnotations === true
193
-                && $tokens[$i]['code'] === T_PHPCS_SET
194
-                && isset($tokens[$i]['sniffCode']) === true
195
-                && $tokens[$i]['sniffCode'] === 'Generic.WhiteSpace.ScopeIndent'
196
-                && $tokens[$i]['sniffProperty'] === 'exact'
192
+            if ( $checkAnnotations === true
193
+                && $tokens[ $i ][ 'code' ] === T_PHPCS_SET
194
+                && isset( $tokens[ $i ][ 'sniffCode' ] ) === true
195
+                && $tokens[ $i ][ 'sniffCode' ] === 'Generic.WhiteSpace.ScopeIndent'
196
+                && $tokens[ $i ][ 'sniffProperty' ] === 'exact'
197 197
             ) {
198
-                $value = $tokens[$i]['sniffPropertyValue'];
199
-                if ($value === 'true') {
198
+                $value = $tokens[ $i ][ 'sniffPropertyValue' ];
199
+                if ( $value === 'true' ) {
200 200
                     $value = true;
201
-                } else if ($value === 'false') {
201
+                } else if ( $value === 'false' ) {
202 202
                     $value = false;
203 203
                 } else {
204
-                    $value = (bool) $value;
204
+                    $value = (bool)$value;
205 205
                 }
206 206
 
207 207
                 $this->exact = $value;
208 208
 
209
-                if ($this->debug === true) {
210
-                    $line = $tokens[$i]['line'];
211
-                    if ($this->exact === true) {
209
+                if ( $this->debug === true ) {
210
+                    $line = $tokens[ $i ][ 'line' ];
211
+                    if ( $this->exact === true ) {
212 212
                         $value = 'true';
213 213
                     } else {
214 214
                         $value = 'false';
215 215
                     }
216 216
 
217
-                    echo "* token $i on line $line set exact flag to $value *".PHP_EOL;
217
+                    echo "* token $i on line $line set exact flag to $value *" . PHP_EOL;
218 218
                 }
219 219
             }//end if
220 220
 
@@ -229,96 +229,96 @@  discard block
 block discarded – undo
229 229
 
230 230
             $exact = $this->exact;
231 231
 
232
-            if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
233
-                $disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
232
+            if ( $tokens[ $i ][ 'code' ] === T_OPEN_SHORT_ARRAY ) {
233
+                $disableExactEnd = max( $disableExactEnd, $tokens[ $i ][ 'bracket_closer' ] );
234 234
             }
235 235
 
236
-            if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
237
-                && isset($tokens[$i]['parenthesis_closer']) === true
236
+            if ( $tokens[ $i ][ 'code' ] === T_OPEN_PARENTHESIS
237
+                && isset( $tokens[ $i ][ 'parenthesis_closer' ] ) === true
238 238
             ) {
239
-                $disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
239
+                $disableExactEnd = max( $disableExactEnd, $tokens[ $i ][ 'parenthesis_closer' ] );
240 240
             }
241 241
 
242
-            if ($exact === true && $i < $disableExactEnd) {
242
+            if ( $exact === true && $i < $disableExactEnd ) {
243 243
                 $exact = false;
244 244
             }
245 245
 
246 246
             // Detect line changes and figure out where the indent is.
247
-            if ($tokens[$i]['column'] === 1) {
248
-                $trimmed = ltrim($tokens[$i]['content']);
249
-                if ($trimmed === '') {
250
-                    if (isset($tokens[($i + 1)]) === true
251
-                        && $tokens[$i]['line'] === $tokens[($i + 1)]['line']
247
+            if ( $tokens[ $i ][ 'column' ] === 1 ) {
248
+                $trimmed = ltrim( $tokens[ $i ][ 'content' ] );
249
+                if ( $trimmed === '' ) {
250
+                    if ( isset( $tokens[ ( $i + 1 ) ] ) === true
251
+                        && $tokens[ $i ][ 'line' ] === $tokens[ ( $i + 1 ) ][ 'line' ]
252 252
                     ) {
253
-                        $checkToken  = ($i + 1);
254
-                        $tokenIndent = ($tokens[($i + 1)]['column'] - 1);
253
+                        $checkToken  = ( $i + 1 );
254
+                        $tokenIndent = ( $tokens[ ( $i + 1 ) ][ 'column' ] - 1 );
255 255
                     }
256 256
                 } else {
257 257
                     $checkToken  = $i;
258
-                    $tokenIndent = (strlen($tokens[$i]['content']) - strlen($trimmed));
258
+                    $tokenIndent = ( strlen( $tokens[ $i ][ 'content' ] ) - strlen( $trimmed ) );
259 259
                 }
260 260
             }
261 261
 
262 262
             // Closing parenthesis should just be indented to at least
263 263
             // the same level as where they were opened (but can be more).
264
-            if (($checkToken !== null
265
-                && $tokens[$checkToken]['code'] === T_CLOSE_PARENTHESIS
266
-                && isset($tokens[$checkToken]['parenthesis_opener']) === true)
267
-                || ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS
268
-                && isset($tokens[$i]['parenthesis_opener']) === true)
264
+            if ( ( $checkToken !== null
265
+                && $tokens[ $checkToken ][ 'code' ] === T_CLOSE_PARENTHESIS
266
+                && isset( $tokens[ $checkToken ][ 'parenthesis_opener' ] ) === true )
267
+                || ( $tokens[ $i ][ 'code' ] === T_CLOSE_PARENTHESIS
268
+                && isset( $tokens[ $i ][ 'parenthesis_opener' ] ) === true )
269 269
             ) {
270
-                if ($checkToken !== null) {
270
+                if ( $checkToken !== null ) {
271 271
                     $parenCloser = $checkToken;
272 272
                 } else {
273 273
                     $parenCloser = $i;
274 274
                 }
275 275
 
276
-                if ($this->debug === true) {
277
-                    $line = $tokens[$i]['line'];
278
-                    echo "Closing parenthesis found on line $line".PHP_EOL;
276
+                if ( $this->debug === true ) {
277
+                    $line = $tokens[ $i ][ 'line' ];
278
+                    echo "Closing parenthesis found on line $line" . PHP_EOL;
279 279
                 }
280 280
 
281
-                $parenOpener = $tokens[$parenCloser]['parenthesis_opener'];
282
-                if ($tokens[$parenCloser]['line'] !== $tokens[$parenOpener]['line']) {
281
+                $parenOpener = $tokens[ $parenCloser ][ 'parenthesis_opener' ];
282
+                if ( $tokens[ $parenCloser ][ 'line' ] !== $tokens[ $parenOpener ][ 'line' ] ) {
283 283
                     $parens = 0;
284
-                    if (isset($tokens[$parenCloser]['nested_parenthesis']) === true
285
-                        && empty($tokens[$parenCloser]['nested_parenthesis']) === false
284
+                    if ( isset( $tokens[ $parenCloser ][ 'nested_parenthesis' ] ) === true
285
+                        && empty( $tokens[ $parenCloser ][ 'nested_parenthesis' ] ) === false
286 286
                     ) {
287
-                        $parens = $tokens[$parenCloser]['nested_parenthesis'];
288
-                        end($parens);
289
-                        $parens = key($parens);
290
-                        if ($this->debug === true) {
291
-                            $line = $tokens[$parens]['line'];
292
-                            echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
287
+                        $parens = $tokens[ $parenCloser ][ 'nested_parenthesis' ];
288
+                        end( $parens );
289
+                        $parens = key( $parens );
290
+                        if ( $this->debug === true ) {
291
+                            $line = $tokens[ $parens ][ 'line' ];
292
+                            echo "\t* token has nested parenthesis $parens on line $line *" . PHP_EOL;
293 293
                         }
294 294
                     }
295 295
 
296 296
                     $condition = 0;
297
-                    if (isset($tokens[$parenCloser]['conditions']) === true
298
-                        && empty($tokens[$parenCloser]['conditions']) === false
299
-                        && (isset($tokens[$parenCloser]['parenthesis_owner']) === false
300
-                        || $parens > 0)
297
+                    if ( isset( $tokens[ $parenCloser ][ 'conditions' ] ) === true
298
+                        && empty( $tokens[ $parenCloser ][ 'conditions' ] ) === false
299
+                        && ( isset( $tokens[ $parenCloser ][ 'parenthesis_owner' ] ) === false
300
+                        || $parens > 0 )
301 301
                     ) {
302
-                        $condition = $tokens[$parenCloser]['conditions'];
303
-                        end($condition);
304
-                        $condition = key($condition);
305
-                        if ($this->debug === true) {
306
-                            $line = $tokens[$condition]['line'];
307
-                            $type = $tokens[$condition]['type'];
308
-                            echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
302
+                        $condition = $tokens[ $parenCloser ][ 'conditions' ];
303
+                        end( $condition );
304
+                        $condition = key( $condition );
305
+                        if ( $this->debug === true ) {
306
+                            $line = $tokens[ $condition ][ 'line' ];
307
+                            $type = $tokens[ $condition ][ 'type' ];
308
+                            echo "\t* token is inside condition $condition ($type) on line $line *" . PHP_EOL;
309 309
                         }
310 310
                     }
311 311
 
312
-                    if ($parens > $condition) {
313
-                        if ($this->debug === true) {
314
-                            echo "\t* using parenthesis *".PHP_EOL;
312
+                    if ( $parens > $condition ) {
313
+                        if ( $this->debug === true ) {
314
+                            echo "\t* using parenthesis *" . PHP_EOL;
315 315
                         }
316 316
 
317 317
                         $parenOpener = $parens;
318 318
                         $condition   = 0;
319
-                    } else if ($condition > 0) {
320
-                        if ($this->debug === true) {
321
-                            echo "\t* using condition *".PHP_EOL;
319
+                    } else if ( $condition > 0 ) {
320
+                        if ( $this->debug === true ) {
321
+                            echo "\t* using condition *" . PHP_EOL;
322 322
                         }
323 323
 
324 324
                         $parenOpener = $condition;
@@ -327,356 +327,356 @@  discard block
 block discarded – undo
327 327
 
328 328
                     $exact = false;
329 329
 
330
-                    $lastOpenTagConditions = array_keys($tokens[$lastOpenTag]['conditions']);
331
-                    $lastOpenTagCondition  = array_pop($lastOpenTagConditions);
330
+                    $lastOpenTagConditions = array_keys( $tokens[ $lastOpenTag ][ 'conditions' ] );
331
+                    $lastOpenTagCondition  = array_pop( $lastOpenTagConditions );
332 332
 
333
-                    if ($condition > 0 && $lastOpenTagCondition === $condition) {
334
-                        if ($this->debug === true) {
335
-                            echo "\t* open tag is inside condition; using open tag *".PHP_EOL;
333
+                    if ( $condition > 0 && $lastOpenTagCondition === $condition ) {
334
+                        if ( $this->debug === true ) {
335
+                            echo "\t* open tag is inside condition; using open tag *" . PHP_EOL;
336 336
                         }
337 337
 
338
-                        $checkIndent = ($tokens[$lastOpenTag]['column'] - 1);
339
-                        if (isset($adjustments[$condition]) === true) {
340
-                            $checkIndent += $adjustments[$condition];
338
+                        $checkIndent = ( $tokens[ $lastOpenTag ][ 'column' ] - 1 );
339
+                        if ( isset( $adjustments[ $condition ] ) === true ) {
340
+                            $checkIndent += $adjustments[ $condition ];
341 341
                         }
342 342
 
343 343
                         $currentIndent = $checkIndent;
344 344
 
345
-                        if ($this->debug === true) {
346
-                            $type = $tokens[$lastOpenTag]['type'];
347
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)".PHP_EOL;
345
+                        if ( $this->debug === true ) {
346
+                            $type = $tokens[ $lastOpenTag ][ 'type' ];
347
+                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $lastOpenTag ($type)" . PHP_EOL;
348 348
                         }
349
-                    } else if ($condition > 0
350
-                        && isset($tokens[$condition]['scope_opener']) === true
351
-                        && isset($setIndents[$tokens[$condition]['scope_opener']]) === true
349
+                    } else if ( $condition > 0
350
+                        && isset( $tokens[ $condition ][ 'scope_opener' ] ) === true
351
+                        && isset( $setIndents[ $tokens[ $condition ][ 'scope_opener' ] ] ) === true
352 352
                     ) {
353
-                        $checkIndent = $setIndents[$tokens[$condition]['scope_opener']];
354
-                        if (isset($adjustments[$condition]) === true) {
355
-                            $checkIndent += $adjustments[$condition];
353
+                        $checkIndent = $setIndents[ $tokens[ $condition ][ 'scope_opener' ] ];
354
+                        if ( isset( $adjustments[ $condition ] ) === true ) {
355
+                            $checkIndent += $adjustments[ $condition ];
356 356
                         }
357 357
 
358 358
                         $currentIndent = $checkIndent;
359 359
 
360
-                        if ($this->debug === true) {
361
-                            $type = $tokens[$condition]['type'];
362
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)".PHP_EOL;
360
+                        if ( $this->debug === true ) {
361
+                            $type = $tokens[ $condition ][ 'type' ];
362
+                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $condition ($type)" . PHP_EOL;
363 363
                         }
364 364
                     } else {
365
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parenOpener, true);
365
+                        $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $parenOpener, true );
366 366
 
367
-                        $checkIndent = ($tokens[$first]['column'] - 1);
368
-                        if (isset($adjustments[$first]) === true) {
369
-                            $checkIndent += $adjustments[$first];
367
+                        $checkIndent = ( $tokens[ $first ][ 'column' ] - 1 );
368
+                        if ( isset( $adjustments[ $first ] ) === true ) {
369
+                            $checkIndent += $adjustments[ $first ];
370 370
                         }
371 371
 
372
-                        if ($this->debug === true) {
373
-                            $line = $tokens[$first]['line'];
374
-                            $type = $tokens[$first]['type'];
375
-                            echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
372
+                        if ( $this->debug === true ) {
373
+                            $line = $tokens[ $first ][ 'line' ];
374
+                            $type = $tokens[ $first ][ 'type' ];
375
+                            echo "\t* first token on line $line is $first ($type) *" . PHP_EOL;
376 376
                         }
377 377
 
378
-                        if ($first === $tokens[$parenCloser]['parenthesis_opener']
379
-                            && $tokens[($first - 1)]['line'] === $tokens[$first]['line']
378
+                        if ( $first === $tokens[ $parenCloser ][ 'parenthesis_opener' ]
379
+                            && $tokens[ ( $first - 1 ) ][ 'line' ] === $tokens[ $first ][ 'line' ]
380 380
                         ) {
381 381
                             // This is unlikely to be the start of the statement, so look
382 382
                             // back further to find it.
383 383
                             $first--;
384
-                            if ($this->debug === true) {
385
-                                $line = $tokens[$first]['line'];
386
-                                $type = $tokens[$first]['type'];
387
-                                echo "\t* first token is the parenthesis opener *".PHP_EOL;
388
-                                echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
384
+                            if ( $this->debug === true ) {
385
+                                $line = $tokens[ $first ][ 'line' ];
386
+                                $type = $tokens[ $first ][ 'type' ];
387
+                                echo "\t* first token is the parenthesis opener *" . PHP_EOL;
388
+                                echo "\t* amended first token is $first ($type) on line $line *" . PHP_EOL;
389 389
                             }
390 390
                         }
391 391
 
392
-                        $prev = $phpcsFile->findStartOfStatement($first, T_COMMA);
393
-                        if ($prev !== $first) {
392
+                        $prev = $phpcsFile->findStartOfStatement( $first, T_COMMA );
393
+                        if ( $prev !== $first ) {
394 394
                             // This is not the start of the statement.
395
-                            if ($this->debug === true) {
396
-                                $line = $tokens[$prev]['line'];
397
-                                $type = $tokens[$prev]['type'];
398
-                                echo "\t* previous is $type on line $line *".PHP_EOL;
395
+                            if ( $this->debug === true ) {
396
+                                $line = $tokens[ $prev ][ 'line' ];
397
+                                $type = $tokens[ $prev ][ 'type' ];
398
+                                echo "\t* previous is $type on line $line *" . PHP_EOL;
399 399
                             }
400 400
 
401
-                            $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
402
-                            if ($first !== false) {
403
-                                $prev  = $phpcsFile->findStartOfStatement($first, T_COMMA);
404
-                                $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $prev, true);
401
+                            $first = $phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_INLINE_HTML ], $prev, true );
402
+                            if ( $first !== false ) {
403
+                                $prev  = $phpcsFile->findStartOfStatement( $first, T_COMMA );
404
+                                $first = $phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_INLINE_HTML ], $prev, true );
405 405
                             } else {
406 406
                                 $first = $prev;
407 407
                             }
408 408
 
409
-                            if ($this->debug === true) {
410
-                                $line = $tokens[$first]['line'];
411
-                                $type = $tokens[$first]['type'];
412
-                                echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
409
+                            if ( $this->debug === true ) {
410
+                                $line = $tokens[ $first ][ 'line' ];
411
+                                $type = $tokens[ $first ][ 'type' ];
412
+                                echo "\t* amended first token is $first ($type) on line $line *" . PHP_EOL;
413 413
                             }
414 414
                         }//end if
415 415
 
416
-                        if (isset($tokens[$first]['scope_closer']) === true
417
-                            && $tokens[$first]['scope_closer'] === $first
416
+                        if ( isset( $tokens[ $first ][ 'scope_closer' ] ) === true
417
+                            && $tokens[ $first ][ 'scope_closer' ] === $first
418 418
                         ) {
419
-                            if ($this->debug === true) {
420
-                                echo "\t* first token is a scope closer *".PHP_EOL;
419
+                            if ( $this->debug === true ) {
420
+                                echo "\t* first token is a scope closer *" . PHP_EOL;
421 421
                             }
422 422
 
423
-                            if (isset($tokens[$first]['scope_condition']) === true) {
423
+                            if ( isset( $tokens[ $first ][ 'scope_condition' ] ) === true ) {
424 424
                                 $scopeCloser = $first;
425
-                                $first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['scope_condition'], true);
425
+                                $first       = $phpcsFile->findFirstOnLine( T_WHITESPACE, $tokens[ $scopeCloser ][ 'scope_condition' ], true );
426 426
 
427
-                                $currentIndent = ($tokens[$first]['column'] - 1);
428
-                                if (isset($adjustments[$first]) === true) {
429
-                                    $currentIndent += $adjustments[$first];
427
+                                $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
428
+                                if ( isset( $adjustments[ $first ] ) === true ) {
429
+                                    $currentIndent += $adjustments[ $first ];
430 430
                                 }
431 431
 
432 432
                                 // Make sure it is divisible by our expected indent.
433
-                                if ($tokens[$tokens[$scopeCloser]['scope_condition']]['code'] !== T_CLOSURE) {
434
-                                    $currentIndent = (int) (ceil($currentIndent / $this->indent) * $this->indent);
433
+                                if ( $tokens[ $tokens[ $scopeCloser ][ 'scope_condition' ] ][ 'code' ] !== T_CLOSURE ) {
434
+                                    $currentIndent = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
435 435
                                 }
436 436
 
437
-                                $setIndents[$first] = $currentIndent;
437
+                                $setIndents[ $first ] = $currentIndent;
438 438
 
439
-                                if ($this->debug === true) {
440
-                                    $type = $tokens[$first]['type'];
441
-                                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
439
+                                if ( $this->debug === true ) {
440
+                                    $type = $tokens[ $first ][ 'type' ];
441
+                                    echo "\t=> indent set to $currentIndent by token $first ($type)" . PHP_EOL;
442 442
                                 }
443 443
                             }//end if
444 444
                         } else {
445 445
                             // Don't force current indent to be divisible because there could be custom
446 446
                             // rules in place between parenthesis, such as with arrays.
447
-                            $currentIndent = ($tokens[$first]['column'] - 1);
448
-                            if (isset($adjustments[$first]) === true) {
449
-                                $currentIndent += $adjustments[$first];
447
+                            $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
448
+                            if ( isset( $adjustments[ $first ] ) === true ) {
449
+                                $currentIndent += $adjustments[ $first ];
450 450
                             }
451 451
 
452
-                            $setIndents[$first] = $currentIndent;
452
+                            $setIndents[ $first ] = $currentIndent;
453 453
 
454
-                            if ($this->debug === true) {
455
-                                $type = $tokens[$first]['type'];
456
-                                echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
454
+                            if ( $this->debug === true ) {
455
+                                $type = $tokens[ $first ][ 'type' ];
456
+                                echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)" . PHP_EOL;
457 457
                             }
458 458
                         }//end if
459 459
                     }//end if
460
-                } else if ($this->debug === true) {
461
-                    echo "\t * ignoring single-line definition *".PHP_EOL;
460
+                } else if ( $this->debug === true ) {
461
+                    echo "\t * ignoring single-line definition *" . PHP_EOL;
462 462
                 }//end if
463 463
             }//end if
464 464
 
465 465
             // Closing short array bracket should just be indented to at least
466 466
             // the same level as where it was opened (but can be more).
467
-            if ($tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY
468
-                || ($checkToken !== null
469
-                && $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY)
467
+            if ( $tokens[ $i ][ 'code' ] === T_CLOSE_SHORT_ARRAY
468
+                || ( $checkToken !== null
469
+                && $tokens[ $checkToken ][ 'code' ] === T_CLOSE_SHORT_ARRAY )
470 470
             ) {
471
-                if ($checkToken !== null) {
471
+                if ( $checkToken !== null ) {
472 472
                     $arrayCloser = $checkToken;
473 473
                 } else {
474 474
                     $arrayCloser = $i;
475 475
                 }
476 476
 
477
-                if ($this->debug === true) {
478
-                    $line = $tokens[$arrayCloser]['line'];
479
-                    echo "Closing short array bracket found on line $line".PHP_EOL;
477
+                if ( $this->debug === true ) {
478
+                    $line = $tokens[ $arrayCloser ][ 'line' ];
479
+                    echo "Closing short array bracket found on line $line" . PHP_EOL;
480 480
                 }
481 481
 
482
-                $arrayOpener = $tokens[$arrayCloser]['bracket_opener'];
483
-                if ($tokens[$arrayCloser]['line'] !== $tokens[$arrayOpener]['line']) {
484
-                    $first       = $phpcsFile->findFirstOnLine(T_WHITESPACE, $arrayOpener, true);
485
-                    $checkIndent = ($tokens[$first]['column'] - 1);
486
-                    if (isset($adjustments[$first]) === true) {
487
-                        $checkIndent += $adjustments[$first];
482
+                $arrayOpener = $tokens[ $arrayCloser ][ 'bracket_opener' ];
483
+                if ( $tokens[ $arrayCloser ][ 'line' ] !== $tokens[ $arrayOpener ][ 'line' ] ) {
484
+                    $first       = $phpcsFile->findFirstOnLine( T_WHITESPACE, $arrayOpener, true );
485
+                    $checkIndent = ( $tokens[ $first ][ 'column' ] - 1 );
486
+                    if ( isset( $adjustments[ $first ] ) === true ) {
487
+                        $checkIndent += $adjustments[ $first ];
488 488
                     }
489 489
 
490 490
                     $exact = false;
491 491
 
492
-                    if ($this->debug === true) {
493
-                        $line = $tokens[$first]['line'];
494
-                        $type = $tokens[$first]['type'];
495
-                        echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
492
+                    if ( $this->debug === true ) {
493
+                        $line = $tokens[ $first ][ 'line' ];
494
+                        $type = $tokens[ $first ][ 'type' ];
495
+                        echo "\t* first token on line $line is $first ($type) *" . PHP_EOL;
496 496
                     }
497 497
 
498
-                    if ($first === $tokens[$arrayCloser]['bracket_opener']) {
498
+                    if ( $first === $tokens[ $arrayCloser ][ 'bracket_opener' ] ) {
499 499
                         // This is unlikely to be the start of the statement, so look
500 500
                         // back further to find it.
501 501
                         $first--;
502 502
                     }
503 503
 
504
-                    $prev = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
505
-                    if ($prev !== $first) {
504
+                    $prev = $phpcsFile->findStartOfStatement( $first, [ T_COMMA, T_DOUBLE_ARROW ] );
505
+                    if ( $prev !== $first ) {
506 506
                         // This is not the start of the statement.
507
-                        if ($this->debug === true) {
508
-                            $line = $tokens[$prev]['line'];
509
-                            $type = $tokens[$prev]['type'];
510
-                            echo "\t* previous is $type on line $line *".PHP_EOL;
507
+                        if ( $this->debug === true ) {
508
+                            $line = $tokens[ $prev ][ 'line' ];
509
+                            $type = $tokens[ $prev ][ 'type' ];
510
+                            echo "\t* previous is $type on line $line *" . PHP_EOL;
511 511
                         }
512 512
 
513
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
514
-                        $prev  = $phpcsFile->findStartOfStatement($first, [T_COMMA, T_DOUBLE_ARROW]);
515
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
516
-                        if ($this->debug === true) {
517
-                            $line = $tokens[$first]['line'];
518
-                            $type = $tokens[$first]['type'];
519
-                            echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
513
+                        $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $prev, true );
514
+                        $prev  = $phpcsFile->findStartOfStatement( $first, [ T_COMMA, T_DOUBLE_ARROW ] );
515
+                        $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $prev, true );
516
+                        if ( $this->debug === true ) {
517
+                            $line = $tokens[ $first ][ 'line' ];
518
+                            $type = $tokens[ $first ][ 'type' ];
519
+                            echo "\t* amended first token is $first ($type) on line $line *" . PHP_EOL;
520 520
                         }
521
-                    } else if ($tokens[$first]['code'] === T_WHITESPACE) {
522
-                        $first = $phpcsFile->findNext(T_WHITESPACE, ($first + 1), null, true);
521
+                    } else if ( $tokens[ $first ][ 'code' ] === T_WHITESPACE ) {
522
+                        $first = $phpcsFile->findNext( T_WHITESPACE, ( $first + 1 ), null, true );
523 523
                     }
524 524
 
525
-                    if (isset($tokens[$first]['scope_closer']) === true
526
-                        && $tokens[$first]['scope_closer'] === $first
525
+                    if ( isset( $tokens[ $first ][ 'scope_closer' ] ) === true
526
+                        && $tokens[ $first ][ 'scope_closer' ] === $first
527 527
                     ) {
528 528
                         // The first token is a scope closer and would have already
529 529
                         // been processed and set the indent level correctly, so
530 530
                         // don't adjust it again.
531
-                        if ($this->debug === true) {
532
-                            echo "\t* first token is a scope closer; ignoring closing short array bracket *".PHP_EOL;
531
+                        if ( $this->debug === true ) {
532
+                            echo "\t* first token is a scope closer; ignoring closing short array bracket *" . PHP_EOL;
533 533
                         }
534 534
 
535
-                        if (isset($setIndents[$first]) === true) {
536
-                            $currentIndent = $setIndents[$first];
537
-                            if ($this->debug === true) {
538
-                                echo "\t=> indent reset to $currentIndent".PHP_EOL;
535
+                        if ( isset( $setIndents[ $first ] ) === true ) {
536
+                            $currentIndent = $setIndents[ $first ];
537
+                            if ( $this->debug === true ) {
538
+                                echo "\t=> indent reset to $currentIndent" . PHP_EOL;
539 539
                             }
540 540
                         }
541 541
                     } else {
542 542
                         // Don't force current indent to be divisible because there could be custom
543 543
                         // rules in place for arrays.
544
-                        $currentIndent = ($tokens[$first]['column'] - 1);
545
-                        if (isset($adjustments[$first]) === true) {
546
-                            $currentIndent += $adjustments[$first];
544
+                        $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
545
+                        if ( isset( $adjustments[ $first ] ) === true ) {
546
+                            $currentIndent += $adjustments[ $first ];
547 547
                         }
548 548
 
549
-                        $setIndents[$first] = $currentIndent;
549
+                        $setIndents[ $first ] = $currentIndent;
550 550
 
551
-                        if ($this->debug === true) {
552
-                            $type = $tokens[$first]['type'];
553
-                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
551
+                        if ( $this->debug === true ) {
552
+                            $type = $tokens[ $first ][ 'type' ];
553
+                            echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)" . PHP_EOL;
554 554
                         }
555 555
                     }//end if
556
-                } else if ($this->debug === true) {
557
-                    echo "\t * ignoring single-line definition *".PHP_EOL;
556
+                } else if ( $this->debug === true ) {
557
+                    echo "\t * ignoring single-line definition *" . PHP_EOL;
558 558
                 }//end if
559 559
             }//end if
560 560
 
561 561
             // Adjust lines within scopes while auto-fixing.
562
-            if ($checkToken !== null
562
+            if ( $checkToken !== null
563 563
                 && $exact === false
564
-                && (empty($tokens[$checkToken]['conditions']) === false
565
-                || (isset($tokens[$checkToken]['scope_opener']) === true
566
-                && $tokens[$checkToken]['scope_opener'] === $checkToken))
564
+                && ( empty( $tokens[ $checkToken ][ 'conditions' ] ) === false
565
+                || ( isset( $tokens[ $checkToken ][ 'scope_opener' ] ) === true
566
+                && $tokens[ $checkToken ][ 'scope_opener' ] === $checkToken ) )
567 567
             ) {
568
-                if (empty($tokens[$checkToken]['conditions']) === false) {
569
-                    $condition = $tokens[$checkToken]['conditions'];
570
-                    end($condition);
571
-                    $condition = key($condition);
568
+                if ( empty( $tokens[ $checkToken ][ 'conditions' ] ) === false ) {
569
+                    $condition = $tokens[ $checkToken ][ 'conditions' ];
570
+                    end( $condition );
571
+                    $condition = key( $condition );
572 572
                 } else {
573
-                    $condition = $tokens[$checkToken]['scope_condition'];
573
+                    $condition = $tokens[ $checkToken ][ 'scope_condition' ];
574 574
                 }
575 575
 
576
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
576
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $condition, true );
577 577
 
578
-                if (isset($adjustments[$first]) === true
579
-                    && (($adjustments[$first] < 0 && $tokenIndent > $currentIndent)
580
-                    || ($adjustments[$first] > 0 && $tokenIndent < $currentIndent))
578
+                if ( isset( $adjustments[ $first ] ) === true
579
+                    && ( ( $adjustments[ $first ] < 0 && $tokenIndent > $currentIndent )
580
+                    || ( $adjustments[ $first ] > 0 && $tokenIndent < $currentIndent ) )
581 581
                 ) {
582
-                    $length = ($tokenIndent + $adjustments[$first]);
582
+                    $length = ( $tokenIndent + $adjustments[ $first ] );
583 583
 
584 584
                     // When fixing, we're going to adjust the indent of this line
585 585
                     // here automatically, so use this new padding value when
586 586
                     // comparing the expected padding to the actual padding.
587
-                    if ($phpcsFile->fixer->enabled === true) {
587
+                    if ( $phpcsFile->fixer->enabled === true ) {
588 588
                         $tokenIndent = $length;
589
-                        $this->adjustIndent($phpcsFile, $checkToken, $length, $adjustments[$first]);
589
+                        $this->adjustIndent( $phpcsFile, $checkToken, $length, $adjustments[ $first ] );
590 590
                     }
591 591
 
592
-                    if ($this->debug === true) {
593
-                        $line = $tokens[$checkToken]['line'];
594
-                        $type = $tokens[$checkToken]['type'];
595
-                        echo "Indent adjusted to $length for $type on line $line".PHP_EOL;
592
+                    if ( $this->debug === true ) {
593
+                        $line = $tokens[ $checkToken ][ 'line' ];
594
+                        $type = $tokens[ $checkToken ][ 'type' ];
595
+                        echo "Indent adjusted to $length for $type on line $line" . PHP_EOL;
596 596
                     }
597 597
 
598
-                    $adjustments[$checkToken] = $adjustments[$first];
598
+                    $adjustments[ $checkToken ] = $adjustments[ $first ];
599 599
 
600
-                    if ($this->debug === true) {
601
-                        $line = $tokens[$checkToken]['line'];
602
-                        $type = $tokens[$checkToken]['type'];
603
-                        echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
600
+                    if ( $this->debug === true ) {
601
+                        $line = $tokens[ $checkToken ][ 'line' ];
602
+                        $type = $tokens[ $checkToken ][ 'type' ];
603
+                        echo "\t=> add adjustment of " . $adjustments[ $checkToken ] . " for token $checkToken ($type) on line $line" . PHP_EOL;
604 604
                     }
605 605
                 }//end if
606 606
             }//end if
607 607
 
608 608
             // Scope closers reset the required indent to the same level as the opening condition.
609
-            if (($checkToken !== null
610
-                && isset($openScopes[$checkToken]) === true
611
-                || (isset($tokens[$checkToken]['scope_condition']) === true
612
-                && isset($tokens[$checkToken]['scope_closer']) === true
613
-                && $tokens[$checkToken]['scope_closer'] === $checkToken
614
-                && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))
615
-                || ($checkToken === null
616
-                && isset($openScopes[$i]) === true
617
-                || (isset($tokens[$i]['scope_condition']) === true
618
-                && isset($tokens[$i]['scope_closer']) === true
619
-                && $tokens[$i]['scope_closer'] === $i
620
-                && $tokens[$i]['line'] !== $tokens[$tokens[$i]['scope_opener']]['line']))
609
+            if ( ( $checkToken !== null
610
+                && isset( $openScopes[ $checkToken ] ) === true
611
+                || ( isset( $tokens[ $checkToken ][ 'scope_condition' ] ) === true
612
+                && isset( $tokens[ $checkToken ][ 'scope_closer' ] ) === true
613
+                && $tokens[ $checkToken ][ 'scope_closer' ] === $checkToken
614
+                && $tokens[ $checkToken ][ 'line' ] !== $tokens[ $tokens[ $checkToken ][ 'scope_opener' ] ][ 'line' ] ) )
615
+                || ( $checkToken === null
616
+                && isset( $openScopes[ $i ] ) === true
617
+                || ( isset( $tokens[ $i ][ 'scope_condition' ] ) === true
618
+                && isset( $tokens[ $i ][ 'scope_closer' ] ) === true
619
+                && $tokens[ $i ][ 'scope_closer' ] === $i
620
+                && $tokens[ $i ][ 'line' ] !== $tokens[ $tokens[ $i ][ 'scope_opener' ] ][ 'line' ] ) )
621 621
             ) {
622
-                if ($this->debug === true) {
623
-                    if ($checkToken === null) {
624
-                        $type = $tokens[$tokens[$i]['scope_condition']]['type'];
625
-                        $line = $tokens[$i]['line'];
622
+                if ( $this->debug === true ) {
623
+                    if ( $checkToken === null ) {
624
+                        $type = $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'type' ];
625
+                        $line = $tokens[ $i ][ 'line' ];
626 626
                     } else {
627
-                        $type = $tokens[$tokens[$checkToken]['scope_condition']]['type'];
628
-                        $line = $tokens[$checkToken]['line'];
627
+                        $type = $tokens[ $tokens[ $checkToken ][ 'scope_condition' ] ][ 'type' ];
628
+                        $line = $tokens[ $checkToken ][ 'line' ];
629 629
                     }
630 630
 
631
-                    echo "Close scope ($type) on line $line".PHP_EOL;
631
+                    echo "Close scope ($type) on line $line" . PHP_EOL;
632 632
                 }
633 633
 
634 634
                 $scopeCloser = $checkToken;
635
-                if ($scopeCloser === null) {
635
+                if ( $scopeCloser === null ) {
636 636
                     $scopeCloser = $i;
637 637
                 }
638 638
 
639
-                $conditionToken = array_pop($openScopes);
640
-                if ($this->debug === true) {
641
-                    $line = $tokens[$conditionToken]['line'];
642
-                    $type = $tokens[$conditionToken]['type'];
643
-                    echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
639
+                $conditionToken = array_pop( $openScopes );
640
+                if ( $this->debug === true ) {
641
+                    $line = $tokens[ $conditionToken ][ 'line' ];
642
+                    $type = $tokens[ $conditionToken ][ 'type' ];
643
+                    echo "\t=> removed open scope $conditionToken ($type) on line $line" . PHP_EOL;
644 644
                 }
645 645
 
646
-                if (isset($tokens[$scopeCloser]['scope_condition']) === true) {
647
-                    $first = $phpcsFile->findFirstOnLine([T_WHITESPACE, T_INLINE_HTML], $tokens[$scopeCloser]['scope_condition'], true);
648
-                    if ($this->debug === true) {
649
-                        $line = $tokens[$first]['line'];
650
-                        $type = $tokens[$first]['type'];
651
-                        echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
646
+                if ( isset( $tokens[ $scopeCloser ][ 'scope_condition' ] ) === true ) {
647
+                    $first = $phpcsFile->findFirstOnLine( [ T_WHITESPACE, T_INLINE_HTML ], $tokens[ $scopeCloser ][ 'scope_condition' ], true );
648
+                    if ( $this->debug === true ) {
649
+                        $line = $tokens[ $first ][ 'line' ];
650
+                        $type = $tokens[ $first ][ 'type' ];
651
+                        echo "\t* first token is $first ($type) on line $line *" . PHP_EOL;
652 652
                     }
653 653
 
654
-                    while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
655
-                        && $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
654
+                    while ( $tokens[ $first ][ 'code' ] === T_CONSTANT_ENCAPSED_STRING
655
+                        && $tokens[ ( $first - 1 ) ][ 'code' ] === T_CONSTANT_ENCAPSED_STRING
656 656
                     ) {
657
-                        $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
658
-                        if ($this->debug === true) {
659
-                            $line = $tokens[$first]['line'];
660
-                            $type = $tokens[$first]['type'];
661
-                            echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
657
+                        $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, ( $first - 1 ), true );
658
+                        if ( $this->debug === true ) {
659
+                            $line = $tokens[ $first ][ 'line' ];
660
+                            $type = $tokens[ $first ][ 'type' ];
661
+                            echo "\t* found multi-line string; amended first token is $first ($type) on line $line *" . PHP_EOL;
662 662
                         }
663 663
                     }
664 664
 
665
-                    $currentIndent = ($tokens[$first]['column'] - 1);
666
-                    if (isset($adjustments[$first]) === true) {
667
-                        $currentIndent += $adjustments[$first];
665
+                    $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
666
+                    if ( isset( $adjustments[ $first ] ) === true ) {
667
+                        $currentIndent += $adjustments[ $first ];
668 668
                     }
669 669
 
670
-                    $setIndents[$scopeCloser] = $currentIndent;
670
+                    $setIndents[ $scopeCloser ] = $currentIndent;
671 671
 
672
-                    if ($this->debug === true) {
673
-                        $type = $tokens[$scopeCloser]['type'];
674
-                        echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)".PHP_EOL;
672
+                    if ( $this->debug === true ) {
673
+                        $type = $tokens[ $scopeCloser ][ 'type' ];
674
+                        echo "\t=> indent set to $currentIndent by token $scopeCloser ($type)" . PHP_EOL;
675 675
                     }
676 676
 
677 677
                     // We only check the indent of scope closers if they are
678 678
                     // curly braces because other constructs tend to have different rules.
679
-                    if ($tokens[$scopeCloser]['code'] === T_CLOSE_CURLY_BRACKET) {
679
+                    if ( $tokens[ $scopeCloser ][ 'code' ] === T_CLOSE_CURLY_BRACKET ) {
680 680
                         $exact = true;
681 681
                     } else {
682 682
                         $checkToken = null;
@@ -685,93 +685,93 @@  discard block
 block discarded – undo
685 685
             }//end if
686 686
 
687 687
             // Handle scope for JS object notation.
688
-            if ($phpcsFile->tokenizerType === 'JS'
689
-                && (($checkToken !== null
690
-                && $tokens[$checkToken]['code'] === T_CLOSE_OBJECT
691
-                && $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['bracket_opener']]['line'])
692
-                || ($checkToken === null
693
-                && $tokens[$i]['code'] === T_CLOSE_OBJECT
694
-                && $tokens[$i]['line'] !== $tokens[$tokens[$i]['bracket_opener']]['line']))
688
+            if ( $phpcsFile->tokenizerType === 'JS'
689
+                && ( ( $checkToken !== null
690
+                && $tokens[ $checkToken ][ 'code' ] === T_CLOSE_OBJECT
691
+                && $tokens[ $checkToken ][ 'line' ] !== $tokens[ $tokens[ $checkToken ][ 'bracket_opener' ] ][ 'line' ] )
692
+                || ( $checkToken === null
693
+                && $tokens[ $i ][ 'code' ] === T_CLOSE_OBJECT
694
+                && $tokens[ $i ][ 'line' ] !== $tokens[ $tokens[ $i ][ 'bracket_opener' ] ][ 'line' ] ) )
695 695
             ) {
696
-                if ($this->debug === true) {
697
-                    $line = $tokens[$i]['line'];
698
-                    echo "Close JS object on line $line".PHP_EOL;
696
+                if ( $this->debug === true ) {
697
+                    $line = $tokens[ $i ][ 'line' ];
698
+                    echo "Close JS object on line $line" . PHP_EOL;
699 699
                 }
700 700
 
701 701
                 $scopeCloser = $checkToken;
702
-                if ($scopeCloser === null) {
702
+                if ( $scopeCloser === null ) {
703 703
                     $scopeCloser = $i;
704 704
                 } else {
705
-                    $conditionToken = array_pop($openScopes);
706
-                    if ($this->debug === true) {
707
-                        $line = $tokens[$conditionToken]['line'];
708
-                        $type = $tokens[$conditionToken]['type'];
709
-                        echo "\t=> removed open scope $conditionToken ($type) on line $line".PHP_EOL;
705
+                    $conditionToken = array_pop( $openScopes );
706
+                    if ( $this->debug === true ) {
707
+                        $line = $tokens[ $conditionToken ][ 'line' ];
708
+                        $type = $tokens[ $conditionToken ][ 'type' ];
709
+                        echo "\t=> removed open scope $conditionToken ($type) on line $line" . PHP_EOL;
710 710
                     }
711 711
                 }
712 712
 
713 713
                 $parens = 0;
714
-                if (isset($tokens[$scopeCloser]['nested_parenthesis']) === true
715
-                    && empty($tokens[$scopeCloser]['nested_parenthesis']) === false
714
+                if ( isset( $tokens[ $scopeCloser ][ 'nested_parenthesis' ] ) === true
715
+                    && empty( $tokens[ $scopeCloser ][ 'nested_parenthesis' ] ) === false
716 716
                 ) {
717
-                    $parens = $tokens[$scopeCloser]['nested_parenthesis'];
718
-                    end($parens);
719
-                    $parens = key($parens);
720
-                    if ($this->debug === true) {
721
-                        $line = $tokens[$parens]['line'];
722
-                        echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
717
+                    $parens = $tokens[ $scopeCloser ][ 'nested_parenthesis' ];
718
+                    end( $parens );
719
+                    $parens = key( $parens );
720
+                    if ( $this->debug === true ) {
721
+                        $line = $tokens[ $parens ][ 'line' ];
722
+                        echo "\t* token has nested parenthesis $parens on line $line *" . PHP_EOL;
723 723
                     }
724 724
                 }
725 725
 
726 726
                 $condition = 0;
727
-                if (isset($tokens[$scopeCloser]['conditions']) === true
728
-                    && empty($tokens[$scopeCloser]['conditions']) === false
727
+                if ( isset( $tokens[ $scopeCloser ][ 'conditions' ] ) === true
728
+                    && empty( $tokens[ $scopeCloser ][ 'conditions' ] ) === false
729 729
                 ) {
730
-                    $condition = $tokens[$scopeCloser]['conditions'];
731
-                    end($condition);
732
-                    $condition = key($condition);
733
-                    if ($this->debug === true) {
734
-                        $line = $tokens[$condition]['line'];
735
-                        $type = $tokens[$condition]['type'];
736
-                        echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
730
+                    $condition = $tokens[ $scopeCloser ][ 'conditions' ];
731
+                    end( $condition );
732
+                    $condition = key( $condition );
733
+                    if ( $this->debug === true ) {
734
+                        $line = $tokens[ $condition ][ 'line' ];
735
+                        $type = $tokens[ $condition ][ 'type' ];
736
+                        echo "\t* token is inside condition $condition ($type) on line $line *" . PHP_EOL;
737 737
                     }
738 738
                 }
739 739
 
740
-                if ($parens > $condition) {
741
-                    if ($this->debug === true) {
742
-                        echo "\t* using parenthesis *".PHP_EOL;
740
+                if ( $parens > $condition ) {
741
+                    if ( $this->debug === true ) {
742
+                        echo "\t* using parenthesis *" . PHP_EOL;
743 743
                     }
744 744
 
745
-                    $first     = $phpcsFile->findFirstOnLine(T_WHITESPACE, $parens, true);
745
+                    $first     = $phpcsFile->findFirstOnLine( T_WHITESPACE, $parens, true );
746 746
                     $condition = 0;
747
-                } else if ($condition > 0) {
748
-                    if ($this->debug === true) {
749
-                        echo "\t* using condition *".PHP_EOL;
747
+                } else if ( $condition > 0 ) {
748
+                    if ( $this->debug === true ) {
749
+                        echo "\t* using condition *" . PHP_EOL;
750 750
                     }
751 751
 
752
-                    $first  = $phpcsFile->findFirstOnLine(T_WHITESPACE, $condition, true);
752
+                    $first  = $phpcsFile->findFirstOnLine( T_WHITESPACE, $condition, true );
753 753
                     $parens = 0;
754 754
                 } else {
755
-                    if ($this->debug === true) {
756
-                        $line = $tokens[$tokens[$scopeCloser]['bracket_opener']]['line'];
757
-                        echo "\t* token is not in parenthesis or condition; using opener on line $line *".PHP_EOL;
755
+                    if ( $this->debug === true ) {
756
+                        $line = $tokens[ $tokens[ $scopeCloser ][ 'bracket_opener' ] ][ 'line' ];
757
+                        echo "\t* token is not in parenthesis or condition; using opener on line $line *" . PHP_EOL;
758 758
                     }
759 759
 
760
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$scopeCloser]['bracket_opener'], true);
760
+                    $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $tokens[ $scopeCloser ][ 'bracket_opener' ], true );
761 761
                 }//end if
762 762
 
763
-                $currentIndent = ($tokens[$first]['column'] - 1);
764
-                if (isset($adjustments[$first]) === true) {
765
-                    $currentIndent += $adjustments[$first];
763
+                $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
764
+                if ( isset( $adjustments[ $first ] ) === true ) {
765
+                    $currentIndent += $adjustments[ $first ];
766 766
                 }
767 767
 
768
-                if ($parens > 0 || $condition > 0) {
769
-                    $checkIndent = ($tokens[$first]['column'] - 1);
770
-                    if (isset($adjustments[$first]) === true) {
771
-                        $checkIndent += $adjustments[$first];
768
+                if ( $parens > 0 || $condition > 0 ) {
769
+                    $checkIndent = ( $tokens[ $first ][ 'column' ] - 1 );
770
+                    if ( isset( $adjustments[ $first ] ) === true ) {
771
+                        $checkIndent += $adjustments[ $first ];
772 772
                     }
773 773
 
774
-                    if ($condition > 0) {
774
+                    if ( $condition > 0 ) {
775 775
                         $checkIndent   += $this->indent;
776 776
                         $currentIndent += $this->indent;
777 777
                         $exact          = true;
@@ -781,76 +781,76 @@  discard block
 block discarded – undo
781 781
                 }
782 782
 
783 783
                 // Make sure it is divisible by our expected indent.
784
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
785
-                $checkIndent        = (int) (ceil($checkIndent / $this->indent) * $this->indent);
786
-                $setIndents[$first] = $currentIndent;
784
+                $currentIndent      = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
785
+                $checkIndent        = (int)( ceil( $checkIndent / $this->indent ) * $this->indent );
786
+                $setIndents[ $first ] = $currentIndent;
787 787
 
788
-                if ($this->debug === true) {
789
-                    $type = $tokens[$first]['type'];
790
-                    echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)".PHP_EOL;
788
+                if ( $this->debug === true ) {
789
+                    $type = $tokens[ $first ][ 'type' ];
790
+                    echo "\t=> checking indent of $checkIndent; main indent set to $currentIndent by token $first ($type)" . PHP_EOL;
791 791
                 }
792 792
             }//end if
793 793
 
794
-            if ($checkToken !== null
795
-                && isset(Tokens::$scopeOpeners[$tokens[$checkToken]['code']]) === true
796
-                && in_array($tokens[$checkToken]['code'], $this->nonIndentingScopes, true) === false
797
-                && isset($tokens[$checkToken]['scope_opener']) === true
794
+            if ( $checkToken !== null
795
+                && isset( Tokens::$scopeOpeners[ $tokens[ $checkToken ][ 'code' ] ] ) === true
796
+                && in_array( $tokens[ $checkToken ][ 'code' ], $this->nonIndentingScopes, true ) === false
797
+                && isset( $tokens[ $checkToken ][ 'scope_opener' ] ) === true
798 798
             ) {
799 799
                 $exact = true;
800 800
 
801 801
                 $lastOpener = null;
802
-                if (empty($openScopes) === false) {
803
-                    end($openScopes);
804
-                    $lastOpener = current($openScopes);
802
+                if ( empty( $openScopes ) === false ) {
803
+                    end( $openScopes );
804
+                    $lastOpener = current( $openScopes );
805 805
                 }
806 806
 
807 807
                 // A scope opener that shares a closer with another token (like multiple
808 808
                 // CASEs using the same BREAK) needs to reduce the indent level so its
809 809
                 // indent is checked correctly. It will then increase the indent again
810 810
                 // (as all openers do) after being checked.
811
-                if ($lastOpener !== null
812
-                    && isset($tokens[$lastOpener]['scope_closer']) === true
813
-                    && $tokens[$lastOpener]['level'] === $tokens[$checkToken]['level']
814
-                    && $tokens[$lastOpener]['scope_closer'] === $tokens[$checkToken]['scope_closer']
811
+                if ( $lastOpener !== null
812
+                    && isset( $tokens[ $lastOpener ][ 'scope_closer' ] ) === true
813
+                    && $tokens[ $lastOpener ][ 'level' ] === $tokens[ $checkToken ][ 'level' ]
814
+                    && $tokens[ $lastOpener ][ 'scope_closer' ] === $tokens[ $checkToken ][ 'scope_closer' ]
815 815
                 ) {
816 816
                     $currentIndent          -= $this->indent;
817
-                    $setIndents[$lastOpener] = $currentIndent;
818
-                    if ($this->debug === true) {
819
-                        $line = $tokens[$i]['line'];
820
-                        $type = $tokens[$lastOpener]['type'];
821
-                        echo "Shared closer found on line $line".PHP_EOL;
822
-                        echo "\t=> indent set to $currentIndent by token $lastOpener ($type)".PHP_EOL;
817
+                    $setIndents[ $lastOpener ] = $currentIndent;
818
+                    if ( $this->debug === true ) {
819
+                        $line = $tokens[ $i ][ 'line' ];
820
+                        $type = $tokens[ $lastOpener ][ 'type' ];
821
+                        echo "Shared closer found on line $line" . PHP_EOL;
822
+                        echo "\t=> indent set to $currentIndent by token $lastOpener ($type)" . PHP_EOL;
823 823
                     }
824 824
                 }
825 825
 
826
-                if ($tokens[$checkToken]['code'] === T_CLOSURE
826
+                if ( $tokens[ $checkToken ][ 'code' ] === T_CLOSURE
827 827
                     && $tokenIndent > $currentIndent
828 828
                 ) {
829 829
                     // The opener is indented more than needed, which is fine.
830 830
                     // But just check that it is divisible by our expected indent.
831
-                    $checkIndent = (int) (ceil($tokenIndent / $this->indent) * $this->indent);
831
+                    $checkIndent = (int)( ceil( $tokenIndent / $this->indent ) * $this->indent );
832 832
                     $exact       = false;
833 833
 
834
-                    if ($this->debug === true) {
835
-                        $line = $tokens[$i]['line'];
836
-                        echo "Closure found on line $line".PHP_EOL;
837
-                        echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent".PHP_EOL;
834
+                    if ( $this->debug === true ) {
835
+                        $line = $tokens[ $i ][ 'line' ];
836
+                        echo "Closure found on line $line" . PHP_EOL;
837
+                        echo "\t=> checking indent of $checkIndent; main indent remains at $currentIndent" . PHP_EOL;
838 838
                     }
839 839
                 }
840 840
             }//end if
841 841
 
842 842
             // Method prefix indentation has to be exact or else it will break
843 843
             // the rest of the function declaration, and potentially future ones.
844
-            if ($checkToken !== null
845
-                && isset(Tokens::$methodPrefixes[$tokens[$checkToken]['code']]) === true
846
-                && $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON
844
+            if ( $checkToken !== null
845
+                && isset( Tokens::$methodPrefixes[ $tokens[ $checkToken ][ 'code' ] ] ) === true
846
+                && $tokens[ ( $checkToken + 1 ) ][ 'code' ] !== T_DOUBLE_COLON
847 847
             ) {
848
-                $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($checkToken + 1), null, true);
849
-                if ($next === false || $tokens[$next]['code'] !== T_CLOSURE) {
850
-                    if ($this->debug === true) {
851
-                        $line = $tokens[$checkToken]['line'];
852
-                        $type = $tokens[$checkToken]['type'];
853
-                        echo "\t* method prefix ($type) found on line $line; indent set to exact *".PHP_EOL;
848
+                $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $checkToken + 1 ), null, true );
849
+                if ( $next === false || $tokens[ $next ][ 'code' ] !== T_CLOSURE ) {
850
+                    if ( $this->debug === true ) {
851
+                        $line = $tokens[ $checkToken ][ 'line' ];
852
+                        $type = $tokens[ $checkToken ][ 'type' ];
853
+                        echo "\t* method prefix ($type) found on line $line; indent set to exact *" . PHP_EOL;
854 854
                     }
855 855
 
856 856
                     $exact = true;
@@ -859,7 +859,7 @@  discard block
 block discarded – undo
859 859
 
860 860
             // JS property indentation has to be exact or else if will break
861 861
             // things like function and object indentation.
862
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_PROPERTY) {
862
+            if ( $checkToken !== null && $tokens[ $checkToken ][ 'code' ] === T_PROPERTY ) {
863 863
                 $exact = true;
864 864
             }
865 865
 
@@ -867,50 +867,50 @@  discard block
 block discarded – undo
867 867
             // so they don't cause problems with indent checks for the code
868 868
             // within them, but they don't need to line up with the current indent
869 869
             // in most cases.
870
-            if ($checkToken !== null
871
-                && ($tokens[$checkToken]['code'] === T_OPEN_TAG
872
-                || $tokens[$checkToken]['code'] === T_OPEN_TAG_WITH_ECHO)
870
+            if ( $checkToken !== null
871
+                && ( $tokens[ $checkToken ][ 'code' ] === T_OPEN_TAG
872
+                || $tokens[ $checkToken ][ 'code' ] === T_OPEN_TAG_WITH_ECHO )
873 873
             ) {
874
-                $checkIndent = ($tokens[$checkToken]['column'] - 1);
874
+                $checkIndent = ( $tokens[ $checkToken ][ 'column' ] - 1 );
875 875
 
876 876
                 // If we are re-opening a block that was closed in the same
877 877
                 // scope as us, then reset the indent back to what the scope opener
878 878
                 // set instead of using whatever indent this open tag has set.
879
-                if (empty($tokens[$checkToken]['conditions']) === false) {
880
-                    $close = $phpcsFile->findPrevious(T_CLOSE_TAG, ($checkToken - 1));
881
-                    if ($close !== false
882
-                        && $tokens[$checkToken]['conditions'] === $tokens[$close]['conditions']
879
+                if ( empty( $tokens[ $checkToken ][ 'conditions' ] ) === false ) {
880
+                    $close = $phpcsFile->findPrevious( T_CLOSE_TAG, ( $checkToken - 1 ) );
881
+                    if ( $close !== false
882
+                        && $tokens[ $checkToken ][ 'conditions' ] === $tokens[ $close ][ 'conditions' ]
883 883
                     ) {
884
-                        $conditions    = array_keys($tokens[$checkToken]['conditions']);
885
-                        $lastCondition = array_pop($conditions);
886
-                        $lastOpener    = $tokens[$lastCondition]['scope_opener'];
887
-                        $lastCloser    = $tokens[$lastCondition]['scope_closer'];
888
-                        if ($tokens[$lastCloser]['line'] !== $tokens[$checkToken]['line']
889
-                            && isset($setIndents[$lastOpener]) === true
884
+                        $conditions    = array_keys( $tokens[ $checkToken ][ 'conditions' ] );
885
+                        $lastCondition = array_pop( $conditions );
886
+                        $lastOpener    = $tokens[ $lastCondition ][ 'scope_opener' ];
887
+                        $lastCloser    = $tokens[ $lastCondition ][ 'scope_closer' ];
888
+                        if ( $tokens[ $lastCloser ][ 'line' ] !== $tokens[ $checkToken ][ 'line' ]
889
+                            && isset( $setIndents[ $lastOpener ] ) === true
890 890
                         ) {
891
-                            $checkIndent = $setIndents[$lastOpener];
891
+                            $checkIndent = $setIndents[ $lastOpener ];
892 892
                         }
893 893
                     }
894 894
                 }
895 895
 
896
-                $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
896
+                $checkIndent = (int)( ceil( $checkIndent / $this->indent ) * $this->indent );
897 897
             }//end if
898 898
 
899 899
             // Close tags needs to be indented to exact column positions.
900
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_CLOSE_TAG) {
900
+            if ( $checkToken !== null && $tokens[ $checkToken ][ 'code' ] === T_CLOSE_TAG ) {
901 901
                 $exact       = true;
902 902
                 $checkIndent = $currentIndent;
903
-                $checkIndent = (int) (ceil($checkIndent / $this->indent) * $this->indent);
903
+                $checkIndent = (int)( ceil( $checkIndent / $this->indent ) * $this->indent );
904 904
             }
905 905
 
906 906
             // Special case for ELSE statements that are not on the same
907 907
             // line as the previous IF statements closing brace. They still need
908 908
             // to have the same indent or it will break code after the block.
909
-            if ($checkToken !== null && $tokens[$checkToken]['code'] === T_ELSE) {
909
+            if ( $checkToken !== null && $tokens[ $checkToken ][ 'code' ] === T_ELSE ) {
910 910
                 $exact = true;
911 911
             }
912 912
 
913
-            if ($checkIndent === null) {
913
+            if ( $checkIndent === null ) {
914 914
                 $checkIndent = $currentIndent;
915 915
             }
916 916
 
@@ -924,23 +924,23 @@  discard block
 block discarded – undo
924 924
                 the checking of future lines
925 925
             */
926 926
 
927
-            if ($checkToken !== null
928
-                && isset($this->ignoreIndentation[$tokens[$checkToken]['code']]) === false
929
-                && (($tokenIndent !== $checkIndent && $exact === true)
930
-                || ($tokenIndent < $checkIndent && $exact === false))
927
+            if ( $checkToken !== null
928
+                && isset( $this->ignoreIndentation[ $tokens[ $checkToken ][ 'code' ] ] ) === false
929
+                && ( ( $tokenIndent !== $checkIndent && $exact === true )
930
+                || ( $tokenIndent < $checkIndent && $exact === false ) )
931 931
             ) {
932 932
                 $type  = 'IncorrectExact';
933 933
                 $error = 'Line indented incorrectly; expected ';
934
-                if ($exact === false) {
934
+                if ( $exact === false ) {
935 935
                     $error .= 'at least ';
936 936
                     $type   = 'Incorrect';
937 937
                 }
938 938
 
939
-                if ($this->tabIndent === true) {
939
+                if ( $this->tabIndent === true ) {
940 940
                     $error .= '%s tabs, found %s';
941 941
                     $data   = [
942
-                        floor($checkIndent / $this->tabWidth),
943
-                        floor($tokenIndent / $this->tabWidth),
942
+                        floor( $checkIndent / $this->tabWidth ),
943
+                        floor( $tokenIndent / $this->tabWidth ),
944 944
                     ];
945 945
                 } else {
946 946
                     $error .= '%s spaces, found %s';
@@ -950,89 +950,89 @@  discard block
 block discarded – undo
950 950
                     ];
951 951
                 }
952 952
 
953
-                if ($this->debug === true) {
954
-                    $line    = $tokens[$checkToken]['line'];
955
-                    $message = vsprintf($error, $data);
956
-                    echo "[Line $line] $message".PHP_EOL;
953
+                if ( $this->debug === true ) {
954
+                    $line    = $tokens[ $checkToken ][ 'line' ];
955
+                    $message = vsprintf( $error, $data );
956
+                    echo "[Line $line] $message" . PHP_EOL;
957 957
                 }
958 958
 
959 959
                 // Assume the change would be applied and continue
960 960
                 // checking indents under this assumption. This gives more
961 961
                 // technically accurate error messages.
962
-                $adjustments[$checkToken] = ($checkIndent - $tokenIndent);
962
+                $adjustments[ $checkToken ] = ( $checkIndent - $tokenIndent );
963 963
 
964
-                $fix = $phpcsFile->addFixableError($error, $checkToken, $type, $data);
965
-                if ($fix === true || $this->debug === true) {
966
-                    $accepted = $this->adjustIndent($phpcsFile, $checkToken, $checkIndent, ($checkIndent - $tokenIndent));
964
+                $fix = $phpcsFile->addFixableError( $error, $checkToken, $type, $data );
965
+                if ( $fix === true || $this->debug === true ) {
966
+                    $accepted = $this->adjustIndent( $phpcsFile, $checkToken, $checkIndent, ( $checkIndent - $tokenIndent ) );
967 967
 
968
-                    if ($accepted === true && $this->debug === true) {
969
-                        $line = $tokens[$checkToken]['line'];
970
-                        $type = $tokens[$checkToken]['type'];
971
-                        echo "\t=> add adjustment of ".$adjustments[$checkToken]." for token $checkToken ($type) on line $line".PHP_EOL;
968
+                    if ( $accepted === true && $this->debug === true ) {
969
+                        $line = $tokens[ $checkToken ][ 'line' ];
970
+                        $type = $tokens[ $checkToken ][ 'type' ];
971
+                        echo "\t=> add adjustment of " . $adjustments[ $checkToken ] . " for token $checkToken ($type) on line $line" . PHP_EOL;
972 972
                     }
973 973
                 }
974 974
             }//end if
975 975
 
976
-            if ($checkToken !== null) {
976
+            if ( $checkToken !== null ) {
977 977
                 $i = $checkToken;
978 978
             }
979 979
 
980 980
             // Completely skip here/now docs as the indent is a part of the
981 981
             // content itself.
982
-            if ($tokens[$i]['code'] === T_START_HEREDOC
983
-                || $tokens[$i]['code'] === T_START_NOWDOC
982
+            if ( $tokens[ $i ][ 'code' ] === T_START_HEREDOC
983
+                || $tokens[ $i ][ 'code' ] === T_START_NOWDOC
984 984
             ) {
985
-                $i = $phpcsFile->findNext([T_END_HEREDOC, T_END_NOWDOC], ($i + 1));
986
-                $i = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
985
+                $i = $phpcsFile->findNext( [ T_END_HEREDOC, T_END_NOWDOC ], ( $i + 1 ) );
986
+                $i = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true );
987 987
                 continue;
988 988
             }
989 989
 
990 990
             // Completely skip multi-line strings as the indent is a part of the
991 991
             // content itself.
992
-            if ($tokens[$i]['code'] === T_CONSTANT_ENCAPSED_STRING
993
-                || $tokens[$i]['code'] === T_DOUBLE_QUOTED_STRING
992
+            if ( $tokens[ $i ][ 'code' ] === T_CONSTANT_ENCAPSED_STRING
993
+                || $tokens[ $i ][ 'code' ] === T_DOUBLE_QUOTED_STRING
994 994
             ) {
995
-                $i = $phpcsFile->findNext($tokens[$i]['code'], ($i + 1), null, true);
995
+                $i = $phpcsFile->findNext( $tokens[ $i ][ 'code' ], ( $i + 1 ), null, true );
996 996
                 $i--;
997 997
                 continue;
998 998
             }
999 999
 
1000 1000
             // Completely skip doc comments as they tend to have complex
1001 1001
             // indentation rules.
1002
-            if ($tokens[$i]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1003
-                $i = $tokens[$i]['comment_closer'];
1002
+            if ( $tokens[ $i ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
1003
+                $i = $tokens[ $i ][ 'comment_closer' ];
1004 1004
                 continue;
1005 1005
             }
1006 1006
 
1007 1007
             // Open tags reset the indent level.
1008
-            if ($tokens[$i]['code'] === T_OPEN_TAG
1009
-                || $tokens[$i]['code'] === T_OPEN_TAG_WITH_ECHO
1008
+            if ( $tokens[ $i ][ 'code' ] === T_OPEN_TAG
1009
+                || $tokens[ $i ][ 'code' ] === T_OPEN_TAG_WITH_ECHO
1010 1010
             ) {
1011
-                if ($this->debug === true) {
1012
-                    $line = $tokens[$i]['line'];
1013
-                    echo "Open PHP tag found on line $line".PHP_EOL;
1011
+                if ( $this->debug === true ) {
1012
+                    $line = $tokens[ $i ][ 'line' ];
1013
+                    echo "Open PHP tag found on line $line" . PHP_EOL;
1014 1014
                 }
1015 1015
 
1016
-                if ($checkToken === null) {
1017
-                    $first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1018
-                    $currentIndent = (strlen($tokens[$first]['content']) - strlen(ltrim($tokens[$first]['content'])));
1016
+                if ( $checkToken === null ) {
1017
+                    $first         = $phpcsFile->findFirstOnLine( T_WHITESPACE, $i, true );
1018
+                    $currentIndent = ( strlen( $tokens[ $first ][ 'content' ] ) - strlen( ltrim( $tokens[ $first ][ 'content' ] ) ) );
1019 1019
                 } else {
1020
-                    $currentIndent = ($tokens[$i]['column'] - 1);
1020
+                    $currentIndent = ( $tokens[ $i ][ 'column' ] - 1 );
1021 1021
                 }
1022 1022
 
1023 1023
                 $lastOpenTag = $i;
1024 1024
 
1025
-                if (isset($adjustments[$i]) === true) {
1026
-                    $currentIndent += $adjustments[$i];
1025
+                if ( isset( $adjustments[ $i ] ) === true ) {
1026
+                    $currentIndent += $adjustments[ $i ];
1027 1027
                 }
1028 1028
 
1029 1029
                 // Make sure it is divisible by our expected indent.
1030
-                $currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1031
-                $setIndents[$i] = $currentIndent;
1030
+                $currentIndent  = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
1031
+                $setIndents[ $i ] = $currentIndent;
1032 1032
 
1033
-                if ($this->debug === true) {
1034
-                    $type = $tokens[$i]['type'];
1035
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1033
+                if ( $this->debug === true ) {
1034
+                    $type = $tokens[ $i ][ 'type' ];
1035
+                    echo "\t=> indent set to $currentIndent by token $i ($type)" . PHP_EOL;
1036 1036
                 }
1037 1037
 
1038 1038
                 continue;
@@ -1040,149 +1040,149 @@  discard block
 block discarded – undo
1040 1040
 
1041 1041
             // Close tags reset the indent level, unless they are closing a tag
1042 1042
             // opened on the same line.
1043
-            if ($tokens[$i]['code'] === T_CLOSE_TAG) {
1044
-                if ($this->debug === true) {
1045
-                    $line = $tokens[$i]['line'];
1046
-                    echo "Close PHP tag found on line $line".PHP_EOL;
1043
+            if ( $tokens[ $i ][ 'code' ] === T_CLOSE_TAG ) {
1044
+                if ( $this->debug === true ) {
1045
+                    $line = $tokens[ $i ][ 'line' ];
1046
+                    echo "Close PHP tag found on line $line" . PHP_EOL;
1047 1047
                 }
1048 1048
 
1049
-                if ($tokens[$lastOpenTag]['line'] !== $tokens[$i]['line']) {
1050
-                    $currentIndent = ($tokens[$i]['column'] - 1);
1049
+                if ( $tokens[ $lastOpenTag ][ 'line' ] !== $tokens[ $i ][ 'line' ] ) {
1050
+                    $currentIndent = ( $tokens[ $i ][ 'column' ] - 1 );
1051 1051
                     $lastCloseTag  = $i;
1052 1052
                 } else {
1053
-                    if ($lastCloseTag === null) {
1053
+                    if ( $lastCloseTag === null ) {
1054 1054
                         $currentIndent = 0;
1055 1055
                     } else {
1056
-                        $currentIndent = ($tokens[$lastCloseTag]['column'] - 1);
1056
+                        $currentIndent = ( $tokens[ $lastCloseTag ][ 'column' ] - 1 );
1057 1057
                     }
1058 1058
                 }
1059 1059
 
1060
-                if (isset($adjustments[$i]) === true) {
1061
-                    $currentIndent += $adjustments[$i];
1060
+                if ( isset( $adjustments[ $i ] ) === true ) {
1061
+                    $currentIndent += $adjustments[ $i ];
1062 1062
                 }
1063 1063
 
1064 1064
                 // Make sure it is divisible by our expected indent.
1065
-                $currentIndent  = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1066
-                $setIndents[$i] = $currentIndent;
1065
+                $currentIndent  = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
1066
+                $setIndents[ $i ] = $currentIndent;
1067 1067
 
1068
-                if ($this->debug === true) {
1069
-                    $type = $tokens[$i]['type'];
1070
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1068
+                if ( $this->debug === true ) {
1069
+                    $type = $tokens[ $i ][ 'type' ];
1070
+                    echo "\t=> indent set to $currentIndent by token $i ($type)" . PHP_EOL;
1071 1071
                 }
1072 1072
 
1073 1073
                 continue;
1074 1074
             }//end if
1075 1075
 
1076 1076
             // Anon classes and functions set the indent based on their own indent level.
1077
-            if ($tokens[$i]['code'] === T_CLOSURE || $tokens[$i]['code'] === T_ANON_CLASS) {
1078
-                $closer = $tokens[$i]['scope_closer'];
1079
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1080
-                    if ($this->debug === true) {
1081
-                        $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1082
-                        $line = $tokens[$i]['line'];
1083
-                        echo "* ignoring single-line $type on line $line".PHP_EOL;
1077
+            if ( $tokens[ $i ][ 'code' ] === T_CLOSURE || $tokens[ $i ][ 'code' ] === T_ANON_CLASS ) {
1078
+                $closer = $tokens[ $i ][ 'scope_closer' ];
1079
+                if ( $tokens[ $i ][ 'line' ] === $tokens[ $closer ][ 'line' ] ) {
1080
+                    if ( $this->debug === true ) {
1081
+                        $type = str_replace( '_', ' ', strtolower( substr( $tokens[ $i ][ 'type' ], 2 ) ) );
1082
+                        $line = $tokens[ $i ][ 'line' ];
1083
+                        echo "* ignoring single-line $type on line $line" . PHP_EOL;
1084 1084
                     }
1085 1085
 
1086 1086
                     $i = $closer;
1087 1087
                     continue;
1088 1088
                 }
1089 1089
 
1090
-                if ($this->debug === true) {
1091
-                    $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1092
-                    $line = $tokens[$i]['line'];
1093
-                    echo "Open $type on line $line".PHP_EOL;
1090
+                if ( $this->debug === true ) {
1091
+                    $type = str_replace( '_', ' ', strtolower( substr( $tokens[ $i ][ 'type' ], 2 ) ) );
1092
+                    $line = $tokens[ $i ][ 'line' ];
1093
+                    echo "Open $type on line $line" . PHP_EOL;
1094 1094
                 }
1095 1095
 
1096
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1097
-                if ($this->debug === true) {
1098
-                    $line = $tokens[$first]['line'];
1099
-                    $type = $tokens[$first]['type'];
1100
-                    echo "\t* first token is $first ($type) on line $line *".PHP_EOL;
1096
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $i, true );
1097
+                if ( $this->debug === true ) {
1098
+                    $line = $tokens[ $first ][ 'line' ];
1099
+                    $type = $tokens[ $first ][ 'type' ];
1100
+                    echo "\t* first token is $first ($type) on line $line *" . PHP_EOL;
1101 1101
                 }
1102 1102
 
1103
-                while ($tokens[$first]['code'] === T_CONSTANT_ENCAPSED_STRING
1104
-                    && $tokens[($first - 1)]['code'] === T_CONSTANT_ENCAPSED_STRING
1103
+                while ( $tokens[ $first ][ 'code' ] === T_CONSTANT_ENCAPSED_STRING
1104
+                    && $tokens[ ( $first - 1 ) ][ 'code' ] === T_CONSTANT_ENCAPSED_STRING
1105 1105
                 ) {
1106
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, ($first - 1), true);
1107
-                    if ($this->debug === true) {
1108
-                        $line = $tokens[$first]['line'];
1109
-                        $type = $tokens[$first]['type'];
1110
-                        echo "\t* found multi-line string; amended first token is $first ($type) on line $line *".PHP_EOL;
1106
+                    $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, ( $first - 1 ), true );
1107
+                    if ( $this->debug === true ) {
1108
+                        $line = $tokens[ $first ][ 'line' ];
1109
+                        $type = $tokens[ $first ][ 'type' ];
1110
+                        echo "\t* found multi-line string; amended first token is $first ($type) on line $line *" . PHP_EOL;
1111 1111
                     }
1112 1112
                 }
1113 1113
 
1114
-                $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1115
-                $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1116
-                if ($this->debug === true) {
1117
-                    $closerToken    = $tokens[$i]['scope_closer'];
1118
-                    $closerLine     = $tokens[$closerToken]['line'];
1119
-                    $closerType     = $tokens[$closerToken]['type'];
1120
-                    $conditionToken = $tokens[$i]['scope_condition'];
1121
-                    $conditionLine  = $tokens[$conditionToken]['line'];
1122
-                    $conditionType  = $tokens[$conditionToken]['type'];
1123
-                    echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1114
+                $currentIndent = ( ( $tokens[ $first ][ 'column' ] - 1 ) + $this->indent );
1115
+                $openScopes[ $tokens[ $i ][ 'scope_closer' ] ] = $tokens[ $i ][ 'scope_condition' ];
1116
+                if ( $this->debug === true ) {
1117
+                    $closerToken    = $tokens[ $i ][ 'scope_closer' ];
1118
+                    $closerLine     = $tokens[ $closerToken ][ 'line' ];
1119
+                    $closerType     = $tokens[ $closerToken ][ 'type' ];
1120
+                    $conditionToken = $tokens[ $i ][ 'scope_condition' ];
1121
+                    $conditionLine  = $tokens[ $conditionToken ][ 'line' ];
1122
+                    $conditionType  = $tokens[ $conditionToken ][ 'type' ];
1123
+                    echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine" . PHP_EOL;
1124 1124
                 }
1125 1125
 
1126
-                if (isset($adjustments[$first]) === true) {
1127
-                    $currentIndent += $adjustments[$first];
1126
+                if ( isset( $adjustments[ $first ] ) === true ) {
1127
+                    $currentIndent += $adjustments[ $first ];
1128 1128
                 }
1129 1129
 
1130 1130
                 // Make sure it is divisible by our expected indent.
1131
-                $currentIndent = (int) (floor($currentIndent / $this->indent) * $this->indent);
1132
-                $i = $tokens[$i]['scope_opener'];
1133
-                $setIndents[$i] = $currentIndent;
1131
+                $currentIndent = (int)( floor( $currentIndent / $this->indent ) * $this->indent );
1132
+                $i = $tokens[ $i ][ 'scope_opener' ];
1133
+                $setIndents[ $i ] = $currentIndent;
1134 1134
 
1135
-                if ($this->debug === true) {
1136
-                    $type = $tokens[$i]['type'];
1137
-                    echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1135
+                if ( $this->debug === true ) {
1136
+                    $type = $tokens[ $i ][ 'type' ];
1137
+                    echo "\t=> indent set to $currentIndent by token $i ($type)" . PHP_EOL;
1138 1138
                 }
1139 1139
 
1140 1140
                 continue;
1141 1141
             }//end if
1142 1142
 
1143 1143
             // Scope openers increase the indent level.
1144
-            if (isset($tokens[$i]['scope_condition']) === true
1145
-                && isset($tokens[$i]['scope_opener']) === true
1146
-                && $tokens[$i]['scope_opener'] === $i
1144
+            if ( isset( $tokens[ $i ][ 'scope_condition' ] ) === true
1145
+                && isset( $tokens[ $i ][ 'scope_opener' ] ) === true
1146
+                && $tokens[ $i ][ 'scope_opener' ] === $i
1147 1147
             ) {
1148
-                $closer = $tokens[$i]['scope_closer'];
1149
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1150
-                    if ($this->debug === true) {
1151
-                        $line = $tokens[$i]['line'];
1152
-                        $type = $tokens[$i]['type'];
1153
-                        echo "* ignoring single-line $type on line $line".PHP_EOL;
1148
+                $closer = $tokens[ $i ][ 'scope_closer' ];
1149
+                if ( $tokens[ $i ][ 'line' ] === $tokens[ $closer ][ 'line' ] ) {
1150
+                    if ( $this->debug === true ) {
1151
+                        $line = $tokens[ $i ][ 'line' ];
1152
+                        $type = $tokens[ $i ][ 'type' ];
1153
+                        echo "* ignoring single-line $type on line $line" . PHP_EOL;
1154 1154
                     }
1155 1155
 
1156 1156
                     $i = $closer;
1157 1157
                     continue;
1158 1158
                 }
1159 1159
 
1160
-                $condition = $tokens[$tokens[$i]['scope_condition']]['code'];
1161
-                if (isset(Tokens::$scopeOpeners[$condition]) === true
1162
-                    && in_array($condition, $this->nonIndentingScopes, true) === false
1160
+                $condition = $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'code' ];
1161
+                if ( isset( Tokens::$scopeOpeners[ $condition ] ) === true
1162
+                    && in_array( $condition, $this->nonIndentingScopes, true ) === false
1163 1163
                 ) {
1164
-                    if ($this->debug === true) {
1165
-                        $line = $tokens[$i]['line'];
1166
-                        $type = $tokens[$tokens[$i]['scope_condition']]['type'];
1167
-                        echo "Open scope ($type) on line $line".PHP_EOL;
1164
+                    if ( $this->debug === true ) {
1165
+                        $line = $tokens[ $i ][ 'line' ];
1166
+                        $type = $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'type' ];
1167
+                        echo "Open scope ($type) on line $line" . PHP_EOL;
1168 1168
                     }
1169 1169
 
1170 1170
                     $currentIndent += $this->indent;
1171
-                    $setIndents[$i] = $currentIndent;
1172
-                    $openScopes[$tokens[$i]['scope_closer']] = $tokens[$i]['scope_condition'];
1173
-                    if ($this->debug === true) {
1174
-                        $closerToken    = $tokens[$i]['scope_closer'];
1175
-                        $closerLine     = $tokens[$closerToken]['line'];
1176
-                        $closerType     = $tokens[$closerToken]['type'];
1177
-                        $conditionToken = $tokens[$i]['scope_condition'];
1178
-                        $conditionLine  = $tokens[$conditionToken]['line'];
1179
-                        $conditionType  = $tokens[$conditionToken]['type'];
1180
-                        echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine".PHP_EOL;
1171
+                    $setIndents[ $i ] = $currentIndent;
1172
+                    $openScopes[ $tokens[ $i ][ 'scope_closer' ] ] = $tokens[ $i ][ 'scope_condition' ];
1173
+                    if ( $this->debug === true ) {
1174
+                        $closerToken    = $tokens[ $i ][ 'scope_closer' ];
1175
+                        $closerLine     = $tokens[ $closerToken ][ 'line' ];
1176
+                        $closerType     = $tokens[ $closerToken ][ 'type' ];
1177
+                        $conditionToken = $tokens[ $i ][ 'scope_condition' ];
1178
+                        $conditionLine  = $tokens[ $conditionToken ][ 'line' ];
1179
+                        $conditionType  = $tokens[ $conditionToken ][ 'type' ];
1180
+                        echo "\t=> added open scope $closerToken ($closerType) on line $closerLine, pointing to condition $conditionToken ($conditionType) on line $conditionLine" . PHP_EOL;
1181 1181
                     }
1182 1182
 
1183
-                    if ($this->debug === true) {
1184
-                        $type = $tokens[$i]['type'];
1185
-                        echo "\t=> indent set to $currentIndent by token $i ($type)".PHP_EOL;
1183
+                    if ( $this->debug === true ) {
1184
+                        $type = $tokens[ $i ][ 'type' ];
1185
+                        echo "\t=> indent set to $currentIndent by token $i ($type)" . PHP_EOL;
1186 1186
                     }
1187 1187
 
1188 1188
                     continue;
@@ -1190,120 +1190,120 @@  discard block
 block discarded – undo
1190 1190
             }//end if
1191 1191
 
1192 1192
             // JS objects set the indent level.
1193
-            if ($phpcsFile->tokenizerType === 'JS'
1194
-                && $tokens[$i]['code'] === T_OBJECT
1193
+            if ( $phpcsFile->tokenizerType === 'JS'
1194
+                && $tokens[ $i ][ 'code' ] === T_OBJECT
1195 1195
             ) {
1196
-                $closer = $tokens[$i]['bracket_closer'];
1197
-                if ($tokens[$i]['line'] === $tokens[$closer]['line']) {
1198
-                    if ($this->debug === true) {
1199
-                        $line = $tokens[$i]['line'];
1200
-                        echo "* ignoring single-line JS object on line $line".PHP_EOL;
1196
+                $closer = $tokens[ $i ][ 'bracket_closer' ];
1197
+                if ( $tokens[ $i ][ 'line' ] === $tokens[ $closer ][ 'line' ] ) {
1198
+                    if ( $this->debug === true ) {
1199
+                        $line = $tokens[ $i ][ 'line' ];
1200
+                        echo "* ignoring single-line JS object on line $line" . PHP_EOL;
1201 1201
                     }
1202 1202
 
1203 1203
                     $i = $closer;
1204 1204
                     continue;
1205 1205
                 }
1206 1206
 
1207
-                if ($this->debug === true) {
1208
-                    $line = $tokens[$i]['line'];
1209
-                    echo "Open JS object on line $line".PHP_EOL;
1207
+                if ( $this->debug === true ) {
1208
+                    $line = $tokens[ $i ][ 'line' ];
1209
+                    echo "Open JS object on line $line" . PHP_EOL;
1210 1210
                 }
1211 1211
 
1212
-                $first         = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
1213
-                $currentIndent = (($tokens[$first]['column'] - 1) + $this->indent);
1214
-                if (isset($adjustments[$first]) === true) {
1215
-                    $currentIndent += $adjustments[$first];
1212
+                $first         = $phpcsFile->findFirstOnLine( T_WHITESPACE, $i, true );
1213
+                $currentIndent = ( ( $tokens[ $first ][ 'column' ] - 1 ) + $this->indent );
1214
+                if ( isset( $adjustments[ $first ] ) === true ) {
1215
+                    $currentIndent += $adjustments[ $first ];
1216 1216
                 }
1217 1217
 
1218 1218
                 // Make sure it is divisible by our expected indent.
1219
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1220
-                $setIndents[$first] = $currentIndent;
1219
+                $currentIndent      = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
1220
+                $setIndents[ $first ] = $currentIndent;
1221 1221
 
1222
-                if ($this->debug === true) {
1223
-                    $type = $tokens[$first]['type'];
1224
-                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1222
+                if ( $this->debug === true ) {
1223
+                    $type = $tokens[ $first ][ 'type' ];
1224
+                    echo "\t=> indent set to $currentIndent by token $first ($type)" . PHP_EOL;
1225 1225
                 }
1226 1226
 
1227 1227
                 continue;
1228 1228
             }//end if
1229 1229
 
1230 1230
             // Closing an anon class or function.
1231
-            if (isset($tokens[$i]['scope_condition']) === true
1232
-                && $tokens[$i]['scope_closer'] === $i
1233
-                && ($tokens[$tokens[$i]['scope_condition']]['code'] === T_CLOSURE
1234
-                || $tokens[$tokens[$i]['scope_condition']]['code'] === T_ANON_CLASS)
1231
+            if ( isset( $tokens[ $i ][ 'scope_condition' ] ) === true
1232
+                && $tokens[ $i ][ 'scope_closer' ] === $i
1233
+                && ( $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'code' ] === T_CLOSURE
1234
+                || $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'code' ] === T_ANON_CLASS )
1235 1235
             ) {
1236
-                if ($this->debug === true) {
1237
-                    $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2)));
1238
-                    $line = $tokens[$i]['line'];
1239
-                    echo "Close $type on line $line".PHP_EOL;
1236
+                if ( $this->debug === true ) {
1237
+                    $type = str_replace( '_', ' ', strtolower( substr( $tokens[ $tokens[ $i ][ 'scope_condition' ] ][ 'type' ], 2 ) ) );
1238
+                    $line = $tokens[ $i ][ 'line' ];
1239
+                    echo "Close $type on line $line" . PHP_EOL;
1240 1240
                 }
1241 1241
 
1242 1242
                 $prev = false;
1243 1243
 
1244 1244
                 $object = 0;
1245
-                if ($phpcsFile->tokenizerType === 'JS') {
1246
-                    $conditions = $tokens[$i]['conditions'];
1247
-                    krsort($conditions, SORT_NUMERIC);
1248
-                    foreach ($conditions as $token => $condition) {
1249
-                        if ($condition === T_OBJECT) {
1245
+                if ( $phpcsFile->tokenizerType === 'JS' ) {
1246
+                    $conditions = $tokens[ $i ][ 'conditions' ];
1247
+                    krsort( $conditions, SORT_NUMERIC );
1248
+                    foreach ( $conditions as $token => $condition ) {
1249
+                        if ( $condition === T_OBJECT ) {
1250 1250
                             $object = $token;
1251 1251
                             break;
1252 1252
                         }
1253 1253
                     }
1254 1254
 
1255
-                    if ($this->debug === true && $object !== 0) {
1256
-                        $line = $tokens[$object]['line'];
1257
-                        echo "\t* token is inside JS object $object on line $line *".PHP_EOL;
1255
+                    if ( $this->debug === true && $object !== 0 ) {
1256
+                        $line = $tokens[ $object ][ 'line' ];
1257
+                        echo "\t* token is inside JS object $object on line $line *" . PHP_EOL;
1258 1258
                     }
1259 1259
                 }
1260 1260
 
1261 1261
                 $parens = 0;
1262
-                if (isset($tokens[$i]['nested_parenthesis']) === true
1263
-                    && empty($tokens[$i]['nested_parenthesis']) === false
1262
+                if ( isset( $tokens[ $i ][ 'nested_parenthesis' ] ) === true
1263
+                    && empty( $tokens[ $i ][ 'nested_parenthesis' ] ) === false
1264 1264
                 ) {
1265
-                    $parens = $tokens[$i]['nested_parenthesis'];
1266
-                    end($parens);
1267
-                    $parens = key($parens);
1268
-                    if ($this->debug === true) {
1269
-                        $line = $tokens[$parens]['line'];
1270
-                        echo "\t* token has nested parenthesis $parens on line $line *".PHP_EOL;
1265
+                    $parens = $tokens[ $i ][ 'nested_parenthesis' ];
1266
+                    end( $parens );
1267
+                    $parens = key( $parens );
1268
+                    if ( $this->debug === true ) {
1269
+                        $line = $tokens[ $parens ][ 'line' ];
1270
+                        echo "\t* token has nested parenthesis $parens on line $line *" . PHP_EOL;
1271 1271
                     }
1272 1272
                 }
1273 1273
 
1274 1274
                 $condition = 0;
1275
-                if (isset($tokens[$i]['conditions']) === true
1276
-                    && empty($tokens[$i]['conditions']) === false
1275
+                if ( isset( $tokens[ $i ][ 'conditions' ] ) === true
1276
+                    && empty( $tokens[ $i ][ 'conditions' ] ) === false
1277 1277
                 ) {
1278
-                    $condition = $tokens[$i]['conditions'];
1279
-                    end($condition);
1280
-                    $condition = key($condition);
1281
-                    if ($this->debug === true) {
1282
-                        $line = $tokens[$condition]['line'];
1283
-                        $type = $tokens[$condition]['type'];
1284
-                        echo "\t* token is inside condition $condition ($type) on line $line *".PHP_EOL;
1278
+                    $condition = $tokens[ $i ][ 'conditions' ];
1279
+                    end( $condition );
1280
+                    $condition = key( $condition );
1281
+                    if ( $this->debug === true ) {
1282
+                        $line = $tokens[ $condition ][ 'line' ];
1283
+                        $type = $tokens[ $condition ][ 'type' ];
1284
+                        echo "\t* token is inside condition $condition ($type) on line $line *" . PHP_EOL;
1285 1285
                     }
1286 1286
                 }
1287 1287
 
1288
-                if ($parens > $object && $parens > $condition) {
1289
-                    if ($this->debug === true) {
1290
-                        echo "\t* using parenthesis *".PHP_EOL;
1288
+                if ( $parens > $object && $parens > $condition ) {
1289
+                    if ( $this->debug === true ) {
1290
+                        echo "\t* using parenthesis *" . PHP_EOL;
1291 1291
                     }
1292 1292
 
1293
-                    $prev      = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($parens - 1), null, true);
1293
+                    $prev      = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parens - 1 ), null, true );
1294 1294
                     $object    = 0;
1295 1295
                     $condition = 0;
1296
-                } else if ($object > 0 && $object >= $condition) {
1297
-                    if ($this->debug === true) {
1298
-                        echo "\t* using object *".PHP_EOL;
1296
+                } else if ( $object > 0 && $object >= $condition ) {
1297
+                    if ( $this->debug === true ) {
1298
+                        echo "\t* using object *" . PHP_EOL;
1299 1299
                     }
1300 1300
 
1301 1301
                     $prev      = $object;
1302 1302
                     $parens    = 0;
1303 1303
                     $condition = 0;
1304
-                } else if ($condition > 0) {
1305
-                    if ($this->debug === true) {
1306
-                        echo "\t* using condition *".PHP_EOL;
1304
+                } else if ( $condition > 0 ) {
1305
+                    if ( $this->debug === true ) {
1306
+                        echo "\t* using condition *" . PHP_EOL;
1307 1307
                     }
1308 1308
 
1309 1309
                     $prev   = $condition;
@@ -1311,72 +1311,72 @@  discard block
 block discarded – undo
1311 1311
                     $parens = 0;
1312 1312
                 }//end if
1313 1313
 
1314
-                if ($prev === false) {
1315
-                    $prev = $phpcsFile->findPrevious([T_EQUAL, T_RETURN], ($tokens[$i]['scope_condition'] - 1), null, false, null, true);
1316
-                    if ($prev === false) {
1314
+                if ( $prev === false ) {
1315
+                    $prev = $phpcsFile->findPrevious( [ T_EQUAL, T_RETURN ], ( $tokens[ $i ][ 'scope_condition' ] - 1 ), null, false, null, true );
1316
+                    if ( $prev === false ) {
1317 1317
                         $prev = $i;
1318
-                        if ($this->debug === true) {
1319
-                            echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *".PHP_EOL;
1318
+                        if ( $this->debug === true ) {
1319
+                            echo "\t* could not find a previous T_EQUAL or T_RETURN token; will use current token *" . PHP_EOL;
1320 1320
                         }
1321 1321
                     }
1322 1322
                 }
1323 1323
 
1324
-                if ($this->debug === true) {
1325
-                    $line = $tokens[$prev]['line'];
1326
-                    $type = $tokens[$prev]['type'];
1327
-                    echo "\t* previous token is $type on line $line *".PHP_EOL;
1324
+                if ( $this->debug === true ) {
1325
+                    $line = $tokens[ $prev ][ 'line' ];
1326
+                    $type = $tokens[ $prev ][ 'type' ];
1327
+                    echo "\t* previous token is $type on line $line *" . PHP_EOL;
1328 1328
                 }
1329 1329
 
1330
-                $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1331
-                if ($this->debug === true) {
1332
-                    $line = $tokens[$first]['line'];
1333
-                    $type = $tokens[$first]['type'];
1334
-                    echo "\t* first token on line $line is $first ($type) *".PHP_EOL;
1330
+                $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $prev, true );
1331
+                if ( $this->debug === true ) {
1332
+                    $line = $tokens[ $first ][ 'line' ];
1333
+                    $type = $tokens[ $first ][ 'type' ];
1334
+                    echo "\t* first token on line $line is $first ($type) *" . PHP_EOL;
1335 1335
                 }
1336 1336
 
1337
-                $prev = $phpcsFile->findStartOfStatement($first);
1338
-                if ($prev !== $first) {
1337
+                $prev = $phpcsFile->findStartOfStatement( $first );
1338
+                if ( $prev !== $first ) {
1339 1339
                     // This is not the start of the statement.
1340
-                    if ($this->debug === true) {
1341
-                        $line = $tokens[$prev]['line'];
1342
-                        $type = $tokens[$prev]['type'];
1343
-                        echo "\t* amended previous is $type on line $line *".PHP_EOL;
1340
+                    if ( $this->debug === true ) {
1341
+                        $line = $tokens[ $prev ][ 'line' ];
1342
+                        $type = $tokens[ $prev ][ 'type' ];
1343
+                        echo "\t* amended previous is $type on line $line *" . PHP_EOL;
1344 1344
                     }
1345 1345
 
1346
-                    $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $prev, true);
1347
-                    if ($this->debug === true) {
1348
-                        $line = $tokens[$first]['line'];
1349
-                        $type = $tokens[$first]['type'];
1350
-                        echo "\t* amended first token is $first ($type) on line $line *".PHP_EOL;
1346
+                    $first = $phpcsFile->findFirstOnLine( T_WHITESPACE, $prev, true );
1347
+                    if ( $this->debug === true ) {
1348
+                        $line = $tokens[ $first ][ 'line' ];
1349
+                        $type = $tokens[ $first ][ 'type' ];
1350
+                        echo "\t* amended first token is $first ($type) on line $line *" . PHP_EOL;
1351 1351
                     }
1352 1352
                 }
1353 1353
 
1354
-                $currentIndent = ($tokens[$first]['column'] - 1);
1355
-                if ($object > 0 || $condition > 0) {
1354
+                $currentIndent = ( $tokens[ $first ][ 'column' ] - 1 );
1355
+                if ( $object > 0 || $condition > 0 ) {
1356 1356
                     $currentIndent += $this->indent;
1357 1357
                 }
1358 1358
 
1359
-                if (isset($tokens[$first]['scope_closer']) === true
1360
-                    && $tokens[$first]['scope_closer'] === $first
1359
+                if ( isset( $tokens[ $first ][ 'scope_closer' ] ) === true
1360
+                    && $tokens[ $first ][ 'scope_closer' ] === $first
1361 1361
                 ) {
1362
-                    if ($this->debug === true) {
1363
-                        echo "\t* first token is a scope closer *".PHP_EOL;
1362
+                    if ( $this->debug === true ) {
1363
+                        echo "\t* first token is a scope closer *" . PHP_EOL;
1364 1364
                     }
1365 1365
 
1366
-                    if ($condition === 0 || $tokens[$condition]['scope_opener'] < $first) {
1367
-                        $currentIndent = $setIndents[$first];
1368
-                    } else if ($this->debug === true) {
1369
-                        echo "\t* ignoring scope closer *".PHP_EOL;
1366
+                    if ( $condition === 0 || $tokens[ $condition ][ 'scope_opener' ] < $first ) {
1367
+                        $currentIndent = $setIndents[ $first ];
1368
+                    } else if ( $this->debug === true ) {
1369
+                        echo "\t* ignoring scope closer *" . PHP_EOL;
1370 1370
                     }
1371 1371
                 }
1372 1372
 
1373 1373
                 // Make sure it is divisible by our expected indent.
1374
-                $currentIndent      = (int) (ceil($currentIndent / $this->indent) * $this->indent);
1375
-                $setIndents[$first] = $currentIndent;
1374
+                $currentIndent      = (int)( ceil( $currentIndent / $this->indent ) * $this->indent );
1375
+                $setIndents[ $first ] = $currentIndent;
1376 1376
 
1377
-                if ($this->debug === true) {
1378
-                    $type = $tokens[$first]['type'];
1379
-                    echo "\t=> indent set to $currentIndent by token $first ($type)".PHP_EOL;
1377
+                if ( $this->debug === true ) {
1378
+                    $type = $tokens[ $first ][ 'type' ];
1379
+                    echo "\t=> indent set to $currentIndent by token $first ($type)" . PHP_EOL;
1380 1380
                 }
1381 1381
             }//end if
1382 1382
         }//end for
@@ -1399,72 +1399,72 @@  discard block
 block discarded – undo
1399 1399
      *
1400 1400
      * @return bool
1401 1401
      */
1402
-    protected function adjustIndent(File $phpcsFile, $stackPtr, $length, $change)
1402
+    protected function adjustIndent( File $phpcsFile, $stackPtr, $length, $change )
1403 1403
     {
1404 1404
         $tokens = $phpcsFile->getTokens();
1405 1405
 
1406 1406
         // We don't adjust indents outside of PHP.
1407
-        if ($tokens[$stackPtr]['code'] === T_INLINE_HTML) {
1407
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_INLINE_HTML ) {
1408 1408
             return false;
1409 1409
         }
1410 1410
 
1411 1411
         $padding = '';
1412
-        if ($length > 0) {
1413
-            if ($this->tabIndent === true) {
1414
-                $numTabs = floor($length / $this->tabWidth);
1415
-                if ($numTabs > 0) {
1416
-                    $numSpaces = ($length - ($numTabs * $this->tabWidth));
1417
-                    $padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1412
+        if ( $length > 0 ) {
1413
+            if ( $this->tabIndent === true ) {
1414
+                $numTabs = floor( $length / $this->tabWidth );
1415
+                if ( $numTabs > 0 ) {
1416
+                    $numSpaces = ( $length - ( $numTabs * $this->tabWidth ) );
1417
+                    $padding   = str_repeat( "\t", $numTabs ) . str_repeat( ' ', $numSpaces );
1418 1418
                 }
1419 1419
             } else {
1420
-                $padding = str_repeat(' ', $length);
1420
+                $padding = str_repeat( ' ', $length );
1421 1421
             }
1422 1422
         }
1423 1423
 
1424
-        if ($tokens[$stackPtr]['column'] === 1) {
1425
-            $trimmed  = ltrim($tokens[$stackPtr]['content']);
1426
-            $accepted = $phpcsFile->fixer->replaceToken($stackPtr, $padding.$trimmed);
1424
+        if ( $tokens[ $stackPtr ][ 'column' ] === 1 ) {
1425
+            $trimmed  = ltrim( $tokens[ $stackPtr ][ 'content' ] );
1426
+            $accepted = $phpcsFile->fixer->replaceToken( $stackPtr, $padding . $trimmed );
1427 1427
         } else {
1428 1428
             // Easier to just replace the entire indent.
1429
-            $accepted = $phpcsFile->fixer->replaceToken(($stackPtr - 1), $padding);
1429
+            $accepted = $phpcsFile->fixer->replaceToken( ( $stackPtr - 1 ), $padding );
1430 1430
         }
1431 1431
 
1432
-        if ($accepted === false) {
1432
+        if ( $accepted === false ) {
1433 1433
             return false;
1434 1434
         }
1435 1435
 
1436
-        if ($tokens[$stackPtr]['code'] === T_DOC_COMMENT_OPEN_TAG) {
1436
+        if ( $tokens[ $stackPtr ][ 'code' ] === T_DOC_COMMENT_OPEN_TAG ) {
1437 1437
             // We adjusted the start of a comment, so adjust the rest of it
1438 1438
             // as well so the alignment remains correct.
1439
-            for ($x = ($stackPtr + 1); $x < $tokens[$stackPtr]['comment_closer']; $x++) {
1440
-                if ($tokens[$x]['column'] !== 1) {
1439
+            for ( $x = ( $stackPtr + 1 ); $x < $tokens[ $stackPtr ][ 'comment_closer' ]; $x++ ) {
1440
+                if ( $tokens[ $x ][ 'column' ] !== 1 ) {
1441 1441
                     continue;
1442 1442
                 }
1443 1443
 
1444 1444
                 $length = 0;
1445
-                if ($tokens[$x]['code'] === T_DOC_COMMENT_WHITESPACE) {
1446
-                    $length = $tokens[$x]['length'];
1445
+                if ( $tokens[ $x ][ 'code' ] === T_DOC_COMMENT_WHITESPACE ) {
1446
+                    $length = $tokens[ $x ][ 'length' ];
1447 1447
                 }
1448 1448
 
1449
-                $padding = ($length + $change);
1450
-                if ($padding > 0) {
1451
-                    if ($this->tabIndent === true) {
1452
-                        $numTabs   = floor($padding / $this->tabWidth);
1453
-                        $numSpaces = ($padding - ($numTabs * $this->tabWidth));
1454
-                        $padding   = str_repeat("\t", $numTabs).str_repeat(' ', $numSpaces);
1449
+                $padding = ( $length + $change );
1450
+                if ( $padding > 0 ) {
1451
+                    if ( $this->tabIndent === true ) {
1452
+                        $numTabs   = floor( $padding / $this->tabWidth );
1453
+                        $numSpaces = ( $padding - ( $numTabs * $this->tabWidth ) );
1454
+                        $padding   = str_repeat( "\t", $numTabs ) . str_repeat( ' ', $numSpaces );
1455 1455
                     } else {
1456
-                        $padding = str_repeat(' ', $padding);
1456
+                        $padding = str_repeat( ' ', $padding );
1457 1457
                     }
1458 1458
                 } else {
1459 1459
                     $padding = '';
1460 1460
                 }
1461 1461
 
1462
-                $phpcsFile->fixer->replaceToken($x, $padding);
1463
-                if ($this->debug === true) {
1464
-                    $length = strlen($padding);
1465
-                    $line   = $tokens[$x]['line'];
1466
-                    $type   = $tokens[$x]['type'];
1467
-                    echo "\t=> Indent adjusted to $length for $type on line $line".PHP_EOL;
1462
+                $phpcsFile->fixer->replaceToken( $x, $padding );
1463
+                if ( $this->debug === true ) {
1464
+                    $length = strlen( $padding );
1465
+                    $line   = $tokens[ $x ][ 'line' ];
1466
+                    $type   = $tokens[ $x ][ 'type' ];
1467
+                    echo "\t=> Indent adjusted to $length for $type on line $line" . PHP_EOL;
1468 1468
                 }
1469 1469
             }//end for
1470 1470
         }//end if
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@  discard block
 block discarded – undo
14 14
 use PHP_CodeSniffer\Util\Tokens;
15 15
 use PHP_CodeSniffer\Config;
16 16
 
17
-class ScopeIndentSniff implements Sniff
18
-{
17
+class ScopeIndentSniff implements Sniff {
19 18
 
20 19
     /**
21 20
      * A list of tokenizers this sniff supports.
@@ -104,8 +103,7 @@  discard block
 block discarded – undo
104 103
      *
105 104
      * @return array
106 105
      */
107
-    public function register()
108
-    {
106
+    public function register() {
109 107
         if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
110 108
             $this->debug = false;
111 109
         }
@@ -124,8 +122,7 @@  discard block
 block discarded – undo
124 122
      *
125 123
      * @return void
126 124
      */
127
-    public function process(File $phpcsFile, $stackPtr)
128
-    {
125
+    public function process(File $phpcsFile, $stackPtr) {
129 126
         $debug = Config::getConfigData('scope_indent_debug');
130 127
         if ($debug !== null) {
131 128
             $this->debug = (bool) $debug;
@@ -1399,8 +1396,7 @@  discard block
 block discarded – undo
1399 1396
      *
1400 1397
      * @return bool
1401 1398
      */
1402
-    protected function adjustIndent(File $phpcsFile, $stackPtr, $length, $change)
1403
-    {
1399
+    protected function adjustIndent(File $phpcsFile, $stackPtr, $length, $change) {
1404 1400
         $tokens = $phpcsFile->getTokens();
1405 1401
 
1406 1402
         // We don't adjust indents outside of PHP.
Please login to merge, or discard this patch.
Upper-Lower-Casing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1090,7 +1090,7 @@  discard block
 block discarded – undo
1090 1090
                 if ($this->debug === true) {
1091 1091
                     $type = str_replace('_', ' ', strtolower(substr($tokens[$i]['type'], 2)));
1092 1092
                     $line = $tokens[$i]['line'];
1093
-                    echo "Open $type on line $line".PHP_EOL;
1093
+                    echo "open $type on line $line".PHP_EOL;
1094 1094
                 }
1095 1095
 
1096 1096
                 $first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $i, true);
@@ -1236,7 +1236,7 @@  discard block
 block discarded – undo
1236 1236
                 if ($this->debug === true) {
1237 1237
                     $type = str_replace('_', ' ', strtolower(substr($tokens[$tokens[$i]['scope_condition']]['type'], 2)));
1238 1238
                     $line = $tokens[$i]['line'];
1239
-                    echo "Close $type on line $line".PHP_EOL;
1239
+                    echo "close $type on line $line".PHP_EOL;
1240 1240
                 }
1241 1241
 
1242 1242
                 $prev = false;
Please login to merge, or discard this patch.
src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.2.inc 6 patches
Doc Comments   -6 removed lines patch added patch discarded remove patch
@@ -9,9 +9,3 @@
 block discarded – undo
9 9
         $arr = array(
10 10
             'a' => 'a',
11 11
 <<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
Please login to merge, or discard this patch.
Indentation   +3 added lines, -9 removed lines patch added patch discarded remove patch
@@ -5,13 +5,7 @@
 block discarded – undo
5 5
 // This is not a merge conflict - it is a valid test case to test handling of arrays without associated closer.
6 6
 // Please do not remove.
7 7
 function test()
8
-    {
9
-        $arr = array(
10
-            'a' => 'a',
8
+	{
9
+		$arr = array(
10
+			'a' => 'a',
11 11
 <<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
Please login to merge, or discard this patch.
Switch Indentation   -6 removed lines patch added patch discarded remove patch
@@ -9,9 +9,3 @@
 block discarded – undo
9 9
         $arr = array(
10 10
             'a' => 'a',
11 11
 <<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,10 +8,4 @@
 block discarded – undo
8 8
     {
9 9
         $arr = array(
10 10
             'a' => 'a',
11
-<<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
11
+<< << <<< HEAD
Please login to merge, or discard this patch.
Braces   +1 added lines, -8 removed lines patch added patch discarded remove patch
@@ -4,14 +4,7 @@
 block discarded – undo
4 4
 // The following function has a simulated git conflict for testing.
5 5
 // This is not a merge conflict - it is a valid test case to test handling of arrays without associated closer.
6 6
 // Please do not remove.
7
-function test()
8
-    {
7
+function test() {
9 8
         $arr = array(
10 9
             'a' => 'a',
11 10
 <<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
Please login to merge, or discard this patch.
Upper-Lower-Casing   -6 removed lines patch added patch discarded remove patch
@@ -9,9 +9,3 @@
 block discarded – undo
9 9
         $arr = array(
10 10
             'a' => 'a',
11 11
 <<<<<<< HEAD
12
-            'b' => 'b'
13
-=======
14
-            'c' => 'c'
15
->>>>>>> master
16
-        );
17
-    }
Please login to merge, or discard this patch.