Completed
Pull Request — develop (#1492)
by Zack
28:58 queued 09:00
created
vendor/squizlabs/php_codesniffer/src/Tokenizers/JS.php 3 patches
Indentation   +1220 added lines, -1220 removed lines patch added patch discarded remove patch
@@ -17,1241 +17,1241 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * A list of tokens that are allowed to open a scope.
22
-     *
23
-     * This array also contains information about what kind of token the scope
24
-     * opener uses to open and close the scope, if the token strictly requires
25
-     * an opener, if the token can share a scope closer, and who it can be shared
26
-     * with. An example of a token that shares a scope closer is a CASE scope.
27
-     *
28
-     * @var array
29
-     */
30
-    public $scopeOpeners = [
31
-        T_IF       => [
32
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
33
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
34
-            'strict' => false,
35
-            'shared' => false,
36
-            'with'   => [],
37
-        ],
38
-        T_TRY      => [
39
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
40
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
41
-            'strict' => true,
42
-            'shared' => false,
43
-            'with'   => [],
44
-        ],
45
-        T_CATCH    => [
46
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
47
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
48
-            'strict' => true,
49
-            'shared' => false,
50
-            'with'   => [],
51
-        ],
52
-        T_ELSE     => [
53
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
54
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
55
-            'strict' => false,
56
-            'shared' => false,
57
-            'with'   => [],
58
-        ],
59
-        T_FOR      => [
60
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
61
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
62
-            'strict' => false,
63
-            'shared' => false,
64
-            'with'   => [],
65
-        ],
66
-        T_CLASS    => [
67
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
68
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
69
-            'strict' => true,
70
-            'shared' => false,
71
-            'with'   => [],
72
-        ],
73
-        T_FUNCTION => [
74
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
75
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
76
-            'strict' => false,
77
-            'shared' => false,
78
-            'with'   => [],
79
-        ],
80
-        T_WHILE    => [
81
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
82
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
83
-            'strict' => false,
84
-            'shared' => false,
85
-            'with'   => [],
86
-        ],
87
-        T_DO       => [
88
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
89
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
90
-            'strict' => true,
91
-            'shared' => false,
92
-            'with'   => [],
93
-        ],
94
-        T_SWITCH   => [
95
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
96
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
97
-            'strict' => true,
98
-            'shared' => false,
99
-            'with'   => [],
100
-        ],
101
-        T_CASE     => [
102
-            'start'  => [T_COLON => T_COLON],
103
-            'end'    => [
104
-                T_BREAK    => T_BREAK,
105
-                T_RETURN   => T_RETURN,
106
-                T_CONTINUE => T_CONTINUE,
107
-                T_THROW    => T_THROW,
108
-            ],
109
-            'strict' => true,
110
-            'shared' => true,
111
-            'with'   => [
112
-                T_DEFAULT => T_DEFAULT,
113
-                T_CASE    => T_CASE,
114
-                T_SWITCH  => T_SWITCH,
115
-            ],
116
-        ],
117
-        T_DEFAULT  => [
118
-            'start'  => [T_COLON => T_COLON],
119
-            'end'    => [
120
-                T_BREAK    => T_BREAK,
121
-                T_RETURN   => T_RETURN,
122
-                T_CONTINUE => T_CONTINUE,
123
-                T_THROW    => T_THROW,
124
-            ],
125
-            'strict' => true,
126
-            'shared' => true,
127
-            'with'   => [
128
-                T_CASE   => T_CASE,
129
-                T_SWITCH => T_SWITCH,
130
-            ],
131
-        ],
132
-    ];
133
-
134
-    /**
135
-     * A list of tokens that end the scope.
136
-     *
137
-     * This array is just a unique collection of the end tokens
138
-     * from the _scopeOpeners array. The data is duplicated here to
139
-     * save time during parsing of the file.
140
-     *
141
-     * @var array
142
-     */
143
-    public $endScopeTokens = [
144
-        T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
145
-        T_BREAK               => T_BREAK,
146
-    ];
147
-
148
-    /**
149
-     * A list of special JS tokens and their types.
150
-     *
151
-     * @var array
152
-     */
153
-    protected $tokenValues = [
154
-        'class'     => 'T_CLASS',
155
-        'function'  => 'T_FUNCTION',
156
-        'prototype' => 'T_PROTOTYPE',
157
-        'try'       => 'T_TRY',
158
-        'catch'     => 'T_CATCH',
159
-        'return'    => 'T_RETURN',
160
-        'throw'     => 'T_THROW',
161
-        'break'     => 'T_BREAK',
162
-        'switch'    => 'T_SWITCH',
163
-        'continue'  => 'T_CONTINUE',
164
-        'if'        => 'T_IF',
165
-        'else'      => 'T_ELSE',
166
-        'do'        => 'T_DO',
167
-        'while'     => 'T_WHILE',
168
-        'for'       => 'T_FOR',
169
-        'var'       => 'T_VAR',
170
-        'case'      => 'T_CASE',
171
-        'default'   => 'T_DEFAULT',
172
-        'true'      => 'T_TRUE',
173
-        'false'     => 'T_FALSE',
174
-        'null'      => 'T_NULL',
175
-        'this'      => 'T_THIS',
176
-        'typeof'    => 'T_TYPEOF',
177
-        '('         => 'T_OPEN_PARENTHESIS',
178
-        ')'         => 'T_CLOSE_PARENTHESIS',
179
-        '{'         => 'T_OPEN_CURLY_BRACKET',
180
-        '}'         => 'T_CLOSE_CURLY_BRACKET',
181
-        '['         => 'T_OPEN_SQUARE_BRACKET',
182
-        ']'         => 'T_CLOSE_SQUARE_BRACKET',
183
-        '?'         => 'T_INLINE_THEN',
184
-        '.'         => 'T_OBJECT_OPERATOR',
185
-        '+'         => 'T_PLUS',
186
-        '-'         => 'T_MINUS',
187
-        '*'         => 'T_MULTIPLY',
188
-        '%'         => 'T_MODULUS',
189
-        '/'         => 'T_DIVIDE',
190
-        '^'         => 'T_LOGICAL_XOR',
191
-        ','         => 'T_COMMA',
192
-        ';'         => 'T_SEMICOLON',
193
-        ':'         => 'T_COLON',
194
-        '<'         => 'T_LESS_THAN',
195
-        '>'         => 'T_GREATER_THAN',
196
-        '<<'        => 'T_SL',
197
-        '>>'        => 'T_SR',
198
-        '>>>'       => 'T_ZSR',
199
-        '<<='       => 'T_SL_EQUAL',
200
-        '>>='       => 'T_SR_EQUAL',
201
-        '>>>='      => 'T_ZSR_EQUAL',
202
-        '<='        => 'T_IS_SMALLER_OR_EQUAL',
203
-        '>='        => 'T_IS_GREATER_OR_EQUAL',
204
-        '=>'        => 'T_DOUBLE_ARROW',
205
-        '!'         => 'T_BOOLEAN_NOT',
206
-        '||'        => 'T_BOOLEAN_OR',
207
-        '&&'        => 'T_BOOLEAN_AND',
208
-        '|'         => 'T_BITWISE_OR',
209
-        '&'         => 'T_BITWISE_AND',
210
-        '!='        => 'T_IS_NOT_EQUAL',
211
-        '!=='       => 'T_IS_NOT_IDENTICAL',
212
-        '='         => 'T_EQUAL',
213
-        '=='        => 'T_IS_EQUAL',
214
-        '==='       => 'T_IS_IDENTICAL',
215
-        '-='        => 'T_MINUS_EQUAL',
216
-        '+='        => 'T_PLUS_EQUAL',
217
-        '*='        => 'T_MUL_EQUAL',
218
-        '/='        => 'T_DIV_EQUAL',
219
-        '%='        => 'T_MOD_EQUAL',
220
-        '++'        => 'T_INC',
221
-        '--'        => 'T_DEC',
222
-        '//'        => 'T_COMMENT',
223
-        '/*'        => 'T_COMMENT',
224
-        '/**'       => 'T_DOC_COMMENT',
225
-        '*/'        => 'T_COMMENT',
226
-    ];
227
-
228
-    /**
229
-     * A list string delimiters.
230
-     *
231
-     * @var array
232
-     */
233
-    protected $stringTokens = [
234
-        '\'' => '\'',
235
-        '"'  => '"',
236
-    ];
237
-
238
-    /**
239
-     * A list tokens that start and end comments.
240
-     *
241
-     * @var array
242
-     */
243
-    protected $commentTokens = [
244
-        '//'  => null,
245
-        '/*'  => '*/',
246
-        '/**' => '*/',
247
-    ];
248
-
249
-
250
-    /**
251
-     * Initialise the tokenizer.
252
-     *
253
-     * Pre-checks the content to see if it looks minified.
254
-     *
255
-     * @param string                  $content The content to tokenize,
256
-     * @param \PHP_CodeSniffer\Config $config  The config data for the run.
257
-     * @param string                  $eolChar The EOL char used in the content.
258
-     *
259
-     * @return void
260
-     * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
261
-     */
262
-    public function __construct($content, Config $config, $eolChar='\n')
263
-    {
264
-        if ($this->isMinifiedContent($content, $eolChar) === true) {
265
-            throw new TokenizerException('File appears to be minified and cannot be processed');
266
-        }
267
-
268
-        parent::__construct($content, $config, $eolChar);
269
-
270
-    }//end __construct()
271
-
272
-
273
-    /**
274
-     * Creates an array of tokens when given some JS code.
275
-     *
276
-     * @param string $string The string to tokenize.
277
-     *
278
-     * @return array
279
-     */
280
-    public function tokenize($string)
281
-    {
282
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
283
-            echo "\t*** START JS TOKENIZING ***".PHP_EOL;
284
-        }
285
-
286
-        $maxTokenLength = 0;
287
-        foreach ($this->tokenValues as $token => $values) {
288
-            if (strlen($token) > $maxTokenLength) {
289
-                $maxTokenLength = strlen($token);
290
-            }
291
-        }
292
-
293
-        $tokens          = [];
294
-        $inString        = '';
295
-        $stringChar      = null;
296
-        $inComment       = '';
297
-        $buffer          = '';
298
-        $preStringBuffer = '';
299
-        $cleanBuffer     = false;
300
-
301
-        $commentTokenizer = new Comment();
302
-
303
-        $tokens[] = [
304
-            'code'    => T_OPEN_TAG,
305
-            'type'    => 'T_OPEN_TAG',
306
-            'content' => '',
307
-        ];
308
-
309
-        // Convert newlines to single characters for ease of
310
-        // processing. We will change them back later.
311
-        $string = str_replace($this->eolChar, "\n", $string);
312
-
313
-        $chars    = str_split($string);
314
-        $numChars = count($chars);
315
-        for ($i = 0; $i < $numChars; $i++) {
316
-            $char = $chars[$i];
317
-
318
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
319
-                $content       = Util\Common::prepareForOutput($char);
320
-                $bufferContent = Util\Common::prepareForOutput($buffer);
321
-
322
-                if ($inString !== '') {
323
-                    echo "\t";
324
-                }
325
-
326
-                if ($inComment !== '') {
327
-                    echo "\t";
328
-                }
329
-
330
-                echo "\tProcess char $i => $content (buffer: $bufferContent)".PHP_EOL;
331
-            }//end if
332
-
333
-            if ($inString === '' && $inComment === '' && $buffer !== '') {
334
-                // If the buffer only has whitespace and we are about to
335
-                // add a character, store the whitespace first.
336
-                if (trim($char) !== '' && trim($buffer) === '') {
337
-                    $tokens[] = [
338
-                        'code'    => T_WHITESPACE,
339
-                        'type'    => 'T_WHITESPACE',
340
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
341
-                    ];
342
-
343
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
344
-                        $content = Util\Common::prepareForOutput($buffer);
345
-                        echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
346
-                    }
347
-
348
-                    $buffer = '';
349
-                }
350
-
351
-                // If the buffer is not whitespace and we are about to
352
-                // add a whitespace character, store the content first.
353
-                if ($inString === ''
354
-                    && $inComment === ''
355
-                    && trim($char) === ''
356
-                    && trim($buffer) !== ''
357
-                ) {
358
-                    $tokens[] = [
359
-                        'code'    => T_STRING,
360
-                        'type'    => 'T_STRING',
361
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
362
-                    ];
363
-
364
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
365
-                        $content = Util\Common::prepareForOutput($buffer);
366
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
367
-                    }
368
-
369
-                    $buffer = '';
370
-                }
371
-            }//end if
372
-
373
-            // Process strings.
374
-            if ($inComment === '' && isset($this->stringTokens[$char]) === true) {
375
-                if ($inString === $char) {
376
-                    // This could be the end of the string, but make sure it
377
-                    // is not escaped first.
378
-                    $escapes = 0;
379
-                    for ($x = ($i - 1); $x >= 0; $x--) {
380
-                        if ($chars[$x] !== '\\') {
381
-                            break;
382
-                        }
383
-
384
-                        $escapes++;
385
-                    }
386
-
387
-                    if ($escapes === 0 || ($escapes % 2) === 0) {
388
-                        // There is an even number escape chars,
389
-                        // so this is not escaped, it is the end of the string.
390
-                        $tokens[] = [
391
-                            'code'    => T_CONSTANT_ENCAPSED_STRING,
392
-                            'type'    => 'T_CONSTANT_ENCAPSED_STRING',
393
-                            'content' => str_replace("\n", $this->eolChar, $buffer).$char,
394
-                        ];
395
-
396
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
397
-                            echo "\t\t* found end of string *".PHP_EOL;
398
-                            $content = Util\Common::prepareForOutput($buffer.$char);
399
-                            echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)".PHP_EOL;
400
-                        }
401
-
402
-                        $buffer          = '';
403
-                        $preStringBuffer = '';
404
-                        $inString        = '';
405
-                        $stringChar      = null;
406
-                        continue;
407
-                    }//end if
408
-                } else if ($inString === '') {
409
-                    $inString        = $char;
410
-                    $stringChar      = $i;
411
-                    $preStringBuffer = $buffer;
412
-
413
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
414
-                        echo "\t\t* looking for string closer *".PHP_EOL;
415
-                    }
416
-                }//end if
417
-            }//end if
418
-
419
-            if ($inString !== '' && $char === "\n") {
420
-                // Unless this newline character is escaped, the string did not
421
-                // end before the end of the line, which means it probably
422
-                // wasn't a string at all (maybe a regex).
423
-                if ($chars[($i - 1)] !== '\\') {
424
-                    $i      = $stringChar;
425
-                    $buffer = $preStringBuffer;
426
-                    $preStringBuffer = '';
427
-                    $inString        = '';
428
-                    $stringChar      = null;
429
-                    $char            = $chars[$i];
430
-
431
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
432
-                        echo "\t\t* found newline before end of string, bailing *".PHP_EOL;
433
-                    }
434
-                }
435
-            }
436
-
437
-            $buffer .= $char;
438
-
439
-            // We don't look for special tokens inside strings,
440
-            // so if we are in a string, we can continue here now
441
-            // that the current char is in the buffer.
442
-            if ($inString !== '') {
443
-                continue;
444
-            }
445
-
446
-            // Special case for T_DIVIDE which can actually be
447
-            // the start of a regular expression.
448
-            if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') {
449
-                $regex = $this->getRegexToken($i, $string, $chars, $tokens);
450
-                if ($regex !== null) {
451
-                    $tokens[] = [
452
-                        'code'    => T_REGULAR_EXPRESSION,
453
-                        'type'    => 'T_REGULAR_EXPRESSION',
454
-                        'content' => $regex['content'],
455
-                    ];
456
-
457
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
458
-                        $content = Util\Common::prepareForOutput($regex['content']);
459
-                        echo "\t=> Added token T_REGULAR_EXPRESSION ($content)".PHP_EOL;
460
-                    }
461
-
462
-                    $i           = $regex['end'];
463
-                    $buffer      = '';
464
-                    $cleanBuffer = false;
465
-                    continue;
466
-                }//end if
467
-            }//end if
468
-
469
-            // Check for known tokens, but ignore tokens found that are not at
470
-            // the end of a string, like FOR and this.FORmat.
471
-            if (isset($this->tokenValues[strtolower($buffer)]) === true
472
-                && (preg_match('|[a-zA-z0-9_]|', $char) === 0
473
-                || isset($chars[($i + 1)]) === false
474
-                || preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0)
475
-            ) {
476
-                $matchedToken    = false;
477
-                $lookAheadLength = ($maxTokenLength - strlen($buffer));
478
-
479
-                if ($lookAheadLength > 0) {
480
-                    // The buffer contains a token type, but we need
481
-                    // to look ahead at the next chars to see if this is
482
-                    // actually part of a larger token. For example,
483
-                    // FOR and FOREACH.
484
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
485
-                        echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL;
486
-                    }
487
-
488
-                    $charBuffer = $buffer;
489
-                    for ($x = 1; $x <= $lookAheadLength; $x++) {
490
-                        if (isset($chars[($i + $x)]) === false) {
491
-                            break;
492
-                        }
493
-
494
-                        $charBuffer .= $chars[($i + $x)];
495
-
496
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
497
-                            $content = Util\Common::prepareForOutput($charBuffer);
498
-                            echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
499
-                        }
500
-
501
-                        if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
502
-                            // We've found something larger that matches
503
-                            // so we can ignore this char. Except for 1 very specific
504
-                            // case where a comment like /**/ needs to tokenize as
505
-                            // T_COMMENT and not T_DOC_COMMENT.
506
-                            $oldType = $this->tokenValues[strtolower($buffer)];
507
-                            $newType = $this->tokenValues[strtolower($charBuffer)];
508
-                            if ($oldType === 'T_COMMENT'
509
-                                && $newType === 'T_DOC_COMMENT'
510
-                                && $chars[($i + $x + 1)] === '/'
511
-                            ) {
512
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
513
-                                    echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *".PHP_EOL;
514
-                                }
515
-                            } else {
516
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
517
-                                    echo "\t\t* look ahead found more specific token ($newType), ignoring $i *".PHP_EOL;
518
-                                }
519
-
520
-                                $matchedToken = true;
521
-                                break;
522
-                            }
523
-                        }//end if
524
-                    }//end for
525
-                }//end if
526
-
527
-                if ($matchedToken === false) {
528
-                    if (PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0) {
529
-                        echo "\t\t* look ahead found nothing *".PHP_EOL;
530
-                    }
531
-
532
-                    $value = $this->tokenValues[strtolower($buffer)];
533
-
534
-                    if ($value === 'T_FUNCTION' && $buffer !== 'function') {
535
-                        // The function keyword needs to be all lowercase or else
536
-                        // it is just a function called "Function".
537
-                        $value = 'T_STRING';
538
-                    }
539
-
540
-                    $tokens[] = [
541
-                        'code'    => constant($value),
542
-                        'type'    => $value,
543
-                        'content' => $buffer,
544
-                    ];
545
-
546
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
547
-                        $content = Util\Common::prepareForOutput($buffer);
548
-                        echo "\t=> Added token $value ($content)".PHP_EOL;
549
-                    }
550
-
551
-                    $cleanBuffer = true;
552
-                }//end if
553
-            } else if (isset($this->tokenValues[strtolower($char)]) === true) {
554
-                // No matter what token we end up using, we don't
555
-                // need the content in the buffer any more because we have
556
-                // found a valid token.
557
-                $newContent = substr(str_replace("\n", $this->eolChar, $buffer), 0, -1);
558
-                if ($newContent !== '') {
559
-                    $tokens[] = [
560
-                        'code'    => T_STRING,
561
-                        'type'    => 'T_STRING',
562
-                        'content' => $newContent,
563
-                    ];
564
-
565
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
566
-                        $content = Util\Common::prepareForOutput(substr($buffer, 0, -1));
567
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
568
-                    }
569
-                }
570
-
571
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
-                    echo "\t\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL;
573
-                }
574
-
575
-                // The char is a token type, but we need to look ahead at the
576
-                // next chars to see if this is actually part of a larger token.
577
-                // For example, = and ===.
578
-                $charBuffer   = $char;
579
-                $matchedToken = false;
580
-                for ($x = 1; $x <= $maxTokenLength; $x++) {
581
-                    if (isset($chars[($i + $x)]) === false) {
582
-                        break;
583
-                    }
584
-
585
-                    $charBuffer .= $chars[($i + $x)];
586
-
587
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
588
-                        $content = Util\Common::prepareForOutput($charBuffer);
589
-                        echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
590
-                    }
591
-
592
-                    if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
593
-                        // We've found something larger that matches
594
-                        // so we can ignore this char.
595
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
-                            $type = $this->tokenValues[strtolower($charBuffer)];
597
-                            echo "\t\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL;
598
-                        }
599
-
600
-                        $matchedToken = true;
601
-                        break;
602
-                    }
603
-                }//end for
604
-
605
-                if ($matchedToken === false) {
606
-                    $value    = $this->tokenValues[strtolower($char)];
607
-                    $tokens[] = [
608
-                        'code'    => constant($value),
609
-                        'type'    => $value,
610
-                        'content' => $char,
611
-                    ];
612
-
613
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
614
-                        echo "\t\t* look ahead found nothing *".PHP_EOL;
615
-                        $content = Util\Common::prepareForOutput($char);
616
-                        echo "\t=> Added token $value ($content)".PHP_EOL;
617
-                    }
618
-
619
-                    $cleanBuffer = true;
620
-                } else {
621
-                    $buffer = $char;
622
-                }//end if
623
-            }//end if
624
-
625
-            // Keep track of content inside comments.
626
-            if ($inComment === ''
627
-                && array_key_exists($buffer, $this->commentTokens) === true
628
-            ) {
629
-                // This is not really a comment if the content
630
-                // looks like \// (i.e., it is escaped).
631
-                if (isset($chars[($i - 2)]) === true && $chars[($i - 2)] === '\\') {
632
-                    $lastToken   = array_pop($tokens);
633
-                    $lastContent = $lastToken['content'];
634
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
635
-                        $value   = $this->tokenValues[strtolower($lastContent)];
636
-                        $content = Util\Common::prepareForOutput($lastContent);
637
-                        echo "\t=> Removed token $value ($content)".PHP_EOL;
638
-                    }
639
-
640
-                    $lastChars    = str_split($lastContent);
641
-                    $lastNumChars = count($lastChars);
642
-                    for ($x = 0; $x < $lastNumChars; $x++) {
643
-                        $lastChar = $lastChars[$x];
644
-                        $value    = $this->tokenValues[strtolower($lastChar)];
645
-                        $tokens[] = [
646
-                            'code'    => constant($value),
647
-                            'type'    => $value,
648
-                            'content' => $lastChar,
649
-                        ];
650
-
651
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
652
-                            $content = Util\Common::prepareForOutput($lastChar);
653
-                            echo "\t=> Added token $value ($content)".PHP_EOL;
654
-                        }
655
-                    }
656
-                } else {
657
-                    // We have started a comment.
658
-                    $inComment = $buffer;
659
-
660
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
661
-                        echo "\t\t* looking for end of comment *".PHP_EOL;
662
-                    }
663
-                }//end if
664
-            } else if ($inComment !== '') {
665
-                if ($this->commentTokens[$inComment] === null) {
666
-                    // Comment ends at the next newline.
667
-                    if (strpos($buffer, "\n") !== false) {
668
-                        $inComment = '';
669
-                    }
670
-                } else {
671
-                    if ($this->commentTokens[$inComment] === $buffer) {
672
-                        $inComment = '';
673
-                    }
674
-                }
675
-
676
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
677
-                    if ($inComment === '') {
678
-                        echo "\t\t* found end of comment *".PHP_EOL;
679
-                    }
680
-                }
681
-
682
-                if ($inComment === '' && $cleanBuffer === false) {
683
-                    $tokens[] = [
684
-                        'code'    => T_STRING,
685
-                        'type'    => 'T_STRING',
686
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
687
-                    ];
688
-
689
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
690
-                        $content = Util\Common::prepareForOutput($buffer);
691
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
692
-                    }
693
-
694
-                    $buffer = '';
695
-                }
696
-            }//end if
697
-
698
-            if ($cleanBuffer === true) {
699
-                $buffer      = '';
700
-                $cleanBuffer = false;
701
-            }
702
-        }//end for
703
-
704
-        if (empty($buffer) === false) {
705
-            if ($inString !== '') {
706
-                // The string did not end before the end of the file,
707
-                // which means there was probably a syntax error somewhere.
708
-                $tokens[] = [
709
-                    'code'    => T_STRING,
710
-                    'type'    => 'T_STRING',
711
-                    'content' => str_replace("\n", $this->eolChar, $buffer),
712
-                ];
713
-
714
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
715
-                    $content = Util\Common::prepareForOutput($buffer);
716
-                    echo "\t=> Added token T_STRING ($content)".PHP_EOL;
717
-                }
718
-            } else {
719
-                // Buffer contains whitespace from the end of the file.
720
-                $tokens[] = [
721
-                    'code'    => T_WHITESPACE,
722
-                    'type'    => 'T_WHITESPACE',
723
-                    'content' => str_replace("\n", $this->eolChar, $buffer),
724
-                ];
725
-
726
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
727
-                    $content = Util\Common::prepareForOutput($buffer);
728
-                    echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
729
-                }
730
-            }//end if
731
-        }//end if
732
-
733
-        $tokens[] = [
734
-            'code'    => T_CLOSE_TAG,
735
-            'type'    => 'T_CLOSE_TAG',
736
-            'content' => '',
737
-        ];
738
-
739
-        /*
20
+	/**
21
+	 * A list of tokens that are allowed to open a scope.
22
+	 *
23
+	 * This array also contains information about what kind of token the scope
24
+	 * opener uses to open and close the scope, if the token strictly requires
25
+	 * an opener, if the token can share a scope closer, and who it can be shared
26
+	 * with. An example of a token that shares a scope closer is a CASE scope.
27
+	 *
28
+	 * @var array
29
+	 */
30
+	public $scopeOpeners = [
31
+		T_IF       => [
32
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
33
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
34
+			'strict' => false,
35
+			'shared' => false,
36
+			'with'   => [],
37
+		],
38
+		T_TRY      => [
39
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
40
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
41
+			'strict' => true,
42
+			'shared' => false,
43
+			'with'   => [],
44
+		],
45
+		T_CATCH    => [
46
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
47
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
48
+			'strict' => true,
49
+			'shared' => false,
50
+			'with'   => [],
51
+		],
52
+		T_ELSE     => [
53
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
54
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
55
+			'strict' => false,
56
+			'shared' => false,
57
+			'with'   => [],
58
+		],
59
+		T_FOR      => [
60
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
61
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
62
+			'strict' => false,
63
+			'shared' => false,
64
+			'with'   => [],
65
+		],
66
+		T_CLASS    => [
67
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
68
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
69
+			'strict' => true,
70
+			'shared' => false,
71
+			'with'   => [],
72
+		],
73
+		T_FUNCTION => [
74
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
75
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
76
+			'strict' => false,
77
+			'shared' => false,
78
+			'with'   => [],
79
+		],
80
+		T_WHILE    => [
81
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
82
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
83
+			'strict' => false,
84
+			'shared' => false,
85
+			'with'   => [],
86
+		],
87
+		T_DO       => [
88
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
89
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
90
+			'strict' => true,
91
+			'shared' => false,
92
+			'with'   => [],
93
+		],
94
+		T_SWITCH   => [
95
+			'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
96
+			'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
97
+			'strict' => true,
98
+			'shared' => false,
99
+			'with'   => [],
100
+		],
101
+		T_CASE     => [
102
+			'start'  => [T_COLON => T_COLON],
103
+			'end'    => [
104
+				T_BREAK    => T_BREAK,
105
+				T_RETURN   => T_RETURN,
106
+				T_CONTINUE => T_CONTINUE,
107
+				T_THROW    => T_THROW,
108
+			],
109
+			'strict' => true,
110
+			'shared' => true,
111
+			'with'   => [
112
+				T_DEFAULT => T_DEFAULT,
113
+				T_CASE    => T_CASE,
114
+				T_SWITCH  => T_SWITCH,
115
+			],
116
+		],
117
+		T_DEFAULT  => [
118
+			'start'  => [T_COLON => T_COLON],
119
+			'end'    => [
120
+				T_BREAK    => T_BREAK,
121
+				T_RETURN   => T_RETURN,
122
+				T_CONTINUE => T_CONTINUE,
123
+				T_THROW    => T_THROW,
124
+			],
125
+			'strict' => true,
126
+			'shared' => true,
127
+			'with'   => [
128
+				T_CASE   => T_CASE,
129
+				T_SWITCH => T_SWITCH,
130
+			],
131
+		],
132
+	];
133
+
134
+	/**
135
+	 * A list of tokens that end the scope.
136
+	 *
137
+	 * This array is just a unique collection of the end tokens
138
+	 * from the _scopeOpeners array. The data is duplicated here to
139
+	 * save time during parsing of the file.
140
+	 *
141
+	 * @var array
142
+	 */
143
+	public $endScopeTokens = [
144
+		T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET,
145
+		T_BREAK               => T_BREAK,
146
+	];
147
+
148
+	/**
149
+	 * A list of special JS tokens and their types.
150
+	 *
151
+	 * @var array
152
+	 */
153
+	protected $tokenValues = [
154
+		'class'     => 'T_CLASS',
155
+		'function'  => 'T_FUNCTION',
156
+		'prototype' => 'T_PROTOTYPE',
157
+		'try'       => 'T_TRY',
158
+		'catch'     => 'T_CATCH',
159
+		'return'    => 'T_RETURN',
160
+		'throw'     => 'T_THROW',
161
+		'break'     => 'T_BREAK',
162
+		'switch'    => 'T_SWITCH',
163
+		'continue'  => 'T_CONTINUE',
164
+		'if'        => 'T_IF',
165
+		'else'      => 'T_ELSE',
166
+		'do'        => 'T_DO',
167
+		'while'     => 'T_WHILE',
168
+		'for'       => 'T_FOR',
169
+		'var'       => 'T_VAR',
170
+		'case'      => 'T_CASE',
171
+		'default'   => 'T_DEFAULT',
172
+		'true'      => 'T_TRUE',
173
+		'false'     => 'T_FALSE',
174
+		'null'      => 'T_NULL',
175
+		'this'      => 'T_THIS',
176
+		'typeof'    => 'T_TYPEOF',
177
+		'('         => 'T_OPEN_PARENTHESIS',
178
+		')'         => 'T_CLOSE_PARENTHESIS',
179
+		'{'         => 'T_OPEN_CURLY_BRACKET',
180
+		'}'         => 'T_CLOSE_CURLY_BRACKET',
181
+		'['         => 'T_OPEN_SQUARE_BRACKET',
182
+		']'         => 'T_CLOSE_SQUARE_BRACKET',
183
+		'?'         => 'T_INLINE_THEN',
184
+		'.'         => 'T_OBJECT_OPERATOR',
185
+		'+'         => 'T_PLUS',
186
+		'-'         => 'T_MINUS',
187
+		'*'         => 'T_MULTIPLY',
188
+		'%'         => 'T_MODULUS',
189
+		'/'         => 'T_DIVIDE',
190
+		'^'         => 'T_LOGICAL_XOR',
191
+		','         => 'T_COMMA',
192
+		';'         => 'T_SEMICOLON',
193
+		':'         => 'T_COLON',
194
+		'<'         => 'T_LESS_THAN',
195
+		'>'         => 'T_GREATER_THAN',
196
+		'<<'        => 'T_SL',
197
+		'>>'        => 'T_SR',
198
+		'>>>'       => 'T_ZSR',
199
+		'<<='       => 'T_SL_EQUAL',
200
+		'>>='       => 'T_SR_EQUAL',
201
+		'>>>='      => 'T_ZSR_EQUAL',
202
+		'<='        => 'T_IS_SMALLER_OR_EQUAL',
203
+		'>='        => 'T_IS_GREATER_OR_EQUAL',
204
+		'=>'        => 'T_DOUBLE_ARROW',
205
+		'!'         => 'T_BOOLEAN_NOT',
206
+		'||'        => 'T_BOOLEAN_OR',
207
+		'&&'        => 'T_BOOLEAN_AND',
208
+		'|'         => 'T_BITWISE_OR',
209
+		'&'         => 'T_BITWISE_AND',
210
+		'!='        => 'T_IS_NOT_EQUAL',
211
+		'!=='       => 'T_IS_NOT_IDENTICAL',
212
+		'='         => 'T_EQUAL',
213
+		'=='        => 'T_IS_EQUAL',
214
+		'==='       => 'T_IS_IDENTICAL',
215
+		'-='        => 'T_MINUS_EQUAL',
216
+		'+='        => 'T_PLUS_EQUAL',
217
+		'*='        => 'T_MUL_EQUAL',
218
+		'/='        => 'T_DIV_EQUAL',
219
+		'%='        => 'T_MOD_EQUAL',
220
+		'++'        => 'T_INC',
221
+		'--'        => 'T_DEC',
222
+		'//'        => 'T_COMMENT',
223
+		'/*'        => 'T_COMMENT',
224
+		'/**'       => 'T_DOC_COMMENT',
225
+		'*/'        => 'T_COMMENT',
226
+	];
227
+
228
+	/**
229
+	 * A list string delimiters.
230
+	 *
231
+	 * @var array
232
+	 */
233
+	protected $stringTokens = [
234
+		'\'' => '\'',
235
+		'"'  => '"',
236
+	];
237
+
238
+	/**
239
+	 * A list tokens that start and end comments.
240
+	 *
241
+	 * @var array
242
+	 */
243
+	protected $commentTokens = [
244
+		'//'  => null,
245
+		'/*'  => '*/',
246
+		'/**' => '*/',
247
+	];
248
+
249
+
250
+	/**
251
+	 * Initialise the tokenizer.
252
+	 *
253
+	 * Pre-checks the content to see if it looks minified.
254
+	 *
255
+	 * @param string                  $content The content to tokenize,
256
+	 * @param \PHP_CodeSniffer\Config $config  The config data for the run.
257
+	 * @param string                  $eolChar The EOL char used in the content.
258
+	 *
259
+	 * @return void
260
+	 * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
261
+	 */
262
+	public function __construct($content, Config $config, $eolChar='\n')
263
+	{
264
+		if ($this->isMinifiedContent($content, $eolChar) === true) {
265
+			throw new TokenizerException('File appears to be minified and cannot be processed');
266
+		}
267
+
268
+		parent::__construct($content, $config, $eolChar);
269
+
270
+	}//end __construct()
271
+
272
+
273
+	/**
274
+	 * Creates an array of tokens when given some JS code.
275
+	 *
276
+	 * @param string $string The string to tokenize.
277
+	 *
278
+	 * @return array
279
+	 */
280
+	public function tokenize($string)
281
+	{
282
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
283
+			echo "\t*** START JS TOKENIZING ***".PHP_EOL;
284
+		}
285
+
286
+		$maxTokenLength = 0;
287
+		foreach ($this->tokenValues as $token => $values) {
288
+			if (strlen($token) > $maxTokenLength) {
289
+				$maxTokenLength = strlen($token);
290
+			}
291
+		}
292
+
293
+		$tokens          = [];
294
+		$inString        = '';
295
+		$stringChar      = null;
296
+		$inComment       = '';
297
+		$buffer          = '';
298
+		$preStringBuffer = '';
299
+		$cleanBuffer     = false;
300
+
301
+		$commentTokenizer = new Comment();
302
+
303
+		$tokens[] = [
304
+			'code'    => T_OPEN_TAG,
305
+			'type'    => 'T_OPEN_TAG',
306
+			'content' => '',
307
+		];
308
+
309
+		// Convert newlines to single characters for ease of
310
+		// processing. We will change them back later.
311
+		$string = str_replace($this->eolChar, "\n", $string);
312
+
313
+		$chars    = str_split($string);
314
+		$numChars = count($chars);
315
+		for ($i = 0; $i < $numChars; $i++) {
316
+			$char = $chars[$i];
317
+
318
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
319
+				$content       = Util\Common::prepareForOutput($char);
320
+				$bufferContent = Util\Common::prepareForOutput($buffer);
321
+
322
+				if ($inString !== '') {
323
+					echo "\t";
324
+				}
325
+
326
+				if ($inComment !== '') {
327
+					echo "\t";
328
+				}
329
+
330
+				echo "\tProcess char $i => $content (buffer: $bufferContent)".PHP_EOL;
331
+			}//end if
332
+
333
+			if ($inString === '' && $inComment === '' && $buffer !== '') {
334
+				// If the buffer only has whitespace and we are about to
335
+				// add a character, store the whitespace first.
336
+				if (trim($char) !== '' && trim($buffer) === '') {
337
+					$tokens[] = [
338
+						'code'    => T_WHITESPACE,
339
+						'type'    => 'T_WHITESPACE',
340
+						'content' => str_replace("\n", $this->eolChar, $buffer),
341
+					];
342
+
343
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
344
+						$content = Util\Common::prepareForOutput($buffer);
345
+						echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
346
+					}
347
+
348
+					$buffer = '';
349
+				}
350
+
351
+				// If the buffer is not whitespace and we are about to
352
+				// add a whitespace character, store the content first.
353
+				if ($inString === ''
354
+					&& $inComment === ''
355
+					&& trim($char) === ''
356
+					&& trim($buffer) !== ''
357
+				) {
358
+					$tokens[] = [
359
+						'code'    => T_STRING,
360
+						'type'    => 'T_STRING',
361
+						'content' => str_replace("\n", $this->eolChar, $buffer),
362
+					];
363
+
364
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
365
+						$content = Util\Common::prepareForOutput($buffer);
366
+						echo "\t=> Added token T_STRING ($content)".PHP_EOL;
367
+					}
368
+
369
+					$buffer = '';
370
+				}
371
+			}//end if
372
+
373
+			// Process strings.
374
+			if ($inComment === '' && isset($this->stringTokens[$char]) === true) {
375
+				if ($inString === $char) {
376
+					// This could be the end of the string, but make sure it
377
+					// is not escaped first.
378
+					$escapes = 0;
379
+					for ($x = ($i - 1); $x >= 0; $x--) {
380
+						if ($chars[$x] !== '\\') {
381
+							break;
382
+						}
383
+
384
+						$escapes++;
385
+					}
386
+
387
+					if ($escapes === 0 || ($escapes % 2) === 0) {
388
+						// There is an even number escape chars,
389
+						// so this is not escaped, it is the end of the string.
390
+						$tokens[] = [
391
+							'code'    => T_CONSTANT_ENCAPSED_STRING,
392
+							'type'    => 'T_CONSTANT_ENCAPSED_STRING',
393
+							'content' => str_replace("\n", $this->eolChar, $buffer).$char,
394
+						];
395
+
396
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
397
+							echo "\t\t* found end of string *".PHP_EOL;
398
+							$content = Util\Common::prepareForOutput($buffer.$char);
399
+							echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)".PHP_EOL;
400
+						}
401
+
402
+						$buffer          = '';
403
+						$preStringBuffer = '';
404
+						$inString        = '';
405
+						$stringChar      = null;
406
+						continue;
407
+					}//end if
408
+				} else if ($inString === '') {
409
+					$inString        = $char;
410
+					$stringChar      = $i;
411
+					$preStringBuffer = $buffer;
412
+
413
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
414
+						echo "\t\t* looking for string closer *".PHP_EOL;
415
+					}
416
+				}//end if
417
+			}//end if
418
+
419
+			if ($inString !== '' && $char === "\n") {
420
+				// Unless this newline character is escaped, the string did not
421
+				// end before the end of the line, which means it probably
422
+				// wasn't a string at all (maybe a regex).
423
+				if ($chars[($i - 1)] !== '\\') {
424
+					$i      = $stringChar;
425
+					$buffer = $preStringBuffer;
426
+					$preStringBuffer = '';
427
+					$inString        = '';
428
+					$stringChar      = null;
429
+					$char            = $chars[$i];
430
+
431
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
432
+						echo "\t\t* found newline before end of string, bailing *".PHP_EOL;
433
+					}
434
+				}
435
+			}
436
+
437
+			$buffer .= $char;
438
+
439
+			// We don't look for special tokens inside strings,
440
+			// so if we are in a string, we can continue here now
441
+			// that the current char is in the buffer.
442
+			if ($inString !== '') {
443
+				continue;
444
+			}
445
+
446
+			// Special case for T_DIVIDE which can actually be
447
+			// the start of a regular expression.
448
+			if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') {
449
+				$regex = $this->getRegexToken($i, $string, $chars, $tokens);
450
+				if ($regex !== null) {
451
+					$tokens[] = [
452
+						'code'    => T_REGULAR_EXPRESSION,
453
+						'type'    => 'T_REGULAR_EXPRESSION',
454
+						'content' => $regex['content'],
455
+					];
456
+
457
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
458
+						$content = Util\Common::prepareForOutput($regex['content']);
459
+						echo "\t=> Added token T_REGULAR_EXPRESSION ($content)".PHP_EOL;
460
+					}
461
+
462
+					$i           = $regex['end'];
463
+					$buffer      = '';
464
+					$cleanBuffer = false;
465
+					continue;
466
+				}//end if
467
+			}//end if
468
+
469
+			// Check for known tokens, but ignore tokens found that are not at
470
+			// the end of a string, like FOR and this.FORmat.
471
+			if (isset($this->tokenValues[strtolower($buffer)]) === true
472
+				&& (preg_match('|[a-zA-z0-9_]|', $char) === 0
473
+				|| isset($chars[($i + 1)]) === false
474
+				|| preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0)
475
+			) {
476
+				$matchedToken    = false;
477
+				$lookAheadLength = ($maxTokenLength - strlen($buffer));
478
+
479
+				if ($lookAheadLength > 0) {
480
+					// The buffer contains a token type, but we need
481
+					// to look ahead at the next chars to see if this is
482
+					// actually part of a larger token. For example,
483
+					// FOR and FOREACH.
484
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
485
+						echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL;
486
+					}
487
+
488
+					$charBuffer = $buffer;
489
+					for ($x = 1; $x <= $lookAheadLength; $x++) {
490
+						if (isset($chars[($i + $x)]) === false) {
491
+							break;
492
+						}
493
+
494
+						$charBuffer .= $chars[($i + $x)];
495
+
496
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
497
+							$content = Util\Common::prepareForOutput($charBuffer);
498
+							echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
499
+						}
500
+
501
+						if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
502
+							// We've found something larger that matches
503
+							// so we can ignore this char. Except for 1 very specific
504
+							// case where a comment like /**/ needs to tokenize as
505
+							// T_COMMENT and not T_DOC_COMMENT.
506
+							$oldType = $this->tokenValues[strtolower($buffer)];
507
+							$newType = $this->tokenValues[strtolower($charBuffer)];
508
+							if ($oldType === 'T_COMMENT'
509
+								&& $newType === 'T_DOC_COMMENT'
510
+								&& $chars[($i + $x + 1)] === '/'
511
+							) {
512
+								if (PHP_CODESNIFFER_VERBOSITY > 1) {
513
+									echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *".PHP_EOL;
514
+								}
515
+							} else {
516
+								if (PHP_CODESNIFFER_VERBOSITY > 1) {
517
+									echo "\t\t* look ahead found more specific token ($newType), ignoring $i *".PHP_EOL;
518
+								}
519
+
520
+								$matchedToken = true;
521
+								break;
522
+							}
523
+						}//end if
524
+					}//end for
525
+				}//end if
526
+
527
+				if ($matchedToken === false) {
528
+					if (PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0) {
529
+						echo "\t\t* look ahead found nothing *".PHP_EOL;
530
+					}
531
+
532
+					$value = $this->tokenValues[strtolower($buffer)];
533
+
534
+					if ($value === 'T_FUNCTION' && $buffer !== 'function') {
535
+						// The function keyword needs to be all lowercase or else
536
+						// it is just a function called "Function".
537
+						$value = 'T_STRING';
538
+					}
539
+
540
+					$tokens[] = [
541
+						'code'    => constant($value),
542
+						'type'    => $value,
543
+						'content' => $buffer,
544
+					];
545
+
546
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
547
+						$content = Util\Common::prepareForOutput($buffer);
548
+						echo "\t=> Added token $value ($content)".PHP_EOL;
549
+					}
550
+
551
+					$cleanBuffer = true;
552
+				}//end if
553
+			} else if (isset($this->tokenValues[strtolower($char)]) === true) {
554
+				// No matter what token we end up using, we don't
555
+				// need the content in the buffer any more because we have
556
+				// found a valid token.
557
+				$newContent = substr(str_replace("\n", $this->eolChar, $buffer), 0, -1);
558
+				if ($newContent !== '') {
559
+					$tokens[] = [
560
+						'code'    => T_STRING,
561
+						'type'    => 'T_STRING',
562
+						'content' => $newContent,
563
+					];
564
+
565
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
566
+						$content = Util\Common::prepareForOutput(substr($buffer, 0, -1));
567
+						echo "\t=> Added token T_STRING ($content)".PHP_EOL;
568
+					}
569
+				}
570
+
571
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
+					echo "\t\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL;
573
+				}
574
+
575
+				// The char is a token type, but we need to look ahead at the
576
+				// next chars to see if this is actually part of a larger token.
577
+				// For example, = and ===.
578
+				$charBuffer   = $char;
579
+				$matchedToken = false;
580
+				for ($x = 1; $x <= $maxTokenLength; $x++) {
581
+					if (isset($chars[($i + $x)]) === false) {
582
+						break;
583
+					}
584
+
585
+					$charBuffer .= $chars[($i + $x)];
586
+
587
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
588
+						$content = Util\Common::prepareForOutput($charBuffer);
589
+						echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
590
+					}
591
+
592
+					if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
593
+						// We've found something larger that matches
594
+						// so we can ignore this char.
595
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
+							$type = $this->tokenValues[strtolower($charBuffer)];
597
+							echo "\t\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL;
598
+						}
599
+
600
+						$matchedToken = true;
601
+						break;
602
+					}
603
+				}//end for
604
+
605
+				if ($matchedToken === false) {
606
+					$value    = $this->tokenValues[strtolower($char)];
607
+					$tokens[] = [
608
+						'code'    => constant($value),
609
+						'type'    => $value,
610
+						'content' => $char,
611
+					];
612
+
613
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
614
+						echo "\t\t* look ahead found nothing *".PHP_EOL;
615
+						$content = Util\Common::prepareForOutput($char);
616
+						echo "\t=> Added token $value ($content)".PHP_EOL;
617
+					}
618
+
619
+					$cleanBuffer = true;
620
+				} else {
621
+					$buffer = $char;
622
+				}//end if
623
+			}//end if
624
+
625
+			// Keep track of content inside comments.
626
+			if ($inComment === ''
627
+				&& array_key_exists($buffer, $this->commentTokens) === true
628
+			) {
629
+				// This is not really a comment if the content
630
+				// looks like \// (i.e., it is escaped).
631
+				if (isset($chars[($i - 2)]) === true && $chars[($i - 2)] === '\\') {
632
+					$lastToken   = array_pop($tokens);
633
+					$lastContent = $lastToken['content'];
634
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
635
+						$value   = $this->tokenValues[strtolower($lastContent)];
636
+						$content = Util\Common::prepareForOutput($lastContent);
637
+						echo "\t=> Removed token $value ($content)".PHP_EOL;
638
+					}
639
+
640
+					$lastChars    = str_split($lastContent);
641
+					$lastNumChars = count($lastChars);
642
+					for ($x = 0; $x < $lastNumChars; $x++) {
643
+						$lastChar = $lastChars[$x];
644
+						$value    = $this->tokenValues[strtolower($lastChar)];
645
+						$tokens[] = [
646
+							'code'    => constant($value),
647
+							'type'    => $value,
648
+							'content' => $lastChar,
649
+						];
650
+
651
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
652
+							$content = Util\Common::prepareForOutput($lastChar);
653
+							echo "\t=> Added token $value ($content)".PHP_EOL;
654
+						}
655
+					}
656
+				} else {
657
+					// We have started a comment.
658
+					$inComment = $buffer;
659
+
660
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
661
+						echo "\t\t* looking for end of comment *".PHP_EOL;
662
+					}
663
+				}//end if
664
+			} else if ($inComment !== '') {
665
+				if ($this->commentTokens[$inComment] === null) {
666
+					// Comment ends at the next newline.
667
+					if (strpos($buffer, "\n") !== false) {
668
+						$inComment = '';
669
+					}
670
+				} else {
671
+					if ($this->commentTokens[$inComment] === $buffer) {
672
+						$inComment = '';
673
+					}
674
+				}
675
+
676
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
677
+					if ($inComment === '') {
678
+						echo "\t\t* found end of comment *".PHP_EOL;
679
+					}
680
+				}
681
+
682
+				if ($inComment === '' && $cleanBuffer === false) {
683
+					$tokens[] = [
684
+						'code'    => T_STRING,
685
+						'type'    => 'T_STRING',
686
+						'content' => str_replace("\n", $this->eolChar, $buffer),
687
+					];
688
+
689
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
690
+						$content = Util\Common::prepareForOutput($buffer);
691
+						echo "\t=> Added token T_STRING ($content)".PHP_EOL;
692
+					}
693
+
694
+					$buffer = '';
695
+				}
696
+			}//end if
697
+
698
+			if ($cleanBuffer === true) {
699
+				$buffer      = '';
700
+				$cleanBuffer = false;
701
+			}
702
+		}//end for
703
+
704
+		if (empty($buffer) === false) {
705
+			if ($inString !== '') {
706
+				// The string did not end before the end of the file,
707
+				// which means there was probably a syntax error somewhere.
708
+				$tokens[] = [
709
+					'code'    => T_STRING,
710
+					'type'    => 'T_STRING',
711
+					'content' => str_replace("\n", $this->eolChar, $buffer),
712
+				];
713
+
714
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
715
+					$content = Util\Common::prepareForOutput($buffer);
716
+					echo "\t=> Added token T_STRING ($content)".PHP_EOL;
717
+				}
718
+			} else {
719
+				// Buffer contains whitespace from the end of the file.
720
+				$tokens[] = [
721
+					'code'    => T_WHITESPACE,
722
+					'type'    => 'T_WHITESPACE',
723
+					'content' => str_replace("\n", $this->eolChar, $buffer),
724
+				];
725
+
726
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
727
+					$content = Util\Common::prepareForOutput($buffer);
728
+					echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
729
+				}
730
+			}//end if
731
+		}//end if
732
+
733
+		$tokens[] = [
734
+			'code'    => T_CLOSE_TAG,
735
+			'type'    => 'T_CLOSE_TAG',
736
+			'content' => '',
737
+		];
738
+
739
+		/*
740 740
             Now that we have done some basic tokenizing, we need to
741 741
             modify the tokens to join some together and split some apart
742 742
             so they match what the PHP tokenizer does.
743 743
         */
744 744
 
745
-        $finalTokens = [];
746
-        $newStackPtr = 0;
747
-        $numTokens   = count($tokens);
748
-        for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
749
-            $token = $tokens[$stackPtr];
745
+		$finalTokens = [];
746
+		$newStackPtr = 0;
747
+		$numTokens   = count($tokens);
748
+		for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
749
+			$token = $tokens[$stackPtr];
750 750
 
751
-            /*
751
+			/*
752 752
                 Look for comments and join the tokens together.
753 753
             */
754 754
 
755
-            if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT) {
756
-                $newContent   = '';
757
-                $tokenContent = $token['content'];
758
-
759
-                $endContent = null;
760
-                if (isset($this->commentTokens[$tokenContent]) === true) {
761
-                    $endContent = $this->commentTokens[$tokenContent];
762
-                }
763
-
764
-                while ($tokenContent !== $endContent) {
765
-                    if ($endContent === null
766
-                        && strpos($tokenContent, $this->eolChar) !== false
767
-                    ) {
768
-                        // A null end token means the comment ends at the end of
769
-                        // the line so we look for newlines and split the token.
770
-                        $tokens[$stackPtr]['content'] = substr(
771
-                            $tokenContent,
772
-                            (strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
773
-                        );
774
-
775
-                        $tokenContent = substr(
776
-                            $tokenContent,
777
-                            0,
778
-                            (strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
779
-                        );
780
-
781
-                        // If the substr failed, skip the token as the content
782
-                        // will now be blank.
783
-                        if ($tokens[$stackPtr]['content'] !== false
784
-                            && $tokens[$stackPtr]['content'] !== ''
785
-                        ) {
786
-                            $stackPtr--;
787
-                        }
788
-
789
-                        break;
790
-                    }//end if
791
-
792
-                    $stackPtr++;
793
-                    $newContent .= $tokenContent;
794
-                    if (isset($tokens[$stackPtr]) === false) {
795
-                        break;
796
-                    }
797
-
798
-                    $tokenContent = $tokens[$stackPtr]['content'];
799
-                }//end while
800
-
801
-                if ($token['code'] === T_DOC_COMMENT) {
802
-                    $commentTokens = $commentTokenizer->tokenizeString($newContent.$tokenContent, $this->eolChar, $newStackPtr);
803
-                    foreach ($commentTokens as $commentToken) {
804
-                        $finalTokens[$newStackPtr] = $commentToken;
805
-                        $newStackPtr++;
806
-                    }
807
-
808
-                    continue;
809
-                } else {
810
-                    // Save the new content in the current token so
811
-                    // the code below can chop it up on newlines.
812
-                    $token['content'] = $newContent.$tokenContent;
813
-                }
814
-            }//end if
815
-
816
-            /*
755
+			if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT) {
756
+				$newContent   = '';
757
+				$tokenContent = $token['content'];
758
+
759
+				$endContent = null;
760
+				if (isset($this->commentTokens[$tokenContent]) === true) {
761
+					$endContent = $this->commentTokens[$tokenContent];
762
+				}
763
+
764
+				while ($tokenContent !== $endContent) {
765
+					if ($endContent === null
766
+						&& strpos($tokenContent, $this->eolChar) !== false
767
+					) {
768
+						// A null end token means the comment ends at the end of
769
+						// the line so we look for newlines and split the token.
770
+						$tokens[$stackPtr]['content'] = substr(
771
+							$tokenContent,
772
+							(strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
773
+						);
774
+
775
+						$tokenContent = substr(
776
+							$tokenContent,
777
+							0,
778
+							(strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
779
+						);
780
+
781
+						// If the substr failed, skip the token as the content
782
+						// will now be blank.
783
+						if ($tokens[$stackPtr]['content'] !== false
784
+							&& $tokens[$stackPtr]['content'] !== ''
785
+						) {
786
+							$stackPtr--;
787
+						}
788
+
789
+						break;
790
+					}//end if
791
+
792
+					$stackPtr++;
793
+					$newContent .= $tokenContent;
794
+					if (isset($tokens[$stackPtr]) === false) {
795
+						break;
796
+					}
797
+
798
+					$tokenContent = $tokens[$stackPtr]['content'];
799
+				}//end while
800
+
801
+				if ($token['code'] === T_DOC_COMMENT) {
802
+					$commentTokens = $commentTokenizer->tokenizeString($newContent.$tokenContent, $this->eolChar, $newStackPtr);
803
+					foreach ($commentTokens as $commentToken) {
804
+						$finalTokens[$newStackPtr] = $commentToken;
805
+						$newStackPtr++;
806
+					}
807
+
808
+					continue;
809
+				} else {
810
+					// Save the new content in the current token so
811
+					// the code below can chop it up on newlines.
812
+					$token['content'] = $newContent.$tokenContent;
813
+				}
814
+			}//end if
815
+
816
+			/*
817 817
                 If this token has newlines in its content, split each line up
818 818
                 and create a new token for each line. We do this so it's easier
819 819
                 to ascertain where errors occur on a line.
820 820
                 Note that $token[1] is the token's content.
821 821
             */
822 822
 
823
-            if (strpos($token['content'], $this->eolChar) !== false) {
824
-                $tokenLines = explode($this->eolChar, $token['content']);
825
-                $numLines   = count($tokenLines);
826
-
827
-                for ($i = 0; $i < $numLines; $i++) {
828
-                    $newToken = ['content' => $tokenLines[$i]];
829
-                    if ($i === ($numLines - 1)) {
830
-                        if ($tokenLines[$i] === '') {
831
-                            break;
832
-                        }
833
-                    } else {
834
-                        $newToken['content'] .= $this->eolChar;
835
-                    }
836
-
837
-                    $newToken['type']          = $token['type'];
838
-                    $newToken['code']          = $token['code'];
839
-                    $finalTokens[$newStackPtr] = $newToken;
840
-                    $newStackPtr++;
841
-                }
842
-            } else {
843
-                $finalTokens[$newStackPtr] = $token;
844
-                $newStackPtr++;
845
-            }//end if
846
-
847
-            // Convert numbers, including decimals.
848
-            if ($token['code'] === T_STRING
849
-                || $token['code'] === T_OBJECT_OPERATOR
850
-            ) {
851
-                $newContent  = '';
852
-                $oldStackPtr = $stackPtr;
853
-                while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) {
854
-                    $newContent .= $tokens[$stackPtr]['content'];
855
-                    $stackPtr++;
856
-                }
857
-
858
-                if ($newContent !== '' && $newContent !== '.') {
859
-                    $finalTokens[($newStackPtr - 1)]['content'] = $newContent;
860
-                    if (ctype_digit($newContent) === true) {
861
-                        $finalTokens[($newStackPtr - 1)]['code'] = constant('T_LNUMBER');
862
-                        $finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER';
863
-                    } else {
864
-                        $finalTokens[($newStackPtr - 1)]['code'] = constant('T_DNUMBER');
865
-                        $finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER';
866
-                    }
867
-
868
-                    $stackPtr--;
869
-                    continue;
870
-                } else {
871
-                    $stackPtr = $oldStackPtr;
872
-                }
873
-            }//end if
874
-
875
-            // Convert the token after an object operator into a string, in most cases.
876
-            if ($token['code'] === T_OBJECT_OPERATOR) {
877
-                for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
878
-                    if (isset(Util\Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
879
-                        continue;
880
-                    }
881
-
882
-                    if ($tokens[$i]['code'] !== T_PROTOTYPE
883
-                        && $tokens[$i]['code'] !== T_LNUMBER
884
-                        && $tokens[$i]['code'] !== T_DNUMBER
885
-                    ) {
886
-                        $tokens[$i]['code'] = T_STRING;
887
-                        $tokens[$i]['type'] = 'T_STRING';
888
-                    }
889
-
890
-                    break;
891
-                }
892
-            }
893
-        }//end for
894
-
895
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
896
-            echo "\t*** END TOKENIZING ***".PHP_EOL;
897
-        }
898
-
899
-        return $finalTokens;
900
-
901
-    }//end tokenize()
902
-
903
-
904
-    /**
905
-     * Tokenizes a regular expression if one is found.
906
-     *
907
-     * If a regular expression is not found, NULL is returned.
908
-     *
909
-     * @param string $char   The index of the possible regex start character.
910
-     * @param string $string The complete content of the string being tokenized.
911
-     * @param string $chars  An array of characters being tokenized.
912
-     * @param string $tokens The current array of tokens found in the string.
913
-     *
914
-     * @return array<string, string>|null
915
-     */
916
-    public function getRegexToken($char, $string, $chars, $tokens)
917
-    {
918
-        $beforeTokens = [
919
-            T_EQUAL               => true,
920
-            T_IS_NOT_EQUAL        => true,
921
-            T_IS_IDENTICAL        => true,
922
-            T_IS_NOT_IDENTICAL    => true,
923
-            T_OPEN_PARENTHESIS    => true,
924
-            T_OPEN_SQUARE_BRACKET => true,
925
-            T_RETURN              => true,
926
-            T_BOOLEAN_OR          => true,
927
-            T_BOOLEAN_AND         => true,
928
-            T_BOOLEAN_NOT         => true,
929
-            T_BITWISE_OR          => true,
930
-            T_BITWISE_AND         => true,
931
-            T_COMMA               => true,
932
-            T_COLON               => true,
933
-            T_TYPEOF              => true,
934
-            T_INLINE_THEN         => true,
935
-            T_INLINE_ELSE         => true,
936
-        ];
937
-
938
-        $afterTokens = [
939
-            ','            => true,
940
-            ')'            => true,
941
-            ']'            => true,
942
-            ';'            => true,
943
-            ' '            => true,
944
-            '.'            => true,
945
-            ':'            => true,
946
-            $this->eolChar => true,
947
-        ];
948
-
949
-        // Find the last non-whitespace token that was added
950
-        // to the tokens array.
951
-        $numTokens = count($tokens);
952
-        for ($prev = ($numTokens - 1); $prev >= 0; $prev--) {
953
-            if (isset(Util\Tokens::$emptyTokens[$tokens[$prev]['code']]) === false) {
954
-                break;
955
-            }
956
-        }
957
-
958
-        if (isset($beforeTokens[$tokens[$prev]['code']]) === false) {
959
-            return null;
960
-        }
961
-
962
-        // This is probably a regular expression, so look for the end of it.
963
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
964
-            echo "\t* token possibly starts a regular expression *".PHP_EOL;
965
-        }
966
-
967
-        $numChars = count($chars);
968
-        for ($next = ($char + 1); $next < $numChars; $next++) {
969
-            if ($chars[$next] === '/') {
970
-                // Just make sure this is not escaped first.
971
-                if ($chars[($next - 1)] !== '\\') {
972
-                    // In the simple form: /.../ so we found the end.
973
-                    break;
974
-                } else if ($chars[($next - 2)] === '\\') {
975
-                    // In the form: /...\\/ so we found the end.
976
-                    break;
977
-                }
978
-            } else {
979
-                $possibleEolChar = substr($string, $next, strlen($this->eolChar));
980
-                if ($possibleEolChar === $this->eolChar) {
981
-                    // This is the last token on the line and regular
982
-                    // expressions need to be defined on a single line,
983
-                    // so this is not a regular expression.
984
-                    break;
985
-                }
986
-            }
987
-        }
988
-
989
-        if ($chars[$next] !== '/') {
990
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
991
-                echo "\t* could not find end of regular expression *".PHP_EOL;
992
-            }
993
-
994
-            return null;
995
-        }
996
-
997
-        while (preg_match('|[a-zA-Z]|', $chars[($next + 1)]) !== 0) {
998
-            // The token directly after the end of the regex can
999
-            // be modifiers like global and case insensitive
1000
-            // (.e.g, /pattern/gi).
1001
-            $next++;
1002
-        }
1003
-
1004
-        $regexEnd = $next;
1005
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1006
-            echo "\t* found end of regular expression at token $regexEnd *".PHP_EOL;
1007
-        }
1008
-
1009
-        for ($next += 1; $next < $numChars; $next++) {
1010
-            if ($chars[$next] !== ' ') {
1011
-                break;
1012
-            } else {
1013
-                $possibleEolChar = substr($string, $next, strlen($this->eolChar));
1014
-                if ($possibleEolChar === $this->eolChar) {
1015
-                    // This is the last token on the line.
1016
-                    break;
1017
-                }
1018
-            }
1019
-        }
1020
-
1021
-        if (isset($afterTokens[$chars[$next]]) === false) {
1022
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1023
-                echo "\t* tokens after regular expression do not look correct *".PHP_EOL;
1024
-            }
1025
-
1026
-            return null;
1027
-        }
1028
-
1029
-        // This is a regular expression, so join all the tokens together.
1030
-        $content = '';
1031
-        for ($x = $char; $x <= $regexEnd; $x++) {
1032
-            $content .= $chars[$x];
1033
-        }
1034
-
1035
-        $token = [
1036
-            'start'   => $char,
1037
-            'end'     => $regexEnd,
1038
-            'content' => $content,
1039
-        ];
1040
-
1041
-        return $token;
1042
-
1043
-    }//end getRegexToken()
1044
-
1045
-
1046
-    /**
1047
-     * Performs additional processing after main tokenizing.
1048
-     *
1049
-     * This additional processing looks for properties, closures, labels and objects.
1050
-     *
1051
-     * @return void
1052
-     */
1053
-    public function processAdditional()
1054
-    {
1055
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1056
-            echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL;
1057
-        }
1058
-
1059
-        $numTokens  = count($this->tokens);
1060
-        $classStack = [];
1061
-
1062
-        for ($i = 0; $i < $numTokens; $i++) {
1063
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1064
-                $type    = $this->tokens[$i]['type'];
1065
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1066
-
1067
-                echo str_repeat("\t", count($classStack));
1068
-                echo "\tProcess token $i: $type => $content".PHP_EOL;
1069
-            }
1070
-
1071
-            // Looking for functions that are actually closures.
1072
-            if ($this->tokens[$i]['code'] === T_FUNCTION && isset($this->tokens[$i]['scope_opener']) === true) {
1073
-                for ($x = ($i + 1); $x < $numTokens; $x++) {
1074
-                    if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
1075
-                        break;
1076
-                    }
1077
-                }
1078
-
1079
-                if ($this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) {
1080
-                    $this->tokens[$i]['code'] = T_CLOSURE;
1081
-                    $this->tokens[$i]['type'] = 'T_CLOSURE';
1082
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1083
-                        $line = $this->tokens[$i]['line'];
1084
-                        echo str_repeat("\t", count($classStack));
1085
-                        echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE *".PHP_EOL;
1086
-                    }
1087
-
1088
-                    for ($x = ($this->tokens[$i]['scope_opener'] + 1); $x < $this->tokens[$i]['scope_closer']; $x++) {
1089
-                        if (isset($this->tokens[$x]['conditions'][$i]) === false) {
1090
-                            continue;
1091
-                        }
1092
-
1093
-                        $this->tokens[$x]['conditions'][$i] = T_CLOSURE;
1094
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1095
-                            $type = $this->tokens[$x]['type'];
1096
-                            echo str_repeat("\t", count($classStack));
1097
-                            echo "\t\t* cleaned $x ($type) *".PHP_EOL;
1098
-                        }
1099
-                    }
1100
-                }//end if
1101
-
1102
-                continue;
1103
-            } else if ($this->tokens[$i]['code'] === T_OPEN_CURLY_BRACKET
1104
-                && isset($this->tokens[$i]['scope_condition']) === false
1105
-                && isset($this->tokens[$i]['bracket_closer']) === true
1106
-            ) {
1107
-                $condition = $this->tokens[$i]['conditions'];
1108
-                $condition = end($condition);
1109
-                if ($condition === T_CLASS) {
1110
-                    // Possibly an ES6 method. To be classified as one, the previous
1111
-                    // non-empty tokens need to be a set of parenthesis, and then a string
1112
-                    // (the method name).
1113
-                    for ($parenCloser = ($i - 1); $parenCloser > 0; $parenCloser--) {
1114
-                        if (isset(Util\Tokens::$emptyTokens[$this->tokens[$parenCloser]['code']]) === false) {
1115
-                            break;
1116
-                        }
1117
-                    }
1118
-
1119
-                    if ($this->tokens[$parenCloser]['code'] === T_CLOSE_PARENTHESIS) {
1120
-                        $parenOpener = $this->tokens[$parenCloser]['parenthesis_opener'];
1121
-                        for ($name = ($parenOpener - 1); $name > 0; $name--) {
1122
-                            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$name]['code']]) === false) {
1123
-                                break;
1124
-                            }
1125
-                        }
1126
-
1127
-                        if ($this->tokens[$name]['code'] === T_STRING) {
1128
-                            // We found a method name.
1129
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1130
-                                $line = $this->tokens[$name]['line'];
1131
-                                echo str_repeat("\t", count($classStack));
1132
-                                echo "\t* token $name on line $line changed from T_STRING to T_FUNCTION *".PHP_EOL;
1133
-                            }
1134
-
1135
-                            $closer = $this->tokens[$i]['bracket_closer'];
1136
-
1137
-                            $this->tokens[$name]['code'] = T_FUNCTION;
1138
-                            $this->tokens[$name]['type'] = 'T_FUNCTION';
1139
-
1140
-                            foreach ([$name, $i, $closer] as $token) {
1141
-                                $this->tokens[$token]['scope_condition']    = $name;
1142
-                                $this->tokens[$token]['scope_opener']       = $i;
1143
-                                $this->tokens[$token]['scope_closer']       = $closer;
1144
-                                $this->tokens[$token]['parenthesis_opener'] = $parenOpener;
1145
-                                $this->tokens[$token]['parenthesis_closer'] = $parenCloser;
1146
-                                $this->tokens[$token]['parenthesis_owner']  = $name;
1147
-                            }
1148
-
1149
-                            $this->tokens[$parenOpener]['parenthesis_owner'] = $name;
1150
-                            $this->tokens[$parenCloser]['parenthesis_owner'] = $name;
1151
-
1152
-                            for ($x = ($i + 1); $x < $closer; $x++) {
1153
-                                $this->tokens[$x]['conditions'][$name] = T_FUNCTION;
1154
-                                ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1155
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1156
-                                    $type = $this->tokens[$x]['type'];
1157
-                                    echo str_repeat("\t", count($classStack));
1158
-                                    echo "\t\t* added T_FUNCTION condition to $x ($type) *".PHP_EOL;
1159
-                                }
1160
-                            }
1161
-
1162
-                            continue;
1163
-                        }//end if
1164
-                    }//end if
1165
-                }//end if
1166
-
1167
-                $classStack[] = $i;
1168
-
1169
-                $closer = $this->tokens[$i]['bracket_closer'];
1170
-                $this->tokens[$i]['code']      = T_OBJECT;
1171
-                $this->tokens[$i]['type']      = 'T_OBJECT';
1172
-                $this->tokens[$closer]['code'] = T_CLOSE_OBJECT;
1173
-                $this->tokens[$closer]['type'] = 'T_CLOSE_OBJECT';
1174
-
1175
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1176
-                    echo str_repeat("\t", count($classStack));
1177
-                    echo "\t* token $i converted from T_OPEN_CURLY_BRACKET to T_OBJECT *".PHP_EOL;
1178
-                    echo str_repeat("\t", count($classStack));
1179
-                    echo "\t* token $closer converted from T_CLOSE_CURLY_BRACKET to T_CLOSE_OBJECT *".PHP_EOL;
1180
-                }
1181
-
1182
-                for ($x = ($i + 1); $x < $closer; $x++) {
1183
-                    $this->tokens[$x]['conditions'][$i] = T_OBJECT;
1184
-                    ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1185
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1186
-                        $type = $this->tokens[$x]['type'];
1187
-                        echo str_repeat("\t", count($classStack));
1188
-                        echo "\t\t* added T_OBJECT condition to $x ($type) *".PHP_EOL;
1189
-                    }
1190
-                }
1191
-            } else if ($this->tokens[$i]['code'] === T_CLOSE_OBJECT) {
1192
-                $opener = array_pop($classStack);
1193
-            } else if ($this->tokens[$i]['code'] === T_COLON) {
1194
-                // If it is a scope opener, it belongs to a
1195
-                // DEFAULT or CASE statement.
1196
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
1197
-                    continue;
1198
-                }
1199
-
1200
-                // Make sure this is not part of an inline IF statement.
1201
-                for ($x = ($i - 1); $x >= 0; $x--) {
1202
-                    if ($this->tokens[$x]['code'] === T_INLINE_THEN) {
1203
-                        $this->tokens[$i]['code'] = T_INLINE_ELSE;
1204
-                        $this->tokens[$i]['type'] = 'T_INLINE_ELSE';
1205
-
1206
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1207
-                            echo str_repeat("\t", count($classStack));
1208
-                            echo "\t* token $i converted from T_COLON to T_INLINE_THEN *".PHP_EOL;
1209
-                        }
1210
-
1211
-                        continue(2);
1212
-                    } else if ($this->tokens[$x]['line'] < $this->tokens[$i]['line']) {
1213
-                        break;
1214
-                    }
1215
-                }
1216
-
1217
-                // The string to the left of the colon is either a property or label.
1218
-                for ($label = ($i - 1); $label >= 0; $label--) {
1219
-                    if (isset(Util\Tokens::$emptyTokens[$this->tokens[$label]['code']]) === false) {
1220
-                        break;
1221
-                    }
1222
-                }
1223
-
1224
-                if ($this->tokens[$label]['code'] !== T_STRING
1225
-                    && $this->tokens[$label]['code'] !== T_CONSTANT_ENCAPSED_STRING
1226
-                ) {
1227
-                    continue;
1228
-                }
1229
-
1230
-                if (empty($classStack) === false) {
1231
-                    $this->tokens[$label]['code'] = T_PROPERTY;
1232
-                    $this->tokens[$label]['type'] = 'T_PROPERTY';
1233
-
1234
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1235
-                        echo str_repeat("\t", count($classStack));
1236
-                        echo "\t* token $label converted from T_STRING to T_PROPERTY *".PHP_EOL;
1237
-                    }
1238
-                } else {
1239
-                    $this->tokens[$label]['code'] = T_LABEL;
1240
-                    $this->tokens[$label]['type'] = 'T_LABEL';
1241
-
1242
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1243
-                        echo str_repeat("\t", count($classStack));
1244
-                        echo "\t* token $label converted from T_STRING to T_LABEL *".PHP_EOL;
1245
-                    }
1246
-                }//end if
1247
-            }//end if
1248
-        }//end for
1249
-
1250
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
-            echo "\t*** END ADDITIONAL JS PROCESSING ***".PHP_EOL;
1252
-        }
1253
-
1254
-    }//end processAdditional()
823
+			if (strpos($token['content'], $this->eolChar) !== false) {
824
+				$tokenLines = explode($this->eolChar, $token['content']);
825
+				$numLines   = count($tokenLines);
826
+
827
+				for ($i = 0; $i < $numLines; $i++) {
828
+					$newToken = ['content' => $tokenLines[$i]];
829
+					if ($i === ($numLines - 1)) {
830
+						if ($tokenLines[$i] === '') {
831
+							break;
832
+						}
833
+					} else {
834
+						$newToken['content'] .= $this->eolChar;
835
+					}
836
+
837
+					$newToken['type']          = $token['type'];
838
+					$newToken['code']          = $token['code'];
839
+					$finalTokens[$newStackPtr] = $newToken;
840
+					$newStackPtr++;
841
+				}
842
+			} else {
843
+				$finalTokens[$newStackPtr] = $token;
844
+				$newStackPtr++;
845
+			}//end if
846
+
847
+			// Convert numbers, including decimals.
848
+			if ($token['code'] === T_STRING
849
+				|| $token['code'] === T_OBJECT_OPERATOR
850
+			) {
851
+				$newContent  = '';
852
+				$oldStackPtr = $stackPtr;
853
+				while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) {
854
+					$newContent .= $tokens[$stackPtr]['content'];
855
+					$stackPtr++;
856
+				}
857
+
858
+				if ($newContent !== '' && $newContent !== '.') {
859
+					$finalTokens[($newStackPtr - 1)]['content'] = $newContent;
860
+					if (ctype_digit($newContent) === true) {
861
+						$finalTokens[($newStackPtr - 1)]['code'] = constant('T_LNUMBER');
862
+						$finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER';
863
+					} else {
864
+						$finalTokens[($newStackPtr - 1)]['code'] = constant('T_DNUMBER');
865
+						$finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER';
866
+					}
867
+
868
+					$stackPtr--;
869
+					continue;
870
+				} else {
871
+					$stackPtr = $oldStackPtr;
872
+				}
873
+			}//end if
874
+
875
+			// Convert the token after an object operator into a string, in most cases.
876
+			if ($token['code'] === T_OBJECT_OPERATOR) {
877
+				for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
878
+					if (isset(Util\Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
879
+						continue;
880
+					}
881
+
882
+					if ($tokens[$i]['code'] !== T_PROTOTYPE
883
+						&& $tokens[$i]['code'] !== T_LNUMBER
884
+						&& $tokens[$i]['code'] !== T_DNUMBER
885
+					) {
886
+						$tokens[$i]['code'] = T_STRING;
887
+						$tokens[$i]['type'] = 'T_STRING';
888
+					}
889
+
890
+					break;
891
+				}
892
+			}
893
+		}//end for
894
+
895
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
896
+			echo "\t*** END TOKENIZING ***".PHP_EOL;
897
+		}
898
+
899
+		return $finalTokens;
900
+
901
+	}//end tokenize()
902
+
903
+
904
+	/**
905
+	 * Tokenizes a regular expression if one is found.
906
+	 *
907
+	 * If a regular expression is not found, NULL is returned.
908
+	 *
909
+	 * @param string $char   The index of the possible regex start character.
910
+	 * @param string $string The complete content of the string being tokenized.
911
+	 * @param string $chars  An array of characters being tokenized.
912
+	 * @param string $tokens The current array of tokens found in the string.
913
+	 *
914
+	 * @return array<string, string>|null
915
+	 */
916
+	public function getRegexToken($char, $string, $chars, $tokens)
917
+	{
918
+		$beforeTokens = [
919
+			T_EQUAL               => true,
920
+			T_IS_NOT_EQUAL        => true,
921
+			T_IS_IDENTICAL        => true,
922
+			T_IS_NOT_IDENTICAL    => true,
923
+			T_OPEN_PARENTHESIS    => true,
924
+			T_OPEN_SQUARE_BRACKET => true,
925
+			T_RETURN              => true,
926
+			T_BOOLEAN_OR          => true,
927
+			T_BOOLEAN_AND         => true,
928
+			T_BOOLEAN_NOT         => true,
929
+			T_BITWISE_OR          => true,
930
+			T_BITWISE_AND         => true,
931
+			T_COMMA               => true,
932
+			T_COLON               => true,
933
+			T_TYPEOF              => true,
934
+			T_INLINE_THEN         => true,
935
+			T_INLINE_ELSE         => true,
936
+		];
937
+
938
+		$afterTokens = [
939
+			','            => true,
940
+			')'            => true,
941
+			']'            => true,
942
+			';'            => true,
943
+			' '            => true,
944
+			'.'            => true,
945
+			':'            => true,
946
+			$this->eolChar => true,
947
+		];
948
+
949
+		// Find the last non-whitespace token that was added
950
+		// to the tokens array.
951
+		$numTokens = count($tokens);
952
+		for ($prev = ($numTokens - 1); $prev >= 0; $prev--) {
953
+			if (isset(Util\Tokens::$emptyTokens[$tokens[$prev]['code']]) === false) {
954
+				break;
955
+			}
956
+		}
957
+
958
+		if (isset($beforeTokens[$tokens[$prev]['code']]) === false) {
959
+			return null;
960
+		}
961
+
962
+		// This is probably a regular expression, so look for the end of it.
963
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
964
+			echo "\t* token possibly starts a regular expression *".PHP_EOL;
965
+		}
966
+
967
+		$numChars = count($chars);
968
+		for ($next = ($char + 1); $next < $numChars; $next++) {
969
+			if ($chars[$next] === '/') {
970
+				// Just make sure this is not escaped first.
971
+				if ($chars[($next - 1)] !== '\\') {
972
+					// In the simple form: /.../ so we found the end.
973
+					break;
974
+				} else if ($chars[($next - 2)] === '\\') {
975
+					// In the form: /...\\/ so we found the end.
976
+					break;
977
+				}
978
+			} else {
979
+				$possibleEolChar = substr($string, $next, strlen($this->eolChar));
980
+				if ($possibleEolChar === $this->eolChar) {
981
+					// This is the last token on the line and regular
982
+					// expressions need to be defined on a single line,
983
+					// so this is not a regular expression.
984
+					break;
985
+				}
986
+			}
987
+		}
988
+
989
+		if ($chars[$next] !== '/') {
990
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
991
+				echo "\t* could not find end of regular expression *".PHP_EOL;
992
+			}
993
+
994
+			return null;
995
+		}
996
+
997
+		while (preg_match('|[a-zA-Z]|', $chars[($next + 1)]) !== 0) {
998
+			// The token directly after the end of the regex can
999
+			// be modifiers like global and case insensitive
1000
+			// (.e.g, /pattern/gi).
1001
+			$next++;
1002
+		}
1003
+
1004
+		$regexEnd = $next;
1005
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
1006
+			echo "\t* found end of regular expression at token $regexEnd *".PHP_EOL;
1007
+		}
1008
+
1009
+		for ($next += 1; $next < $numChars; $next++) {
1010
+			if ($chars[$next] !== ' ') {
1011
+				break;
1012
+			} else {
1013
+				$possibleEolChar = substr($string, $next, strlen($this->eolChar));
1014
+				if ($possibleEolChar === $this->eolChar) {
1015
+					// This is the last token on the line.
1016
+					break;
1017
+				}
1018
+			}
1019
+		}
1020
+
1021
+		if (isset($afterTokens[$chars[$next]]) === false) {
1022
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
1023
+				echo "\t* tokens after regular expression do not look correct *".PHP_EOL;
1024
+			}
1025
+
1026
+			return null;
1027
+		}
1028
+
1029
+		// This is a regular expression, so join all the tokens together.
1030
+		$content = '';
1031
+		for ($x = $char; $x <= $regexEnd; $x++) {
1032
+			$content .= $chars[$x];
1033
+		}
1034
+
1035
+		$token = [
1036
+			'start'   => $char,
1037
+			'end'     => $regexEnd,
1038
+			'content' => $content,
1039
+		];
1040
+
1041
+		return $token;
1042
+
1043
+	}//end getRegexToken()
1044
+
1045
+
1046
+	/**
1047
+	 * Performs additional processing after main tokenizing.
1048
+	 *
1049
+	 * This additional processing looks for properties, closures, labels and objects.
1050
+	 *
1051
+	 * @return void
1052
+	 */
1053
+	public function processAdditional()
1054
+	{
1055
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
1056
+			echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL;
1057
+		}
1058
+
1059
+		$numTokens  = count($this->tokens);
1060
+		$classStack = [];
1061
+
1062
+		for ($i = 0; $i < $numTokens; $i++) {
1063
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
1064
+				$type    = $this->tokens[$i]['type'];
1065
+				$content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1066
+
1067
+				echo str_repeat("\t", count($classStack));
1068
+				echo "\tProcess token $i: $type => $content".PHP_EOL;
1069
+			}
1070
+
1071
+			// Looking for functions that are actually closures.
1072
+			if ($this->tokens[$i]['code'] === T_FUNCTION && isset($this->tokens[$i]['scope_opener']) === true) {
1073
+				for ($x = ($i + 1); $x < $numTokens; $x++) {
1074
+					if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
1075
+						break;
1076
+					}
1077
+				}
1078
+
1079
+				if ($this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) {
1080
+					$this->tokens[$i]['code'] = T_CLOSURE;
1081
+					$this->tokens[$i]['type'] = 'T_CLOSURE';
1082
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1083
+						$line = $this->tokens[$i]['line'];
1084
+						echo str_repeat("\t", count($classStack));
1085
+						echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE *".PHP_EOL;
1086
+					}
1087
+
1088
+					for ($x = ($this->tokens[$i]['scope_opener'] + 1); $x < $this->tokens[$i]['scope_closer']; $x++) {
1089
+						if (isset($this->tokens[$x]['conditions'][$i]) === false) {
1090
+							continue;
1091
+						}
1092
+
1093
+						$this->tokens[$x]['conditions'][$i] = T_CLOSURE;
1094
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1095
+							$type = $this->tokens[$x]['type'];
1096
+							echo str_repeat("\t", count($classStack));
1097
+							echo "\t\t* cleaned $x ($type) *".PHP_EOL;
1098
+						}
1099
+					}
1100
+				}//end if
1101
+
1102
+				continue;
1103
+			} else if ($this->tokens[$i]['code'] === T_OPEN_CURLY_BRACKET
1104
+				&& isset($this->tokens[$i]['scope_condition']) === false
1105
+				&& isset($this->tokens[$i]['bracket_closer']) === true
1106
+			) {
1107
+				$condition = $this->tokens[$i]['conditions'];
1108
+				$condition = end($condition);
1109
+				if ($condition === T_CLASS) {
1110
+					// Possibly an ES6 method. To be classified as one, the previous
1111
+					// non-empty tokens need to be a set of parenthesis, and then a string
1112
+					// (the method name).
1113
+					for ($parenCloser = ($i - 1); $parenCloser > 0; $parenCloser--) {
1114
+						if (isset(Util\Tokens::$emptyTokens[$this->tokens[$parenCloser]['code']]) === false) {
1115
+							break;
1116
+						}
1117
+					}
1118
+
1119
+					if ($this->tokens[$parenCloser]['code'] === T_CLOSE_PARENTHESIS) {
1120
+						$parenOpener = $this->tokens[$parenCloser]['parenthesis_opener'];
1121
+						for ($name = ($parenOpener - 1); $name > 0; $name--) {
1122
+							if (isset(Util\Tokens::$emptyTokens[$this->tokens[$name]['code']]) === false) {
1123
+								break;
1124
+							}
1125
+						}
1126
+
1127
+						if ($this->tokens[$name]['code'] === T_STRING) {
1128
+							// We found a method name.
1129
+							if (PHP_CODESNIFFER_VERBOSITY > 1) {
1130
+								$line = $this->tokens[$name]['line'];
1131
+								echo str_repeat("\t", count($classStack));
1132
+								echo "\t* token $name on line $line changed from T_STRING to T_FUNCTION *".PHP_EOL;
1133
+							}
1134
+
1135
+							$closer = $this->tokens[$i]['bracket_closer'];
1136
+
1137
+							$this->tokens[$name]['code'] = T_FUNCTION;
1138
+							$this->tokens[$name]['type'] = 'T_FUNCTION';
1139
+
1140
+							foreach ([$name, $i, $closer] as $token) {
1141
+								$this->tokens[$token]['scope_condition']    = $name;
1142
+								$this->tokens[$token]['scope_opener']       = $i;
1143
+								$this->tokens[$token]['scope_closer']       = $closer;
1144
+								$this->tokens[$token]['parenthesis_opener'] = $parenOpener;
1145
+								$this->tokens[$token]['parenthesis_closer'] = $parenCloser;
1146
+								$this->tokens[$token]['parenthesis_owner']  = $name;
1147
+							}
1148
+
1149
+							$this->tokens[$parenOpener]['parenthesis_owner'] = $name;
1150
+							$this->tokens[$parenCloser]['parenthesis_owner'] = $name;
1151
+
1152
+							for ($x = ($i + 1); $x < $closer; $x++) {
1153
+								$this->tokens[$x]['conditions'][$name] = T_FUNCTION;
1154
+								ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1155
+								if (PHP_CODESNIFFER_VERBOSITY > 1) {
1156
+									$type = $this->tokens[$x]['type'];
1157
+									echo str_repeat("\t", count($classStack));
1158
+									echo "\t\t* added T_FUNCTION condition to $x ($type) *".PHP_EOL;
1159
+								}
1160
+							}
1161
+
1162
+							continue;
1163
+						}//end if
1164
+					}//end if
1165
+				}//end if
1166
+
1167
+				$classStack[] = $i;
1168
+
1169
+				$closer = $this->tokens[$i]['bracket_closer'];
1170
+				$this->tokens[$i]['code']      = T_OBJECT;
1171
+				$this->tokens[$i]['type']      = 'T_OBJECT';
1172
+				$this->tokens[$closer]['code'] = T_CLOSE_OBJECT;
1173
+				$this->tokens[$closer]['type'] = 'T_CLOSE_OBJECT';
1174
+
1175
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1176
+					echo str_repeat("\t", count($classStack));
1177
+					echo "\t* token $i converted from T_OPEN_CURLY_BRACKET to T_OBJECT *".PHP_EOL;
1178
+					echo str_repeat("\t", count($classStack));
1179
+					echo "\t* token $closer converted from T_CLOSE_CURLY_BRACKET to T_CLOSE_OBJECT *".PHP_EOL;
1180
+				}
1181
+
1182
+				for ($x = ($i + 1); $x < $closer; $x++) {
1183
+					$this->tokens[$x]['conditions'][$i] = T_OBJECT;
1184
+					ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1185
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1186
+						$type = $this->tokens[$x]['type'];
1187
+						echo str_repeat("\t", count($classStack));
1188
+						echo "\t\t* added T_OBJECT condition to $x ($type) *".PHP_EOL;
1189
+					}
1190
+				}
1191
+			} else if ($this->tokens[$i]['code'] === T_CLOSE_OBJECT) {
1192
+				$opener = array_pop($classStack);
1193
+			} else if ($this->tokens[$i]['code'] === T_COLON) {
1194
+				// If it is a scope opener, it belongs to a
1195
+				// DEFAULT or CASE statement.
1196
+				if (isset($this->tokens[$i]['scope_condition']) === true) {
1197
+					continue;
1198
+				}
1199
+
1200
+				// Make sure this is not part of an inline IF statement.
1201
+				for ($x = ($i - 1); $x >= 0; $x--) {
1202
+					if ($this->tokens[$x]['code'] === T_INLINE_THEN) {
1203
+						$this->tokens[$i]['code'] = T_INLINE_ELSE;
1204
+						$this->tokens[$i]['type'] = 'T_INLINE_ELSE';
1205
+
1206
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1207
+							echo str_repeat("\t", count($classStack));
1208
+							echo "\t* token $i converted from T_COLON to T_INLINE_THEN *".PHP_EOL;
1209
+						}
1210
+
1211
+						continue(2);
1212
+					} else if ($this->tokens[$x]['line'] < $this->tokens[$i]['line']) {
1213
+						break;
1214
+					}
1215
+				}
1216
+
1217
+				// The string to the left of the colon is either a property or label.
1218
+				for ($label = ($i - 1); $label >= 0; $label--) {
1219
+					if (isset(Util\Tokens::$emptyTokens[$this->tokens[$label]['code']]) === false) {
1220
+						break;
1221
+					}
1222
+				}
1223
+
1224
+				if ($this->tokens[$label]['code'] !== T_STRING
1225
+					&& $this->tokens[$label]['code'] !== T_CONSTANT_ENCAPSED_STRING
1226
+				) {
1227
+					continue;
1228
+				}
1229
+
1230
+				if (empty($classStack) === false) {
1231
+					$this->tokens[$label]['code'] = T_PROPERTY;
1232
+					$this->tokens[$label]['type'] = 'T_PROPERTY';
1233
+
1234
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1235
+						echo str_repeat("\t", count($classStack));
1236
+						echo "\t* token $label converted from T_STRING to T_PROPERTY *".PHP_EOL;
1237
+					}
1238
+				} else {
1239
+					$this->tokens[$label]['code'] = T_LABEL;
1240
+					$this->tokens[$label]['type'] = 'T_LABEL';
1241
+
1242
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
1243
+						echo str_repeat("\t", count($classStack));
1244
+						echo "\t* token $label converted from T_STRING to T_LABEL *".PHP_EOL;
1245
+					}
1246
+				}//end if
1247
+			}//end if
1248
+		}//end for
1249
+
1250
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
+			echo "\t*** END ADDITIONAL JS PROCESSING ***".PHP_EOL;
1252
+		}
1253
+
1254
+	}//end processAdditional()
1255 1255
 
1256 1256
 
1257 1257
 }//end class
Please login to merge, or discard this patch.
Spacing   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -29,77 +29,77 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public $scopeOpeners = [
31 31
         T_IF       => [
32
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
33
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
32
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
33
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
34 34
             'strict' => false,
35 35
             'shared' => false,
36
-            'with'   => [],
36
+            'with'   => [ ],
37 37
         ],
38 38
         T_TRY      => [
39
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
40
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
39
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
40
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
41 41
             'strict' => true,
42 42
             'shared' => false,
43
-            'with'   => [],
43
+            'with'   => [ ],
44 44
         ],
45 45
         T_CATCH    => [
46
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
47
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
46
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
47
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
48 48
             'strict' => true,
49 49
             'shared' => false,
50
-            'with'   => [],
50
+            'with'   => [ ],
51 51
         ],
52 52
         T_ELSE     => [
53
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
54
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
53
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
54
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
55 55
             'strict' => false,
56 56
             'shared' => false,
57
-            'with'   => [],
57
+            'with'   => [ ],
58 58
         ],
59 59
         T_FOR      => [
60
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
61
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
60
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
61
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
62 62
             'strict' => false,
63 63
             'shared' => false,
64
-            'with'   => [],
64
+            'with'   => [ ],
65 65
         ],
66 66
         T_CLASS    => [
67
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
68
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
67
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
68
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
69 69
             'strict' => true,
70 70
             'shared' => false,
71
-            'with'   => [],
71
+            'with'   => [ ],
72 72
         ],
73 73
         T_FUNCTION => [
74
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
75
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
74
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
75
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
76 76
             'strict' => false,
77 77
             'shared' => false,
78
-            'with'   => [],
78
+            'with'   => [ ],
79 79
         ],
80 80
         T_WHILE    => [
81
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
82
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
81
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
82
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
83 83
             'strict' => false,
84 84
             'shared' => false,
85
-            'with'   => [],
85
+            'with'   => [ ],
86 86
         ],
87 87
         T_DO       => [
88
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
89
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
88
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
89
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
90 90
             'strict' => true,
91 91
             'shared' => false,
92
-            'with'   => [],
92
+            'with'   => [ ],
93 93
         ],
94 94
         T_SWITCH   => [
95
-            'start'  => [T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET],
96
-            'end'    => [T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET],
95
+            'start'  => [ T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET ],
96
+            'end'    => [ T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET ],
97 97
             'strict' => true,
98 98
             'shared' => false,
99
-            'with'   => [],
99
+            'with'   => [ ],
100 100
         ],
101 101
         T_CASE     => [
102
-            'start'  => [T_COLON => T_COLON],
102
+            'start'  => [ T_COLON => T_COLON ],
103 103
             'end'    => [
104 104
                 T_BREAK    => T_BREAK,
105 105
                 T_RETURN   => T_RETURN,
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
             ],
116 116
         ],
117 117
         T_DEFAULT  => [
118
-            'start'  => [T_COLON => T_COLON],
118
+            'start'  => [ T_COLON => T_COLON ],
119 119
             'end'    => [
120 120
                 T_BREAK    => T_BREAK,
121 121
                 T_RETURN   => T_RETURN,
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
      * @return void
260 260
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
261 261
      */
262
-    public function __construct($content, Config $config, $eolChar='\n')
262
+    public function __construct( $content, Config $config, $eolChar = '\n' )
263 263
     {
264
-        if ($this->isMinifiedContent($content, $eolChar) === true) {
265
-            throw new TokenizerException('File appears to be minified and cannot be processed');
264
+        if ( $this->isMinifiedContent( $content, $eolChar ) === true ) {
265
+            throw new TokenizerException( 'File appears to be minified and cannot be processed' );
266 266
         }
267 267
 
268
-        parent::__construct($content, $config, $eolChar);
268
+        parent::__construct( $content, $config, $eolChar );
269 269
 
270 270
     }//end __construct()
271 271
 
@@ -277,20 +277,20 @@  discard block
 block discarded – undo
277 277
      *
278 278
      * @return array
279 279
      */
280
-    public function tokenize($string)
280
+    public function tokenize( $string )
281 281
     {
282
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
283
-            echo "\t*** START JS TOKENIZING ***".PHP_EOL;
282
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
283
+            echo "\t*** START JS TOKENIZING ***" . PHP_EOL;
284 284
         }
285 285
 
286 286
         $maxTokenLength = 0;
287
-        foreach ($this->tokenValues as $token => $values) {
288
-            if (strlen($token) > $maxTokenLength) {
289
-                $maxTokenLength = strlen($token);
287
+        foreach ( $this->tokenValues as $token => $values ) {
288
+            if ( strlen( $token ) > $maxTokenLength ) {
289
+                $maxTokenLength = strlen( $token );
290 290
             }
291 291
         }
292 292
 
293
-        $tokens          = [];
293
+        $tokens          = [ ];
294 294
         $inString        = '';
295 295
         $stringChar      = null;
296 296
         $inComment       = '';
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 
301 301
         $commentTokenizer = new Comment();
302 302
 
303
-        $tokens[] = [
303
+        $tokens[ ] = [
304 304
             'code'    => T_OPEN_TAG,
305 305
             'type'    => 'T_OPEN_TAG',
306 306
             'content' => '',
@@ -308,41 +308,41 @@  discard block
 block discarded – undo
308 308
 
309 309
         // Convert newlines to single characters for ease of
310 310
         // processing. We will change them back later.
311
-        $string = str_replace($this->eolChar, "\n", $string);
311
+        $string = str_replace( $this->eolChar, "\n", $string );
312 312
 
313
-        $chars    = str_split($string);
314
-        $numChars = count($chars);
315
-        for ($i = 0; $i < $numChars; $i++) {
316
-            $char = $chars[$i];
313
+        $chars    = str_split( $string );
314
+        $numChars = count( $chars );
315
+        for ( $i = 0; $i < $numChars; $i++ ) {
316
+            $char = $chars[ $i ];
317 317
 
318
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
319
-                $content       = Util\Common::prepareForOutput($char);
320
-                $bufferContent = Util\Common::prepareForOutput($buffer);
318
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
319
+                $content       = Util\Common::prepareForOutput( $char );
320
+                $bufferContent = Util\Common::prepareForOutput( $buffer );
321 321
 
322
-                if ($inString !== '') {
322
+                if ( $inString !== '' ) {
323 323
                     echo "\t";
324 324
                 }
325 325
 
326
-                if ($inComment !== '') {
326
+                if ( $inComment !== '' ) {
327 327
                     echo "\t";
328 328
                 }
329 329
 
330
-                echo "\tProcess char $i => $content (buffer: $bufferContent)".PHP_EOL;
330
+                echo "\tProcess char $i => $content (buffer: $bufferContent)" . PHP_EOL;
331 331
             }//end if
332 332
 
333
-            if ($inString === '' && $inComment === '' && $buffer !== '') {
333
+            if ( $inString === '' && $inComment === '' && $buffer !== '' ) {
334 334
                 // If the buffer only has whitespace and we are about to
335 335
                 // add a character, store the whitespace first.
336
-                if (trim($char) !== '' && trim($buffer) === '') {
337
-                    $tokens[] = [
336
+                if ( trim( $char ) !== '' && trim( $buffer ) === '' ) {
337
+                    $tokens[ ] = [
338 338
                         'code'    => T_WHITESPACE,
339 339
                         'type'    => 'T_WHITESPACE',
340
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
340
+                        'content' => str_replace( "\n", $this->eolChar, $buffer ),
341 341
                     ];
342 342
 
343
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
344
-                        $content = Util\Common::prepareForOutput($buffer);
345
-                        echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
343
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
344
+                        $content = Util\Common::prepareForOutput( $buffer );
345
+                        echo "\t=> Added token T_WHITESPACE ($content)" . PHP_EOL;
346 346
                     }
347 347
 
348 348
                     $buffer = '';
@@ -350,20 +350,20 @@  discard block
 block discarded – undo
350 350
 
351 351
                 // If the buffer is not whitespace and we are about to
352 352
                 // add a whitespace character, store the content first.
353
-                if ($inString === ''
353
+                if ( $inString === ''
354 354
                     && $inComment === ''
355
-                    && trim($char) === ''
356
-                    && trim($buffer) !== ''
355
+                    && trim( $char ) === ''
356
+                    && trim( $buffer ) !== ''
357 357
                 ) {
358
-                    $tokens[] = [
358
+                    $tokens[ ] = [
359 359
                         'code'    => T_STRING,
360 360
                         'type'    => 'T_STRING',
361
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
361
+                        'content' => str_replace( "\n", $this->eolChar, $buffer ),
362 362
                     ];
363 363
 
364
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
365
-                        $content = Util\Common::prepareForOutput($buffer);
366
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
364
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
365
+                        $content = Util\Common::prepareForOutput( $buffer );
366
+                        echo "\t=> Added token T_STRING ($content)" . PHP_EOL;
367 367
                     }
368 368
 
369 369
                     $buffer = '';
@@ -371,32 +371,32 @@  discard block
 block discarded – undo
371 371
             }//end if
372 372
 
373 373
             // Process strings.
374
-            if ($inComment === '' && isset($this->stringTokens[$char]) === true) {
375
-                if ($inString === $char) {
374
+            if ( $inComment === '' && isset( $this->stringTokens[ $char ] ) === true ) {
375
+                if ( $inString === $char ) {
376 376
                     // This could be the end of the string, but make sure it
377 377
                     // is not escaped first.
378 378
                     $escapes = 0;
379
-                    for ($x = ($i - 1); $x >= 0; $x--) {
380
-                        if ($chars[$x] !== '\\') {
379
+                    for ( $x = ( $i - 1 ); $x >= 0; $x-- ) {
380
+                        if ( $chars[ $x ] !== '\\' ) {
381 381
                             break;
382 382
                         }
383 383
 
384 384
                         $escapes++;
385 385
                     }
386 386
 
387
-                    if ($escapes === 0 || ($escapes % 2) === 0) {
387
+                    if ( $escapes === 0 || ( $escapes % 2 ) === 0 ) {
388 388
                         // There is an even number escape chars,
389 389
                         // so this is not escaped, it is the end of the string.
390
-                        $tokens[] = [
390
+                        $tokens[ ] = [
391 391
                             'code'    => T_CONSTANT_ENCAPSED_STRING,
392 392
                             'type'    => 'T_CONSTANT_ENCAPSED_STRING',
393
-                            'content' => str_replace("\n", $this->eolChar, $buffer).$char,
393
+                            'content' => str_replace( "\n", $this->eolChar, $buffer ) . $char,
394 394
                         ];
395 395
 
396
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
397
-                            echo "\t\t* found end of string *".PHP_EOL;
398
-                            $content = Util\Common::prepareForOutput($buffer.$char);
399
-                            echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)".PHP_EOL;
396
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
397
+                            echo "\t\t* found end of string *" . PHP_EOL;
398
+                            $content = Util\Common::prepareForOutput( $buffer . $char );
399
+                            echo "\t=> Added token T_CONSTANT_ENCAPSED_STRING ($content)" . PHP_EOL;
400 400
                         }
401 401
 
402 402
                         $buffer          = '';
@@ -405,31 +405,31 @@  discard block
 block discarded – undo
405 405
                         $stringChar      = null;
406 406
                         continue;
407 407
                     }//end if
408
-                } else if ($inString === '') {
408
+                } else if ( $inString === '' ) {
409 409
                     $inString        = $char;
410 410
                     $stringChar      = $i;
411 411
                     $preStringBuffer = $buffer;
412 412
 
413
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
414
-                        echo "\t\t* looking for string closer *".PHP_EOL;
413
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
414
+                        echo "\t\t* looking for string closer *" . PHP_EOL;
415 415
                     }
416 416
                 }//end if
417 417
             }//end if
418 418
 
419
-            if ($inString !== '' && $char === "\n") {
419
+            if ( $inString !== '' && $char === "\n" ) {
420 420
                 // Unless this newline character is escaped, the string did not
421 421
                 // end before the end of the line, which means it probably
422 422
                 // wasn't a string at all (maybe a regex).
423
-                if ($chars[($i - 1)] !== '\\') {
423
+                if ( $chars[ ( $i - 1 ) ] !== '\\' ) {
424 424
                     $i      = $stringChar;
425 425
                     $buffer = $preStringBuffer;
426 426
                     $preStringBuffer = '';
427 427
                     $inString        = '';
428 428
                     $stringChar      = null;
429
-                    $char            = $chars[$i];
429
+                    $char            = $chars[ $i ];
430 430
 
431
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
432
-                        echo "\t\t* found newline before end of string, bailing *".PHP_EOL;
431
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
432
+                        echo "\t\t* found newline before end of string, bailing *" . PHP_EOL;
433 433
                     }
434 434
                 }
435 435
             }
@@ -439,27 +439,27 @@  discard block
 block discarded – undo
439 439
             // We don't look for special tokens inside strings,
440 440
             // so if we are in a string, we can continue here now
441 441
             // that the current char is in the buffer.
442
-            if ($inString !== '') {
442
+            if ( $inString !== '' ) {
443 443
                 continue;
444 444
             }
445 445
 
446 446
             // Special case for T_DIVIDE which can actually be
447 447
             // the start of a regular expression.
448
-            if ($buffer === $char && $char === '/' && $chars[($i + 1)] !== '*') {
449
-                $regex = $this->getRegexToken($i, $string, $chars, $tokens);
450
-                if ($regex !== null) {
451
-                    $tokens[] = [
448
+            if ( $buffer === $char && $char === '/' && $chars[ ( $i + 1 ) ] !== '*' ) {
449
+                $regex = $this->getRegexToken( $i, $string, $chars, $tokens );
450
+                if ( $regex !== null ) {
451
+                    $tokens[ ] = [
452 452
                         'code'    => T_REGULAR_EXPRESSION,
453 453
                         'type'    => 'T_REGULAR_EXPRESSION',
454
-                        'content' => $regex['content'],
454
+                        'content' => $regex[ 'content' ],
455 455
                     ];
456 456
 
457
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
458
-                        $content = Util\Common::prepareForOutput($regex['content']);
459
-                        echo "\t=> Added token T_REGULAR_EXPRESSION ($content)".PHP_EOL;
457
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
458
+                        $content = Util\Common::prepareForOutput( $regex[ 'content' ] );
459
+                        echo "\t=> Added token T_REGULAR_EXPRESSION ($content)" . PHP_EOL;
460 460
                     }
461 461
 
462
-                    $i           = $regex['end'];
462
+                    $i           = $regex[ 'end' ];
463 463
                     $buffer      = '';
464 464
                     $cleanBuffer = false;
465 465
                     continue;
@@ -468,53 +468,53 @@  discard block
 block discarded – undo
468 468
 
469 469
             // Check for known tokens, but ignore tokens found that are not at
470 470
             // the end of a string, like FOR and this.FORmat.
471
-            if (isset($this->tokenValues[strtolower($buffer)]) === true
472
-                && (preg_match('|[a-zA-z0-9_]|', $char) === 0
473
-                || isset($chars[($i + 1)]) === false
474
-                || preg_match('|[a-zA-z0-9_]|', $chars[($i + 1)]) === 0)
471
+            if ( isset( $this->tokenValues[ strtolower( $buffer ) ] ) === true
472
+                && ( preg_match( '|[a-zA-z0-9_]|', $char ) === 0
473
+                || isset( $chars[ ( $i + 1 ) ] ) === false
474
+                || preg_match( '|[a-zA-z0-9_]|', $chars[ ( $i + 1 ) ] ) === 0 )
475 475
             ) {
476 476
                 $matchedToken    = false;
477
-                $lookAheadLength = ($maxTokenLength - strlen($buffer));
477
+                $lookAheadLength = ( $maxTokenLength - strlen( $buffer ) );
478 478
 
479
-                if ($lookAheadLength > 0) {
479
+                if ( $lookAheadLength > 0 ) {
480 480
                     // The buffer contains a token type, but we need
481 481
                     // to look ahead at the next chars to see if this is
482 482
                     // actually part of a larger token. For example,
483 483
                     // FOR and FOREACH.
484
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
485
-                        echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *".PHP_EOL;
484
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
485
+                        echo "\t\t* buffer possibly contains token, looking ahead $lookAheadLength chars *" . PHP_EOL;
486 486
                     }
487 487
 
488 488
                     $charBuffer = $buffer;
489
-                    for ($x = 1; $x <= $lookAheadLength; $x++) {
490
-                        if (isset($chars[($i + $x)]) === false) {
489
+                    for ( $x = 1; $x <= $lookAheadLength; $x++ ) {
490
+                        if ( isset( $chars[ ( $i + $x ) ] ) === false ) {
491 491
                             break;
492 492
                         }
493 493
 
494
-                        $charBuffer .= $chars[($i + $x)];
494
+                        $charBuffer .= $chars[ ( $i + $x ) ];
495 495
 
496
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
497
-                            $content = Util\Common::prepareForOutput($charBuffer);
498
-                            echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
496
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
497
+                            $content = Util\Common::prepareForOutput( $charBuffer );
498
+                            echo "\t\t=> Looking ahead $x chars => $content" . PHP_EOL;
499 499
                         }
500 500
 
501
-                        if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
501
+                        if ( isset( $this->tokenValues[ strtolower( $charBuffer ) ] ) === true ) {
502 502
                             // We've found something larger that matches
503 503
                             // so we can ignore this char. Except for 1 very specific
504 504
                             // case where a comment like /**/ needs to tokenize as
505 505
                             // T_COMMENT and not T_DOC_COMMENT.
506
-                            $oldType = $this->tokenValues[strtolower($buffer)];
507
-                            $newType = $this->tokenValues[strtolower($charBuffer)];
508
-                            if ($oldType === 'T_COMMENT'
506
+                            $oldType = $this->tokenValues[ strtolower( $buffer ) ];
507
+                            $newType = $this->tokenValues[ strtolower( $charBuffer ) ];
508
+                            if ( $oldType === 'T_COMMENT'
509 509
                                 && $newType === 'T_DOC_COMMENT'
510
-                                && $chars[($i + $x + 1)] === '/'
510
+                                && $chars[ ( $i + $x + 1 ) ] === '/'
511 511
                             ) {
512
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
513
-                                    echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *".PHP_EOL;
512
+                                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
513
+                                    echo "\t\t* look ahead ignored T_DOC_COMMENT, continuing *" . PHP_EOL;
514 514
                                 }
515 515
                             } else {
516
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
517
-                                    echo "\t\t* look ahead found more specific token ($newType), ignoring $i *".PHP_EOL;
516
+                                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
517
+                                    echo "\t\t* look ahead found more specific token ($newType), ignoring $i *" . PHP_EOL;
518 518
                                 }
519 519
 
520 520
                                 $matchedToken = true;
@@ -524,52 +524,52 @@  discard block
 block discarded – undo
524 524
                     }//end for
525 525
                 }//end if
526 526
 
527
-                if ($matchedToken === false) {
528
-                    if (PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0) {
529
-                        echo "\t\t* look ahead found nothing *".PHP_EOL;
527
+                if ( $matchedToken === false ) {
528
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 && $lookAheadLength > 0 ) {
529
+                        echo "\t\t* look ahead found nothing *" . PHP_EOL;
530 530
                     }
531 531
 
532
-                    $value = $this->tokenValues[strtolower($buffer)];
532
+                    $value = $this->tokenValues[ strtolower( $buffer ) ];
533 533
 
534
-                    if ($value === 'T_FUNCTION' && $buffer !== 'function') {
534
+                    if ( $value === 'T_FUNCTION' && $buffer !== 'function' ) {
535 535
                         // The function keyword needs to be all lowercase or else
536 536
                         // it is just a function called "Function".
537 537
                         $value = 'T_STRING';
538 538
                     }
539 539
 
540
-                    $tokens[] = [
541
-                        'code'    => constant($value),
540
+                    $tokens[ ] = [
541
+                        'code'    => constant( $value ),
542 542
                         'type'    => $value,
543 543
                         'content' => $buffer,
544 544
                     ];
545 545
 
546
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
547
-                        $content = Util\Common::prepareForOutput($buffer);
548
-                        echo "\t=> Added token $value ($content)".PHP_EOL;
546
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
547
+                        $content = Util\Common::prepareForOutput( $buffer );
548
+                        echo "\t=> Added token $value ($content)" . PHP_EOL;
549 549
                     }
550 550
 
551 551
                     $cleanBuffer = true;
552 552
                 }//end if
553
-            } else if (isset($this->tokenValues[strtolower($char)]) === true) {
553
+            } else if ( isset( $this->tokenValues[ strtolower( $char ) ] ) === true ) {
554 554
                 // No matter what token we end up using, we don't
555 555
                 // need the content in the buffer any more because we have
556 556
                 // found a valid token.
557
-                $newContent = substr(str_replace("\n", $this->eolChar, $buffer), 0, -1);
558
-                if ($newContent !== '') {
559
-                    $tokens[] = [
557
+                $newContent = substr( str_replace( "\n", $this->eolChar, $buffer ), 0, -1 );
558
+                if ( $newContent !== '' ) {
559
+                    $tokens[ ] = [
560 560
                         'code'    => T_STRING,
561 561
                         'type'    => 'T_STRING',
562 562
                         'content' => $newContent,
563 563
                     ];
564 564
 
565
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
566
-                        $content = Util\Common::prepareForOutput(substr($buffer, 0, -1));
567
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
565
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
566
+                        $content = Util\Common::prepareForOutput( substr( $buffer, 0, -1 ) );
567
+                        echo "\t=> Added token T_STRING ($content)" . PHP_EOL;
568 568
                     }
569 569
                 }
570 570
 
571
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
-                    echo "\t\t* char is token, looking ahead ".($maxTokenLength - 1).' chars *'.PHP_EOL;
571
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
572
+                    echo "\t\t* char is token, looking ahead " . ( $maxTokenLength - 1 ) . ' chars *' . PHP_EOL;
573 573
                 }
574 574
 
575 575
                 // The char is a token type, but we need to look ahead at the
@@ -577,24 +577,24 @@  discard block
 block discarded – undo
577 577
                 // For example, = and ===.
578 578
                 $charBuffer   = $char;
579 579
                 $matchedToken = false;
580
-                for ($x = 1; $x <= $maxTokenLength; $x++) {
581
-                    if (isset($chars[($i + $x)]) === false) {
580
+                for ( $x = 1; $x <= $maxTokenLength; $x++ ) {
581
+                    if ( isset( $chars[ ( $i + $x ) ] ) === false ) {
582 582
                         break;
583 583
                     }
584 584
 
585
-                    $charBuffer .= $chars[($i + $x)];
585
+                    $charBuffer .= $chars[ ( $i + $x ) ];
586 586
 
587
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
588
-                        $content = Util\Common::prepareForOutput($charBuffer);
589
-                        echo "\t\t=> Looking ahead $x chars => $content".PHP_EOL;
587
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
588
+                        $content = Util\Common::prepareForOutput( $charBuffer );
589
+                        echo "\t\t=> Looking ahead $x chars => $content" . PHP_EOL;
590 590
                     }
591 591
 
592
-                    if (isset($this->tokenValues[strtolower($charBuffer)]) === true) {
592
+                    if ( isset( $this->tokenValues[ strtolower( $charBuffer ) ] ) === true ) {
593 593
                         // We've found something larger that matches
594 594
                         // so we can ignore this char.
595
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
596
-                            $type = $this->tokenValues[strtolower($charBuffer)];
597
-                            echo "\t\t* look ahead found more specific token ($type), ignoring $i *".PHP_EOL;
595
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
596
+                            $type = $this->tokenValues[ strtolower( $charBuffer ) ];
597
+                            echo "\t\t* look ahead found more specific token ($type), ignoring $i *" . PHP_EOL;
598 598
                         }
599 599
 
600 600
                         $matchedToken = true;
@@ -602,18 +602,18 @@  discard block
 block discarded – undo
602 602
                     }
603 603
                 }//end for
604 604
 
605
-                if ($matchedToken === false) {
606
-                    $value    = $this->tokenValues[strtolower($char)];
607
-                    $tokens[] = [
608
-                        'code'    => constant($value),
605
+                if ( $matchedToken === false ) {
606
+                    $value    = $this->tokenValues[ strtolower( $char ) ];
607
+                    $tokens[ ] = [
608
+                        'code'    => constant( $value ),
609 609
                         'type'    => $value,
610 610
                         'content' => $char,
611 611
                     ];
612 612
 
613
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
614
-                        echo "\t\t* look ahead found nothing *".PHP_EOL;
615
-                        $content = Util\Common::prepareForOutput($char);
616
-                        echo "\t=> Added token $value ($content)".PHP_EOL;
613
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
614
+                        echo "\t\t* look ahead found nothing *" . PHP_EOL;
615
+                        $content = Util\Common::prepareForOutput( $char );
616
+                        echo "\t=> Added token $value ($content)" . PHP_EOL;
617 617
                     }
618 618
 
619 619
                     $cleanBuffer = true;
@@ -623,114 +623,114 @@  discard block
 block discarded – undo
623 623
             }//end if
624 624
 
625 625
             // Keep track of content inside comments.
626
-            if ($inComment === ''
627
-                && array_key_exists($buffer, $this->commentTokens) === true
626
+            if ( $inComment === ''
627
+                && array_key_exists( $buffer, $this->commentTokens ) === true
628 628
             ) {
629 629
                 // This is not really a comment if the content
630 630
                 // looks like \// (i.e., it is escaped).
631
-                if (isset($chars[($i - 2)]) === true && $chars[($i - 2)] === '\\') {
632
-                    $lastToken   = array_pop($tokens);
633
-                    $lastContent = $lastToken['content'];
634
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
635
-                        $value   = $this->tokenValues[strtolower($lastContent)];
636
-                        $content = Util\Common::prepareForOutput($lastContent);
637
-                        echo "\t=> Removed token $value ($content)".PHP_EOL;
631
+                if ( isset( $chars[ ( $i - 2 ) ] ) === true && $chars[ ( $i - 2 ) ] === '\\' ) {
632
+                    $lastToken   = array_pop( $tokens );
633
+                    $lastContent = $lastToken[ 'content' ];
634
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
635
+                        $value   = $this->tokenValues[ strtolower( $lastContent ) ];
636
+                        $content = Util\Common::prepareForOutput( $lastContent );
637
+                        echo "\t=> Removed token $value ($content)" . PHP_EOL;
638 638
                     }
639 639
 
640
-                    $lastChars    = str_split($lastContent);
641
-                    $lastNumChars = count($lastChars);
642
-                    for ($x = 0; $x < $lastNumChars; $x++) {
643
-                        $lastChar = $lastChars[$x];
644
-                        $value    = $this->tokenValues[strtolower($lastChar)];
645
-                        $tokens[] = [
646
-                            'code'    => constant($value),
640
+                    $lastChars    = str_split( $lastContent );
641
+                    $lastNumChars = count( $lastChars );
642
+                    for ( $x = 0; $x < $lastNumChars; $x++ ) {
643
+                        $lastChar = $lastChars[ $x ];
644
+                        $value    = $this->tokenValues[ strtolower( $lastChar ) ];
645
+                        $tokens[ ] = [
646
+                            'code'    => constant( $value ),
647 647
                             'type'    => $value,
648 648
                             'content' => $lastChar,
649 649
                         ];
650 650
 
651
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
652
-                            $content = Util\Common::prepareForOutput($lastChar);
653
-                            echo "\t=> Added token $value ($content)".PHP_EOL;
651
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
652
+                            $content = Util\Common::prepareForOutput( $lastChar );
653
+                            echo "\t=> Added token $value ($content)" . PHP_EOL;
654 654
                         }
655 655
                     }
656 656
                 } else {
657 657
                     // We have started a comment.
658 658
                     $inComment = $buffer;
659 659
 
660
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
661
-                        echo "\t\t* looking for end of comment *".PHP_EOL;
660
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
661
+                        echo "\t\t* looking for end of comment *" . PHP_EOL;
662 662
                     }
663 663
                 }//end if
664
-            } else if ($inComment !== '') {
665
-                if ($this->commentTokens[$inComment] === null) {
664
+            } else if ( $inComment !== '' ) {
665
+                if ( $this->commentTokens[ $inComment ] === null ) {
666 666
                     // Comment ends at the next newline.
667
-                    if (strpos($buffer, "\n") !== false) {
667
+                    if ( strpos( $buffer, "\n" ) !== false ) {
668 668
                         $inComment = '';
669 669
                     }
670 670
                 } else {
671
-                    if ($this->commentTokens[$inComment] === $buffer) {
671
+                    if ( $this->commentTokens[ $inComment ] === $buffer ) {
672 672
                         $inComment = '';
673 673
                     }
674 674
                 }
675 675
 
676
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
677
-                    if ($inComment === '') {
678
-                        echo "\t\t* found end of comment *".PHP_EOL;
676
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
677
+                    if ( $inComment === '' ) {
678
+                        echo "\t\t* found end of comment *" . PHP_EOL;
679 679
                     }
680 680
                 }
681 681
 
682
-                if ($inComment === '' && $cleanBuffer === false) {
683
-                    $tokens[] = [
682
+                if ( $inComment === '' && $cleanBuffer === false ) {
683
+                    $tokens[ ] = [
684 684
                         'code'    => T_STRING,
685 685
                         'type'    => 'T_STRING',
686
-                        'content' => str_replace("\n", $this->eolChar, $buffer),
686
+                        'content' => str_replace( "\n", $this->eolChar, $buffer ),
687 687
                     ];
688 688
 
689
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
690
-                        $content = Util\Common::prepareForOutput($buffer);
691
-                        echo "\t=> Added token T_STRING ($content)".PHP_EOL;
689
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
690
+                        $content = Util\Common::prepareForOutput( $buffer );
691
+                        echo "\t=> Added token T_STRING ($content)" . PHP_EOL;
692 692
                     }
693 693
 
694 694
                     $buffer = '';
695 695
                 }
696 696
             }//end if
697 697
 
698
-            if ($cleanBuffer === true) {
698
+            if ( $cleanBuffer === true ) {
699 699
                 $buffer      = '';
700 700
                 $cleanBuffer = false;
701 701
             }
702 702
         }//end for
703 703
 
704
-        if (empty($buffer) === false) {
705
-            if ($inString !== '') {
704
+        if ( empty( $buffer ) === false ) {
705
+            if ( $inString !== '' ) {
706 706
                 // The string did not end before the end of the file,
707 707
                 // which means there was probably a syntax error somewhere.
708
-                $tokens[] = [
708
+                $tokens[ ] = [
709 709
                     'code'    => T_STRING,
710 710
                     'type'    => 'T_STRING',
711
-                    'content' => str_replace("\n", $this->eolChar, $buffer),
711
+                    'content' => str_replace( "\n", $this->eolChar, $buffer ),
712 712
                 ];
713 713
 
714
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
715
-                    $content = Util\Common::prepareForOutput($buffer);
716
-                    echo "\t=> Added token T_STRING ($content)".PHP_EOL;
714
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
715
+                    $content = Util\Common::prepareForOutput( $buffer );
716
+                    echo "\t=> Added token T_STRING ($content)" . PHP_EOL;
717 717
                 }
718 718
             } else {
719 719
                 // Buffer contains whitespace from the end of the file.
720
-                $tokens[] = [
720
+                $tokens[ ] = [
721 721
                     'code'    => T_WHITESPACE,
722 722
                     'type'    => 'T_WHITESPACE',
723
-                    'content' => str_replace("\n", $this->eolChar, $buffer),
723
+                    'content' => str_replace( "\n", $this->eolChar, $buffer ),
724 724
                 ];
725 725
 
726
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
727
-                    $content = Util\Common::prepareForOutput($buffer);
728
-                    echo "\t=> Added token T_WHITESPACE ($content)".PHP_EOL;
726
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
727
+                    $content = Util\Common::prepareForOutput( $buffer );
728
+                    echo "\t=> Added token T_WHITESPACE ($content)" . PHP_EOL;
729 729
                 }
730 730
             }//end if
731 731
         }//end if
732 732
 
733
-        $tokens[] = [
733
+        $tokens[ ] = [
734 734
             'code'    => T_CLOSE_TAG,
735 735
             'type'    => 'T_CLOSE_TAG',
736 736
             'content' => '',
@@ -742,46 +742,46 @@  discard block
 block discarded – undo
742 742
             so they match what the PHP tokenizer does.
743 743
         */
744 744
 
745
-        $finalTokens = [];
745
+        $finalTokens = [ ];
746 746
         $newStackPtr = 0;
747
-        $numTokens   = count($tokens);
748
-        for ($stackPtr = 0; $stackPtr < $numTokens; $stackPtr++) {
749
-            $token = $tokens[$stackPtr];
747
+        $numTokens   = count( $tokens );
748
+        for ( $stackPtr = 0; $stackPtr < $numTokens; $stackPtr++ ) {
749
+            $token = $tokens[ $stackPtr ];
750 750
 
751 751
             /*
752 752
                 Look for comments and join the tokens together.
753 753
             */
754 754
 
755
-            if ($token['code'] === T_COMMENT || $token['code'] === T_DOC_COMMENT) {
755
+            if ( $token[ 'code' ] === T_COMMENT || $token[ 'code' ] === T_DOC_COMMENT ) {
756 756
                 $newContent   = '';
757
-                $tokenContent = $token['content'];
757
+                $tokenContent = $token[ 'content' ];
758 758
 
759 759
                 $endContent = null;
760
-                if (isset($this->commentTokens[$tokenContent]) === true) {
761
-                    $endContent = $this->commentTokens[$tokenContent];
760
+                if ( isset( $this->commentTokens[ $tokenContent ] ) === true ) {
761
+                    $endContent = $this->commentTokens[ $tokenContent ];
762 762
                 }
763 763
 
764
-                while ($tokenContent !== $endContent) {
765
-                    if ($endContent === null
766
-                        && strpos($tokenContent, $this->eolChar) !== false
764
+                while ( $tokenContent !== $endContent ) {
765
+                    if ( $endContent === null
766
+                        && strpos( $tokenContent, $this->eolChar ) !== false
767 767
                     ) {
768 768
                         // A null end token means the comment ends at the end of
769 769
                         // the line so we look for newlines and split the token.
770
-                        $tokens[$stackPtr]['content'] = substr(
770
+                        $tokens[ $stackPtr ][ 'content' ] = substr(
771 771
                             $tokenContent,
772
-                            (strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
772
+                            ( strpos( $tokenContent, $this->eolChar ) + strlen( $this->eolChar ) )
773 773
                         );
774 774
 
775 775
                         $tokenContent = substr(
776 776
                             $tokenContent,
777 777
                             0,
778
-                            (strpos($tokenContent, $this->eolChar) + strlen($this->eolChar))
778
+                            ( strpos( $tokenContent, $this->eolChar ) + strlen( $this->eolChar ) )
779 779
                         );
780 780
 
781 781
                         // If the substr failed, skip the token as the content
782 782
                         // will now be blank.
783
-                        if ($tokens[$stackPtr]['content'] !== false
784
-                            && $tokens[$stackPtr]['content'] !== ''
783
+                        if ( $tokens[ $stackPtr ][ 'content' ] !== false
784
+                            && $tokens[ $stackPtr ][ 'content' ] !== ''
785 785
                         ) {
786 786
                             $stackPtr--;
787 787
                         }
@@ -791,17 +791,17 @@  discard block
 block discarded – undo
791 791
 
792 792
                     $stackPtr++;
793 793
                     $newContent .= $tokenContent;
794
-                    if (isset($tokens[$stackPtr]) === false) {
794
+                    if ( isset( $tokens[ $stackPtr ] ) === false ) {
795 795
                         break;
796 796
                     }
797 797
 
798
-                    $tokenContent = $tokens[$stackPtr]['content'];
798
+                    $tokenContent = $tokens[ $stackPtr ][ 'content' ];
799 799
                 }//end while
800 800
 
801
-                if ($token['code'] === T_DOC_COMMENT) {
802
-                    $commentTokens = $commentTokenizer->tokenizeString($newContent.$tokenContent, $this->eolChar, $newStackPtr);
803
-                    foreach ($commentTokens as $commentToken) {
804
-                        $finalTokens[$newStackPtr] = $commentToken;
801
+                if ( $token[ 'code' ] === T_DOC_COMMENT ) {
802
+                    $commentTokens = $commentTokenizer->tokenizeString( $newContent . $tokenContent, $this->eolChar, $newStackPtr );
803
+                    foreach ( $commentTokens as $commentToken ) {
804
+                        $finalTokens[ $newStackPtr ] = $commentToken;
805 805
                         $newStackPtr++;
806 806
                     }
807 807
 
@@ -809,7 +809,7 @@  discard block
 block discarded – undo
809 809
                 } else {
810 810
                     // Save the new content in the current token so
811 811
                     // the code below can chop it up on newlines.
812
-                    $token['content'] = $newContent.$tokenContent;
812
+                    $token[ 'content' ] = $newContent . $tokenContent;
813 813
                 }
814 814
             }//end if
815 815
 
@@ -820,49 +820,49 @@  discard block
 block discarded – undo
820 820
                 Note that $token[1] is the token's content.
821 821
             */
822 822
 
823
-            if (strpos($token['content'], $this->eolChar) !== false) {
824
-                $tokenLines = explode($this->eolChar, $token['content']);
825
-                $numLines   = count($tokenLines);
823
+            if ( strpos( $token[ 'content' ], $this->eolChar ) !== false ) {
824
+                $tokenLines = explode( $this->eolChar, $token[ 'content' ] );
825
+                $numLines   = count( $tokenLines );
826 826
 
827
-                for ($i = 0; $i < $numLines; $i++) {
828
-                    $newToken = ['content' => $tokenLines[$i]];
829
-                    if ($i === ($numLines - 1)) {
830
-                        if ($tokenLines[$i] === '') {
827
+                for ( $i = 0; $i < $numLines; $i++ ) {
828
+                    $newToken = [ 'content' => $tokenLines[ $i ] ];
829
+                    if ( $i === ( $numLines - 1 ) ) {
830
+                        if ( $tokenLines[ $i ] === '' ) {
831 831
                             break;
832 832
                         }
833 833
                     } else {
834
-                        $newToken['content'] .= $this->eolChar;
834
+                        $newToken[ 'content' ] .= $this->eolChar;
835 835
                     }
836 836
 
837
-                    $newToken['type']          = $token['type'];
838
-                    $newToken['code']          = $token['code'];
839
-                    $finalTokens[$newStackPtr] = $newToken;
837
+                    $newToken[ 'type' ]          = $token[ 'type' ];
838
+                    $newToken[ 'code' ]          = $token[ 'code' ];
839
+                    $finalTokens[ $newStackPtr ] = $newToken;
840 840
                     $newStackPtr++;
841 841
                 }
842 842
             } else {
843
-                $finalTokens[$newStackPtr] = $token;
843
+                $finalTokens[ $newStackPtr ] = $token;
844 844
                 $newStackPtr++;
845 845
             }//end if
846 846
 
847 847
             // Convert numbers, including decimals.
848
-            if ($token['code'] === T_STRING
849
-                || $token['code'] === T_OBJECT_OPERATOR
848
+            if ( $token[ 'code' ] === T_STRING
849
+                || $token[ 'code' ] === T_OBJECT_OPERATOR
850 850
             ) {
851 851
                 $newContent  = '';
852 852
                 $oldStackPtr = $stackPtr;
853
-                while (preg_match('|^[0-9\.]+$|', $tokens[$stackPtr]['content']) !== 0) {
854
-                    $newContent .= $tokens[$stackPtr]['content'];
853
+                while ( preg_match( '|^[0-9\.]+$|', $tokens[ $stackPtr ][ 'content' ] ) !== 0 ) {
854
+                    $newContent .= $tokens[ $stackPtr ][ 'content' ];
855 855
                     $stackPtr++;
856 856
                 }
857 857
 
858
-                if ($newContent !== '' && $newContent !== '.') {
859
-                    $finalTokens[($newStackPtr - 1)]['content'] = $newContent;
860
-                    if (ctype_digit($newContent) === true) {
861
-                        $finalTokens[($newStackPtr - 1)]['code'] = constant('T_LNUMBER');
862
-                        $finalTokens[($newStackPtr - 1)]['type'] = 'T_LNUMBER';
858
+                if ( $newContent !== '' && $newContent !== '.' ) {
859
+                    $finalTokens[ ( $newStackPtr - 1 ) ][ 'content' ] = $newContent;
860
+                    if ( ctype_digit( $newContent ) === true ) {
861
+                        $finalTokens[ ( $newStackPtr - 1 ) ][ 'code' ] = constant( 'T_LNUMBER' );
862
+                        $finalTokens[ ( $newStackPtr - 1 ) ][ 'type' ] = 'T_LNUMBER';
863 863
                     } else {
864
-                        $finalTokens[($newStackPtr - 1)]['code'] = constant('T_DNUMBER');
865
-                        $finalTokens[($newStackPtr - 1)]['type'] = 'T_DNUMBER';
864
+                        $finalTokens[ ( $newStackPtr - 1 ) ][ 'code' ] = constant( 'T_DNUMBER' );
865
+                        $finalTokens[ ( $newStackPtr - 1 ) ][ 'type' ] = 'T_DNUMBER';
866 866
                     }
867 867
 
868 868
                     $stackPtr--;
@@ -873,18 +873,18 @@  discard block
 block discarded – undo
873 873
             }//end if
874 874
 
875 875
             // Convert the token after an object operator into a string, in most cases.
876
-            if ($token['code'] === T_OBJECT_OPERATOR) {
877
-                for ($i = ($stackPtr + 1); $i < $numTokens; $i++) {
878
-                    if (isset(Util\Tokens::$emptyTokens[$tokens[$i]['code']]) === true) {
876
+            if ( $token[ 'code' ] === T_OBJECT_OPERATOR ) {
877
+                for ( $i = ( $stackPtr + 1 ); $i < $numTokens; $i++ ) {
878
+                    if ( isset( Util\Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) === true ) {
879 879
                         continue;
880 880
                     }
881 881
 
882
-                    if ($tokens[$i]['code'] !== T_PROTOTYPE
883
-                        && $tokens[$i]['code'] !== T_LNUMBER
884
-                        && $tokens[$i]['code'] !== T_DNUMBER
882
+                    if ( $tokens[ $i ][ 'code' ] !== T_PROTOTYPE
883
+                        && $tokens[ $i ][ 'code' ] !== T_LNUMBER
884
+                        && $tokens[ $i ][ 'code' ] !== T_DNUMBER
885 885
                     ) {
886
-                        $tokens[$i]['code'] = T_STRING;
887
-                        $tokens[$i]['type'] = 'T_STRING';
886
+                        $tokens[ $i ][ 'code' ] = T_STRING;
887
+                        $tokens[ $i ][ 'type' ] = 'T_STRING';
888 888
                     }
889 889
 
890 890
                     break;
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
             }
893 893
         }//end for
894 894
 
895
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
896
-            echo "\t*** END TOKENIZING ***".PHP_EOL;
895
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
896
+            echo "\t*** END TOKENIZING ***" . PHP_EOL;
897 897
         }
898 898
 
899 899
         return $finalTokens;
@@ -913,7 +913,7 @@  discard block
 block discarded – undo
913 913
      *
914 914
      * @return array<string, string>|null
915 915
      */
916
-    public function getRegexToken($char, $string, $chars, $tokens)
916
+    public function getRegexToken( $char, $string, $chars, $tokens )
917 917
     {
918 918
         $beforeTokens = [
919 919
             T_EQUAL               => true,
@@ -948,36 +948,36 @@  discard block
 block discarded – undo
948 948
 
949 949
         // Find the last non-whitespace token that was added
950 950
         // to the tokens array.
951
-        $numTokens = count($tokens);
952
-        for ($prev = ($numTokens - 1); $prev >= 0; $prev--) {
953
-            if (isset(Util\Tokens::$emptyTokens[$tokens[$prev]['code']]) === false) {
951
+        $numTokens = count( $tokens );
952
+        for ( $prev = ( $numTokens - 1 ); $prev >= 0; $prev-- ) {
953
+            if ( isset( Util\Tokens::$emptyTokens[ $tokens[ $prev ][ 'code' ] ] ) === false ) {
954 954
                 break;
955 955
             }
956 956
         }
957 957
 
958
-        if (isset($beforeTokens[$tokens[$prev]['code']]) === false) {
958
+        if ( isset( $beforeTokens[ $tokens[ $prev ][ 'code' ] ] ) === false ) {
959 959
             return null;
960 960
         }
961 961
 
962 962
         // This is probably a regular expression, so look for the end of it.
963
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
964
-            echo "\t* token possibly starts a regular expression *".PHP_EOL;
963
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
964
+            echo "\t* token possibly starts a regular expression *" . PHP_EOL;
965 965
         }
966 966
 
967
-        $numChars = count($chars);
968
-        for ($next = ($char + 1); $next < $numChars; $next++) {
969
-            if ($chars[$next] === '/') {
967
+        $numChars = count( $chars );
968
+        for ( $next = ( $char + 1 ); $next < $numChars; $next++ ) {
969
+            if ( $chars[ $next ] === '/' ) {
970 970
                 // Just make sure this is not escaped first.
971
-                if ($chars[($next - 1)] !== '\\') {
971
+                if ( $chars[ ( $next - 1 ) ] !== '\\' ) {
972 972
                     // In the simple form: /.../ so we found the end.
973 973
                     break;
974
-                } else if ($chars[($next - 2)] === '\\') {
974
+                } else if ( $chars[ ( $next - 2 ) ] === '\\' ) {
975 975
                     // In the form: /...\\/ so we found the end.
976 976
                     break;
977 977
                 }
978 978
             } else {
979
-                $possibleEolChar = substr($string, $next, strlen($this->eolChar));
980
-                if ($possibleEolChar === $this->eolChar) {
979
+                $possibleEolChar = substr( $string, $next, strlen( $this->eolChar ) );
980
+                if ( $possibleEolChar === $this->eolChar ) {
981 981
                     // This is the last token on the line and regular
982 982
                     // expressions need to be defined on a single line,
983 983
                     // so this is not a regular expression.
@@ -986,15 +986,15 @@  discard block
 block discarded – undo
986 986
             }
987 987
         }
988 988
 
989
-        if ($chars[$next] !== '/') {
990
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
991
-                echo "\t* could not find end of regular expression *".PHP_EOL;
989
+        if ( $chars[ $next ] !== '/' ) {
990
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
991
+                echo "\t* could not find end of regular expression *" . PHP_EOL;
992 992
             }
993 993
 
994 994
             return null;
995 995
         }
996 996
 
997
-        while (preg_match('|[a-zA-Z]|', $chars[($next + 1)]) !== 0) {
997
+        while ( preg_match( '|[a-zA-Z]|', $chars[ ( $next + 1 ) ] ) !== 0 ) {
998 998
             // The token directly after the end of the regex can
999 999
             // be modifiers like global and case insensitive
1000 1000
             // (.e.g, /pattern/gi).
@@ -1002,25 +1002,25 @@  discard block
 block discarded – undo
1002 1002
         }
1003 1003
 
1004 1004
         $regexEnd = $next;
1005
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1006
-            echo "\t* found end of regular expression at token $regexEnd *".PHP_EOL;
1005
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1006
+            echo "\t* found end of regular expression at token $regexEnd *" . PHP_EOL;
1007 1007
         }
1008 1008
 
1009
-        for ($next += 1; $next < $numChars; $next++) {
1010
-            if ($chars[$next] !== ' ') {
1009
+        for ( $next += 1; $next < $numChars; $next++ ) {
1010
+            if ( $chars[ $next ] !== ' ' ) {
1011 1011
                 break;
1012 1012
             } else {
1013
-                $possibleEolChar = substr($string, $next, strlen($this->eolChar));
1014
-                if ($possibleEolChar === $this->eolChar) {
1013
+                $possibleEolChar = substr( $string, $next, strlen( $this->eolChar ) );
1014
+                if ( $possibleEolChar === $this->eolChar ) {
1015 1015
                     // This is the last token on the line.
1016 1016
                     break;
1017 1017
                 }
1018 1018
             }
1019 1019
         }
1020 1020
 
1021
-        if (isset($afterTokens[$chars[$next]]) === false) {
1022
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1023
-                echo "\t* tokens after regular expression do not look correct *".PHP_EOL;
1021
+        if ( isset( $afterTokens[ $chars[ $next ] ] ) === false ) {
1022
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1023
+                echo "\t* tokens after regular expression do not look correct *" . PHP_EOL;
1024 1024
             }
1025 1025
 
1026 1026
             return null;
@@ -1028,8 +1028,8 @@  discard block
 block discarded – undo
1028 1028
 
1029 1029
         // This is a regular expression, so join all the tokens together.
1030 1030
         $content = '';
1031
-        for ($x = $char; $x <= $regexEnd; $x++) {
1032
-            $content .= $chars[$x];
1031
+        for ( $x = $char; $x <= $regexEnd; $x++ ) {
1032
+            $content .= $chars[ $x ];
1033 1033
         }
1034 1034
 
1035 1035
         $token = [
@@ -1052,110 +1052,110 @@  discard block
 block discarded – undo
1052 1052
      */
1053 1053
     public function processAdditional()
1054 1054
     {
1055
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1056
-            echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL;
1055
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1056
+            echo "\t*** START ADDITIONAL JS PROCESSING ***" . PHP_EOL;
1057 1057
         }
1058 1058
 
1059
-        $numTokens  = count($this->tokens);
1060
-        $classStack = [];
1059
+        $numTokens  = count( $this->tokens );
1060
+        $classStack = [ ];
1061 1061
 
1062
-        for ($i = 0; $i < $numTokens; $i++) {
1063
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1064
-                $type    = $this->tokens[$i]['type'];
1065
-                $content = Util\Common::prepareForOutput($this->tokens[$i]['content']);
1062
+        for ( $i = 0; $i < $numTokens; $i++ ) {
1063
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1064
+                $type    = $this->tokens[ $i ][ 'type' ];
1065
+                $content = Util\Common::prepareForOutput( $this->tokens[ $i ][ 'content' ] );
1066 1066
 
1067
-                echo str_repeat("\t", count($classStack));
1068
-                echo "\tProcess token $i: $type => $content".PHP_EOL;
1067
+                echo str_repeat( "\t", count( $classStack ) );
1068
+                echo "\tProcess token $i: $type => $content" . PHP_EOL;
1069 1069
             }
1070 1070
 
1071 1071
             // Looking for functions that are actually closures.
1072
-            if ($this->tokens[$i]['code'] === T_FUNCTION && isset($this->tokens[$i]['scope_opener']) === true) {
1073
-                for ($x = ($i + 1); $x < $numTokens; $x++) {
1074
-                    if (isset(Util\Tokens::$emptyTokens[$this->tokens[$x]['code']]) === false) {
1072
+            if ( $this->tokens[ $i ][ 'code' ] === T_FUNCTION && isset( $this->tokens[ $i ][ 'scope_opener' ] ) === true ) {
1073
+                for ( $x = ( $i + 1 ); $x < $numTokens; $x++ ) {
1074
+                    if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $x ][ 'code' ] ] ) === false ) {
1075 1075
                         break;
1076 1076
                     }
1077 1077
                 }
1078 1078
 
1079
-                if ($this->tokens[$x]['code'] === T_OPEN_PARENTHESIS) {
1080
-                    $this->tokens[$i]['code'] = T_CLOSURE;
1081
-                    $this->tokens[$i]['type'] = 'T_CLOSURE';
1082
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1083
-                        $line = $this->tokens[$i]['line'];
1084
-                        echo str_repeat("\t", count($classStack));
1085
-                        echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE *".PHP_EOL;
1079
+                if ( $this->tokens[ $x ][ 'code' ] === T_OPEN_PARENTHESIS ) {
1080
+                    $this->tokens[ $i ][ 'code' ] = T_CLOSURE;
1081
+                    $this->tokens[ $i ][ 'type' ] = 'T_CLOSURE';
1082
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1083
+                        $line = $this->tokens[ $i ][ 'line' ];
1084
+                        echo str_repeat( "\t", count( $classStack ) );
1085
+                        echo "\t* token $i on line $line changed from T_FUNCTION to T_CLOSURE *" . PHP_EOL;
1086 1086
                     }
1087 1087
 
1088
-                    for ($x = ($this->tokens[$i]['scope_opener'] + 1); $x < $this->tokens[$i]['scope_closer']; $x++) {
1089
-                        if (isset($this->tokens[$x]['conditions'][$i]) === false) {
1088
+                    for ( $x = ( $this->tokens[ $i ][ 'scope_opener' ] + 1 ); $x < $this->tokens[ $i ][ 'scope_closer' ]; $x++ ) {
1089
+                        if ( isset( $this->tokens[ $x ][ 'conditions' ][ $i ] ) === false ) {
1090 1090
                             continue;
1091 1091
                         }
1092 1092
 
1093
-                        $this->tokens[$x]['conditions'][$i] = T_CLOSURE;
1094
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1095
-                            $type = $this->tokens[$x]['type'];
1096
-                            echo str_repeat("\t", count($classStack));
1097
-                            echo "\t\t* cleaned $x ($type) *".PHP_EOL;
1093
+                        $this->tokens[ $x ][ 'conditions' ][ $i ] = T_CLOSURE;
1094
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1095
+                            $type = $this->tokens[ $x ][ 'type' ];
1096
+                            echo str_repeat( "\t", count( $classStack ) );
1097
+                            echo "\t\t* cleaned $x ($type) *" . PHP_EOL;
1098 1098
                         }
1099 1099
                     }
1100 1100
                 }//end if
1101 1101
 
1102 1102
                 continue;
1103
-            } else if ($this->tokens[$i]['code'] === T_OPEN_CURLY_BRACKET
1104
-                && isset($this->tokens[$i]['scope_condition']) === false
1105
-                && isset($this->tokens[$i]['bracket_closer']) === true
1103
+            } else if ( $this->tokens[ $i ][ 'code' ] === T_OPEN_CURLY_BRACKET
1104
+                && isset( $this->tokens[ $i ][ 'scope_condition' ] ) === false
1105
+                && isset( $this->tokens[ $i ][ 'bracket_closer' ] ) === true
1106 1106
             ) {
1107
-                $condition = $this->tokens[$i]['conditions'];
1108
-                $condition = end($condition);
1109
-                if ($condition === T_CLASS) {
1107
+                $condition = $this->tokens[ $i ][ 'conditions' ];
1108
+                $condition = end( $condition );
1109
+                if ( $condition === T_CLASS ) {
1110 1110
                     // Possibly an ES6 method. To be classified as one, the previous
1111 1111
                     // non-empty tokens need to be a set of parenthesis, and then a string
1112 1112
                     // (the method name).
1113
-                    for ($parenCloser = ($i - 1); $parenCloser > 0; $parenCloser--) {
1114
-                        if (isset(Util\Tokens::$emptyTokens[$this->tokens[$parenCloser]['code']]) === false) {
1113
+                    for ( $parenCloser = ( $i - 1 ); $parenCloser > 0; $parenCloser-- ) {
1114
+                        if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $parenCloser ][ 'code' ] ] ) === false ) {
1115 1115
                             break;
1116 1116
                         }
1117 1117
                     }
1118 1118
 
1119
-                    if ($this->tokens[$parenCloser]['code'] === T_CLOSE_PARENTHESIS) {
1120
-                        $parenOpener = $this->tokens[$parenCloser]['parenthesis_opener'];
1121
-                        for ($name = ($parenOpener - 1); $name > 0; $name--) {
1122
-                            if (isset(Util\Tokens::$emptyTokens[$this->tokens[$name]['code']]) === false) {
1119
+                    if ( $this->tokens[ $parenCloser ][ 'code' ] === T_CLOSE_PARENTHESIS ) {
1120
+                        $parenOpener = $this->tokens[ $parenCloser ][ 'parenthesis_opener' ];
1121
+                        for ( $name = ( $parenOpener - 1 ); $name > 0; $name-- ) {
1122
+                            if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $name ][ 'code' ] ] ) === false ) {
1123 1123
                                 break;
1124 1124
                             }
1125 1125
                         }
1126 1126
 
1127
-                        if ($this->tokens[$name]['code'] === T_STRING) {
1127
+                        if ( $this->tokens[ $name ][ 'code' ] === T_STRING ) {
1128 1128
                             // We found a method name.
1129
-                            if (PHP_CODESNIFFER_VERBOSITY > 1) {
1130
-                                $line = $this->tokens[$name]['line'];
1131
-                                echo str_repeat("\t", count($classStack));
1132
-                                echo "\t* token $name on line $line changed from T_STRING to T_FUNCTION *".PHP_EOL;
1129
+                            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1130
+                                $line = $this->tokens[ $name ][ 'line' ];
1131
+                                echo str_repeat( "\t", count( $classStack ) );
1132
+                                echo "\t* token $name on line $line changed from T_STRING to T_FUNCTION *" . PHP_EOL;
1133 1133
                             }
1134 1134
 
1135
-                            $closer = $this->tokens[$i]['bracket_closer'];
1135
+                            $closer = $this->tokens[ $i ][ 'bracket_closer' ];
1136 1136
 
1137
-                            $this->tokens[$name]['code'] = T_FUNCTION;
1138
-                            $this->tokens[$name]['type'] = 'T_FUNCTION';
1137
+                            $this->tokens[ $name ][ 'code' ] = T_FUNCTION;
1138
+                            $this->tokens[ $name ][ 'type' ] = 'T_FUNCTION';
1139 1139
 
1140
-                            foreach ([$name, $i, $closer] as $token) {
1141
-                                $this->tokens[$token]['scope_condition']    = $name;
1142
-                                $this->tokens[$token]['scope_opener']       = $i;
1143
-                                $this->tokens[$token]['scope_closer']       = $closer;
1144
-                                $this->tokens[$token]['parenthesis_opener'] = $parenOpener;
1145
-                                $this->tokens[$token]['parenthesis_closer'] = $parenCloser;
1146
-                                $this->tokens[$token]['parenthesis_owner']  = $name;
1140
+                            foreach ( [ $name, $i, $closer ] as $token ) {
1141
+                                $this->tokens[ $token ][ 'scope_condition' ]    = $name;
1142
+                                $this->tokens[ $token ][ 'scope_opener' ]       = $i;
1143
+                                $this->tokens[ $token ][ 'scope_closer' ]       = $closer;
1144
+                                $this->tokens[ $token ][ 'parenthesis_opener' ] = $parenOpener;
1145
+                                $this->tokens[ $token ][ 'parenthesis_closer' ] = $parenCloser;
1146
+                                $this->tokens[ $token ][ 'parenthesis_owner' ]  = $name;
1147 1147
                             }
1148 1148
 
1149
-                            $this->tokens[$parenOpener]['parenthesis_owner'] = $name;
1150
-                            $this->tokens[$parenCloser]['parenthesis_owner'] = $name;
1149
+                            $this->tokens[ $parenOpener ][ 'parenthesis_owner' ] = $name;
1150
+                            $this->tokens[ $parenCloser ][ 'parenthesis_owner' ] = $name;
1151 1151
 
1152
-                            for ($x = ($i + 1); $x < $closer; $x++) {
1153
-                                $this->tokens[$x]['conditions'][$name] = T_FUNCTION;
1154
-                                ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1155
-                                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1156
-                                    $type = $this->tokens[$x]['type'];
1157
-                                    echo str_repeat("\t", count($classStack));
1158
-                                    echo "\t\t* added T_FUNCTION condition to $x ($type) *".PHP_EOL;
1152
+                            for ( $x = ( $i + 1 ); $x < $closer; $x++ ) {
1153
+                                $this->tokens[ $x ][ 'conditions' ][ $name ] = T_FUNCTION;
1154
+                                ksort( $this->tokens[ $x ][ 'conditions' ], SORT_NUMERIC );
1155
+                                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1156
+                                    $type = $this->tokens[ $x ][ 'type' ];
1157
+                                    echo str_repeat( "\t", count( $classStack ) );
1158
+                                    echo "\t\t* added T_FUNCTION condition to $x ($type) *" . PHP_EOL;
1159 1159
                                 }
1160 1160
                             }
1161 1161
 
@@ -1164,91 +1164,91 @@  discard block
 block discarded – undo
1164 1164
                     }//end if
1165 1165
                 }//end if
1166 1166
 
1167
-                $classStack[] = $i;
1167
+                $classStack[ ] = $i;
1168 1168
 
1169
-                $closer = $this->tokens[$i]['bracket_closer'];
1170
-                $this->tokens[$i]['code']      = T_OBJECT;
1171
-                $this->tokens[$i]['type']      = 'T_OBJECT';
1172
-                $this->tokens[$closer]['code'] = T_CLOSE_OBJECT;
1173
-                $this->tokens[$closer]['type'] = 'T_CLOSE_OBJECT';
1169
+                $closer = $this->tokens[ $i ][ 'bracket_closer' ];
1170
+                $this->tokens[ $i ][ 'code' ]      = T_OBJECT;
1171
+                $this->tokens[ $i ][ 'type' ]      = 'T_OBJECT';
1172
+                $this->tokens[ $closer ][ 'code' ] = T_CLOSE_OBJECT;
1173
+                $this->tokens[ $closer ][ 'type' ] = 'T_CLOSE_OBJECT';
1174 1174
 
1175
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1176
-                    echo str_repeat("\t", count($classStack));
1177
-                    echo "\t* token $i converted from T_OPEN_CURLY_BRACKET to T_OBJECT *".PHP_EOL;
1178
-                    echo str_repeat("\t", count($classStack));
1179
-                    echo "\t* token $closer converted from T_CLOSE_CURLY_BRACKET to T_CLOSE_OBJECT *".PHP_EOL;
1175
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1176
+                    echo str_repeat( "\t", count( $classStack ) );
1177
+                    echo "\t* token $i converted from T_OPEN_CURLY_BRACKET to T_OBJECT *" . PHP_EOL;
1178
+                    echo str_repeat( "\t", count( $classStack ) );
1179
+                    echo "\t* token $closer converted from T_CLOSE_CURLY_BRACKET to T_CLOSE_OBJECT *" . PHP_EOL;
1180 1180
                 }
1181 1181
 
1182
-                for ($x = ($i + 1); $x < $closer; $x++) {
1183
-                    $this->tokens[$x]['conditions'][$i] = T_OBJECT;
1184
-                    ksort($this->tokens[$x]['conditions'], SORT_NUMERIC);
1185
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1186
-                        $type = $this->tokens[$x]['type'];
1187
-                        echo str_repeat("\t", count($classStack));
1188
-                        echo "\t\t* added T_OBJECT condition to $x ($type) *".PHP_EOL;
1182
+                for ( $x = ( $i + 1 ); $x < $closer; $x++ ) {
1183
+                    $this->tokens[ $x ][ 'conditions' ][ $i ] = T_OBJECT;
1184
+                    ksort( $this->tokens[ $x ][ 'conditions' ], SORT_NUMERIC );
1185
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1186
+                        $type = $this->tokens[ $x ][ 'type' ];
1187
+                        echo str_repeat( "\t", count( $classStack ) );
1188
+                        echo "\t\t* added T_OBJECT condition to $x ($type) *" . PHP_EOL;
1189 1189
                     }
1190 1190
                 }
1191
-            } else if ($this->tokens[$i]['code'] === T_CLOSE_OBJECT) {
1192
-                $opener = array_pop($classStack);
1193
-            } else if ($this->tokens[$i]['code'] === T_COLON) {
1191
+            } else if ( $this->tokens[ $i ][ 'code' ] === T_CLOSE_OBJECT ) {
1192
+                $opener = array_pop( $classStack );
1193
+            } else if ( $this->tokens[ $i ][ 'code' ] === T_COLON ) {
1194 1194
                 // If it is a scope opener, it belongs to a
1195 1195
                 // DEFAULT or CASE statement.
1196
-                if (isset($this->tokens[$i]['scope_condition']) === true) {
1196
+                if ( isset( $this->tokens[ $i ][ 'scope_condition' ] ) === true ) {
1197 1197
                     continue;
1198 1198
                 }
1199 1199
 
1200 1200
                 // Make sure this is not part of an inline IF statement.
1201
-                for ($x = ($i - 1); $x >= 0; $x--) {
1202
-                    if ($this->tokens[$x]['code'] === T_INLINE_THEN) {
1203
-                        $this->tokens[$i]['code'] = T_INLINE_ELSE;
1204
-                        $this->tokens[$i]['type'] = 'T_INLINE_ELSE';
1205
-
1206
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1207
-                            echo str_repeat("\t", count($classStack));
1208
-                            echo "\t* token $i converted from T_COLON to T_INLINE_THEN *".PHP_EOL;
1201
+                for ( $x = ( $i - 1 ); $x >= 0; $x-- ) {
1202
+                    if ( $this->tokens[ $x ][ 'code' ] === T_INLINE_THEN ) {
1203
+                        $this->tokens[ $i ][ 'code' ] = T_INLINE_ELSE;
1204
+                        $this->tokens[ $i ][ 'type' ] = 'T_INLINE_ELSE';
1205
+
1206
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1207
+                            echo str_repeat( "\t", count( $classStack ) );
1208
+                            echo "\t* token $i converted from T_COLON to T_INLINE_THEN *" . PHP_EOL;
1209 1209
                         }
1210 1210
 
1211
-                        continue(2);
1212
-                    } else if ($this->tokens[$x]['line'] < $this->tokens[$i]['line']) {
1211
+                        continue( 2 );
1212
+                    } else if ( $this->tokens[ $x ][ 'line' ] < $this->tokens[ $i ][ 'line' ] ) {
1213 1213
                         break;
1214 1214
                     }
1215 1215
                 }
1216 1216
 
1217 1217
                 // The string to the left of the colon is either a property or label.
1218
-                for ($label = ($i - 1); $label >= 0; $label--) {
1219
-                    if (isset(Util\Tokens::$emptyTokens[$this->tokens[$label]['code']]) === false) {
1218
+                for ( $label = ( $i - 1 ); $label >= 0; $label-- ) {
1219
+                    if ( isset( Util\Tokens::$emptyTokens[ $this->tokens[ $label ][ 'code' ] ] ) === false ) {
1220 1220
                         break;
1221 1221
                     }
1222 1222
                 }
1223 1223
 
1224
-                if ($this->tokens[$label]['code'] !== T_STRING
1225
-                    && $this->tokens[$label]['code'] !== T_CONSTANT_ENCAPSED_STRING
1224
+                if ( $this->tokens[ $label ][ 'code' ] !== T_STRING
1225
+                    && $this->tokens[ $label ][ 'code' ] !== T_CONSTANT_ENCAPSED_STRING
1226 1226
                 ) {
1227 1227
                     continue;
1228 1228
                 }
1229 1229
 
1230
-                if (empty($classStack) === false) {
1231
-                    $this->tokens[$label]['code'] = T_PROPERTY;
1232
-                    $this->tokens[$label]['type'] = 'T_PROPERTY';
1230
+                if ( empty( $classStack ) === false ) {
1231
+                    $this->tokens[ $label ][ 'code' ] = T_PROPERTY;
1232
+                    $this->tokens[ $label ][ 'type' ] = 'T_PROPERTY';
1233 1233
 
1234
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1235
-                        echo str_repeat("\t", count($classStack));
1236
-                        echo "\t* token $label converted from T_STRING to T_PROPERTY *".PHP_EOL;
1234
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1235
+                        echo str_repeat( "\t", count( $classStack ) );
1236
+                        echo "\t* token $label converted from T_STRING to T_PROPERTY *" . PHP_EOL;
1237 1237
                     }
1238 1238
                 } else {
1239
-                    $this->tokens[$label]['code'] = T_LABEL;
1240
-                    $this->tokens[$label]['type'] = 'T_LABEL';
1239
+                    $this->tokens[ $label ][ 'code' ] = T_LABEL;
1240
+                    $this->tokens[ $label ][ 'type' ] = 'T_LABEL';
1241 1241
 
1242
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
1243
-                        echo str_repeat("\t", count($classStack));
1244
-                        echo "\t* token $label converted from T_STRING to T_LABEL *".PHP_EOL;
1242
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1243
+                        echo str_repeat( "\t", count( $classStack ) );
1244
+                        echo "\t* token $label converted from T_STRING to T_LABEL *" . PHP_EOL;
1245 1245
                     }
1246 1246
                 }//end if
1247 1247
             }//end if
1248 1248
         }//end for
1249 1249
 
1250
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1251
-            echo "\t*** END ADDITIONAL JS PROCESSING ***".PHP_EOL;
1250
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1251
+            echo "\t*** END ADDITIONAL JS PROCESSING ***" . PHP_EOL;
1252 1252
         }
1253 1253
 
1254 1254
     }//end processAdditional()
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Exceptions\TokenizerException;
14 14
 use PHP_CodeSniffer\Config;
15 15
 
16
-class JS extends Tokenizer
17
-{
16
+class JS extends Tokenizer {
18 17
 
19 18
 
20 19
     /**
@@ -259,8 +258,7 @@  discard block
 block discarded – undo
259 258
      * @return void
260 259
      * @throws \PHP_CodeSniffer\Exceptions\TokenizerException If the file appears to be minified.
261 260
      */
262
-    public function __construct($content, Config $config, $eolChar='\n')
263
-    {
261
+    public function __construct($content, Config $config, $eolChar='\n') {
264 262
         if ($this->isMinifiedContent($content, $eolChar) === true) {
265 263
             throw new TokenizerException('File appears to be minified and cannot be processed');
266 264
         }
@@ -277,8 +275,7 @@  discard block
 block discarded – undo
277 275
      *
278 276
      * @return array
279 277
      */
280
-    public function tokenize($string)
281
-    {
278
+    public function tokenize($string) {
282 279
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
283 280
             echo "\t*** START JS TOKENIZING ***".PHP_EOL;
284 281
         }
@@ -913,8 +910,7 @@  discard block
 block discarded – undo
913 910
      *
914 911
      * @return array<string, string>|null
915 912
      */
916
-    public function getRegexToken($char, $string, $chars, $tokens)
917
-    {
913
+    public function getRegexToken($char, $string, $chars, $tokens) {
918 914
         $beforeTokens = [
919 915
             T_EQUAL               => true,
920 916
             T_IS_NOT_EQUAL        => true,
@@ -1050,8 +1046,7 @@  discard block
 block discarded – undo
1050 1046
      *
1051 1047
      * @return void
1052 1048
      */
1053
-    public function processAdditional()
1054
-    {
1049
+    public function processAdditional() {
1055 1050
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
1056 1051
             echo "\t*** START ADDITIONAL JS PROCESSING ***".PHP_EOL;
1057 1052
         }
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Tokenizers/Comment.php 3 patches
Indentation   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -15,263 +15,263 @@
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * Creates an array of tokens when given some PHP code.
20
-     *
21
-     * Starts by using token_get_all() but does a lot of extra processing
22
-     * to insert information about the context of the token.
23
-     *
24
-     * @param string $string   The string to tokenize.
25
-     * @param string $eolChar  The EOL character to use for splitting strings.
26
-     * @param int    $stackPtr The position of the first token in the file.
27
-     *
28
-     * @return array
29
-     */
30
-    public function tokenizeString($string, $eolChar, $stackPtr)
31
-    {
32
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
33
-            echo "\t\t*** START COMMENT TOKENIZING ***".PHP_EOL;
34
-        }
35
-
36
-        $tokens   = [];
37
-        $numChars = strlen($string);
38
-
39
-        /*
18
+	/**
19
+	 * Creates an array of tokens when given some PHP code.
20
+	 *
21
+	 * Starts by using token_get_all() but does a lot of extra processing
22
+	 * to insert information about the context of the token.
23
+	 *
24
+	 * @param string $string   The string to tokenize.
25
+	 * @param string $eolChar  The EOL character to use for splitting strings.
26
+	 * @param int    $stackPtr The position of the first token in the file.
27
+	 *
28
+	 * @return array
29
+	 */
30
+	public function tokenizeString($string, $eolChar, $stackPtr)
31
+	{
32
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
33
+			echo "\t\t*** START COMMENT TOKENIZING ***".PHP_EOL;
34
+		}
35
+
36
+		$tokens   = [];
37
+		$numChars = strlen($string);
38
+
39
+		/*
40 40
             Doc block comments start with /*, but typically contain an
41 41
             extra star when they are used for function and class comments.
42 42
         */
43 43
 
44
-        $char    = ($numChars - strlen(ltrim($string, '/*')));
45
-        $openTag = substr($string, 0, $char);
46
-        $string  = ltrim($string, '/*');
44
+		$char    = ($numChars - strlen(ltrim($string, '/*')));
45
+		$openTag = substr($string, 0, $char);
46
+		$string  = ltrim($string, '/*');
47 47
 
48
-        $tokens[$stackPtr] = [
49
-            'content'      => $openTag,
50
-            'code'         => T_DOC_COMMENT_OPEN_TAG,
51
-            'type'         => 'T_DOC_COMMENT_OPEN_TAG',
52
-            'comment_tags' => [],
53
-        ];
48
+		$tokens[$stackPtr] = [
49
+			'content'      => $openTag,
50
+			'code'         => T_DOC_COMMENT_OPEN_TAG,
51
+			'type'         => 'T_DOC_COMMENT_OPEN_TAG',
52
+			'comment_tags' => [],
53
+		];
54 54
 
55
-        $openPtr = $stackPtr;
56
-        $stackPtr++;
55
+		$openPtr = $stackPtr;
56
+		$stackPtr++;
57 57
 
58
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
59
-            $content = Util\Common::prepareForOutput($openTag);
60
-            echo "\t\tCreate comment token: T_DOC_COMMENT_OPEN_TAG => $content".PHP_EOL;
61
-        }
58
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
59
+			$content = Util\Common::prepareForOutput($openTag);
60
+			echo "\t\tCreate comment token: T_DOC_COMMENT_OPEN_TAG => $content".PHP_EOL;
61
+		}
62 62
 
63
-        /*
63
+		/*
64 64
             Strip off the close tag so it doesn't interfere with any
65 65
             of our comment line processing. The token will be added to the
66 66
             stack just before we return it.
67 67
         */
68 68
 
69
-        $closeTag = [
70
-            'content'        => substr($string, strlen(rtrim($string, '/*'))),
71
-            'code'           => T_DOC_COMMENT_CLOSE_TAG,
72
-            'type'           => 'T_DOC_COMMENT_CLOSE_TAG',
73
-            'comment_opener' => $openPtr,
74
-        ];
69
+		$closeTag = [
70
+			'content'        => substr($string, strlen(rtrim($string, '/*'))),
71
+			'code'           => T_DOC_COMMENT_CLOSE_TAG,
72
+			'type'           => 'T_DOC_COMMENT_CLOSE_TAG',
73
+			'comment_opener' => $openPtr,
74
+		];
75 75
 
76
-        if ($closeTag['content'] === false) {
77
-            $closeTag['content'] = '';
78
-        }
76
+		if ($closeTag['content'] === false) {
77
+			$closeTag['content'] = '';
78
+		}
79 79
 
80
-        $string = rtrim($string, '/*');
80
+		$string = rtrim($string, '/*');
81 81
 
82
-        /*
82
+		/*
83 83
             Process each line of the comment.
84 84
         */
85 85
 
86
-        $lines    = explode($eolChar, $string);
87
-        $numLines = count($lines);
88
-        foreach ($lines as $lineNum => $string) {
89
-            if ($lineNum !== ($numLines - 1)) {
90
-                $string .= $eolChar;
91
-            }
92
-
93
-            $char     = 0;
94
-            $numChars = strlen($string);
95
-
96
-            // We've started a new line, so process the indent.
97
-            $space = $this->collectWhitespace($string, $char, $numChars);
98
-            if ($space !== null) {
99
-                $tokens[$stackPtr] = $space;
100
-                $stackPtr++;
101
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
102
-                    $content = Util\Common::prepareForOutput($space['content']);
103
-                    echo "\t\tCreate comment token: T_DOC_COMMENT_WHITESPACE => $content".PHP_EOL;
104
-                }
105
-
106
-                $char += strlen($space['content']);
107
-                if ($char === $numChars) {
108
-                    break;
109
-                }
110
-            }
111
-
112
-            if ($string === '') {
113
-                continue;
114
-            }
115
-
116
-            if ($lineNum > 0 && $string[$char] === '*') {
117
-                // This is a function or class doc block line.
118
-                $char++;
119
-                $tokens[$stackPtr] = [
120
-                    'content' => '*',
121
-                    'code'    => T_DOC_COMMENT_STAR,
122
-                    'type'    => 'T_DOC_COMMENT_STAR',
123
-                ];
124
-
125
-                $stackPtr++;
126
-
127
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
128
-                    echo "\t\tCreate comment token: T_DOC_COMMENT_STAR => *".PHP_EOL;
129
-                }
130
-            }
131
-
132
-            // Now we are ready to process the actual content of the line.
133
-            $lineTokens = $this->processLine($string, $eolChar, $char, $numChars);
134
-            foreach ($lineTokens as $lineToken) {
135
-                $tokens[$stackPtr] = $lineToken;
136
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
137
-                    $content = Util\Common::prepareForOutput($lineToken['content']);
138
-                    $type    = $lineToken['type'];
139
-                    echo "\t\tCreate comment token: $type => $content".PHP_EOL;
140
-                }
141
-
142
-                if ($lineToken['code'] === T_DOC_COMMENT_TAG) {
143
-                    $tokens[$openPtr]['comment_tags'][] = $stackPtr;
144
-                }
145
-
146
-                $stackPtr++;
147
-            }
148
-        }//end foreach
149
-
150
-        $tokens[$stackPtr] = $closeTag;
151
-        $tokens[$openPtr]['comment_closer'] = $stackPtr;
152
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
153
-            $content = Util\Common::prepareForOutput($closeTag['content']);
154
-            echo "\t\tCreate comment token: T_DOC_COMMENT_CLOSE_TAG => $content".PHP_EOL;
155
-        }
156
-
157
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
158
-            echo "\t\t*** END COMMENT TOKENIZING ***".PHP_EOL;
159
-        }
160
-
161
-        return $tokens;
162
-
163
-    }//end tokenizeString()
164
-
165
-
166
-    /**
167
-     * Process a single line of a comment.
168
-     *
169
-     * @param string $string  The comment string being tokenized.
170
-     * @param string $eolChar The EOL character to use for splitting strings.
171
-     * @param int    $start   The position in the string to start processing.
172
-     * @param int    $end     The position in the string to end processing.
173
-     *
174
-     * @return array
175
-     */
176
-    private function processLine($string, $eolChar, $start, $end)
177
-    {
178
-        $tokens = [];
179
-
180
-        // Collect content padding.
181
-        $space = $this->collectWhitespace($string, $start, $end);
182
-        if ($space !== null) {
183
-            $tokens[] = $space;
184
-            $start   += strlen($space['content']);
185
-        }
186
-
187
-        if (isset($string[$start]) === false) {
188
-            return $tokens;
189
-        }
190
-
191
-        if ($string[$start] === '@') {
192
-            // The content up until the first whitespace is the tag name.
193
-            $matches = [];
194
-            preg_match('/@[^\s]+/', $string, $matches, 0, $start);
195
-            if (isset($matches[0]) === true
196
-                && substr(strtolower($matches[0]), 0, 7) !== '@phpcs:'
197
-            ) {
198
-                $tagName  = $matches[0];
199
-                $start   += strlen($tagName);
200
-                $tokens[] = [
201
-                    'content' => $tagName,
202
-                    'code'    => T_DOC_COMMENT_TAG,
203
-                    'type'    => 'T_DOC_COMMENT_TAG',
204
-                ];
205
-
206
-                // Then there will be some whitespace.
207
-                $space = $this->collectWhitespace($string, $start, $end);
208
-                if ($space !== null) {
209
-                    $tokens[] = $space;
210
-                    $start   += strlen($space['content']);
211
-                }
212
-            }
213
-        }//end if
214
-
215
-        // Process the rest of the line.
216
-        $eol = strpos($string, $eolChar, $start);
217
-        if ($eol === false) {
218
-            $eol = $end;
219
-        }
220
-
221
-        if ($eol > $start) {
222
-            $tokens[] = [
223
-                'content' => substr($string, $start, ($eol - $start)),
224
-                'code'    => T_DOC_COMMENT_STRING,
225
-                'type'    => 'T_DOC_COMMENT_STRING',
226
-            ];
227
-        }
228
-
229
-        if ($eol !== $end) {
230
-            $tokens[] = [
231
-                'content' => substr($string, $eol, strlen($eolChar)),
232
-                'code'    => T_DOC_COMMENT_WHITESPACE,
233
-                'type'    => 'T_DOC_COMMENT_WHITESPACE',
234
-            ];
235
-        }
236
-
237
-        return $tokens;
238
-
239
-    }//end processLine()
240
-
241
-
242
-    /**
243
-     * Collect consecutive whitespace into a single token.
244
-     *
245
-     * @param string $string The comment string being tokenized.
246
-     * @param int    $start  The position in the string to start processing.
247
-     * @param int    $end    The position in the string to end processing.
248
-     *
249
-     * @return array|null
250
-     */
251
-    private function collectWhitespace($string, $start, $end)
252
-    {
253
-        $space = '';
254
-        for ($start; $start < $end; $start++) {
255
-            if ($string[$start] !== ' ' && $string[$start] !== "\t") {
256
-                break;
257
-            }
258
-
259
-            $space .= $string[$start];
260
-        }
261
-
262
-        if ($space === '') {
263
-            return null;
264
-        }
265
-
266
-        $token = [
267
-            'content' => $space,
268
-            'code'    => T_DOC_COMMENT_WHITESPACE,
269
-            'type'    => 'T_DOC_COMMENT_WHITESPACE',
270
-        ];
271
-
272
-        return $token;
273
-
274
-    }//end collectWhitespace()
86
+		$lines    = explode($eolChar, $string);
87
+		$numLines = count($lines);
88
+		foreach ($lines as $lineNum => $string) {
89
+			if ($lineNum !== ($numLines - 1)) {
90
+				$string .= $eolChar;
91
+			}
92
+
93
+			$char     = 0;
94
+			$numChars = strlen($string);
95
+
96
+			// We've started a new line, so process the indent.
97
+			$space = $this->collectWhitespace($string, $char, $numChars);
98
+			if ($space !== null) {
99
+				$tokens[$stackPtr] = $space;
100
+				$stackPtr++;
101
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
102
+					$content = Util\Common::prepareForOutput($space['content']);
103
+					echo "\t\tCreate comment token: T_DOC_COMMENT_WHITESPACE => $content".PHP_EOL;
104
+				}
105
+
106
+				$char += strlen($space['content']);
107
+				if ($char === $numChars) {
108
+					break;
109
+				}
110
+			}
111
+
112
+			if ($string === '') {
113
+				continue;
114
+			}
115
+
116
+			if ($lineNum > 0 && $string[$char] === '*') {
117
+				// This is a function or class doc block line.
118
+				$char++;
119
+				$tokens[$stackPtr] = [
120
+					'content' => '*',
121
+					'code'    => T_DOC_COMMENT_STAR,
122
+					'type'    => 'T_DOC_COMMENT_STAR',
123
+				];
124
+
125
+				$stackPtr++;
126
+
127
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
128
+					echo "\t\tCreate comment token: T_DOC_COMMENT_STAR => *".PHP_EOL;
129
+				}
130
+			}
131
+
132
+			// Now we are ready to process the actual content of the line.
133
+			$lineTokens = $this->processLine($string, $eolChar, $char, $numChars);
134
+			foreach ($lineTokens as $lineToken) {
135
+				$tokens[$stackPtr] = $lineToken;
136
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
137
+					$content = Util\Common::prepareForOutput($lineToken['content']);
138
+					$type    = $lineToken['type'];
139
+					echo "\t\tCreate comment token: $type => $content".PHP_EOL;
140
+				}
141
+
142
+				if ($lineToken['code'] === T_DOC_COMMENT_TAG) {
143
+					$tokens[$openPtr]['comment_tags'][] = $stackPtr;
144
+				}
145
+
146
+				$stackPtr++;
147
+			}
148
+		}//end foreach
149
+
150
+		$tokens[$stackPtr] = $closeTag;
151
+		$tokens[$openPtr]['comment_closer'] = $stackPtr;
152
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
153
+			$content = Util\Common::prepareForOutput($closeTag['content']);
154
+			echo "\t\tCreate comment token: T_DOC_COMMENT_CLOSE_TAG => $content".PHP_EOL;
155
+		}
156
+
157
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
158
+			echo "\t\t*** END COMMENT TOKENIZING ***".PHP_EOL;
159
+		}
160
+
161
+		return $tokens;
162
+
163
+	}//end tokenizeString()
164
+
165
+
166
+	/**
167
+	 * Process a single line of a comment.
168
+	 *
169
+	 * @param string $string  The comment string being tokenized.
170
+	 * @param string $eolChar The EOL character to use for splitting strings.
171
+	 * @param int    $start   The position in the string to start processing.
172
+	 * @param int    $end     The position in the string to end processing.
173
+	 *
174
+	 * @return array
175
+	 */
176
+	private function processLine($string, $eolChar, $start, $end)
177
+	{
178
+		$tokens = [];
179
+
180
+		// Collect content padding.
181
+		$space = $this->collectWhitespace($string, $start, $end);
182
+		if ($space !== null) {
183
+			$tokens[] = $space;
184
+			$start   += strlen($space['content']);
185
+		}
186
+
187
+		if (isset($string[$start]) === false) {
188
+			return $tokens;
189
+		}
190
+
191
+		if ($string[$start] === '@') {
192
+			// The content up until the first whitespace is the tag name.
193
+			$matches = [];
194
+			preg_match('/@[^\s]+/', $string, $matches, 0, $start);
195
+			if (isset($matches[0]) === true
196
+				&& substr(strtolower($matches[0]), 0, 7) !== '@phpcs:'
197
+			) {
198
+				$tagName  = $matches[0];
199
+				$start   += strlen($tagName);
200
+				$tokens[] = [
201
+					'content' => $tagName,
202
+					'code'    => T_DOC_COMMENT_TAG,
203
+					'type'    => 'T_DOC_COMMENT_TAG',
204
+				];
205
+
206
+				// Then there will be some whitespace.
207
+				$space = $this->collectWhitespace($string, $start, $end);
208
+				if ($space !== null) {
209
+					$tokens[] = $space;
210
+					$start   += strlen($space['content']);
211
+				}
212
+			}
213
+		}//end if
214
+
215
+		// Process the rest of the line.
216
+		$eol = strpos($string, $eolChar, $start);
217
+		if ($eol === false) {
218
+			$eol = $end;
219
+		}
220
+
221
+		if ($eol > $start) {
222
+			$tokens[] = [
223
+				'content' => substr($string, $start, ($eol - $start)),
224
+				'code'    => T_DOC_COMMENT_STRING,
225
+				'type'    => 'T_DOC_COMMENT_STRING',
226
+			];
227
+		}
228
+
229
+		if ($eol !== $end) {
230
+			$tokens[] = [
231
+				'content' => substr($string, $eol, strlen($eolChar)),
232
+				'code'    => T_DOC_COMMENT_WHITESPACE,
233
+				'type'    => 'T_DOC_COMMENT_WHITESPACE',
234
+			];
235
+		}
236
+
237
+		return $tokens;
238
+
239
+	}//end processLine()
240
+
241
+
242
+	/**
243
+	 * Collect consecutive whitespace into a single token.
244
+	 *
245
+	 * @param string $string The comment string being tokenized.
246
+	 * @param int    $start  The position in the string to start processing.
247
+	 * @param int    $end    The position in the string to end processing.
248
+	 *
249
+	 * @return array|null
250
+	 */
251
+	private function collectWhitespace($string, $start, $end)
252
+	{
253
+		$space = '';
254
+		for ($start; $start < $end; $start++) {
255
+			if ($string[$start] !== ' ' && $string[$start] !== "\t") {
256
+				break;
257
+			}
258
+
259
+			$space .= $string[$start];
260
+		}
261
+
262
+		if ($space === '') {
263
+			return null;
264
+		}
265
+
266
+		$token = [
267
+			'content' => $space,
268
+			'code'    => T_DOC_COMMENT_WHITESPACE,
269
+			'type'    => 'T_DOC_COMMENT_WHITESPACE',
270
+		];
271
+
272
+		return $token;
273
+
274
+	}//end collectWhitespace()
275 275
 
276 276
 
277 277
 }//end class
Please login to merge, or discard this patch.
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -27,37 +27,37 @@  discard block
 block discarded – undo
27 27
      *
28 28
      * @return array
29 29
      */
30
-    public function tokenizeString($string, $eolChar, $stackPtr)
30
+    public function tokenizeString( $string, $eolChar, $stackPtr )
31 31
     {
32
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
33
-            echo "\t\t*** START COMMENT TOKENIZING ***".PHP_EOL;
32
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
33
+            echo "\t\t*** START COMMENT TOKENIZING ***" . PHP_EOL;
34 34
         }
35 35
 
36
-        $tokens   = [];
37
-        $numChars = strlen($string);
36
+        $tokens   = [ ];
37
+        $numChars = strlen( $string );
38 38
 
39 39
         /*
40 40
             Doc block comments start with /*, but typically contain an
41 41
             extra star when they are used for function and class comments.
42 42
         */
43 43
 
44
-        $char    = ($numChars - strlen(ltrim($string, '/*')));
45
-        $openTag = substr($string, 0, $char);
46
-        $string  = ltrim($string, '/*');
44
+        $char    = ( $numChars - strlen( ltrim( $string, '/*' ) ) );
45
+        $openTag = substr( $string, 0, $char );
46
+        $string  = ltrim( $string, '/*' );
47 47
 
48
-        $tokens[$stackPtr] = [
48
+        $tokens[ $stackPtr ] = [
49 49
             'content'      => $openTag,
50 50
             'code'         => T_DOC_COMMENT_OPEN_TAG,
51 51
             'type'         => 'T_DOC_COMMENT_OPEN_TAG',
52
-            'comment_tags' => [],
52
+            'comment_tags' => [ ],
53 53
         ];
54 54
 
55 55
         $openPtr = $stackPtr;
56 56
         $stackPtr++;
57 57
 
58
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
59
-            $content = Util\Common::prepareForOutput($openTag);
60
-            echo "\t\tCreate comment token: T_DOC_COMMENT_OPEN_TAG => $content".PHP_EOL;
58
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
59
+            $content = Util\Common::prepareForOutput( $openTag );
60
+            echo "\t\tCreate comment token: T_DOC_COMMENT_OPEN_TAG => $content" . PHP_EOL;
61 61
         }
62 62
 
63 63
         /*
@@ -67,56 +67,56 @@  discard block
 block discarded – undo
67 67
         */
68 68
 
69 69
         $closeTag = [
70
-            'content'        => substr($string, strlen(rtrim($string, '/*'))),
70
+            'content'        => substr( $string, strlen( rtrim( $string, '/*' ) ) ),
71 71
             'code'           => T_DOC_COMMENT_CLOSE_TAG,
72 72
             'type'           => 'T_DOC_COMMENT_CLOSE_TAG',
73 73
             'comment_opener' => $openPtr,
74 74
         ];
75 75
 
76
-        if ($closeTag['content'] === false) {
77
-            $closeTag['content'] = '';
76
+        if ( $closeTag[ 'content' ] === false ) {
77
+            $closeTag[ 'content' ] = '';
78 78
         }
79 79
 
80
-        $string = rtrim($string, '/*');
80
+        $string = rtrim( $string, '/*' );
81 81
 
82 82
         /*
83 83
             Process each line of the comment.
84 84
         */
85 85
 
86
-        $lines    = explode($eolChar, $string);
87
-        $numLines = count($lines);
88
-        foreach ($lines as $lineNum => $string) {
89
-            if ($lineNum !== ($numLines - 1)) {
86
+        $lines    = explode( $eolChar, $string );
87
+        $numLines = count( $lines );
88
+        foreach ( $lines as $lineNum => $string ) {
89
+            if ( $lineNum !== ( $numLines - 1 ) ) {
90 90
                 $string .= $eolChar;
91 91
             }
92 92
 
93 93
             $char     = 0;
94
-            $numChars = strlen($string);
94
+            $numChars = strlen( $string );
95 95
 
96 96
             // We've started a new line, so process the indent.
97
-            $space = $this->collectWhitespace($string, $char, $numChars);
98
-            if ($space !== null) {
99
-                $tokens[$stackPtr] = $space;
97
+            $space = $this->collectWhitespace( $string, $char, $numChars );
98
+            if ( $space !== null ) {
99
+                $tokens[ $stackPtr ] = $space;
100 100
                 $stackPtr++;
101
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
102
-                    $content = Util\Common::prepareForOutput($space['content']);
103
-                    echo "\t\tCreate comment token: T_DOC_COMMENT_WHITESPACE => $content".PHP_EOL;
101
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
102
+                    $content = Util\Common::prepareForOutput( $space[ 'content' ] );
103
+                    echo "\t\tCreate comment token: T_DOC_COMMENT_WHITESPACE => $content" . PHP_EOL;
104 104
                 }
105 105
 
106
-                $char += strlen($space['content']);
107
-                if ($char === $numChars) {
106
+                $char += strlen( $space[ 'content' ] );
107
+                if ( $char === $numChars ) {
108 108
                     break;
109 109
                 }
110 110
             }
111 111
 
112
-            if ($string === '') {
112
+            if ( $string === '' ) {
113 113
                 continue;
114 114
             }
115 115
 
116
-            if ($lineNum > 0 && $string[$char] === '*') {
116
+            if ( $lineNum > 0 && $string[ $char ] === '*' ) {
117 117
                 // This is a function or class doc block line.
118 118
                 $char++;
119
-                $tokens[$stackPtr] = [
119
+                $tokens[ $stackPtr ] = [
120 120
                     'content' => '*',
121 121
                     'code'    => T_DOC_COMMENT_STAR,
122 122
                     'type'    => 'T_DOC_COMMENT_STAR',
@@ -124,38 +124,38 @@  discard block
 block discarded – undo
124 124
 
125 125
                 $stackPtr++;
126 126
 
127
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
128
-                    echo "\t\tCreate comment token: T_DOC_COMMENT_STAR => *".PHP_EOL;
127
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
128
+                    echo "\t\tCreate comment token: T_DOC_COMMENT_STAR => *" . PHP_EOL;
129 129
                 }
130 130
             }
131 131
 
132 132
             // Now we are ready to process the actual content of the line.
133
-            $lineTokens = $this->processLine($string, $eolChar, $char, $numChars);
134
-            foreach ($lineTokens as $lineToken) {
135
-                $tokens[$stackPtr] = $lineToken;
136
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
137
-                    $content = Util\Common::prepareForOutput($lineToken['content']);
138
-                    $type    = $lineToken['type'];
139
-                    echo "\t\tCreate comment token: $type => $content".PHP_EOL;
133
+            $lineTokens = $this->processLine( $string, $eolChar, $char, $numChars );
134
+            foreach ( $lineTokens as $lineToken ) {
135
+                $tokens[ $stackPtr ] = $lineToken;
136
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
137
+                    $content = Util\Common::prepareForOutput( $lineToken[ 'content' ] );
138
+                    $type    = $lineToken[ 'type' ];
139
+                    echo "\t\tCreate comment token: $type => $content" . PHP_EOL;
140 140
                 }
141 141
 
142
-                if ($lineToken['code'] === T_DOC_COMMENT_TAG) {
143
-                    $tokens[$openPtr]['comment_tags'][] = $stackPtr;
142
+                if ( $lineToken[ 'code' ] === T_DOC_COMMENT_TAG ) {
143
+                    $tokens[ $openPtr ][ 'comment_tags' ][ ] = $stackPtr;
144 144
                 }
145 145
 
146 146
                 $stackPtr++;
147 147
             }
148 148
         }//end foreach
149 149
 
150
-        $tokens[$stackPtr] = $closeTag;
151
-        $tokens[$openPtr]['comment_closer'] = $stackPtr;
152
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
153
-            $content = Util\Common::prepareForOutput($closeTag['content']);
154
-            echo "\t\tCreate comment token: T_DOC_COMMENT_CLOSE_TAG => $content".PHP_EOL;
150
+        $tokens[ $stackPtr ] = $closeTag;
151
+        $tokens[ $openPtr ][ 'comment_closer' ] = $stackPtr;
152
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
153
+            $content = Util\Common::prepareForOutput( $closeTag[ 'content' ] );
154
+            echo "\t\tCreate comment token: T_DOC_COMMENT_CLOSE_TAG => $content" . PHP_EOL;
155 155
         }
156 156
 
157
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
158
-            echo "\t\t*** END COMMENT TOKENIZING ***".PHP_EOL;
157
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
158
+            echo "\t\t*** END COMMENT TOKENIZING ***" . PHP_EOL;
159 159
         }
160 160
 
161 161
         return $tokens;
@@ -173,62 +173,62 @@  discard block
 block discarded – undo
173 173
      *
174 174
      * @return array
175 175
      */
176
-    private function processLine($string, $eolChar, $start, $end)
176
+    private function processLine( $string, $eolChar, $start, $end )
177 177
     {
178
-        $tokens = [];
178
+        $tokens = [ ];
179 179
 
180 180
         // Collect content padding.
181
-        $space = $this->collectWhitespace($string, $start, $end);
182
-        if ($space !== null) {
183
-            $tokens[] = $space;
184
-            $start   += strlen($space['content']);
181
+        $space = $this->collectWhitespace( $string, $start, $end );
182
+        if ( $space !== null ) {
183
+            $tokens[ ] = $space;
184
+            $start   += strlen( $space[ 'content' ] );
185 185
         }
186 186
 
187
-        if (isset($string[$start]) === false) {
187
+        if ( isset( $string[ $start ] ) === false ) {
188 188
             return $tokens;
189 189
         }
190 190
 
191
-        if ($string[$start] === '@') {
191
+        if ( $string[ $start ] === '@' ) {
192 192
             // The content up until the first whitespace is the tag name.
193
-            $matches = [];
194
-            preg_match('/@[^\s]+/', $string, $matches, 0, $start);
195
-            if (isset($matches[0]) === true
196
-                && substr(strtolower($matches[0]), 0, 7) !== '@phpcs:'
193
+            $matches = [ ];
194
+            preg_match( '/@[^\s]+/', $string, $matches, 0, $start );
195
+            if ( isset( $matches[ 0 ] ) === true
196
+                && substr( strtolower( $matches[ 0 ] ), 0, 7 ) !== '@phpcs:'
197 197
             ) {
198
-                $tagName  = $matches[0];
199
-                $start   += strlen($tagName);
200
-                $tokens[] = [
198
+                $tagName  = $matches[ 0 ];
199
+                $start   += strlen( $tagName );
200
+                $tokens[ ] = [
201 201
                     'content' => $tagName,
202 202
                     'code'    => T_DOC_COMMENT_TAG,
203 203
                     'type'    => 'T_DOC_COMMENT_TAG',
204 204
                 ];
205 205
 
206 206
                 // Then there will be some whitespace.
207
-                $space = $this->collectWhitespace($string, $start, $end);
208
-                if ($space !== null) {
209
-                    $tokens[] = $space;
210
-                    $start   += strlen($space['content']);
207
+                $space = $this->collectWhitespace( $string, $start, $end );
208
+                if ( $space !== null ) {
209
+                    $tokens[ ] = $space;
210
+                    $start   += strlen( $space[ 'content' ] );
211 211
                 }
212 212
             }
213 213
         }//end if
214 214
 
215 215
         // Process the rest of the line.
216
-        $eol = strpos($string, $eolChar, $start);
217
-        if ($eol === false) {
216
+        $eol = strpos( $string, $eolChar, $start );
217
+        if ( $eol === false ) {
218 218
             $eol = $end;
219 219
         }
220 220
 
221
-        if ($eol > $start) {
222
-            $tokens[] = [
223
-                'content' => substr($string, $start, ($eol - $start)),
221
+        if ( $eol > $start ) {
222
+            $tokens[ ] = [
223
+                'content' => substr( $string, $start, ( $eol - $start ) ),
224 224
                 'code'    => T_DOC_COMMENT_STRING,
225 225
                 'type'    => 'T_DOC_COMMENT_STRING',
226 226
             ];
227 227
         }
228 228
 
229
-        if ($eol !== $end) {
230
-            $tokens[] = [
231
-                'content' => substr($string, $eol, strlen($eolChar)),
229
+        if ( $eol !== $end ) {
230
+            $tokens[ ] = [
231
+                'content' => substr( $string, $eol, strlen( $eolChar ) ),
232 232
                 'code'    => T_DOC_COMMENT_WHITESPACE,
233 233
                 'type'    => 'T_DOC_COMMENT_WHITESPACE',
234 234
             ];
@@ -248,18 +248,18 @@  discard block
 block discarded – undo
248 248
      *
249 249
      * @return array|null
250 250
      */
251
-    private function collectWhitespace($string, $start, $end)
251
+    private function collectWhitespace( $string, $start, $end )
252 252
     {
253 253
         $space = '';
254
-        for ($start; $start < $end; $start++) {
255
-            if ($string[$start] !== ' ' && $string[$start] !== "\t") {
254
+        for ( $start; $start < $end; $start++ ) {
255
+            if ( $string[ $start ] !== ' ' && $string[ $start ] !== "\t" ) {
256 256
                 break;
257 257
             }
258 258
 
259
-            $space .= $string[$start];
259
+            $space .= $string[ $start ];
260 260
         }
261 261
 
262
-        if ($space === '') {
262
+        if ( $space === '' ) {
263 263
             return null;
264 264
         }
265 265
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,8 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 use PHP_CodeSniffer\Util;
13 13
 
14
-class Comment
15
-{
14
+class Comment {
16 15
 
17 16
 
18 17
     /**
@@ -27,8 +26,7 @@  discard block
 block discarded – undo
27 26
      *
28 27
      * @return array
29 28
      */
30
-    public function tokenizeString($string, $eolChar, $stackPtr)
31
-    {
29
+    public function tokenizeString($string, $eolChar, $stackPtr) {
32 30
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
33 31
             echo "\t\t*** START COMMENT TOKENIZING ***".PHP_EOL;
34 32
         }
@@ -173,8 +171,7 @@  discard block
 block discarded – undo
173 171
      *
174 172
      * @return array
175 173
      */
176
-    private function processLine($string, $eolChar, $start, $end)
177
-    {
174
+    private function processLine($string, $eolChar, $start, $end) {
178 175
         $tokens = [];
179 176
 
180 177
         // Collect content padding.
@@ -248,8 +245,7 @@  discard block
 block discarded – undo
248 245
      *
249 246
      * @return array|null
250 247
      */
251
-    private function collectWhitespace($string, $start, $end)
252
-    {
248
+    private function collectWhitespace($string, $start, $end) {
253 249
         $space = '';
254 250
         for ($start; $start < $end; $start++) {
255 251
             if ($string[$start] !== ' ' && $string[$start] !== "\t") {
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Exceptions/TokenizerException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@
 block discarded – undo
9 9
 
10 10
 namespace PHP_CodeSniffer\Exceptions;
11 11
 
12
-class TokenizerException extends \Exception
13
-{
12
+class TokenizerException extends \Exception {
14 13
 
15 14
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Exceptions/RuntimeException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,6 @@
 block discarded – undo
9 9
 
10 10
 namespace PHP_CodeSniffer\Exceptions;
11 11
 
12
-class RuntimeException extends \RuntimeException
13
-{
12
+class RuntimeException extends \RuntimeException {
14 13
 
15 14
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Exceptions/DeepExitException.php 1 patch
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,7 +12,6 @@
 block discarded – undo
12 12
 
13 13
 namespace PHP_CodeSniffer\Exceptions;
14 14
 
15
-class DeepExitException extends \Exception
16
-{
15
+class DeepExitException extends \Exception {
17 16
 
18 17
 }//end class
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php 3 patches
Indentation   +191 added lines, -191 removed lines patch added patch discarded remove patch
@@ -17,197 +17,197 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * Creates a LocalFile object and sets the content.
22
-     *
23
-     * @param string                   $path    The absolute path to the file.
24
-     * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
25
-     * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
26
-     *
27
-     * @return void
28
-     */
29
-    public function __construct($path, Ruleset $ruleset, Config $config)
30
-    {
31
-        $this->path = trim($path);
32
-        if (is_readable($this->path) === false) {
33
-            parent::__construct($this->path, $ruleset, $config);
34
-            $error = 'Error opening file; file no longer exists or you do not have access to read the file';
35
-            $this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', [], 5, false);
36
-            $this->ignored = true;
37
-            return;
38
-        }
39
-
40
-        // Before we go and spend time tokenizing this file, just check
41
-        // to see if there is a tag up top to indicate that the whole
42
-        // file should be ignored. It must be on one of the first two lines.
43
-        if ($config->annotations === true) {
44
-            $handle = fopen($this->path, 'r');
45
-            if ($handle !== false) {
46
-                $firstContent  = fgets($handle);
47
-                $firstContent .= fgets($handle);
48
-                fclose($handle);
49
-
50
-                if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false
51
-                    || stripos($firstContent, 'phpcs:ignorefile') !== false
52
-                ) {
53
-                    // We are ignoring the whole file.
54
-                    $this->ignored = true;
55
-                    return;
56
-                }
57
-            }
58
-        }
59
-
60
-        $this->reloadContent();
61
-
62
-        parent::__construct($this->path, $ruleset, $config);
63
-
64
-    }//end __construct()
65
-
66
-
67
-    /**
68
-     * Loads the latest version of the file's content from the file system.
69
-     *
70
-     * @return void
71
-     */
72
-    public function reloadContent()
73
-    {
74
-        $this->setContent(file_get_contents($this->path));
75
-
76
-    }//end reloadContent()
77
-
78
-
79
-    /**
80
-     * Processes the file.
81
-     *
82
-     * @return void
83
-     */
84
-    public function process()
85
-    {
86
-        if ($this->ignored === true) {
87
-            return;
88
-        }
89
-
90
-        if ($this->configCache['cache'] === false) {
91
-            parent::process();
92
-            return;
93
-        }
94
-
95
-        $hash  = md5_file($this->path);
96
-        $cache = Cache::get($this->path);
97
-        if ($cache !== false && $cache['hash'] === $hash) {
98
-            // We can't filter metrics, so just load all of them.
99
-            $this->metrics = $cache['metrics'];
100
-
101
-            if ($this->configCache['recordErrors'] === true) {
102
-                // Replay the cached errors and warnings to filter out the ones
103
-                // we don't need for this specific run.
104
-                $this->configCache['cache'] = false;
105
-                $this->replayErrors($cache['errors'], $cache['warnings']);
106
-                $this->configCache['cache'] = true;
107
-            } else {
108
-                $this->errorCount   = $cache['errorCount'];
109
-                $this->warningCount = $cache['warningCount'];
110
-                $this->fixableCount = $cache['fixableCount'];
111
-            }
112
-
113
-            if (PHP_CODESNIFFER_VERBOSITY > 0
114
-                || (PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false)
115
-            ) {
116
-                echo "[loaded from cache]... ";
117
-            }
118
-
119
-            $this->numTokens = $cache['numTokens'];
120
-            $this->fromCache = true;
121
-            return;
122
-        }//end if
123
-
124
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
125
-            echo PHP_EOL;
126
-        }
127
-
128
-        parent::process();
129
-
130
-        $cache = [
131
-            'hash'         => $hash,
132
-            'errors'       => $this->errors,
133
-            'warnings'     => $this->warnings,
134
-            'metrics'      => $this->metrics,
135
-            'errorCount'   => $this->errorCount,
136
-            'warningCount' => $this->warningCount,
137
-            'fixableCount' => $this->fixableCount,
138
-            'numTokens'    => $this->numTokens,
139
-        ];
140
-
141
-        Cache::set($this->path, $cache);
142
-
143
-        // During caching, we don't filter out errors in any way, so
144
-        // we need to do that manually now by replaying them.
145
-        if ($this->configCache['recordErrors'] === true) {
146
-            $this->configCache['cache'] = false;
147
-            $this->replayErrors($this->errors, $this->warnings);
148
-            $this->configCache['cache'] = true;
149
-        }
150
-
151
-    }//end process()
152
-
153
-
154
-    /**
155
-     * Clears and replays error and warnings for the file.
156
-     *
157
-     * Replaying errors and warnings allows for filtering rules to be changed
158
-     * and then errors and warnings to be reapplied with the new rules. This is
159
-     * particularly useful while caching.
160
-     *
161
-     * @param array $errors   The list of errors to replay.
162
-     * @param array $warnings The list of warnings to replay.
163
-     *
164
-     * @return void
165
-     */
166
-    private function replayErrors($errors, $warnings)
167
-    {
168
-        $this->errors       = [];
169
-        $this->warnings     = [];
170
-        $this->errorCount   = 0;
171
-        $this->warningCount = 0;
172
-        $this->fixableCount = 0;
173
-
174
-        foreach ($errors as $line => $lineErrors) {
175
-            foreach ($lineErrors as $column => $colErrors) {
176
-                foreach ($colErrors as $error) {
177
-                    $this->activeListener = $error['listener'];
178
-                    $this->addMessage(
179
-                        true,
180
-                        $error['message'],
181
-                        $line,
182
-                        $column,
183
-                        $error['source'],
184
-                        [],
185
-                        $error['severity'],
186
-                        $error['fixable']
187
-                    );
188
-                }
189
-            }
190
-        }
191
-
192
-        foreach ($warnings as $line => $lineErrors) {
193
-            foreach ($lineErrors as $column => $colErrors) {
194
-                foreach ($colErrors as $error) {
195
-                    $this->activeListener = $error['listener'];
196
-                    $this->addMessage(
197
-                        false,
198
-                        $error['message'],
199
-                        $line,
200
-                        $column,
201
-                        $error['source'],
202
-                        [],
203
-                        $error['severity'],
204
-                        $error['fixable']
205
-                    );
206
-                }
207
-            }
208
-        }
209
-
210
-    }//end replayErrors()
20
+	/**
21
+	 * Creates a LocalFile object and sets the content.
22
+	 *
23
+	 * @param string                   $path    The absolute path to the file.
24
+	 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
25
+	 * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
26
+	 *
27
+	 * @return void
28
+	 */
29
+	public function __construct($path, Ruleset $ruleset, Config $config)
30
+	{
31
+		$this->path = trim($path);
32
+		if (is_readable($this->path) === false) {
33
+			parent::__construct($this->path, $ruleset, $config);
34
+			$error = 'Error opening file; file no longer exists or you do not have access to read the file';
35
+			$this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', [], 5, false);
36
+			$this->ignored = true;
37
+			return;
38
+		}
39
+
40
+		// Before we go and spend time tokenizing this file, just check
41
+		// to see if there is a tag up top to indicate that the whole
42
+		// file should be ignored. It must be on one of the first two lines.
43
+		if ($config->annotations === true) {
44
+			$handle = fopen($this->path, 'r');
45
+			if ($handle !== false) {
46
+				$firstContent  = fgets($handle);
47
+				$firstContent .= fgets($handle);
48
+				fclose($handle);
49
+
50
+				if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false
51
+					|| stripos($firstContent, 'phpcs:ignorefile') !== false
52
+				) {
53
+					// We are ignoring the whole file.
54
+					$this->ignored = true;
55
+					return;
56
+				}
57
+			}
58
+		}
59
+
60
+		$this->reloadContent();
61
+
62
+		parent::__construct($this->path, $ruleset, $config);
63
+
64
+	}//end __construct()
65
+
66
+
67
+	/**
68
+	 * Loads the latest version of the file's content from the file system.
69
+	 *
70
+	 * @return void
71
+	 */
72
+	public function reloadContent()
73
+	{
74
+		$this->setContent(file_get_contents($this->path));
75
+
76
+	}//end reloadContent()
77
+
78
+
79
+	/**
80
+	 * Processes the file.
81
+	 *
82
+	 * @return void
83
+	 */
84
+	public function process()
85
+	{
86
+		if ($this->ignored === true) {
87
+			return;
88
+		}
89
+
90
+		if ($this->configCache['cache'] === false) {
91
+			parent::process();
92
+			return;
93
+		}
94
+
95
+		$hash  = md5_file($this->path);
96
+		$cache = Cache::get($this->path);
97
+		if ($cache !== false && $cache['hash'] === $hash) {
98
+			// We can't filter metrics, so just load all of them.
99
+			$this->metrics = $cache['metrics'];
100
+
101
+			if ($this->configCache['recordErrors'] === true) {
102
+				// Replay the cached errors and warnings to filter out the ones
103
+				// we don't need for this specific run.
104
+				$this->configCache['cache'] = false;
105
+				$this->replayErrors($cache['errors'], $cache['warnings']);
106
+				$this->configCache['cache'] = true;
107
+			} else {
108
+				$this->errorCount   = $cache['errorCount'];
109
+				$this->warningCount = $cache['warningCount'];
110
+				$this->fixableCount = $cache['fixableCount'];
111
+			}
112
+
113
+			if (PHP_CODESNIFFER_VERBOSITY > 0
114
+				|| (PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false)
115
+			) {
116
+				echo "[loaded from cache]... ";
117
+			}
118
+
119
+			$this->numTokens = $cache['numTokens'];
120
+			$this->fromCache = true;
121
+			return;
122
+		}//end if
123
+
124
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
125
+			echo PHP_EOL;
126
+		}
127
+
128
+		parent::process();
129
+
130
+		$cache = [
131
+			'hash'         => $hash,
132
+			'errors'       => $this->errors,
133
+			'warnings'     => $this->warnings,
134
+			'metrics'      => $this->metrics,
135
+			'errorCount'   => $this->errorCount,
136
+			'warningCount' => $this->warningCount,
137
+			'fixableCount' => $this->fixableCount,
138
+			'numTokens'    => $this->numTokens,
139
+		];
140
+
141
+		Cache::set($this->path, $cache);
142
+
143
+		// During caching, we don't filter out errors in any way, so
144
+		// we need to do that manually now by replaying them.
145
+		if ($this->configCache['recordErrors'] === true) {
146
+			$this->configCache['cache'] = false;
147
+			$this->replayErrors($this->errors, $this->warnings);
148
+			$this->configCache['cache'] = true;
149
+		}
150
+
151
+	}//end process()
152
+
153
+
154
+	/**
155
+	 * Clears and replays error and warnings for the file.
156
+	 *
157
+	 * Replaying errors and warnings allows for filtering rules to be changed
158
+	 * and then errors and warnings to be reapplied with the new rules. This is
159
+	 * particularly useful while caching.
160
+	 *
161
+	 * @param array $errors   The list of errors to replay.
162
+	 * @param array $warnings The list of warnings to replay.
163
+	 *
164
+	 * @return void
165
+	 */
166
+	private function replayErrors($errors, $warnings)
167
+	{
168
+		$this->errors       = [];
169
+		$this->warnings     = [];
170
+		$this->errorCount   = 0;
171
+		$this->warningCount = 0;
172
+		$this->fixableCount = 0;
173
+
174
+		foreach ($errors as $line => $lineErrors) {
175
+			foreach ($lineErrors as $column => $colErrors) {
176
+				foreach ($colErrors as $error) {
177
+					$this->activeListener = $error['listener'];
178
+					$this->addMessage(
179
+						true,
180
+						$error['message'],
181
+						$line,
182
+						$column,
183
+						$error['source'],
184
+						[],
185
+						$error['severity'],
186
+						$error['fixable']
187
+					);
188
+				}
189
+			}
190
+		}
191
+
192
+		foreach ($warnings as $line => $lineErrors) {
193
+			foreach ($lineErrors as $column => $colErrors) {
194
+				foreach ($colErrors as $error) {
195
+					$this->activeListener = $error['listener'];
196
+					$this->addMessage(
197
+						false,
198
+						$error['message'],
199
+						$line,
200
+						$column,
201
+						$error['source'],
202
+						[],
203
+						$error['severity'],
204
+						$error['fixable']
205
+					);
206
+				}
207
+			}
208
+		}
209
+
210
+	}//end replayErrors()
211 211
 
212 212
 
213 213
 }//end class
Please login to merge, or discard this patch.
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -26,13 +26,13 @@  discard block
 block discarded – undo
26 26
      *
27 27
      * @return void
28 28
      */
29
-    public function __construct($path, Ruleset $ruleset, Config $config)
29
+    public function __construct( $path, Ruleset $ruleset, Config $config )
30 30
     {
31
-        $this->path = trim($path);
32
-        if (is_readable($this->path) === false) {
33
-            parent::__construct($this->path, $ruleset, $config);
31
+        $this->path = trim( $path );
32
+        if ( is_readable( $this->path ) === false ) {
33
+            parent::__construct( $this->path, $ruleset, $config );
34 34
             $error = 'Error opening file; file no longer exists or you do not have access to read the file';
35
-            $this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', [], 5, false);
35
+            $this->addMessage( true, $error, 1, 1, 'Internal.LocalFile', [ ], 5, false );
36 36
             $this->ignored = true;
37 37
             return;
38 38
         }
@@ -40,15 +40,15 @@  discard block
 block discarded – undo
40 40
         // Before we go and spend time tokenizing this file, just check
41 41
         // to see if there is a tag up top to indicate that the whole
42 42
         // file should be ignored. It must be on one of the first two lines.
43
-        if ($config->annotations === true) {
44
-            $handle = fopen($this->path, 'r');
45
-            if ($handle !== false) {
46
-                $firstContent  = fgets($handle);
47
-                $firstContent .= fgets($handle);
48
-                fclose($handle);
49
-
50
-                if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false
51
-                    || stripos($firstContent, 'phpcs:ignorefile') !== false
43
+        if ( $config->annotations === true ) {
44
+            $handle = fopen( $this->path, 'r' );
45
+            if ( $handle !== false ) {
46
+                $firstContent  = fgets( $handle );
47
+                $firstContent .= fgets( $handle );
48
+                fclose( $handle );
49
+
50
+                if ( strpos( $firstContent, '@codingStandardsIgnoreFile' ) !== false
51
+                    || stripos( $firstContent, 'phpcs:ignorefile' ) !== false
52 52
                 ) {
53 53
                     // We are ignoring the whole file.
54 54
                     $this->ignored = true;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 
60 60
         $this->reloadContent();
61 61
 
62
-        parent::__construct($this->path, $ruleset, $config);
62
+        parent::__construct( $this->path, $ruleset, $config );
63 63
 
64 64
     }//end __construct()
65 65
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
      */
72 72
     public function reloadContent()
73 73
     {
74
-        $this->setContent(file_get_contents($this->path));
74
+        $this->setContent( file_get_contents( $this->path ) );
75 75
 
76 76
     }//end reloadContent()
77 77
 
@@ -83,45 +83,45 @@  discard block
 block discarded – undo
83 83
      */
84 84
     public function process()
85 85
     {
86
-        if ($this->ignored === true) {
86
+        if ( $this->ignored === true ) {
87 87
             return;
88 88
         }
89 89
 
90
-        if ($this->configCache['cache'] === false) {
90
+        if ( $this->configCache[ 'cache' ] === false ) {
91 91
             parent::process();
92 92
             return;
93 93
         }
94 94
 
95
-        $hash  = md5_file($this->path);
96
-        $cache = Cache::get($this->path);
97
-        if ($cache !== false && $cache['hash'] === $hash) {
95
+        $hash  = md5_file( $this->path );
96
+        $cache = Cache::get( $this->path );
97
+        if ( $cache !== false && $cache[ 'hash' ] === $hash ) {
98 98
             // We can't filter metrics, so just load all of them.
99
-            $this->metrics = $cache['metrics'];
99
+            $this->metrics = $cache[ 'metrics' ];
100 100
 
101
-            if ($this->configCache['recordErrors'] === true) {
101
+            if ( $this->configCache[ 'recordErrors' ] === true ) {
102 102
                 // Replay the cached errors and warnings to filter out the ones
103 103
                 // we don't need for this specific run.
104
-                $this->configCache['cache'] = false;
105
-                $this->replayErrors($cache['errors'], $cache['warnings']);
106
-                $this->configCache['cache'] = true;
104
+                $this->configCache[ 'cache' ] = false;
105
+                $this->replayErrors( $cache[ 'errors' ], $cache[ 'warnings' ] );
106
+                $this->configCache[ 'cache' ] = true;
107 107
             } else {
108
-                $this->errorCount   = $cache['errorCount'];
109
-                $this->warningCount = $cache['warningCount'];
110
-                $this->fixableCount = $cache['fixableCount'];
108
+                $this->errorCount   = $cache[ 'errorCount' ];
109
+                $this->warningCount = $cache[ 'warningCount' ];
110
+                $this->fixableCount = $cache[ 'fixableCount' ];
111 111
             }
112 112
 
113
-            if (PHP_CODESNIFFER_VERBOSITY > 0
114
-                || (PHP_CODESNIFFER_CBF === true && empty($this->config->files) === false)
113
+            if ( PHP_CODESNIFFER_VERBOSITY > 0
114
+                || ( PHP_CODESNIFFER_CBF === true && empty( $this->config->files ) === false )
115 115
             ) {
116 116
                 echo "[loaded from cache]... ";
117 117
             }
118 118
 
119
-            $this->numTokens = $cache['numTokens'];
119
+            $this->numTokens = $cache[ 'numTokens' ];
120 120
             $this->fromCache = true;
121 121
             return;
122 122
         }//end if
123 123
 
124
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
124
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
125 125
             echo PHP_EOL;
126 126
         }
127 127
 
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
             'numTokens'    => $this->numTokens,
139 139
         ];
140 140
 
141
-        Cache::set($this->path, $cache);
141
+        Cache::set( $this->path, $cache );
142 142
 
143 143
         // During caching, we don't filter out errors in any way, so
144 144
         // we need to do that manually now by replaying them.
145
-        if ($this->configCache['recordErrors'] === true) {
146
-            $this->configCache['cache'] = false;
147
-            $this->replayErrors($this->errors, $this->warnings);
148
-            $this->configCache['cache'] = true;
145
+        if ( $this->configCache[ 'recordErrors' ] === true ) {
146
+            $this->configCache[ 'cache' ] = false;
147
+            $this->replayErrors( $this->errors, $this->warnings );
148
+            $this->configCache[ 'cache' ] = true;
149 149
         }
150 150
 
151 151
     }//end process()
@@ -163,45 +163,45 @@  discard block
 block discarded – undo
163 163
      *
164 164
      * @return void
165 165
      */
166
-    private function replayErrors($errors, $warnings)
166
+    private function replayErrors( $errors, $warnings )
167 167
     {
168
-        $this->errors       = [];
169
-        $this->warnings     = [];
168
+        $this->errors       = [ ];
169
+        $this->warnings     = [ ];
170 170
         $this->errorCount   = 0;
171 171
         $this->warningCount = 0;
172 172
         $this->fixableCount = 0;
173 173
 
174
-        foreach ($errors as $line => $lineErrors) {
175
-            foreach ($lineErrors as $column => $colErrors) {
176
-                foreach ($colErrors as $error) {
177
-                    $this->activeListener = $error['listener'];
174
+        foreach ( $errors as $line => $lineErrors ) {
175
+            foreach ( $lineErrors as $column => $colErrors ) {
176
+                foreach ( $colErrors as $error ) {
177
+                    $this->activeListener = $error[ 'listener' ];
178 178
                     $this->addMessage(
179 179
                         true,
180
-                        $error['message'],
180
+                        $error[ 'message' ],
181 181
                         $line,
182 182
                         $column,
183
-                        $error['source'],
184
-                        [],
185
-                        $error['severity'],
186
-                        $error['fixable']
183
+                        $error[ 'source' ],
184
+                        [ ],
185
+                        $error[ 'severity' ],
186
+                        $error[ 'fixable' ]
187 187
                     );
188 188
                 }
189 189
             }
190 190
         }
191 191
 
192
-        foreach ($warnings as $line => $lineErrors) {
193
-            foreach ($lineErrors as $column => $colErrors) {
194
-                foreach ($colErrors as $error) {
195
-                    $this->activeListener = $error['listener'];
192
+        foreach ( $warnings as $line => $lineErrors ) {
193
+            foreach ( $lineErrors as $column => $colErrors ) {
194
+                foreach ( $colErrors as $error ) {
195
+                    $this->activeListener = $error[ 'listener' ];
196 196
                     $this->addMessage(
197 197
                         false,
198
-                        $error['message'],
198
+                        $error[ 'message' ],
199 199
                         $line,
200 200
                         $column,
201
-                        $error['source'],
202
-                        [],
203
-                        $error['severity'],
204
-                        $error['fixable']
201
+                        $error[ 'source' ],
202
+                        [ ],
203
+                        $error[ 'severity' ],
204
+                        $error[ 'fixable' ]
205 205
                     );
206 206
                 }
207 207
             }
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 use PHP_CodeSniffer\Config;
14 14
 use PHP_CodeSniffer\Util\Cache;
15 15
 
16
-class LocalFile extends File
17
-{
16
+class LocalFile extends File {
18 17
 
19 18
 
20 19
     /**
@@ -26,8 +25,7 @@  discard block
 block discarded – undo
26 25
      *
27 26
      * @return void
28 27
      */
29
-    public function __construct($path, Ruleset $ruleset, Config $config)
30
-    {
28
+    public function __construct($path, Ruleset $ruleset, Config $config) {
31 29
         $this->path = trim($path);
32 30
         if (is_readable($this->path) === false) {
33 31
             parent::__construct($this->path, $ruleset, $config);
@@ -69,8 +67,7 @@  discard block
 block discarded – undo
69 67
      *
70 68
      * @return void
71 69
      */
72
-    public function reloadContent()
73
-    {
70
+    public function reloadContent() {
74 71
         $this->setContent(file_get_contents($this->path));
75 72
 
76 73
     }//end reloadContent()
@@ -81,8 +78,7 @@  discard block
 block discarded – undo
81 78
      *
82 79
      * @return void
83 80
      */
84
-    public function process()
85
-    {
81
+    public function process() {
86 82
         if ($this->ignored === true) {
87 83
             return;
88 84
         }
@@ -163,8 +159,7 @@  discard block
 block discarded – undo
163 159
      *
164 160
      * @return void
165 161
      */
166
-    private function replayErrors($errors, $warnings)
167
-    {
162
+    private function replayErrors($errors, $warnings) {
168 163
         $this->errors       = [];
169 164
         $this->warnings     = [];
170 165
         $this->errorCount   = 0;
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php 3 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -21,62 +21,62 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * Creates a DummyFile object and sets the content.
26
-     *
27
-     * @param string                   $content The content of the file.
28
-     * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
29
-     * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
30
-     *
31
-     * @return void
32
-     */
33
-    public function __construct($content, Ruleset $ruleset, Config $config)
34
-    {
35
-        $this->setContent($content);
24
+	/**
25
+	 * Creates a DummyFile object and sets the content.
26
+	 *
27
+	 * @param string                   $content The content of the file.
28
+	 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
29
+	 * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
30
+	 *
31
+	 * @return void
32
+	 */
33
+	public function __construct($content, Ruleset $ruleset, Config $config)
34
+	{
35
+		$this->setContent($content);
36 36
 
37
-        // See if a filename was defined in the content.
38
-        // This is done by including: phpcs_input_file: [file path]
39
-        // as the first line of content.
40
-        $path = 'STDIN';
41
-        if ($content !== null) {
42
-            if (substr($content, 0, 17) === 'phpcs_input_file:') {
43
-                $eolPos   = strpos($content, $this->eolChar);
44
-                $filename = trim(substr($content, 17, ($eolPos - 17)));
45
-                $content  = substr($content, ($eolPos + strlen($this->eolChar)));
46
-                $path     = $filename;
37
+		// See if a filename was defined in the content.
38
+		// This is done by including: phpcs_input_file: [file path]
39
+		// as the first line of content.
40
+		$path = 'STDIN';
41
+		if ($content !== null) {
42
+			if (substr($content, 0, 17) === 'phpcs_input_file:') {
43
+				$eolPos   = strpos($content, $this->eolChar);
44
+				$filename = trim(substr($content, 17, ($eolPos - 17)));
45
+				$content  = substr($content, ($eolPos + strlen($this->eolChar)));
46
+				$path     = $filename;
47 47
 
48
-                $this->setContent($content);
49
-            }
50
-        }
48
+				$this->setContent($content);
49
+			}
50
+		}
51 51
 
52
-        // The CLI arg overrides anything passed in the content.
53
-        if ($config->stdinPath !== null) {
54
-            $path = $config->stdinPath;
55
-        }
52
+		// The CLI arg overrides anything passed in the content.
53
+		if ($config->stdinPath !== null) {
54
+			$path = $config->stdinPath;
55
+		}
56 56
 
57
-        parent::__construct($path, $ruleset, $config);
57
+		parent::__construct($path, $ruleset, $config);
58 58
 
59
-    }//end __construct()
59
+	}//end __construct()
60 60
 
61 61
 
62
-    /**
63
-     * Set the error, warning, and fixable counts for the file.
64
-     *
65
-     * @param int $errorCount   The number of errors found.
66
-     * @param int $warningCount The number of warnings found.
67
-     * @param int $fixableCount The number of fixable errors found.
68
-     * @param int $fixedCount   The number of errors that were fixed.
69
-     *
70
-     * @return void
71
-     */
72
-    public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount)
73
-    {
74
-        $this->errorCount   = $errorCount;
75
-        $this->warningCount = $warningCount;
76
-        $this->fixableCount = $fixableCount;
77
-        $this->fixedCount   = $fixedCount;
62
+	/**
63
+	 * Set the error, warning, and fixable counts for the file.
64
+	 *
65
+	 * @param int $errorCount   The number of errors found.
66
+	 * @param int $warningCount The number of warnings found.
67
+	 * @param int $fixableCount The number of fixable errors found.
68
+	 * @param int $fixedCount   The number of errors that were fixed.
69
+	 *
70
+	 * @return void
71
+	 */
72
+	public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount)
73
+	{
74
+		$this->errorCount   = $errorCount;
75
+		$this->warningCount = $warningCount;
76
+		$this->fixableCount = $fixableCount;
77
+		$this->fixedCount   = $fixedCount;
78 78
 
79
-    }//end setErrorCounts()
79
+	}//end setErrorCounts()
80 80
 
81 81
 
82 82
 }//end class
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,31 +30,31 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @return void
32 32
      */
33
-    public function __construct($content, Ruleset $ruleset, Config $config)
33
+    public function __construct( $content, Ruleset $ruleset, Config $config )
34 34
     {
35
-        $this->setContent($content);
35
+        $this->setContent( $content );
36 36
 
37 37
         // See if a filename was defined in the content.
38 38
         // This is done by including: phpcs_input_file: [file path]
39 39
         // as the first line of content.
40 40
         $path = 'STDIN';
41
-        if ($content !== null) {
42
-            if (substr($content, 0, 17) === 'phpcs_input_file:') {
43
-                $eolPos   = strpos($content, $this->eolChar);
44
-                $filename = trim(substr($content, 17, ($eolPos - 17)));
45
-                $content  = substr($content, ($eolPos + strlen($this->eolChar)));
41
+        if ( $content !== null ) {
42
+            if ( substr( $content, 0, 17 ) === 'phpcs_input_file:' ) {
43
+                $eolPos   = strpos( $content, $this->eolChar );
44
+                $filename = trim( substr( $content, 17, ( $eolPos - 17 ) ) );
45
+                $content  = substr( $content, ( $eolPos + strlen( $this->eolChar ) ) );
46 46
                 $path     = $filename;
47 47
 
48
-                $this->setContent($content);
48
+                $this->setContent( $content );
49 49
             }
50 50
         }
51 51
 
52 52
         // The CLI arg overrides anything passed in the content.
53
-        if ($config->stdinPath !== null) {
53
+        if ( $config->stdinPath !== null ) {
54 54
             $path = $config->stdinPath;
55 55
         }
56 56
 
57
-        parent::__construct($path, $ruleset, $config);
57
+        parent::__construct( $path, $ruleset, $config );
58 58
 
59 59
     }//end __construct()
60 60
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @return void
71 71
      */
72
-    public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount)
72
+    public function setErrorCounts( $errorCount, $warningCount, $fixableCount, $fixedCount )
73 73
     {
74 74
         $this->errorCount   = $errorCount;
75 75
         $this->warningCount = $warningCount;
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,8 +17,7 @@  discard block
 block discarded – undo
17 17
 use PHP_CodeSniffer\Ruleset;
18 18
 use PHP_CodeSniffer\Config;
19 19
 
20
-class DummyFile extends File
21
-{
20
+class DummyFile extends File {
22 21
 
23 22
 
24 23
     /**
@@ -30,8 +29,7 @@  discard block
 block discarded – undo
30 29
      *
31 30
      * @return void
32 31
      */
33
-    public function __construct($content, Ruleset $ruleset, Config $config)
34
-    {
32
+    public function __construct($content, Ruleset $ruleset, Config $config) {
35 33
         $this->setContent($content);
36 34
 
37 35
         // See if a filename was defined in the content.
@@ -69,8 +67,7 @@  discard block
 block discarded – undo
69 67
      *
70 68
      * @return void
71 69
      */
72
-    public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount)
73
-    {
70
+    public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount) {
74 71
         $this->errorCount   = $errorCount;
75 72
         $this->warningCount = $warningCount;
76 73
         $this->fixableCount = $fixableCount;
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Ruleset.php 4 patches
Indentation   +1348 added lines, -1348 removed lines patch added patch discarded remove patch
@@ -17,1354 +17,1354 @@
 block discarded – undo
17 17
 class Ruleset
18 18
 {
19 19
 
20
-    /**
21
-     * The name of the coding standard being used.
22
-     *
23
-     * If a top-level standard includes other standards, or sniffs
24
-     * from other standards, only the name of the top-level standard
25
-     * will be stored in here.
26
-     *
27
-     * If multiple top-level standards are being loaded into
28
-     * a single ruleset object, this will store a comma separated list
29
-     * of the top-level standard names.
30
-     *
31
-     * @var string
32
-     */
33
-    public $name = '';
34
-
35
-    /**
36
-     * A list of file paths for the ruleset files being used.
37
-     *
38
-     * @var string[]
39
-     */
40
-    public $paths = [];
41
-
42
-    /**
43
-     * A list of regular expressions used to ignore specific sniffs for files and folders.
44
-     *
45
-     * Is also used to set global exclude patterns.
46
-     * The key is the regular expression and the value is the type
47
-     * of ignore pattern (absolute or relative).
48
-     *
49
-     * @var array<string, string>
50
-     */
51
-    public $ignorePatterns = [];
52
-
53
-    /**
54
-     * A list of regular expressions used to include specific sniffs for files and folders.
55
-     *
56
-     * The key is the sniff code and the value is an array with
57
-     * the key being a regular expression and the value is the type
58
-     * of ignore pattern (absolute or relative).
59
-     *
60
-     * @var array<string, array<string, string>>
61
-     */
62
-    public $includePatterns = [];
63
-
64
-    /**
65
-     * An array of sniff objects that are being used to check files.
66
-     *
67
-     * The key is the fully qualified name of the sniff class
68
-     * and the value is the sniff object.
69
-     *
70
-     * @var array<string, \PHP_CodeSniffer\Sniffs\Sniff>
71
-     */
72
-    public $sniffs = [];
73
-
74
-    /**
75
-     * A mapping of sniff codes to fully qualified class names.
76
-     *
77
-     * The key is the sniff code and the value
78
-     * is the fully qualified name of the sniff class.
79
-     *
80
-     * @var array<string, string>
81
-     */
82
-    public $sniffCodes = [];
83
-
84
-    /**
85
-     * An array of token types and the sniffs that are listening for them.
86
-     *
87
-     * The key is the token name being listened for and the value
88
-     * is the sniff object.
89
-     *
90
-     * @var array<int, \PHP_CodeSniffer\Sniffs\Sniff>
91
-     */
92
-    public $tokenListeners = [];
93
-
94
-    /**
95
-     * An array of rules from the ruleset.xml file.
96
-     *
97
-     * It may be empty, indicating that the ruleset does not override
98
-     * any of the default sniff settings.
99
-     *
100
-     * @var array<string, mixed>
101
-     */
102
-    public $ruleset = [];
103
-
104
-    /**
105
-     * The directories that the processed rulesets are in.
106
-     *
107
-     * @var string[]
108
-     */
109
-    protected $rulesetDirs = [];
110
-
111
-    /**
112
-     * The config data for the run.
113
-     *
114
-     * @var \PHP_CodeSniffer\Config
115
-     */
116
-    private $config = null;
117
-
118
-
119
-    /**
120
-     * Initialise the ruleset that the run will use.
121
-     *
122
-     * @param \PHP_CodeSniffer\Config $config The config data for the run.
123
-     *
124
-     * @return void
125
-     */
126
-    public function __construct(Config $config)
127
-    {
128
-        // Ignore sniff restrictions if caching is on.
129
-        $restrictions = [];
130
-        $exclusions   = [];
131
-        if ($config->cache === false) {
132
-            $restrictions = $config->sniffs;
133
-            $exclusions   = $config->exclude;
134
-        }
135
-
136
-        $this->config = $config;
137
-        $sniffs       = [];
138
-
139
-        $standardPaths = [];
140
-        foreach ($config->standards as $standard) {
141
-            $installed = Util\Standards::getInstalledStandardPath($standard);
142
-            if ($installed === null) {
143
-                $standard = Util\Common::realpath($standard);
144
-                if (is_dir($standard) === true
145
-                    && is_file(Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml')) === true
146
-                ) {
147
-                    $standard = Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml');
148
-                }
149
-            } else {
150
-                $standard = $installed;
151
-            }
152
-
153
-            $standardPaths[] = $standard;
154
-        }
155
-
156
-        foreach ($standardPaths as $standard) {
157
-            $ruleset = @simplexml_load_string(file_get_contents($standard));
158
-            if ($ruleset !== false) {
159
-                $standardName = (string) $ruleset['name'];
160
-                if ($this->name !== '') {
161
-                    $this->name .= ', ';
162
-                }
163
-
164
-                $this->name .= $standardName;
165
-
166
-                // Allow autoloading of custom files inside this standard.
167
-                if (isset($ruleset['namespace']) === true) {
168
-                    $namespace = (string) $ruleset['namespace'];
169
-                } else {
170
-                    $namespace = basename(dirname($standard));
171
-                }
172
-
173
-                Autoload::addSearchPath(dirname($standard), $namespace);
174
-            }
175
-
176
-            if (defined('PHP_CODESNIFFER_IN_TESTS') === true && empty($restrictions) === false) {
177
-                // In unit tests, only register the sniffs that the test wants and not the entire standard.
178
-                try {
179
-                    foreach ($restrictions as $restriction) {
180
-                        $sniffs = array_merge($sniffs, $this->expandRulesetReference($restriction, dirname($standard)));
181
-                    }
182
-                } catch (RuntimeException $e) {
183
-                    // Sniff reference could not be expanded, which probably means this
184
-                    // is an installed standard. Let the unit test system take care of
185
-                    // setting the correct sniff for testing.
186
-                    return;
187
-                }
188
-
189
-                break;
190
-            }
191
-
192
-            if (PHP_CODESNIFFER_VERBOSITY === 1) {
193
-                echo "Registering sniffs in the $standardName standard... ";
194
-                if (count($config->standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) {
195
-                    echo PHP_EOL;
196
-                }
197
-            }
198
-
199
-            $sniffs = array_merge($sniffs, $this->processRuleset($standard));
200
-        }//end foreach
201
-
202
-        $sniffRestrictions = [];
203
-        foreach ($restrictions as $sniffCode) {
204
-            $parts     = explode('.', strtolower($sniffCode));
205
-            $sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
206
-            $sniffRestrictions[$sniffName] = true;
207
-        }
208
-
209
-        $sniffExclusions = [];
210
-        foreach ($exclusions as $sniffCode) {
211
-            $parts     = explode('.', strtolower($sniffCode));
212
-            $sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
213
-            $sniffExclusions[$sniffName] = true;
214
-        }
215
-
216
-        $this->registerSniffs($sniffs, $sniffRestrictions, $sniffExclusions);
217
-        $this->populateTokenListeners();
218
-
219
-        $numSniffs = count($this->sniffs);
220
-        if (PHP_CODESNIFFER_VERBOSITY === 1) {
221
-            echo "DONE ($numSniffs sniffs registered)".PHP_EOL;
222
-        }
223
-
224
-        if ($numSniffs === 0) {
225
-            throw new RuntimeException('No sniffs were registered');
226
-        }
227
-
228
-    }//end __construct()
229
-
230
-
231
-    /**
232
-     * Prints a report showing the sniffs contained in a standard.
233
-     *
234
-     * @return void
235
-     */
236
-    public function explain()
237
-    {
238
-        $sniffs = array_keys($this->sniffCodes);
239
-        sort($sniffs);
240
-
241
-        ob_start();
242
-
243
-        $lastStandard = null;
244
-        $lastCount    = '';
245
-        $sniffCount   = count($sniffs);
246
-
247
-        // Add a dummy entry to the end so we loop
248
-        // one last time and clear the output buffer.
249
-        $sniffs[] = '';
250
-
251
-        echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL;
252
-
253
-        ob_start();
254
-
255
-        foreach ($sniffs as $i => $sniff) {
256
-            if ($i === $sniffCount) {
257
-                $currentStandard = null;
258
-            } else {
259
-                $currentStandard = substr($sniff, 0, strpos($sniff, '.'));
260
-                if ($lastStandard === null) {
261
-                    $lastStandard = $currentStandard;
262
-                }
263
-            }
264
-
265
-            if ($currentStandard !== $lastStandard) {
266
-                $sniffList = ob_get_contents();
267
-                ob_end_clean();
268
-
269
-                echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniff';
270
-                if ($lastCount > 1) {
271
-                    echo 's';
272
-                }
273
-
274
-                echo ')'.PHP_EOL;
275
-                echo str_repeat('-', (strlen($lastStandard.$lastCount) + 10));
276
-                echo PHP_EOL;
277
-                echo $sniffList;
278
-
279
-                $lastStandard = $currentStandard;
280
-                $lastCount    = 0;
281
-
282
-                if ($currentStandard === null) {
283
-                    break;
284
-                }
285
-
286
-                ob_start();
287
-            }//end if
288
-
289
-            echo '  '.$sniff.PHP_EOL;
290
-            $lastCount++;
291
-        }//end foreach
292
-
293
-    }//end explain()
294
-
295
-
296
-    /**
297
-     * Processes a single ruleset and returns a list of the sniffs it represents.
298
-     *
299
-     * Rules founds within the ruleset are processed immediately, but sniff classes
300
-     * are not registered by this method.
301
-     *
302
-     * @param string $rulesetPath The path to a ruleset XML file.
303
-     * @param int    $depth       How many nested processing steps we are in. This
304
-     *                            is only used for debug output.
305
-     *
306
-     * @return string[]
307
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid.
308
-     */
309
-    public function processRuleset($rulesetPath, $depth=0)
310
-    {
311
-        $rulesetPath = Util\Common::realpath($rulesetPath);
312
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
313
-            echo str_repeat("\t", $depth);
314
-            echo 'Processing ruleset '.Util\Common::stripBasepath($rulesetPath, $this->config->basepath).PHP_EOL;
315
-        }
316
-
317
-        libxml_use_internal_errors(true);
318
-        $ruleset = simplexml_load_string(file_get_contents($rulesetPath));
319
-        if ($ruleset === false) {
320
-            $errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL;
321
-            $errors   = libxml_get_errors();
322
-            foreach ($errors as $error) {
323
-                $errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message;
324
-            }
325
-
326
-            libxml_clear_errors();
327
-            throw new RuntimeException($errorMsg);
328
-        }
329
-
330
-        libxml_use_internal_errors(false);
331
-
332
-        $ownSniffs      = [];
333
-        $includedSniffs = [];
334
-        $excludedSniffs = [];
335
-
336
-        $this->paths[]       = $rulesetPath;
337
-        $rulesetDir          = dirname($rulesetPath);
338
-        $this->rulesetDirs[] = $rulesetDir;
339
-
340
-        $sniffDir = $rulesetDir.DIRECTORY_SEPARATOR.'Sniffs';
341
-        if (is_dir($sniffDir) === true) {
342
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
343
-                echo str_repeat("\t", $depth);
344
-                echo "\tAdding sniff files from ".Util\Common::stripBasepath($sniffDir, $this->config->basepath).' directory'.PHP_EOL;
345
-            }
346
-
347
-            $ownSniffs = $this->expandSniffDirectory($sniffDir, $depth);
348
-        }
349
-
350
-        // Included custom autoloaders.
351
-        foreach ($ruleset->{'autoload'} as $autoload) {
352
-            if ($this->shouldProcessElement($autoload) === false) {
353
-                continue;
354
-            }
355
-
356
-            $autoloadPath = (string) $autoload;
357
-            if (is_file($autoloadPath) === false) {
358
-                $autoloadPath = Util\Common::realPath(dirname($rulesetPath).DIRECTORY_SEPARATOR.$autoloadPath);
359
-            }
360
-
361
-            if ($autoloadPath === false) {
362
-                throw new RuntimeException('The specified autoload file "'.$autoload.'" does not exist');
363
-            }
364
-
365
-            include_once $autoloadPath;
366
-
367
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
368
-                echo str_repeat("\t", $depth);
369
-                echo "\t=> included autoloader $autoloadPath".PHP_EOL;
370
-            }
371
-        }//end foreach
372
-
373
-        // Process custom sniff config settings.
374
-        foreach ($ruleset->{'config'} as $config) {
375
-            if ($this->shouldProcessElement($config) === false) {
376
-                continue;
377
-            }
378
-
379
-            Config::setConfigData((string) $config['name'], (string) $config['value'], true);
380
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
381
-                echo str_repeat("\t", $depth);
382
-                echo "\t=> set config value ".(string) $config['name'].': '.(string) $config['value'].PHP_EOL;
383
-            }
384
-        }
385
-
386
-        foreach ($ruleset->rule as $rule) {
387
-            if (isset($rule['ref']) === false
388
-                || $this->shouldProcessElement($rule) === false
389
-            ) {
390
-                continue;
391
-            }
392
-
393
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
394
-                echo str_repeat("\t", $depth);
395
-                echo "\tProcessing rule \"".$rule['ref'].'"'.PHP_EOL;
396
-            }
397
-
398
-            $expandedSniffs = $this->expandRulesetReference((string) $rule['ref'], $rulesetDir, $depth);
399
-            $newSniffs      = array_diff($expandedSniffs, $includedSniffs);
400
-            $includedSniffs = array_merge($includedSniffs, $expandedSniffs);
401
-
402
-            $parts = explode('.', $rule['ref']);
403
-            if (count($parts) === 4
404
-                && $parts[0] !== ''
405
-                && $parts[1] !== ''
406
-                && $parts[2] !== ''
407
-            ) {
408
-                $sniffCode = $parts[0].'.'.$parts[1].'.'.$parts[2];
409
-                if (isset($this->ruleset[$sniffCode]['severity']) === true
410
-                    && $this->ruleset[$sniffCode]['severity'] === 0
411
-                ) {
412
-                    // This sniff code has already been turned off, but now
413
-                    // it is being explicitly included again, so turn it back on.
414
-                    $this->ruleset[(string) $rule['ref']]['severity'] = 5;
415
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
416
-                        echo str_repeat("\t", $depth);
417
-                        echo "\t\t* disabling sniff exclusion for specific message code *".PHP_EOL;
418
-                        echo str_repeat("\t", $depth);
419
-                        echo "\t\t=> severity set to 5".PHP_EOL;
420
-                    }
421
-                } else if (empty($newSniffs) === false) {
422
-                    $newSniff = $newSniffs[0];
423
-                    if (in_array($newSniff, $ownSniffs, true) === false) {
424
-                        // Including a sniff that hasn't been included higher up, but
425
-                        // only including a single message from it. So turn off all messages in
426
-                        // the sniff, except this one.
427
-                        $this->ruleset[$sniffCode]['severity']            = 0;
428
-                        $this->ruleset[(string) $rule['ref']]['severity'] = 5;
429
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
430
-                            echo str_repeat("\t", $depth);
431
-                            echo "\t\tExcluding sniff \"".$sniffCode.'" except for "'.$parts[3].'"'.PHP_EOL;
432
-                        }
433
-                    }
434
-                }//end if
435
-            }//end if
436
-
437
-            if (isset($rule->exclude) === true) {
438
-                foreach ($rule->exclude as $exclude) {
439
-                    if (isset($exclude['name']) === false) {
440
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
441
-                            echo str_repeat("\t", $depth);
442
-                            echo "\t\t* ignoring empty exclude rule *".PHP_EOL;
443
-                            echo "\t\t\t=> ".$exclude->asXML().PHP_EOL;
444
-                        }
445
-
446
-                        continue;
447
-                    }
448
-
449
-                    if ($this->shouldProcessElement($exclude) === false) {
450
-                        continue;
451
-                    }
452
-
453
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
454
-                        echo str_repeat("\t", $depth);
455
-                        echo "\t\tExcluding rule \"".$exclude['name'].'"'.PHP_EOL;
456
-                    }
457
-
458
-                    // Check if a single code is being excluded, which is a shortcut
459
-                    // for setting the severity of the message to 0.
460
-                    $parts = explode('.', $exclude['name']);
461
-                    if (count($parts) === 4) {
462
-                        $this->ruleset[(string) $exclude['name']]['severity'] = 0;
463
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
464
-                            echo str_repeat("\t", $depth);
465
-                            echo "\t\t=> severity set to 0".PHP_EOL;
466
-                        }
467
-                    } else {
468
-                        $excludedSniffs = array_merge(
469
-                            $excludedSniffs,
470
-                            $this->expandRulesetReference((string) $exclude['name'], $rulesetDir, ($depth + 1))
471
-                        );
472
-                    }
473
-                }//end foreach
474
-            }//end if
475
-
476
-            $this->processRule($rule, $newSniffs, $depth);
477
-        }//end foreach
478
-
479
-        // Process custom command line arguments.
480
-        $cliArgs = [];
481
-        foreach ($ruleset->{'arg'} as $arg) {
482
-            if ($this->shouldProcessElement($arg) === false) {
483
-                continue;
484
-            }
485
-
486
-            if (isset($arg['name']) === true) {
487
-                $argString = '--'.(string) $arg['name'];
488
-                if (isset($arg['value']) === true) {
489
-                    $argString .= '='.(string) $arg['value'];
490
-                }
491
-            } else {
492
-                $argString = '-'.(string) $arg['value'];
493
-            }
494
-
495
-            $cliArgs[] = $argString;
496
-
497
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
498
-                echo str_repeat("\t", $depth);
499
-                echo "\t=> set command line value $argString".PHP_EOL;
500
-            }
501
-        }//end foreach
502
-
503
-        // Set custom php ini values as CLI args.
504
-        foreach ($ruleset->{'ini'} as $arg) {
505
-            if ($this->shouldProcessElement($arg) === false) {
506
-                continue;
507
-            }
508
-
509
-            if (isset($arg['name']) === false) {
510
-                continue;
511
-            }
512
-
513
-            $name      = (string) $arg['name'];
514
-            $argString = $name;
515
-            if (isset($arg['value']) === true) {
516
-                $value      = (string) $arg['value'];
517
-                $argString .= "=$value";
518
-            } else {
519
-                $value = 'true';
520
-            }
521
-
522
-            $cliArgs[] = '-d';
523
-            $cliArgs[] = $argString;
524
-
525
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
526
-                echo str_repeat("\t", $depth);
527
-                echo "\t=> set PHP ini value $name to $value".PHP_EOL;
528
-            }
529
-        }//end foreach
530
-
531
-        if (empty($this->config->files) === true) {
532
-            // Process hard-coded file paths.
533
-            foreach ($ruleset->{'file'} as $file) {
534
-                $file      = (string) $file;
535
-                $cliArgs[] = $file;
536
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
537
-                    echo str_repeat("\t", $depth);
538
-                    echo "\t=> added \"$file\" to the file list".PHP_EOL;
539
-                }
540
-            }
541
-        }
542
-
543
-        if (empty($cliArgs) === false) {
544
-            // Change the directory so all relative paths are worked
545
-            // out based on the location of the ruleset instead of
546
-            // the location of the user.
547
-            $inPhar = Util\Common::isPharFile($rulesetDir);
548
-            if ($inPhar === false) {
549
-                $currentDir = getcwd();
550
-                chdir($rulesetDir);
551
-            }
552
-
553
-            $this->config->setCommandLineValues($cliArgs);
554
-
555
-            if ($inPhar === false) {
556
-                chdir($currentDir);
557
-            }
558
-        }
559
-
560
-        // Process custom ignore pattern rules.
561
-        foreach ($ruleset->{'exclude-pattern'} as $pattern) {
562
-            if ($this->shouldProcessElement($pattern) === false) {
563
-                continue;
564
-            }
565
-
566
-            if (isset($pattern['type']) === false) {
567
-                $pattern['type'] = 'absolute';
568
-            }
569
-
570
-            $this->ignorePatterns[(string) $pattern] = (string) $pattern['type'];
571
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
-                echo str_repeat("\t", $depth);
573
-                echo "\t=> added global ".(string) $pattern['type'].' ignore pattern: '.(string) $pattern.PHP_EOL;
574
-            }
575
-        }
576
-
577
-        $includedSniffs = array_unique(array_merge($ownSniffs, $includedSniffs));
578
-        $excludedSniffs = array_unique($excludedSniffs);
579
-
580
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
581
-            $included = count($includedSniffs);
582
-            $excluded = count($excludedSniffs);
583
-            echo str_repeat("\t", $depth);
584
-            echo "=> Ruleset processing complete; included $included sniffs and excluded $excluded".PHP_EOL;
585
-        }
586
-
587
-        // Merge our own sniff list with our externally included
588
-        // sniff list, but filter out any excluded sniffs.
589
-        $files = [];
590
-        foreach ($includedSniffs as $sniff) {
591
-            if (in_array($sniff, $excludedSniffs, true) === true) {
592
-                continue;
593
-            } else {
594
-                $files[] = Util\Common::realpath($sniff);
595
-            }
596
-        }
597
-
598
-        return $files;
599
-
600
-    }//end processRuleset()
601
-
602
-
603
-    /**
604
-     * Expands a directory into a list of sniff files within.
605
-     *
606
-     * @param string $directory The path to a directory.
607
-     * @param int    $depth     How many nested processing steps we are in. This
608
-     *                          is only used for debug output.
609
-     *
610
-     * @return array
611
-     */
612
-    private function expandSniffDirectory($directory, $depth=0)
613
-    {
614
-        $sniffs = [];
615
-
616
-        $rdi = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
617
-        $di  = new \RecursiveIteratorIterator($rdi, 0, \RecursiveIteratorIterator::CATCH_GET_CHILD);
618
-
619
-        $dirLen = strlen($directory);
620
-
621
-        foreach ($di as $file) {
622
-            $filename = $file->getFilename();
623
-
624
-            // Skip hidden files.
625
-            if (substr($filename, 0, 1) === '.') {
626
-                continue;
627
-            }
628
-
629
-            // We are only interested in PHP and sniff files.
630
-            $fileParts = explode('.', $filename);
631
-            if (array_pop($fileParts) !== 'php') {
632
-                continue;
633
-            }
634
-
635
-            $basename = basename($filename, '.php');
636
-            if (substr($basename, -5) !== 'Sniff') {
637
-                continue;
638
-            }
639
-
640
-            $path = $file->getPathname();
641
-
642
-            // Skip files in hidden directories within the Sniffs directory of this
643
-            // standard. We use the offset with strpos() to allow hidden directories
644
-            // before, valid example:
645
-            // /home/foo/.composer/vendor/squiz/custom_tool/MyStandard/Sniffs/...
646
-            if (strpos($path, DIRECTORY_SEPARATOR.'.', $dirLen) !== false) {
647
-                continue;
648
-            }
649
-
650
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
651
-                echo str_repeat("\t", $depth);
652
-                echo "\t\t=> ".Util\Common::stripBasepath($path, $this->config->basepath).PHP_EOL;
653
-            }
654
-
655
-            $sniffs[] = $path;
656
-        }//end foreach
657
-
658
-        return $sniffs;
659
-
660
-    }//end expandSniffDirectory()
661
-
662
-
663
-    /**
664
-     * Expands a ruleset reference into a list of sniff files.
665
-     *
666
-     * @param string $ref        The reference from the ruleset XML file.
667
-     * @param string $rulesetDir The directory of the ruleset XML file, used to
668
-     *                           evaluate relative paths.
669
-     * @param int    $depth      How many nested processing steps we are in. This
670
-     *                           is only used for debug output.
671
-     *
672
-     * @return array
673
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the reference is invalid.
674
-     */
675
-    private function expandRulesetReference($ref, $rulesetDir, $depth=0)
676
-    {
677
-        // Ignore internal sniffs codes as they are used to only
678
-        // hide and change internal messages.
679
-        if (substr($ref, 0, 9) === 'Internal.') {
680
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
681
-                echo str_repeat("\t", $depth);
682
-                echo "\t\t* ignoring internal sniff code *".PHP_EOL;
683
-            }
684
-
685
-            return [];
686
-        }
687
-
688
-        // As sniffs can't begin with a full stop, assume references in
689
-        // this format are relative paths and attempt to convert them
690
-        // to absolute paths. If this fails, let the reference run through
691
-        // the normal checks and have it fail as normal.
692
-        if (substr($ref, 0, 1) === '.') {
693
-            $realpath = Util\Common::realpath($rulesetDir.'/'.$ref);
694
-            if ($realpath !== false) {
695
-                $ref = $realpath;
696
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
697
-                    echo str_repeat("\t", $depth);
698
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
699
-                }
700
-            }
701
-        }
702
-
703
-        // As sniffs can't begin with a tilde, assume references in
704
-        // this format are relative to the user's home directory.
705
-        if (substr($ref, 0, 2) === '~/') {
706
-            $realpath = Util\Common::realpath($ref);
707
-            if ($realpath !== false) {
708
-                $ref = $realpath;
709
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
710
-                    echo str_repeat("\t", $depth);
711
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
712
-                }
713
-            }
714
-        }
715
-
716
-        if (is_file($ref) === true) {
717
-            if (substr($ref, -9) === 'Sniff.php') {
718
-                // A single external sniff.
719
-                $this->rulesetDirs[] = dirname(dirname(dirname($ref)));
720
-                return [$ref];
721
-            }
722
-        } else {
723
-            // See if this is a whole standard being referenced.
724
-            $path = Util\Standards::getInstalledStandardPath($ref);
725
-            if (Util\Common::isPharFile($path) === true && strpos($path, 'ruleset.xml') === false) {
726
-                // If the ruleset exists inside the phar file, use it.
727
-                if (file_exists($path.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
728
-                    $path .= DIRECTORY_SEPARATOR.'ruleset.xml';
729
-                } else {
730
-                    $path = null;
731
-                }
732
-            }
733
-
734
-            if ($path !== null) {
735
-                $ref = $path;
736
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
737
-                    echo str_repeat("\t", $depth);
738
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
739
-                }
740
-            } else if (is_dir($ref) === false) {
741
-                // Work out the sniff path.
742
-                $sepPos = strpos($ref, DIRECTORY_SEPARATOR);
743
-                if ($sepPos !== false) {
744
-                    $stdName = substr($ref, 0, $sepPos);
745
-                    $path    = substr($ref, $sepPos);
746
-                } else {
747
-                    $parts   = explode('.', $ref);
748
-                    $stdName = $parts[0];
749
-                    if (count($parts) === 1) {
750
-                        // A whole standard?
751
-                        $path = '';
752
-                    } else if (count($parts) === 2) {
753
-                        // A directory of sniffs?
754
-                        $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1];
755
-                    } else {
756
-                        // A single sniff?
757
-                        $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1].DIRECTORY_SEPARATOR.$parts[2].'Sniff.php';
758
-                    }
759
-                }
760
-
761
-                $newRef  = false;
762
-                $stdPath = Util\Standards::getInstalledStandardPath($stdName);
763
-                if ($stdPath !== null && $path !== '') {
764
-                    if (Util\Common::isPharFile($stdPath) === true
765
-                        && strpos($stdPath, 'ruleset.xml') === false
766
-                    ) {
767
-                        // Phar files can only return the directory,
768
-                        // since ruleset can be omitted if building one standard.
769
-                        $newRef = Util\Common::realpath($stdPath.$path);
770
-                    } else {
771
-                        $newRef = Util\Common::realpath(dirname($stdPath).$path);
772
-                    }
773
-                }
774
-
775
-                if ($newRef === false) {
776
-                    // The sniff is not locally installed, so check if it is being
777
-                    // referenced as a remote sniff outside the install. We do this
778
-                    // by looking through all directories where we have found ruleset
779
-                    // files before, looking for ones for this particular standard,
780
-                    // and seeing if it is in there.
781
-                    foreach ($this->rulesetDirs as $dir) {
782
-                        if (strtolower(basename($dir)) !== strtolower($stdName)) {
783
-                            continue;
784
-                        }
785
-
786
-                        $newRef = Util\Common::realpath($dir.$path);
787
-
788
-                        if ($newRef !== false) {
789
-                            $ref = $newRef;
790
-                        }
791
-                    }
792
-                } else {
793
-                    $ref = $newRef;
794
-                }
795
-
796
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
797
-                    echo str_repeat("\t", $depth);
798
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
799
-                }
800
-            }//end if
801
-        }//end if
802
-
803
-        if (is_dir($ref) === true) {
804
-            if (is_file($ref.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
805
-                // We are referencing an external coding standard.
806
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
807
-                    echo str_repeat("\t", $depth);
808
-                    echo "\t\t* rule is referencing a standard using directory name; processing *".PHP_EOL;
809
-                }
810
-
811
-                return $this->processRuleset($ref.DIRECTORY_SEPARATOR.'ruleset.xml', ($depth + 2));
812
-            } else {
813
-                // We are referencing a whole directory of sniffs.
814
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
815
-                    echo str_repeat("\t", $depth);
816
-                    echo "\t\t* rule is referencing a directory of sniffs *".PHP_EOL;
817
-                    echo str_repeat("\t", $depth);
818
-                    echo "\t\tAdding sniff files from directory".PHP_EOL;
819
-                }
820
-
821
-                return $this->expandSniffDirectory($ref, ($depth + 1));
822
-            }
823
-        } else {
824
-            if (is_file($ref) === false) {
825
-                $error = "Referenced sniff \"$ref\" does not exist";
826
-                throw new RuntimeException($error);
827
-            }
828
-
829
-            if (substr($ref, -9) === 'Sniff.php') {
830
-                // A single sniff.
831
-                return [$ref];
832
-            } else {
833
-                // Assume an external ruleset.xml file.
834
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
835
-                    echo str_repeat("\t", $depth);
836
-                    echo "\t\t* rule is referencing a standard using ruleset path; processing *".PHP_EOL;
837
-                }
838
-
839
-                return $this->processRuleset($ref, ($depth + 2));
840
-            }
841
-        }//end if
842
-
843
-    }//end expandRulesetReference()
844
-
845
-
846
-    /**
847
-     * Processes a rule from a ruleset XML file, overriding built-in defaults.
848
-     *
849
-     * @param \SimpleXMLElement $rule      The rule object from a ruleset XML file.
850
-     * @param string[]          $newSniffs An array of sniffs that got included by this rule.
851
-     * @param int               $depth     How many nested processing steps we are in.
852
-     *                                     This is only used for debug output.
853
-     *
854
-     * @return void
855
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If rule settings are invalid.
856
-     */
857
-    private function processRule($rule, $newSniffs, $depth=0)
858
-    {
859
-        $ref  = (string) $rule['ref'];
860
-        $todo = [$ref];
861
-
862
-        $parts = explode('.', $ref);
863
-        if (count($parts) <= 2) {
864
-            // We are processing a standard or a category of sniffs.
865
-            foreach ($newSniffs as $sniffFile) {
866
-                $parts         = explode(DIRECTORY_SEPARATOR, $sniffFile);
867
-                $sniffName     = array_pop($parts);
868
-                $sniffCategory = array_pop($parts);
869
-                array_pop($parts);
870
-                $sniffStandard = array_pop($parts);
871
-                $todo[]        = $sniffStandard.'.'.$sniffCategory.'.'.substr($sniffName, 0, -9);
872
-            }
873
-        }
874
-
875
-        foreach ($todo as $code) {
876
-            // Custom severity.
877
-            if (isset($rule->severity) === true
878
-                && $this->shouldProcessElement($rule->severity) === true
879
-            ) {
880
-                if (isset($this->ruleset[$code]) === false) {
881
-                    $this->ruleset[$code] = [];
882
-                }
883
-
884
-                $this->ruleset[$code]['severity'] = (int) $rule->severity;
885
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
-                    echo str_repeat("\t", $depth);
887
-                    echo "\t\t=> severity set to ".(int) $rule->severity;
888
-                    if ($code !== $ref) {
889
-                        echo " for $code";
890
-                    }
891
-
892
-                    echo PHP_EOL;
893
-                }
894
-            }
895
-
896
-            // Custom message type.
897
-            if (isset($rule->type) === true
898
-                && $this->shouldProcessElement($rule->type) === true
899
-            ) {
900
-                if (isset($this->ruleset[$code]) === false) {
901
-                    $this->ruleset[$code] = [];
902
-                }
903
-
904
-                $type = strtolower((string) $rule->type);
905
-                if ($type !== 'error' && $type !== 'warning') {
906
-                    throw new RuntimeException("Message type \"$type\" is invalid; must be \"error\" or \"warning\"");
907
-                }
908
-
909
-                $this->ruleset[$code]['type'] = $type;
910
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
911
-                    echo str_repeat("\t", $depth);
912
-                    echo "\t\t=> message type set to ".(string) $rule->type;
913
-                    if ($code !== $ref) {
914
-                        echo " for $code";
915
-                    }
916
-
917
-                    echo PHP_EOL;
918
-                }
919
-            }//end if
920
-
921
-            // Custom message.
922
-            if (isset($rule->message) === true
923
-                && $this->shouldProcessElement($rule->message) === true
924
-            ) {
925
-                if (isset($this->ruleset[$code]) === false) {
926
-                    $this->ruleset[$code] = [];
927
-                }
928
-
929
-                $this->ruleset[$code]['message'] = (string) $rule->message;
930
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
931
-                    echo str_repeat("\t", $depth);
932
-                    echo "\t\t=> message set to ".(string) $rule->message;
933
-                    if ($code !== $ref) {
934
-                        echo " for $code";
935
-                    }
936
-
937
-                    echo PHP_EOL;
938
-                }
939
-            }
940
-
941
-            // Custom properties.
942
-            if (isset($rule->properties) === true
943
-                && $this->shouldProcessElement($rule->properties) === true
944
-            ) {
945
-                foreach ($rule->properties->property as $prop) {
946
-                    if ($this->shouldProcessElement($prop) === false) {
947
-                        continue;
948
-                    }
949
-
950
-                    if (isset($this->ruleset[$code]) === false) {
951
-                        $this->ruleset[$code] = [
952
-                            'properties' => [],
953
-                        ];
954
-                    } else if (isset($this->ruleset[$code]['properties']) === false) {
955
-                        $this->ruleset[$code]['properties'] = [];
956
-                    }
957
-
958
-                    $name = (string) $prop['name'];
959
-                    if (isset($prop['type']) === true
960
-                        && (string) $prop['type'] === 'array'
961
-                    ) {
962
-                        $values = [];
963
-                        if (isset($prop['extend']) === true
964
-                            && (string) $prop['extend'] === 'true'
965
-                            && isset($this->ruleset[$code]['properties'][$name]) === true
966
-                        ) {
967
-                            $values = $this->ruleset[$code]['properties'][$name];
968
-                        }
969
-
970
-                        if (isset($prop->element) === true) {
971
-                            $printValue = '';
972
-                            foreach ($prop->element as $element) {
973
-                                if ($this->shouldProcessElement($element) === false) {
974
-                                    continue;
975
-                                }
976
-
977
-                                $value = (string) $element['value'];
978
-                                if (isset($element['key']) === true) {
979
-                                    $key          = (string) $element['key'];
980
-                                    $values[$key] = $value;
981
-                                    $printValue  .= $key.'=>'.$value.',';
982
-                                } else {
983
-                                    $values[]    = $value;
984
-                                    $printValue .= $value.',';
985
-                                }
986
-                            }
987
-
988
-                            $printValue = rtrim($printValue, ',');
989
-                        } else {
990
-                            $value      = (string) $prop['value'];
991
-                            $printValue = $value;
992
-                            foreach (explode(',', $value) as $val) {
993
-                                list($k, $v) = explode('=>', $val.'=>');
994
-                                if ($v !== '') {
995
-                                    $values[trim($k)] = trim($v);
996
-                                } else {
997
-                                    $values[] = trim($k);
998
-                                }
999
-                            }
1000
-                        }//end if
1001
-
1002
-                        $this->ruleset[$code]['properties'][$name] = $values;
1003
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
-                            echo str_repeat("\t", $depth);
1005
-                            echo "\t\t=> array property \"$name\" set to \"$printValue\"";
1006
-                            if ($code !== $ref) {
1007
-                                echo " for $code";
1008
-                            }
1009
-
1010
-                            echo PHP_EOL;
1011
-                        }
1012
-                    } else {
1013
-                        $this->ruleset[$code]['properties'][$name] = (string) $prop['value'];
1014
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1015
-                            echo str_repeat("\t", $depth);
1016
-                            echo "\t\t=> property \"$name\" set to \"".(string) $prop['value'].'"';
1017
-                            if ($code !== $ref) {
1018
-                                echo " for $code";
1019
-                            }
1020
-
1021
-                            echo PHP_EOL;
1022
-                        }
1023
-                    }//end if
1024
-                }//end foreach
1025
-            }//end if
1026
-
1027
-            // Ignore patterns.
1028
-            foreach ($rule->{'exclude-pattern'} as $pattern) {
1029
-                if ($this->shouldProcessElement($pattern) === false) {
1030
-                    continue;
1031
-                }
1032
-
1033
-                if (isset($this->ignorePatterns[$code]) === false) {
1034
-                    $this->ignorePatterns[$code] = [];
1035
-                }
1036
-
1037
-                if (isset($pattern['type']) === false) {
1038
-                    $pattern['type'] = 'absolute';
1039
-                }
1040
-
1041
-                $this->ignorePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1042
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1043
-                    echo str_repeat("\t", $depth);
1044
-                    echo "\t\t=> added rule-specific ".(string) $pattern['type'].' ignore pattern';
1045
-                    if ($code !== $ref) {
1046
-                        echo " for $code";
1047
-                    }
1048
-
1049
-                    echo ': '.(string) $pattern.PHP_EOL;
1050
-                }
1051
-            }//end foreach
1052
-
1053
-            // Include patterns.
1054
-            foreach ($rule->{'include-pattern'} as $pattern) {
1055
-                if ($this->shouldProcessElement($pattern) === false) {
1056
-                    continue;
1057
-                }
1058
-
1059
-                if (isset($this->includePatterns[$code]) === false) {
1060
-                    $this->includePatterns[$code] = [];
1061
-                }
1062
-
1063
-                if (isset($pattern['type']) === false) {
1064
-                    $pattern['type'] = 'absolute';
1065
-                }
1066
-
1067
-                $this->includePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1068
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1069
-                    echo str_repeat("\t", $depth);
1070
-                    echo "\t\t=> added rule-specific ".(string) $pattern['type'].' include pattern';
1071
-                    if ($code !== $ref) {
1072
-                        echo " for $code";
1073
-                    }
1074
-
1075
-                    echo ': '.(string) $pattern.PHP_EOL;
1076
-                }
1077
-            }//end foreach
1078
-        }//end foreach
1079
-
1080
-    }//end processRule()
1081
-
1082
-
1083
-    /**
1084
-     * Determine if an element should be processed or ignored.
1085
-     *
1086
-     * @param \SimpleXMLElement $element An object from a ruleset XML file.
1087
-     *
1088
-     * @return bool
1089
-     */
1090
-    private function shouldProcessElement($element)
1091
-    {
1092
-        if (isset($element['phpcbf-only']) === false
1093
-            && isset($element['phpcs-only']) === false
1094
-        ) {
1095
-            // No exceptions are being made.
1096
-            return true;
1097
-        }
1098
-
1099
-        if (PHP_CODESNIFFER_CBF === true
1100
-            && isset($element['phpcbf-only']) === true
1101
-            && (string) $element['phpcbf-only'] === 'true'
1102
-        ) {
1103
-            return true;
1104
-        }
1105
-
1106
-        if (PHP_CODESNIFFER_CBF === false
1107
-            && isset($element['phpcs-only']) === true
1108
-            && (string) $element['phpcs-only'] === 'true'
1109
-        ) {
1110
-            return true;
1111
-        }
1112
-
1113
-        return false;
1114
-
1115
-    }//end shouldProcessElement()
1116
-
1117
-
1118
-    /**
1119
-     * Loads and stores sniffs objects used for sniffing files.
1120
-     *
1121
-     * @param array $files        Paths to the sniff files to register.
1122
-     * @param array $restrictions The sniff class names to restrict the allowed
1123
-     *                            listeners to.
1124
-     * @param array $exclusions   The sniff class names to exclude from the
1125
-     *                            listeners list.
1126
-     *
1127
-     * @return void
1128
-     */
1129
-    public function registerSniffs($files, $restrictions, $exclusions)
1130
-    {
1131
-        $listeners = [];
1132
-
1133
-        foreach ($files as $file) {
1134
-            // Work out where the position of /StandardName/Sniffs/... is
1135
-            // so we can determine what the class will be called.
1136
-            $sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
1137
-            if ($sniffPos === false) {
1138
-                continue;
1139
-            }
1140
-
1141
-            $slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
1142
-            if ($slashPos === false) {
1143
-                continue;
1144
-            }
1145
-
1146
-            $className   = Autoload::loadFile($file);
1147
-            $compareName = Util\Common::cleanSniffClass($className);
1148
-
1149
-            // If they have specified a list of sniffs to restrict to, check
1150
-            // to see if this sniff is allowed.
1151
-            if (empty($restrictions) === false
1152
-                && isset($restrictions[$compareName]) === false
1153
-            ) {
1154
-                continue;
1155
-            }
1156
-
1157
-            // If they have specified a list of sniffs to exclude, check
1158
-            // to see if this sniff is allowed.
1159
-            if (empty($exclusions) === false
1160
-                && isset($exclusions[$compareName]) === true
1161
-            ) {
1162
-                continue;
1163
-            }
1164
-
1165
-            // Skip abstract classes.
1166
-            $reflection = new \ReflectionClass($className);
1167
-            if ($reflection->isAbstract() === true) {
1168
-                continue;
1169
-            }
1170
-
1171
-            $listeners[$className] = $className;
1172
-
1173
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
1174
-                echo "Registered $className".PHP_EOL;
1175
-            }
1176
-        }//end foreach
1177
-
1178
-        $this->sniffs = $listeners;
1179
-
1180
-    }//end registerSniffs()
1181
-
1182
-
1183
-    /**
1184
-     * Populates the array of PHP_CodeSniffer_Sniff's for this file.
1185
-     *
1186
-     * @return void
1187
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If sniff registration fails.
1188
-     */
1189
-    public function populateTokenListeners()
1190
-    {
1191
-        // Construct a list of listeners indexed by token being listened for.
1192
-        $this->tokenListeners = [];
1193
-
1194
-        foreach ($this->sniffs as $sniffClass => $sniffObject) {
1195
-            $this->sniffs[$sniffClass] = null;
1196
-            $this->sniffs[$sniffClass] = new $sniffClass();
1197
-
1198
-            $sniffCode = Util\Common::getSniffCode($sniffClass);
1199
-            $this->sniffCodes[$sniffCode] = $sniffClass;
1200
-
1201
-            // Set custom properties.
1202
-            if (isset($this->ruleset[$sniffCode]['properties']) === true) {
1203
-                foreach ($this->ruleset[$sniffCode]['properties'] as $name => $value) {
1204
-                    $this->setSniffProperty($sniffClass, $name, $value);
1205
-                }
1206
-            }
1207
-
1208
-            $tokenizers = [];
1209
-            $vars       = get_class_vars($sniffClass);
1210
-            if (isset($vars['supportedTokenizers']) === true) {
1211
-                foreach ($vars['supportedTokenizers'] as $tokenizer) {
1212
-                    $tokenizers[$tokenizer] = $tokenizer;
1213
-                }
1214
-            } else {
1215
-                $tokenizers = ['PHP' => 'PHP'];
1216
-            }
1217
-
1218
-            $tokens = $this->sniffs[$sniffClass]->register();
1219
-            if (is_array($tokens) === false) {
1220
-                $msg = "Sniff $sniffClass register() method must return an array";
1221
-                throw new RuntimeException($msg);
1222
-            }
1223
-
1224
-            $ignorePatterns = [];
1225
-            $patterns       = $this->getIgnorePatterns($sniffCode);
1226
-            foreach ($patterns as $pattern => $type) {
1227
-                $replacements = [
1228
-                    '\\,' => ',',
1229
-                    '*'   => '.*',
1230
-                ];
1231
-
1232
-                $ignorePatterns[] = strtr($pattern, $replacements);
1233
-            }
1234
-
1235
-            $includePatterns = [];
1236
-            $patterns        = $this->getIncludePatterns($sniffCode);
1237
-            foreach ($patterns as $pattern => $type) {
1238
-                $replacements = [
1239
-                    '\\,' => ',',
1240
-                    '*'   => '.*',
1241
-                ];
1242
-
1243
-                $includePatterns[] = strtr($pattern, $replacements);
1244
-            }
1245
-
1246
-            foreach ($tokens as $token) {
1247
-                if (isset($this->tokenListeners[$token]) === false) {
1248
-                    $this->tokenListeners[$token] = [];
1249
-                }
1250
-
1251
-                if (isset($this->tokenListeners[$token][$sniffClass]) === false) {
1252
-                    $this->tokenListeners[$token][$sniffClass] = [
1253
-                        'class'      => $sniffClass,
1254
-                        'source'     => $sniffCode,
1255
-                        'tokenizers' => $tokenizers,
1256
-                        'ignore'     => $ignorePatterns,
1257
-                        'include'    => $includePatterns,
1258
-                    ];
1259
-                }
1260
-            }
1261
-        }//end foreach
1262
-
1263
-    }//end populateTokenListeners()
1264
-
1265
-
1266
-    /**
1267
-     * Set a single property for a sniff.
1268
-     *
1269
-     * @param string $sniffClass The class name of the sniff.
1270
-     * @param string $name       The name of the property to change.
1271
-     * @param string $value      The new value of the property.
1272
-     *
1273
-     * @return void
1274
-     */
1275
-    public function setSniffProperty($sniffClass, $name, $value)
1276
-    {
1277
-        // Setting a property for a sniff we are not using.
1278
-        if (isset($this->sniffs[$sniffClass]) === false) {
1279
-            return;
1280
-        }
1281
-
1282
-        $name = trim($name);
1283
-        if (is_string($value) === true) {
1284
-            $value = trim($value);
1285
-        }
1286
-
1287
-        if ($value === '') {
1288
-            $value = null;
1289
-        }
1290
-
1291
-        // Special case for booleans.
1292
-        if ($value === 'true') {
1293
-            $value = true;
1294
-        } else if ($value === 'false') {
1295
-            $value = false;
1296
-        } else if (substr($name, -2) === '[]') {
1297
-            $name   = substr($name, 0, -2);
1298
-            $values = [];
1299
-            if ($value !== null) {
1300
-                foreach (explode(',', $value) as $val) {
1301
-                    list($k, $v) = explode('=>', $val.'=>');
1302
-                    if ($v !== '') {
1303
-                        $values[trim($k)] = trim($v);
1304
-                    } else {
1305
-                        $values[] = trim($k);
1306
-                    }
1307
-                }
1308
-            }
1309
-
1310
-            $value = $values;
1311
-        }
1312
-
1313
-        $this->sniffs[$sniffClass]->$name = $value;
1314
-
1315
-    }//end setSniffProperty()
1316
-
1317
-
1318
-    /**
1319
-     * Gets the array of ignore patterns.
1320
-     *
1321
-     * Optionally takes a listener to get ignore patterns specified
1322
-     * for that sniff only.
1323
-     *
1324
-     * @param string $listener The listener to get patterns for. If NULL, all
1325
-     *                         patterns are returned.
1326
-     *
1327
-     * @return array
1328
-     */
1329
-    public function getIgnorePatterns($listener=null)
1330
-    {
1331
-        if ($listener === null) {
1332
-            return $this->ignorePatterns;
1333
-        }
1334
-
1335
-        if (isset($this->ignorePatterns[$listener]) === true) {
1336
-            return $this->ignorePatterns[$listener];
1337
-        }
1338
-
1339
-        return [];
1340
-
1341
-    }//end getIgnorePatterns()
1342
-
1343
-
1344
-    /**
1345
-     * Gets the array of include patterns.
1346
-     *
1347
-     * Optionally takes a listener to get include patterns specified
1348
-     * for that sniff only.
1349
-     *
1350
-     * @param string $listener The listener to get patterns for. If NULL, all
1351
-     *                         patterns are returned.
1352
-     *
1353
-     * @return array
1354
-     */
1355
-    public function getIncludePatterns($listener=null)
1356
-    {
1357
-        if ($listener === null) {
1358
-            return $this->includePatterns;
1359
-        }
1360
-
1361
-        if (isset($this->includePatterns[$listener]) === true) {
1362
-            return $this->includePatterns[$listener];
1363
-        }
1364
-
1365
-        return [];
1366
-
1367
-    }//end getIncludePatterns()
20
+	/**
21
+	 * The name of the coding standard being used.
22
+	 *
23
+	 * If a top-level standard includes other standards, or sniffs
24
+	 * from other standards, only the name of the top-level standard
25
+	 * will be stored in here.
26
+	 *
27
+	 * If multiple top-level standards are being loaded into
28
+	 * a single ruleset object, this will store a comma separated list
29
+	 * of the top-level standard names.
30
+	 *
31
+	 * @var string
32
+	 */
33
+	public $name = '';
34
+
35
+	/**
36
+	 * A list of file paths for the ruleset files being used.
37
+	 *
38
+	 * @var string[]
39
+	 */
40
+	public $paths = [];
41
+
42
+	/**
43
+	 * A list of regular expressions used to ignore specific sniffs for files and folders.
44
+	 *
45
+	 * Is also used to set global exclude patterns.
46
+	 * The key is the regular expression and the value is the type
47
+	 * of ignore pattern (absolute or relative).
48
+	 *
49
+	 * @var array<string, string>
50
+	 */
51
+	public $ignorePatterns = [];
52
+
53
+	/**
54
+	 * A list of regular expressions used to include specific sniffs for files and folders.
55
+	 *
56
+	 * The key is the sniff code and the value is an array with
57
+	 * the key being a regular expression and the value is the type
58
+	 * of ignore pattern (absolute or relative).
59
+	 *
60
+	 * @var array<string, array<string, string>>
61
+	 */
62
+	public $includePatterns = [];
63
+
64
+	/**
65
+	 * An array of sniff objects that are being used to check files.
66
+	 *
67
+	 * The key is the fully qualified name of the sniff class
68
+	 * and the value is the sniff object.
69
+	 *
70
+	 * @var array<string, \PHP_CodeSniffer\Sniffs\Sniff>
71
+	 */
72
+	public $sniffs = [];
73
+
74
+	/**
75
+	 * A mapping of sniff codes to fully qualified class names.
76
+	 *
77
+	 * The key is the sniff code and the value
78
+	 * is the fully qualified name of the sniff class.
79
+	 *
80
+	 * @var array<string, string>
81
+	 */
82
+	public $sniffCodes = [];
83
+
84
+	/**
85
+	 * An array of token types and the sniffs that are listening for them.
86
+	 *
87
+	 * The key is the token name being listened for and the value
88
+	 * is the sniff object.
89
+	 *
90
+	 * @var array<int, \PHP_CodeSniffer\Sniffs\Sniff>
91
+	 */
92
+	public $tokenListeners = [];
93
+
94
+	/**
95
+	 * An array of rules from the ruleset.xml file.
96
+	 *
97
+	 * It may be empty, indicating that the ruleset does not override
98
+	 * any of the default sniff settings.
99
+	 *
100
+	 * @var array<string, mixed>
101
+	 */
102
+	public $ruleset = [];
103
+
104
+	/**
105
+	 * The directories that the processed rulesets are in.
106
+	 *
107
+	 * @var string[]
108
+	 */
109
+	protected $rulesetDirs = [];
110
+
111
+	/**
112
+	 * The config data for the run.
113
+	 *
114
+	 * @var \PHP_CodeSniffer\Config
115
+	 */
116
+	private $config = null;
117
+
118
+
119
+	/**
120
+	 * Initialise the ruleset that the run will use.
121
+	 *
122
+	 * @param \PHP_CodeSniffer\Config $config The config data for the run.
123
+	 *
124
+	 * @return void
125
+	 */
126
+	public function __construct(Config $config)
127
+	{
128
+		// Ignore sniff restrictions if caching is on.
129
+		$restrictions = [];
130
+		$exclusions   = [];
131
+		if ($config->cache === false) {
132
+			$restrictions = $config->sniffs;
133
+			$exclusions   = $config->exclude;
134
+		}
135
+
136
+		$this->config = $config;
137
+		$sniffs       = [];
138
+
139
+		$standardPaths = [];
140
+		foreach ($config->standards as $standard) {
141
+			$installed = Util\Standards::getInstalledStandardPath($standard);
142
+			if ($installed === null) {
143
+				$standard = Util\Common::realpath($standard);
144
+				if (is_dir($standard) === true
145
+					&& is_file(Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml')) === true
146
+				) {
147
+					$standard = Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml');
148
+				}
149
+			} else {
150
+				$standard = $installed;
151
+			}
152
+
153
+			$standardPaths[] = $standard;
154
+		}
155
+
156
+		foreach ($standardPaths as $standard) {
157
+			$ruleset = @simplexml_load_string(file_get_contents($standard));
158
+			if ($ruleset !== false) {
159
+				$standardName = (string) $ruleset['name'];
160
+				if ($this->name !== '') {
161
+					$this->name .= ', ';
162
+				}
163
+
164
+				$this->name .= $standardName;
165
+
166
+				// Allow autoloading of custom files inside this standard.
167
+				if (isset($ruleset['namespace']) === true) {
168
+					$namespace = (string) $ruleset['namespace'];
169
+				} else {
170
+					$namespace = basename(dirname($standard));
171
+				}
172
+
173
+				Autoload::addSearchPath(dirname($standard), $namespace);
174
+			}
175
+
176
+			if (defined('PHP_CODESNIFFER_IN_TESTS') === true && empty($restrictions) === false) {
177
+				// In unit tests, only register the sniffs that the test wants and not the entire standard.
178
+				try {
179
+					foreach ($restrictions as $restriction) {
180
+						$sniffs = array_merge($sniffs, $this->expandRulesetReference($restriction, dirname($standard)));
181
+					}
182
+				} catch (RuntimeException $e) {
183
+					// Sniff reference could not be expanded, which probably means this
184
+					// is an installed standard. Let the unit test system take care of
185
+					// setting the correct sniff for testing.
186
+					return;
187
+				}
188
+
189
+				break;
190
+			}
191
+
192
+			if (PHP_CODESNIFFER_VERBOSITY === 1) {
193
+				echo "Registering sniffs in the $standardName standard... ";
194
+				if (count($config->standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) {
195
+					echo PHP_EOL;
196
+				}
197
+			}
198
+
199
+			$sniffs = array_merge($sniffs, $this->processRuleset($standard));
200
+		}//end foreach
201
+
202
+		$sniffRestrictions = [];
203
+		foreach ($restrictions as $sniffCode) {
204
+			$parts     = explode('.', strtolower($sniffCode));
205
+			$sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
206
+			$sniffRestrictions[$sniffName] = true;
207
+		}
208
+
209
+		$sniffExclusions = [];
210
+		foreach ($exclusions as $sniffCode) {
211
+			$parts     = explode('.', strtolower($sniffCode));
212
+			$sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
213
+			$sniffExclusions[$sniffName] = true;
214
+		}
215
+
216
+		$this->registerSniffs($sniffs, $sniffRestrictions, $sniffExclusions);
217
+		$this->populateTokenListeners();
218
+
219
+		$numSniffs = count($this->sniffs);
220
+		if (PHP_CODESNIFFER_VERBOSITY === 1) {
221
+			echo "DONE ($numSniffs sniffs registered)".PHP_EOL;
222
+		}
223
+
224
+		if ($numSniffs === 0) {
225
+			throw new RuntimeException('No sniffs were registered');
226
+		}
227
+
228
+	}//end __construct()
229
+
230
+
231
+	/**
232
+	 * Prints a report showing the sniffs contained in a standard.
233
+	 *
234
+	 * @return void
235
+	 */
236
+	public function explain()
237
+	{
238
+		$sniffs = array_keys($this->sniffCodes);
239
+		sort($sniffs);
240
+
241
+		ob_start();
242
+
243
+		$lastStandard = null;
244
+		$lastCount    = '';
245
+		$sniffCount   = count($sniffs);
246
+
247
+		// Add a dummy entry to the end so we loop
248
+		// one last time and clear the output buffer.
249
+		$sniffs[] = '';
250
+
251
+		echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL;
252
+
253
+		ob_start();
254
+
255
+		foreach ($sniffs as $i => $sniff) {
256
+			if ($i === $sniffCount) {
257
+				$currentStandard = null;
258
+			} else {
259
+				$currentStandard = substr($sniff, 0, strpos($sniff, '.'));
260
+				if ($lastStandard === null) {
261
+					$lastStandard = $currentStandard;
262
+				}
263
+			}
264
+
265
+			if ($currentStandard !== $lastStandard) {
266
+				$sniffList = ob_get_contents();
267
+				ob_end_clean();
268
+
269
+				echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniff';
270
+				if ($lastCount > 1) {
271
+					echo 's';
272
+				}
273
+
274
+				echo ')'.PHP_EOL;
275
+				echo str_repeat('-', (strlen($lastStandard.$lastCount) + 10));
276
+				echo PHP_EOL;
277
+				echo $sniffList;
278
+
279
+				$lastStandard = $currentStandard;
280
+				$lastCount    = 0;
281
+
282
+				if ($currentStandard === null) {
283
+					break;
284
+				}
285
+
286
+				ob_start();
287
+			}//end if
288
+
289
+			echo '  '.$sniff.PHP_EOL;
290
+			$lastCount++;
291
+		}//end foreach
292
+
293
+	}//end explain()
294
+
295
+
296
+	/**
297
+	 * Processes a single ruleset and returns a list of the sniffs it represents.
298
+	 *
299
+	 * Rules founds within the ruleset are processed immediately, but sniff classes
300
+	 * are not registered by this method.
301
+	 *
302
+	 * @param string $rulesetPath The path to a ruleset XML file.
303
+	 * @param int    $depth       How many nested processing steps we are in. This
304
+	 *                            is only used for debug output.
305
+	 *
306
+	 * @return string[]
307
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid.
308
+	 */
309
+	public function processRuleset($rulesetPath, $depth=0)
310
+	{
311
+		$rulesetPath = Util\Common::realpath($rulesetPath);
312
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
313
+			echo str_repeat("\t", $depth);
314
+			echo 'Processing ruleset '.Util\Common::stripBasepath($rulesetPath, $this->config->basepath).PHP_EOL;
315
+		}
316
+
317
+		libxml_use_internal_errors(true);
318
+		$ruleset = simplexml_load_string(file_get_contents($rulesetPath));
319
+		if ($ruleset === false) {
320
+			$errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL;
321
+			$errors   = libxml_get_errors();
322
+			foreach ($errors as $error) {
323
+				$errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message;
324
+			}
325
+
326
+			libxml_clear_errors();
327
+			throw new RuntimeException($errorMsg);
328
+		}
329
+
330
+		libxml_use_internal_errors(false);
331
+
332
+		$ownSniffs      = [];
333
+		$includedSniffs = [];
334
+		$excludedSniffs = [];
335
+
336
+		$this->paths[]       = $rulesetPath;
337
+		$rulesetDir          = dirname($rulesetPath);
338
+		$this->rulesetDirs[] = $rulesetDir;
339
+
340
+		$sniffDir = $rulesetDir.DIRECTORY_SEPARATOR.'Sniffs';
341
+		if (is_dir($sniffDir) === true) {
342
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
343
+				echo str_repeat("\t", $depth);
344
+				echo "\tAdding sniff files from ".Util\Common::stripBasepath($sniffDir, $this->config->basepath).' directory'.PHP_EOL;
345
+			}
346
+
347
+			$ownSniffs = $this->expandSniffDirectory($sniffDir, $depth);
348
+		}
349
+
350
+		// Included custom autoloaders.
351
+		foreach ($ruleset->{'autoload'} as $autoload) {
352
+			if ($this->shouldProcessElement($autoload) === false) {
353
+				continue;
354
+			}
355
+
356
+			$autoloadPath = (string) $autoload;
357
+			if (is_file($autoloadPath) === false) {
358
+				$autoloadPath = Util\Common::realPath(dirname($rulesetPath).DIRECTORY_SEPARATOR.$autoloadPath);
359
+			}
360
+
361
+			if ($autoloadPath === false) {
362
+				throw new RuntimeException('The specified autoload file "'.$autoload.'" does not exist');
363
+			}
364
+
365
+			include_once $autoloadPath;
366
+
367
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
368
+				echo str_repeat("\t", $depth);
369
+				echo "\t=> included autoloader $autoloadPath".PHP_EOL;
370
+			}
371
+		}//end foreach
372
+
373
+		// Process custom sniff config settings.
374
+		foreach ($ruleset->{'config'} as $config) {
375
+			if ($this->shouldProcessElement($config) === false) {
376
+				continue;
377
+			}
378
+
379
+			Config::setConfigData((string) $config['name'], (string) $config['value'], true);
380
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
381
+				echo str_repeat("\t", $depth);
382
+				echo "\t=> set config value ".(string) $config['name'].': '.(string) $config['value'].PHP_EOL;
383
+			}
384
+		}
385
+
386
+		foreach ($ruleset->rule as $rule) {
387
+			if (isset($rule['ref']) === false
388
+				|| $this->shouldProcessElement($rule) === false
389
+			) {
390
+				continue;
391
+			}
392
+
393
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
394
+				echo str_repeat("\t", $depth);
395
+				echo "\tProcessing rule \"".$rule['ref'].'"'.PHP_EOL;
396
+			}
397
+
398
+			$expandedSniffs = $this->expandRulesetReference((string) $rule['ref'], $rulesetDir, $depth);
399
+			$newSniffs      = array_diff($expandedSniffs, $includedSniffs);
400
+			$includedSniffs = array_merge($includedSniffs, $expandedSniffs);
401
+
402
+			$parts = explode('.', $rule['ref']);
403
+			if (count($parts) === 4
404
+				&& $parts[0] !== ''
405
+				&& $parts[1] !== ''
406
+				&& $parts[2] !== ''
407
+			) {
408
+				$sniffCode = $parts[0].'.'.$parts[1].'.'.$parts[2];
409
+				if (isset($this->ruleset[$sniffCode]['severity']) === true
410
+					&& $this->ruleset[$sniffCode]['severity'] === 0
411
+				) {
412
+					// This sniff code has already been turned off, but now
413
+					// it is being explicitly included again, so turn it back on.
414
+					$this->ruleset[(string) $rule['ref']]['severity'] = 5;
415
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
416
+						echo str_repeat("\t", $depth);
417
+						echo "\t\t* disabling sniff exclusion for specific message code *".PHP_EOL;
418
+						echo str_repeat("\t", $depth);
419
+						echo "\t\t=> severity set to 5".PHP_EOL;
420
+					}
421
+				} else if (empty($newSniffs) === false) {
422
+					$newSniff = $newSniffs[0];
423
+					if (in_array($newSniff, $ownSniffs, true) === false) {
424
+						// Including a sniff that hasn't been included higher up, but
425
+						// only including a single message from it. So turn off all messages in
426
+						// the sniff, except this one.
427
+						$this->ruleset[$sniffCode]['severity']            = 0;
428
+						$this->ruleset[(string) $rule['ref']]['severity'] = 5;
429
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
430
+							echo str_repeat("\t", $depth);
431
+							echo "\t\tExcluding sniff \"".$sniffCode.'" except for "'.$parts[3].'"'.PHP_EOL;
432
+						}
433
+					}
434
+				}//end if
435
+			}//end if
436
+
437
+			if (isset($rule->exclude) === true) {
438
+				foreach ($rule->exclude as $exclude) {
439
+					if (isset($exclude['name']) === false) {
440
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
441
+							echo str_repeat("\t", $depth);
442
+							echo "\t\t* ignoring empty exclude rule *".PHP_EOL;
443
+							echo "\t\t\t=> ".$exclude->asXML().PHP_EOL;
444
+						}
445
+
446
+						continue;
447
+					}
448
+
449
+					if ($this->shouldProcessElement($exclude) === false) {
450
+						continue;
451
+					}
452
+
453
+					if (PHP_CODESNIFFER_VERBOSITY > 1) {
454
+						echo str_repeat("\t", $depth);
455
+						echo "\t\tExcluding rule \"".$exclude['name'].'"'.PHP_EOL;
456
+					}
457
+
458
+					// Check if a single code is being excluded, which is a shortcut
459
+					// for setting the severity of the message to 0.
460
+					$parts = explode('.', $exclude['name']);
461
+					if (count($parts) === 4) {
462
+						$this->ruleset[(string) $exclude['name']]['severity'] = 0;
463
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
464
+							echo str_repeat("\t", $depth);
465
+							echo "\t\t=> severity set to 0".PHP_EOL;
466
+						}
467
+					} else {
468
+						$excludedSniffs = array_merge(
469
+							$excludedSniffs,
470
+							$this->expandRulesetReference((string) $exclude['name'], $rulesetDir, ($depth + 1))
471
+						);
472
+					}
473
+				}//end foreach
474
+			}//end if
475
+
476
+			$this->processRule($rule, $newSniffs, $depth);
477
+		}//end foreach
478
+
479
+		// Process custom command line arguments.
480
+		$cliArgs = [];
481
+		foreach ($ruleset->{'arg'} as $arg) {
482
+			if ($this->shouldProcessElement($arg) === false) {
483
+				continue;
484
+			}
485
+
486
+			if (isset($arg['name']) === true) {
487
+				$argString = '--'.(string) $arg['name'];
488
+				if (isset($arg['value']) === true) {
489
+					$argString .= '='.(string) $arg['value'];
490
+				}
491
+			} else {
492
+				$argString = '-'.(string) $arg['value'];
493
+			}
494
+
495
+			$cliArgs[] = $argString;
496
+
497
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
498
+				echo str_repeat("\t", $depth);
499
+				echo "\t=> set command line value $argString".PHP_EOL;
500
+			}
501
+		}//end foreach
502
+
503
+		// Set custom php ini values as CLI args.
504
+		foreach ($ruleset->{'ini'} as $arg) {
505
+			if ($this->shouldProcessElement($arg) === false) {
506
+				continue;
507
+			}
508
+
509
+			if (isset($arg['name']) === false) {
510
+				continue;
511
+			}
512
+
513
+			$name      = (string) $arg['name'];
514
+			$argString = $name;
515
+			if (isset($arg['value']) === true) {
516
+				$value      = (string) $arg['value'];
517
+				$argString .= "=$value";
518
+			} else {
519
+				$value = 'true';
520
+			}
521
+
522
+			$cliArgs[] = '-d';
523
+			$cliArgs[] = $argString;
524
+
525
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
526
+				echo str_repeat("\t", $depth);
527
+				echo "\t=> set PHP ini value $name to $value".PHP_EOL;
528
+			}
529
+		}//end foreach
530
+
531
+		if (empty($this->config->files) === true) {
532
+			// Process hard-coded file paths.
533
+			foreach ($ruleset->{'file'} as $file) {
534
+				$file      = (string) $file;
535
+				$cliArgs[] = $file;
536
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
537
+					echo str_repeat("\t", $depth);
538
+					echo "\t=> added \"$file\" to the file list".PHP_EOL;
539
+				}
540
+			}
541
+		}
542
+
543
+		if (empty($cliArgs) === false) {
544
+			// Change the directory so all relative paths are worked
545
+			// out based on the location of the ruleset instead of
546
+			// the location of the user.
547
+			$inPhar = Util\Common::isPharFile($rulesetDir);
548
+			if ($inPhar === false) {
549
+				$currentDir = getcwd();
550
+				chdir($rulesetDir);
551
+			}
552
+
553
+			$this->config->setCommandLineValues($cliArgs);
554
+
555
+			if ($inPhar === false) {
556
+				chdir($currentDir);
557
+			}
558
+		}
559
+
560
+		// Process custom ignore pattern rules.
561
+		foreach ($ruleset->{'exclude-pattern'} as $pattern) {
562
+			if ($this->shouldProcessElement($pattern) === false) {
563
+				continue;
564
+			}
565
+
566
+			if (isset($pattern['type']) === false) {
567
+				$pattern['type'] = 'absolute';
568
+			}
569
+
570
+			$this->ignorePatterns[(string) $pattern] = (string) $pattern['type'];
571
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
+				echo str_repeat("\t", $depth);
573
+				echo "\t=> added global ".(string) $pattern['type'].' ignore pattern: '.(string) $pattern.PHP_EOL;
574
+			}
575
+		}
576
+
577
+		$includedSniffs = array_unique(array_merge($ownSniffs, $includedSniffs));
578
+		$excludedSniffs = array_unique($excludedSniffs);
579
+
580
+		if (PHP_CODESNIFFER_VERBOSITY > 1) {
581
+			$included = count($includedSniffs);
582
+			$excluded = count($excludedSniffs);
583
+			echo str_repeat("\t", $depth);
584
+			echo "=> Ruleset processing complete; included $included sniffs and excluded $excluded".PHP_EOL;
585
+		}
586
+
587
+		// Merge our own sniff list with our externally included
588
+		// sniff list, but filter out any excluded sniffs.
589
+		$files = [];
590
+		foreach ($includedSniffs as $sniff) {
591
+			if (in_array($sniff, $excludedSniffs, true) === true) {
592
+				continue;
593
+			} else {
594
+				$files[] = Util\Common::realpath($sniff);
595
+			}
596
+		}
597
+
598
+		return $files;
599
+
600
+	}//end processRuleset()
601
+
602
+
603
+	/**
604
+	 * Expands a directory into a list of sniff files within.
605
+	 *
606
+	 * @param string $directory The path to a directory.
607
+	 * @param int    $depth     How many nested processing steps we are in. This
608
+	 *                          is only used for debug output.
609
+	 *
610
+	 * @return array
611
+	 */
612
+	private function expandSniffDirectory($directory, $depth=0)
613
+	{
614
+		$sniffs = [];
615
+
616
+		$rdi = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
617
+		$di  = new \RecursiveIteratorIterator($rdi, 0, \RecursiveIteratorIterator::CATCH_GET_CHILD);
618
+
619
+		$dirLen = strlen($directory);
620
+
621
+		foreach ($di as $file) {
622
+			$filename = $file->getFilename();
623
+
624
+			// Skip hidden files.
625
+			if (substr($filename, 0, 1) === '.') {
626
+				continue;
627
+			}
628
+
629
+			// We are only interested in PHP and sniff files.
630
+			$fileParts = explode('.', $filename);
631
+			if (array_pop($fileParts) !== 'php') {
632
+				continue;
633
+			}
634
+
635
+			$basename = basename($filename, '.php');
636
+			if (substr($basename, -5) !== 'Sniff') {
637
+				continue;
638
+			}
639
+
640
+			$path = $file->getPathname();
641
+
642
+			// Skip files in hidden directories within the Sniffs directory of this
643
+			// standard. We use the offset with strpos() to allow hidden directories
644
+			// before, valid example:
645
+			// /home/foo/.composer/vendor/squiz/custom_tool/MyStandard/Sniffs/...
646
+			if (strpos($path, DIRECTORY_SEPARATOR.'.', $dirLen) !== false) {
647
+				continue;
648
+			}
649
+
650
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
651
+				echo str_repeat("\t", $depth);
652
+				echo "\t\t=> ".Util\Common::stripBasepath($path, $this->config->basepath).PHP_EOL;
653
+			}
654
+
655
+			$sniffs[] = $path;
656
+		}//end foreach
657
+
658
+		return $sniffs;
659
+
660
+	}//end expandSniffDirectory()
661
+
662
+
663
+	/**
664
+	 * Expands a ruleset reference into a list of sniff files.
665
+	 *
666
+	 * @param string $ref        The reference from the ruleset XML file.
667
+	 * @param string $rulesetDir The directory of the ruleset XML file, used to
668
+	 *                           evaluate relative paths.
669
+	 * @param int    $depth      How many nested processing steps we are in. This
670
+	 *                           is only used for debug output.
671
+	 *
672
+	 * @return array
673
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the reference is invalid.
674
+	 */
675
+	private function expandRulesetReference($ref, $rulesetDir, $depth=0)
676
+	{
677
+		// Ignore internal sniffs codes as they are used to only
678
+		// hide and change internal messages.
679
+		if (substr($ref, 0, 9) === 'Internal.') {
680
+			if (PHP_CODESNIFFER_VERBOSITY > 1) {
681
+				echo str_repeat("\t", $depth);
682
+				echo "\t\t* ignoring internal sniff code *".PHP_EOL;
683
+			}
684
+
685
+			return [];
686
+		}
687
+
688
+		// As sniffs can't begin with a full stop, assume references in
689
+		// this format are relative paths and attempt to convert them
690
+		// to absolute paths. If this fails, let the reference run through
691
+		// the normal checks and have it fail as normal.
692
+		if (substr($ref, 0, 1) === '.') {
693
+			$realpath = Util\Common::realpath($rulesetDir.'/'.$ref);
694
+			if ($realpath !== false) {
695
+				$ref = $realpath;
696
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
697
+					echo str_repeat("\t", $depth);
698
+					echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
699
+				}
700
+			}
701
+		}
702
+
703
+		// As sniffs can't begin with a tilde, assume references in
704
+		// this format are relative to the user's home directory.
705
+		if (substr($ref, 0, 2) === '~/') {
706
+			$realpath = Util\Common::realpath($ref);
707
+			if ($realpath !== false) {
708
+				$ref = $realpath;
709
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
710
+					echo str_repeat("\t", $depth);
711
+					echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
712
+				}
713
+			}
714
+		}
715
+
716
+		if (is_file($ref) === true) {
717
+			if (substr($ref, -9) === 'Sniff.php') {
718
+				// A single external sniff.
719
+				$this->rulesetDirs[] = dirname(dirname(dirname($ref)));
720
+				return [$ref];
721
+			}
722
+		} else {
723
+			// See if this is a whole standard being referenced.
724
+			$path = Util\Standards::getInstalledStandardPath($ref);
725
+			if (Util\Common::isPharFile($path) === true && strpos($path, 'ruleset.xml') === false) {
726
+				// If the ruleset exists inside the phar file, use it.
727
+				if (file_exists($path.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
728
+					$path .= DIRECTORY_SEPARATOR.'ruleset.xml';
729
+				} else {
730
+					$path = null;
731
+				}
732
+			}
733
+
734
+			if ($path !== null) {
735
+				$ref = $path;
736
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
737
+					echo str_repeat("\t", $depth);
738
+					echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
739
+				}
740
+			} else if (is_dir($ref) === false) {
741
+				// Work out the sniff path.
742
+				$sepPos = strpos($ref, DIRECTORY_SEPARATOR);
743
+				if ($sepPos !== false) {
744
+					$stdName = substr($ref, 0, $sepPos);
745
+					$path    = substr($ref, $sepPos);
746
+				} else {
747
+					$parts   = explode('.', $ref);
748
+					$stdName = $parts[0];
749
+					if (count($parts) === 1) {
750
+						// A whole standard?
751
+						$path = '';
752
+					} else if (count($parts) === 2) {
753
+						// A directory of sniffs?
754
+						$path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1];
755
+					} else {
756
+						// A single sniff?
757
+						$path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1].DIRECTORY_SEPARATOR.$parts[2].'Sniff.php';
758
+					}
759
+				}
760
+
761
+				$newRef  = false;
762
+				$stdPath = Util\Standards::getInstalledStandardPath($stdName);
763
+				if ($stdPath !== null && $path !== '') {
764
+					if (Util\Common::isPharFile($stdPath) === true
765
+						&& strpos($stdPath, 'ruleset.xml') === false
766
+					) {
767
+						// Phar files can only return the directory,
768
+						// since ruleset can be omitted if building one standard.
769
+						$newRef = Util\Common::realpath($stdPath.$path);
770
+					} else {
771
+						$newRef = Util\Common::realpath(dirname($stdPath).$path);
772
+					}
773
+				}
774
+
775
+				if ($newRef === false) {
776
+					// The sniff is not locally installed, so check if it is being
777
+					// referenced as a remote sniff outside the install. We do this
778
+					// by looking through all directories where we have found ruleset
779
+					// files before, looking for ones for this particular standard,
780
+					// and seeing if it is in there.
781
+					foreach ($this->rulesetDirs as $dir) {
782
+						if (strtolower(basename($dir)) !== strtolower($stdName)) {
783
+							continue;
784
+						}
785
+
786
+						$newRef = Util\Common::realpath($dir.$path);
787
+
788
+						if ($newRef !== false) {
789
+							$ref = $newRef;
790
+						}
791
+					}
792
+				} else {
793
+					$ref = $newRef;
794
+				}
795
+
796
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
797
+					echo str_repeat("\t", $depth);
798
+					echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
799
+				}
800
+			}//end if
801
+		}//end if
802
+
803
+		if (is_dir($ref) === true) {
804
+			if (is_file($ref.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
805
+				// We are referencing an external coding standard.
806
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
807
+					echo str_repeat("\t", $depth);
808
+					echo "\t\t* rule is referencing a standard using directory name; processing *".PHP_EOL;
809
+				}
810
+
811
+				return $this->processRuleset($ref.DIRECTORY_SEPARATOR.'ruleset.xml', ($depth + 2));
812
+			} else {
813
+				// We are referencing a whole directory of sniffs.
814
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
815
+					echo str_repeat("\t", $depth);
816
+					echo "\t\t* rule is referencing a directory of sniffs *".PHP_EOL;
817
+					echo str_repeat("\t", $depth);
818
+					echo "\t\tAdding sniff files from directory".PHP_EOL;
819
+				}
820
+
821
+				return $this->expandSniffDirectory($ref, ($depth + 1));
822
+			}
823
+		} else {
824
+			if (is_file($ref) === false) {
825
+				$error = "Referenced sniff \"$ref\" does not exist";
826
+				throw new RuntimeException($error);
827
+			}
828
+
829
+			if (substr($ref, -9) === 'Sniff.php') {
830
+				// A single sniff.
831
+				return [$ref];
832
+			} else {
833
+				// Assume an external ruleset.xml file.
834
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
835
+					echo str_repeat("\t", $depth);
836
+					echo "\t\t* rule is referencing a standard using ruleset path; processing *".PHP_EOL;
837
+				}
838
+
839
+				return $this->processRuleset($ref, ($depth + 2));
840
+			}
841
+		}//end if
842
+
843
+	}//end expandRulesetReference()
844
+
845
+
846
+	/**
847
+	 * Processes a rule from a ruleset XML file, overriding built-in defaults.
848
+	 *
849
+	 * @param \SimpleXMLElement $rule      The rule object from a ruleset XML file.
850
+	 * @param string[]          $newSniffs An array of sniffs that got included by this rule.
851
+	 * @param int               $depth     How many nested processing steps we are in.
852
+	 *                                     This is only used for debug output.
853
+	 *
854
+	 * @return void
855
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If rule settings are invalid.
856
+	 */
857
+	private function processRule($rule, $newSniffs, $depth=0)
858
+	{
859
+		$ref  = (string) $rule['ref'];
860
+		$todo = [$ref];
861
+
862
+		$parts = explode('.', $ref);
863
+		if (count($parts) <= 2) {
864
+			// We are processing a standard or a category of sniffs.
865
+			foreach ($newSniffs as $sniffFile) {
866
+				$parts         = explode(DIRECTORY_SEPARATOR, $sniffFile);
867
+				$sniffName     = array_pop($parts);
868
+				$sniffCategory = array_pop($parts);
869
+				array_pop($parts);
870
+				$sniffStandard = array_pop($parts);
871
+				$todo[]        = $sniffStandard.'.'.$sniffCategory.'.'.substr($sniffName, 0, -9);
872
+			}
873
+		}
874
+
875
+		foreach ($todo as $code) {
876
+			// Custom severity.
877
+			if (isset($rule->severity) === true
878
+				&& $this->shouldProcessElement($rule->severity) === true
879
+			) {
880
+				if (isset($this->ruleset[$code]) === false) {
881
+					$this->ruleset[$code] = [];
882
+				}
883
+
884
+				$this->ruleset[$code]['severity'] = (int) $rule->severity;
885
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
+					echo str_repeat("\t", $depth);
887
+					echo "\t\t=> severity set to ".(int) $rule->severity;
888
+					if ($code !== $ref) {
889
+						echo " for $code";
890
+					}
891
+
892
+					echo PHP_EOL;
893
+				}
894
+			}
895
+
896
+			// Custom message type.
897
+			if (isset($rule->type) === true
898
+				&& $this->shouldProcessElement($rule->type) === true
899
+			) {
900
+				if (isset($this->ruleset[$code]) === false) {
901
+					$this->ruleset[$code] = [];
902
+				}
903
+
904
+				$type = strtolower((string) $rule->type);
905
+				if ($type !== 'error' && $type !== 'warning') {
906
+					throw new RuntimeException("Message type \"$type\" is invalid; must be \"error\" or \"warning\"");
907
+				}
908
+
909
+				$this->ruleset[$code]['type'] = $type;
910
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
911
+					echo str_repeat("\t", $depth);
912
+					echo "\t\t=> message type set to ".(string) $rule->type;
913
+					if ($code !== $ref) {
914
+						echo " for $code";
915
+					}
916
+
917
+					echo PHP_EOL;
918
+				}
919
+			}//end if
920
+
921
+			// Custom message.
922
+			if (isset($rule->message) === true
923
+				&& $this->shouldProcessElement($rule->message) === true
924
+			) {
925
+				if (isset($this->ruleset[$code]) === false) {
926
+					$this->ruleset[$code] = [];
927
+				}
928
+
929
+				$this->ruleset[$code]['message'] = (string) $rule->message;
930
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
931
+					echo str_repeat("\t", $depth);
932
+					echo "\t\t=> message set to ".(string) $rule->message;
933
+					if ($code !== $ref) {
934
+						echo " for $code";
935
+					}
936
+
937
+					echo PHP_EOL;
938
+				}
939
+			}
940
+
941
+			// Custom properties.
942
+			if (isset($rule->properties) === true
943
+				&& $this->shouldProcessElement($rule->properties) === true
944
+			) {
945
+				foreach ($rule->properties->property as $prop) {
946
+					if ($this->shouldProcessElement($prop) === false) {
947
+						continue;
948
+					}
949
+
950
+					if (isset($this->ruleset[$code]) === false) {
951
+						$this->ruleset[$code] = [
952
+							'properties' => [],
953
+						];
954
+					} else if (isset($this->ruleset[$code]['properties']) === false) {
955
+						$this->ruleset[$code]['properties'] = [];
956
+					}
957
+
958
+					$name = (string) $prop['name'];
959
+					if (isset($prop['type']) === true
960
+						&& (string) $prop['type'] === 'array'
961
+					) {
962
+						$values = [];
963
+						if (isset($prop['extend']) === true
964
+							&& (string) $prop['extend'] === 'true'
965
+							&& isset($this->ruleset[$code]['properties'][$name]) === true
966
+						) {
967
+							$values = $this->ruleset[$code]['properties'][$name];
968
+						}
969
+
970
+						if (isset($prop->element) === true) {
971
+							$printValue = '';
972
+							foreach ($prop->element as $element) {
973
+								if ($this->shouldProcessElement($element) === false) {
974
+									continue;
975
+								}
976
+
977
+								$value = (string) $element['value'];
978
+								if (isset($element['key']) === true) {
979
+									$key          = (string) $element['key'];
980
+									$values[$key] = $value;
981
+									$printValue  .= $key.'=>'.$value.',';
982
+								} else {
983
+									$values[]    = $value;
984
+									$printValue .= $value.',';
985
+								}
986
+							}
987
+
988
+							$printValue = rtrim($printValue, ',');
989
+						} else {
990
+							$value      = (string) $prop['value'];
991
+							$printValue = $value;
992
+							foreach (explode(',', $value) as $val) {
993
+								list($k, $v) = explode('=>', $val.'=>');
994
+								if ($v !== '') {
995
+									$values[trim($k)] = trim($v);
996
+								} else {
997
+									$values[] = trim($k);
998
+								}
999
+							}
1000
+						}//end if
1001
+
1002
+						$this->ruleset[$code]['properties'][$name] = $values;
1003
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
+							echo str_repeat("\t", $depth);
1005
+							echo "\t\t=> array property \"$name\" set to \"$printValue\"";
1006
+							if ($code !== $ref) {
1007
+								echo " for $code";
1008
+							}
1009
+
1010
+							echo PHP_EOL;
1011
+						}
1012
+					} else {
1013
+						$this->ruleset[$code]['properties'][$name] = (string) $prop['value'];
1014
+						if (PHP_CODESNIFFER_VERBOSITY > 1) {
1015
+							echo str_repeat("\t", $depth);
1016
+							echo "\t\t=> property \"$name\" set to \"".(string) $prop['value'].'"';
1017
+							if ($code !== $ref) {
1018
+								echo " for $code";
1019
+							}
1020
+
1021
+							echo PHP_EOL;
1022
+						}
1023
+					}//end if
1024
+				}//end foreach
1025
+			}//end if
1026
+
1027
+			// Ignore patterns.
1028
+			foreach ($rule->{'exclude-pattern'} as $pattern) {
1029
+				if ($this->shouldProcessElement($pattern) === false) {
1030
+					continue;
1031
+				}
1032
+
1033
+				if (isset($this->ignorePatterns[$code]) === false) {
1034
+					$this->ignorePatterns[$code] = [];
1035
+				}
1036
+
1037
+				if (isset($pattern['type']) === false) {
1038
+					$pattern['type'] = 'absolute';
1039
+				}
1040
+
1041
+				$this->ignorePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1042
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1043
+					echo str_repeat("\t", $depth);
1044
+					echo "\t\t=> added rule-specific ".(string) $pattern['type'].' ignore pattern';
1045
+					if ($code !== $ref) {
1046
+						echo " for $code";
1047
+					}
1048
+
1049
+					echo ': '.(string) $pattern.PHP_EOL;
1050
+				}
1051
+			}//end foreach
1052
+
1053
+			// Include patterns.
1054
+			foreach ($rule->{'include-pattern'} as $pattern) {
1055
+				if ($this->shouldProcessElement($pattern) === false) {
1056
+					continue;
1057
+				}
1058
+
1059
+				if (isset($this->includePatterns[$code]) === false) {
1060
+					$this->includePatterns[$code] = [];
1061
+				}
1062
+
1063
+				if (isset($pattern['type']) === false) {
1064
+					$pattern['type'] = 'absolute';
1065
+				}
1066
+
1067
+				$this->includePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1068
+				if (PHP_CODESNIFFER_VERBOSITY > 1) {
1069
+					echo str_repeat("\t", $depth);
1070
+					echo "\t\t=> added rule-specific ".(string) $pattern['type'].' include pattern';
1071
+					if ($code !== $ref) {
1072
+						echo " for $code";
1073
+					}
1074
+
1075
+					echo ': '.(string) $pattern.PHP_EOL;
1076
+				}
1077
+			}//end foreach
1078
+		}//end foreach
1079
+
1080
+	}//end processRule()
1081
+
1082
+
1083
+	/**
1084
+	 * Determine if an element should be processed or ignored.
1085
+	 *
1086
+	 * @param \SimpleXMLElement $element An object from a ruleset XML file.
1087
+	 *
1088
+	 * @return bool
1089
+	 */
1090
+	private function shouldProcessElement($element)
1091
+	{
1092
+		if (isset($element['phpcbf-only']) === false
1093
+			&& isset($element['phpcs-only']) === false
1094
+		) {
1095
+			// No exceptions are being made.
1096
+			return true;
1097
+		}
1098
+
1099
+		if (PHP_CODESNIFFER_CBF === true
1100
+			&& isset($element['phpcbf-only']) === true
1101
+			&& (string) $element['phpcbf-only'] === 'true'
1102
+		) {
1103
+			return true;
1104
+		}
1105
+
1106
+		if (PHP_CODESNIFFER_CBF === false
1107
+			&& isset($element['phpcs-only']) === true
1108
+			&& (string) $element['phpcs-only'] === 'true'
1109
+		) {
1110
+			return true;
1111
+		}
1112
+
1113
+		return false;
1114
+
1115
+	}//end shouldProcessElement()
1116
+
1117
+
1118
+	/**
1119
+	 * Loads and stores sniffs objects used for sniffing files.
1120
+	 *
1121
+	 * @param array $files        Paths to the sniff files to register.
1122
+	 * @param array $restrictions The sniff class names to restrict the allowed
1123
+	 *                            listeners to.
1124
+	 * @param array $exclusions   The sniff class names to exclude from the
1125
+	 *                            listeners list.
1126
+	 *
1127
+	 * @return void
1128
+	 */
1129
+	public function registerSniffs($files, $restrictions, $exclusions)
1130
+	{
1131
+		$listeners = [];
1132
+
1133
+		foreach ($files as $file) {
1134
+			// Work out where the position of /StandardName/Sniffs/... is
1135
+			// so we can determine what the class will be called.
1136
+			$sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
1137
+			if ($sniffPos === false) {
1138
+				continue;
1139
+			}
1140
+
1141
+			$slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
1142
+			if ($slashPos === false) {
1143
+				continue;
1144
+			}
1145
+
1146
+			$className   = Autoload::loadFile($file);
1147
+			$compareName = Util\Common::cleanSniffClass($className);
1148
+
1149
+			// If they have specified a list of sniffs to restrict to, check
1150
+			// to see if this sniff is allowed.
1151
+			if (empty($restrictions) === false
1152
+				&& isset($restrictions[$compareName]) === false
1153
+			) {
1154
+				continue;
1155
+			}
1156
+
1157
+			// If they have specified a list of sniffs to exclude, check
1158
+			// to see if this sniff is allowed.
1159
+			if (empty($exclusions) === false
1160
+				&& isset($exclusions[$compareName]) === true
1161
+			) {
1162
+				continue;
1163
+			}
1164
+
1165
+			// Skip abstract classes.
1166
+			$reflection = new \ReflectionClass($className);
1167
+			if ($reflection->isAbstract() === true) {
1168
+				continue;
1169
+			}
1170
+
1171
+			$listeners[$className] = $className;
1172
+
1173
+			if (PHP_CODESNIFFER_VERBOSITY > 2) {
1174
+				echo "Registered $className".PHP_EOL;
1175
+			}
1176
+		}//end foreach
1177
+
1178
+		$this->sniffs = $listeners;
1179
+
1180
+	}//end registerSniffs()
1181
+
1182
+
1183
+	/**
1184
+	 * Populates the array of PHP_CodeSniffer_Sniff's for this file.
1185
+	 *
1186
+	 * @return void
1187
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If sniff registration fails.
1188
+	 */
1189
+	public function populateTokenListeners()
1190
+	{
1191
+		// Construct a list of listeners indexed by token being listened for.
1192
+		$this->tokenListeners = [];
1193
+
1194
+		foreach ($this->sniffs as $sniffClass => $sniffObject) {
1195
+			$this->sniffs[$sniffClass] = null;
1196
+			$this->sniffs[$sniffClass] = new $sniffClass();
1197
+
1198
+			$sniffCode = Util\Common::getSniffCode($sniffClass);
1199
+			$this->sniffCodes[$sniffCode] = $sniffClass;
1200
+
1201
+			// Set custom properties.
1202
+			if (isset($this->ruleset[$sniffCode]['properties']) === true) {
1203
+				foreach ($this->ruleset[$sniffCode]['properties'] as $name => $value) {
1204
+					$this->setSniffProperty($sniffClass, $name, $value);
1205
+				}
1206
+			}
1207
+
1208
+			$tokenizers = [];
1209
+			$vars       = get_class_vars($sniffClass);
1210
+			if (isset($vars['supportedTokenizers']) === true) {
1211
+				foreach ($vars['supportedTokenizers'] as $tokenizer) {
1212
+					$tokenizers[$tokenizer] = $tokenizer;
1213
+				}
1214
+			} else {
1215
+				$tokenizers = ['PHP' => 'PHP'];
1216
+			}
1217
+
1218
+			$tokens = $this->sniffs[$sniffClass]->register();
1219
+			if (is_array($tokens) === false) {
1220
+				$msg = "Sniff $sniffClass register() method must return an array";
1221
+				throw new RuntimeException($msg);
1222
+			}
1223
+
1224
+			$ignorePatterns = [];
1225
+			$patterns       = $this->getIgnorePatterns($sniffCode);
1226
+			foreach ($patterns as $pattern => $type) {
1227
+				$replacements = [
1228
+					'\\,' => ',',
1229
+					'*'   => '.*',
1230
+				];
1231
+
1232
+				$ignorePatterns[] = strtr($pattern, $replacements);
1233
+			}
1234
+
1235
+			$includePatterns = [];
1236
+			$patterns        = $this->getIncludePatterns($sniffCode);
1237
+			foreach ($patterns as $pattern => $type) {
1238
+				$replacements = [
1239
+					'\\,' => ',',
1240
+					'*'   => '.*',
1241
+				];
1242
+
1243
+				$includePatterns[] = strtr($pattern, $replacements);
1244
+			}
1245
+
1246
+			foreach ($tokens as $token) {
1247
+				if (isset($this->tokenListeners[$token]) === false) {
1248
+					$this->tokenListeners[$token] = [];
1249
+				}
1250
+
1251
+				if (isset($this->tokenListeners[$token][$sniffClass]) === false) {
1252
+					$this->tokenListeners[$token][$sniffClass] = [
1253
+						'class'      => $sniffClass,
1254
+						'source'     => $sniffCode,
1255
+						'tokenizers' => $tokenizers,
1256
+						'ignore'     => $ignorePatterns,
1257
+						'include'    => $includePatterns,
1258
+					];
1259
+				}
1260
+			}
1261
+		}//end foreach
1262
+
1263
+	}//end populateTokenListeners()
1264
+
1265
+
1266
+	/**
1267
+	 * Set a single property for a sniff.
1268
+	 *
1269
+	 * @param string $sniffClass The class name of the sniff.
1270
+	 * @param string $name       The name of the property to change.
1271
+	 * @param string $value      The new value of the property.
1272
+	 *
1273
+	 * @return void
1274
+	 */
1275
+	public function setSniffProperty($sniffClass, $name, $value)
1276
+	{
1277
+		// Setting a property for a sniff we are not using.
1278
+		if (isset($this->sniffs[$sniffClass]) === false) {
1279
+			return;
1280
+		}
1281
+
1282
+		$name = trim($name);
1283
+		if (is_string($value) === true) {
1284
+			$value = trim($value);
1285
+		}
1286
+
1287
+		if ($value === '') {
1288
+			$value = null;
1289
+		}
1290
+
1291
+		// Special case for booleans.
1292
+		if ($value === 'true') {
1293
+			$value = true;
1294
+		} else if ($value === 'false') {
1295
+			$value = false;
1296
+		} else if (substr($name, -2) === '[]') {
1297
+			$name   = substr($name, 0, -2);
1298
+			$values = [];
1299
+			if ($value !== null) {
1300
+				foreach (explode(',', $value) as $val) {
1301
+					list($k, $v) = explode('=>', $val.'=>');
1302
+					if ($v !== '') {
1303
+						$values[trim($k)] = trim($v);
1304
+					} else {
1305
+						$values[] = trim($k);
1306
+					}
1307
+				}
1308
+			}
1309
+
1310
+			$value = $values;
1311
+		}
1312
+
1313
+		$this->sniffs[$sniffClass]->$name = $value;
1314
+
1315
+	}//end setSniffProperty()
1316
+
1317
+
1318
+	/**
1319
+	 * Gets the array of ignore patterns.
1320
+	 *
1321
+	 * Optionally takes a listener to get ignore patterns specified
1322
+	 * for that sniff only.
1323
+	 *
1324
+	 * @param string $listener The listener to get patterns for. If NULL, all
1325
+	 *                         patterns are returned.
1326
+	 *
1327
+	 * @return array
1328
+	 */
1329
+	public function getIgnorePatterns($listener=null)
1330
+	{
1331
+		if ($listener === null) {
1332
+			return $this->ignorePatterns;
1333
+		}
1334
+
1335
+		if (isset($this->ignorePatterns[$listener]) === true) {
1336
+			return $this->ignorePatterns[$listener];
1337
+		}
1338
+
1339
+		return [];
1340
+
1341
+	}//end getIgnorePatterns()
1342
+
1343
+
1344
+	/**
1345
+	 * Gets the array of include patterns.
1346
+	 *
1347
+	 * Optionally takes a listener to get include patterns specified
1348
+	 * for that sniff only.
1349
+	 *
1350
+	 * @param string $listener The listener to get patterns for. If NULL, all
1351
+	 *                         patterns are returned.
1352
+	 *
1353
+	 * @return array
1354
+	 */
1355
+	public function getIncludePatterns($listener=null)
1356
+	{
1357
+		if ($listener === null) {
1358
+			return $this->includePatterns;
1359
+		}
1360
+
1361
+		if (isset($this->includePatterns[$listener]) === true) {
1362
+			return $this->includePatterns[$listener];
1363
+		}
1364
+
1365
+		return [];
1366
+
1367
+	}//end getIncludePatterns()
1368 1368
 
1369 1369
 
1370 1370
 }//end class
Please login to merge, or discard this patch.
Spacing   +505 added lines, -505 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      *
38 38
      * @var string[]
39 39
      */
40
-    public $paths = [];
40
+    public $paths = [ ];
41 41
 
42 42
     /**
43 43
      * A list of regular expressions used to ignore specific sniffs for files and folders.
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @var array<string, string>
50 50
      */
51
-    public $ignorePatterns = [];
51
+    public $ignorePatterns = [ ];
52 52
 
53 53
     /**
54 54
      * A list of regular expressions used to include specific sniffs for files and folders.
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @var array<string, array<string, string>>
61 61
      */
62
-    public $includePatterns = [];
62
+    public $includePatterns = [ ];
63 63
 
64 64
     /**
65 65
      * An array of sniff objects that are being used to check files.
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
      *
70 70
      * @var array<string, \PHP_CodeSniffer\Sniffs\Sniff>
71 71
      */
72
-    public $sniffs = [];
72
+    public $sniffs = [ ];
73 73
 
74 74
     /**
75 75
      * A mapping of sniff codes to fully qualified class names.
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      *
80 80
      * @var array<string, string>
81 81
      */
82
-    public $sniffCodes = [];
82
+    public $sniffCodes = [ ];
83 83
 
84 84
     /**
85 85
      * An array of token types and the sniffs that are listening for them.
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
      *
90 90
      * @var array<int, \PHP_CodeSniffer\Sniffs\Sniff>
91 91
      */
92
-    public $tokenListeners = [];
92
+    public $tokenListeners = [ ];
93 93
 
94 94
     /**
95 95
      * An array of rules from the ruleset.xml file.
@@ -99,14 +99,14 @@  discard block
 block discarded – undo
99 99
      *
100 100
      * @var array<string, mixed>
101 101
      */
102
-    public $ruleset = [];
102
+    public $ruleset = [ ];
103 103
 
104 104
     /**
105 105
      * The directories that the processed rulesets are in.
106 106
      *
107 107
      * @var string[]
108 108
      */
109
-    protected $rulesetDirs = [];
109
+    protected $rulesetDirs = [ ];
110 110
 
111 111
     /**
112 112
      * The config data for the run.
@@ -123,63 +123,63 @@  discard block
 block discarded – undo
123 123
      *
124 124
      * @return void
125 125
      */
126
-    public function __construct(Config $config)
126
+    public function __construct( Config $config )
127 127
     {
128 128
         // Ignore sniff restrictions if caching is on.
129
-        $restrictions = [];
130
-        $exclusions   = [];
131
-        if ($config->cache === false) {
129
+        $restrictions = [ ];
130
+        $exclusions   = [ ];
131
+        if ( $config->cache === false ) {
132 132
             $restrictions = $config->sniffs;
133 133
             $exclusions   = $config->exclude;
134 134
         }
135 135
 
136 136
         $this->config = $config;
137
-        $sniffs       = [];
138
-
139
-        $standardPaths = [];
140
-        foreach ($config->standards as $standard) {
141
-            $installed = Util\Standards::getInstalledStandardPath($standard);
142
-            if ($installed === null) {
143
-                $standard = Util\Common::realpath($standard);
144
-                if (is_dir($standard) === true
145
-                    && is_file(Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml')) === true
137
+        $sniffs       = [ ];
138
+
139
+        $standardPaths = [ ];
140
+        foreach ( $config->standards as $standard ) {
141
+            $installed = Util\Standards::getInstalledStandardPath( $standard );
142
+            if ( $installed === null ) {
143
+                $standard = Util\Common::realpath( $standard );
144
+                if ( is_dir( $standard ) === true
145
+                    && is_file( Util\Common::realpath( $standard . DIRECTORY_SEPARATOR . 'ruleset.xml' ) ) === true
146 146
                 ) {
147
-                    $standard = Util\Common::realpath($standard.DIRECTORY_SEPARATOR.'ruleset.xml');
147
+                    $standard = Util\Common::realpath( $standard . DIRECTORY_SEPARATOR . 'ruleset.xml' );
148 148
                 }
149 149
             } else {
150 150
                 $standard = $installed;
151 151
             }
152 152
 
153
-            $standardPaths[] = $standard;
153
+            $standardPaths[ ] = $standard;
154 154
         }
155 155
 
156
-        foreach ($standardPaths as $standard) {
157
-            $ruleset = @simplexml_load_string(file_get_contents($standard));
158
-            if ($ruleset !== false) {
159
-                $standardName = (string) $ruleset['name'];
160
-                if ($this->name !== '') {
156
+        foreach ( $standardPaths as $standard ) {
157
+            $ruleset = @simplexml_load_string( file_get_contents( $standard ) );
158
+            if ( $ruleset !== false ) {
159
+                $standardName = (string)$ruleset[ 'name' ];
160
+                if ( $this->name !== '' ) {
161 161
                     $this->name .= ', ';
162 162
                 }
163 163
 
164 164
                 $this->name .= $standardName;
165 165
 
166 166
                 // Allow autoloading of custom files inside this standard.
167
-                if (isset($ruleset['namespace']) === true) {
168
-                    $namespace = (string) $ruleset['namespace'];
167
+                if ( isset( $ruleset[ 'namespace' ] ) === true ) {
168
+                    $namespace = (string)$ruleset[ 'namespace' ];
169 169
                 } else {
170
-                    $namespace = basename(dirname($standard));
170
+                    $namespace = basename( dirname( $standard ) );
171 171
                 }
172 172
 
173
-                Autoload::addSearchPath(dirname($standard), $namespace);
173
+                Autoload::addSearchPath( dirname( $standard ), $namespace );
174 174
             }
175 175
 
176
-            if (defined('PHP_CODESNIFFER_IN_TESTS') === true && empty($restrictions) === false) {
176
+            if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === true && empty( $restrictions ) === false ) {
177 177
                 // In unit tests, only register the sniffs that the test wants and not the entire standard.
178 178
                 try {
179
-                    foreach ($restrictions as $restriction) {
180
-                        $sniffs = array_merge($sniffs, $this->expandRulesetReference($restriction, dirname($standard)));
179
+                    foreach ( $restrictions as $restriction ) {
180
+                        $sniffs = array_merge( $sniffs, $this->expandRulesetReference( $restriction, dirname( $standard ) ) );
181 181
                     }
182
-                } catch (RuntimeException $e) {
182
+                } catch ( RuntimeException $e ) {
183 183
                     // Sniff reference could not be expanded, which probably means this
184 184
                     // is an installed standard. Let the unit test system take care of
185 185
                     // setting the correct sniff for testing.
@@ -189,40 +189,40 @@  discard block
 block discarded – undo
189 189
                 break;
190 190
             }
191 191
 
192
-            if (PHP_CODESNIFFER_VERBOSITY === 1) {
192
+            if ( PHP_CODESNIFFER_VERBOSITY === 1 ) {
193 193
                 echo "Registering sniffs in the $standardName standard... ";
194
-                if (count($config->standards) > 1 || PHP_CODESNIFFER_VERBOSITY > 2) {
194
+                if ( count( $config->standards ) > 1 || PHP_CODESNIFFER_VERBOSITY > 2 ) {
195 195
                     echo PHP_EOL;
196 196
                 }
197 197
             }
198 198
 
199
-            $sniffs = array_merge($sniffs, $this->processRuleset($standard));
199
+            $sniffs = array_merge( $sniffs, $this->processRuleset( $standard ) );
200 200
         }//end foreach
201 201
 
202
-        $sniffRestrictions = [];
203
-        foreach ($restrictions as $sniffCode) {
204
-            $parts     = explode('.', strtolower($sniffCode));
205
-            $sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
206
-            $sniffRestrictions[$sniffName] = true;
202
+        $sniffRestrictions = [ ];
203
+        foreach ( $restrictions as $sniffCode ) {
204
+            $parts     = explode( '.', strtolower( $sniffCode ) );
205
+            $sniffName = $parts[ 0 ] . '\sniffs\\' . $parts[ 1 ] . '\\' . $parts[ 2 ] . 'sniff';
206
+            $sniffRestrictions[ $sniffName ] = true;
207 207
         }
208 208
 
209
-        $sniffExclusions = [];
210
-        foreach ($exclusions as $sniffCode) {
211
-            $parts     = explode('.', strtolower($sniffCode));
212
-            $sniffName = $parts[0].'\sniffs\\'.$parts[1].'\\'.$parts[2].'sniff';
213
-            $sniffExclusions[$sniffName] = true;
209
+        $sniffExclusions = [ ];
210
+        foreach ( $exclusions as $sniffCode ) {
211
+            $parts     = explode( '.', strtolower( $sniffCode ) );
212
+            $sniffName = $parts[ 0 ] . '\sniffs\\' . $parts[ 1 ] . '\\' . $parts[ 2 ] . 'sniff';
213
+            $sniffExclusions[ $sniffName ] = true;
214 214
         }
215 215
 
216
-        $this->registerSniffs($sniffs, $sniffRestrictions, $sniffExclusions);
216
+        $this->registerSniffs( $sniffs, $sniffRestrictions, $sniffExclusions );
217 217
         $this->populateTokenListeners();
218 218
 
219
-        $numSniffs = count($this->sniffs);
220
-        if (PHP_CODESNIFFER_VERBOSITY === 1) {
221
-            echo "DONE ($numSniffs sniffs registered)".PHP_EOL;
219
+        $numSniffs = count( $this->sniffs );
220
+        if ( PHP_CODESNIFFER_VERBOSITY === 1 ) {
221
+            echo "DONE ($numSniffs sniffs registered)" . PHP_EOL;
222 222
         }
223 223
 
224
-        if ($numSniffs === 0) {
225
-            throw new RuntimeException('No sniffs were registered');
224
+        if ( $numSniffs === 0 ) {
225
+            throw new RuntimeException( 'No sniffs were registered' );
226 226
         }
227 227
 
228 228
     }//end __construct()
@@ -235,58 +235,58 @@  discard block
 block discarded – undo
235 235
      */
236 236
     public function explain()
237 237
     {
238
-        $sniffs = array_keys($this->sniffCodes);
239
-        sort($sniffs);
238
+        $sniffs = array_keys( $this->sniffCodes );
239
+        sort( $sniffs );
240 240
 
241 241
         ob_start();
242 242
 
243 243
         $lastStandard = null;
244 244
         $lastCount    = '';
245
-        $sniffCount   = count($sniffs);
245
+        $sniffCount   = count( $sniffs );
246 246
 
247 247
         // Add a dummy entry to the end so we loop
248 248
         // one last time and clear the output buffer.
249
-        $sniffs[] = '';
249
+        $sniffs[ ] = '';
250 250
 
251
-        echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL;
251
+        echo PHP_EOL . "The $this->name standard contains $sniffCount sniffs" . PHP_EOL;
252 252
 
253 253
         ob_start();
254 254
 
255
-        foreach ($sniffs as $i => $sniff) {
256
-            if ($i === $sniffCount) {
255
+        foreach ( $sniffs as $i => $sniff ) {
256
+            if ( $i === $sniffCount ) {
257 257
                 $currentStandard = null;
258 258
             } else {
259
-                $currentStandard = substr($sniff, 0, strpos($sniff, '.'));
260
-                if ($lastStandard === null) {
259
+                $currentStandard = substr( $sniff, 0, strpos( $sniff, '.' ) );
260
+                if ( $lastStandard === null ) {
261 261
                     $lastStandard = $currentStandard;
262 262
                 }
263 263
             }
264 264
 
265
-            if ($currentStandard !== $lastStandard) {
265
+            if ( $currentStandard !== $lastStandard ) {
266 266
                 $sniffList = ob_get_contents();
267 267
                 ob_end_clean();
268 268
 
269
-                echo PHP_EOL.$lastStandard.' ('.$lastCount.' sniff';
270
-                if ($lastCount > 1) {
269
+                echo PHP_EOL . $lastStandard . ' (' . $lastCount . ' sniff';
270
+                if ( $lastCount > 1 ) {
271 271
                     echo 's';
272 272
                 }
273 273
 
274
-                echo ')'.PHP_EOL;
275
-                echo str_repeat('-', (strlen($lastStandard.$lastCount) + 10));
274
+                echo ')' . PHP_EOL;
275
+                echo str_repeat( '-', ( strlen( $lastStandard . $lastCount ) + 10 ) );
276 276
                 echo PHP_EOL;
277 277
                 echo $sniffList;
278 278
 
279 279
                 $lastStandard = $currentStandard;
280 280
                 $lastCount    = 0;
281 281
 
282
-                if ($currentStandard === null) {
282
+                if ( $currentStandard === null ) {
283 283
                     break;
284 284
                 }
285 285
 
286 286
                 ob_start();
287 287
             }//end if
288 288
 
289
-            echo '  '.$sniff.PHP_EOL;
289
+            echo '  ' . $sniff . PHP_EOL;
290 290
             $lastCount++;
291 291
         }//end foreach
292 292
 
@@ -306,292 +306,292 @@  discard block
 block discarded – undo
306 306
      * @return string[]
307 307
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid.
308 308
      */
309
-    public function processRuleset($rulesetPath, $depth=0)
309
+    public function processRuleset( $rulesetPath, $depth = 0 )
310 310
     {
311
-        $rulesetPath = Util\Common::realpath($rulesetPath);
312
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
313
-            echo str_repeat("\t", $depth);
314
-            echo 'Processing ruleset '.Util\Common::stripBasepath($rulesetPath, $this->config->basepath).PHP_EOL;
311
+        $rulesetPath = Util\Common::realpath( $rulesetPath );
312
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
313
+            echo str_repeat( "\t", $depth );
314
+            echo 'Processing ruleset ' . Util\Common::stripBasepath( $rulesetPath, $this->config->basepath ) . PHP_EOL;
315 315
         }
316 316
 
317
-        libxml_use_internal_errors(true);
318
-        $ruleset = simplexml_load_string(file_get_contents($rulesetPath));
319
-        if ($ruleset === false) {
320
-            $errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL;
317
+        libxml_use_internal_errors( true );
318
+        $ruleset = simplexml_load_string( file_get_contents( $rulesetPath ) );
319
+        if ( $ruleset === false ) {
320
+            $errorMsg = "Ruleset $rulesetPath is not valid" . PHP_EOL;
321 321
             $errors   = libxml_get_errors();
322
-            foreach ($errors as $error) {
323
-                $errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message;
322
+            foreach ( $errors as $error ) {
323
+                $errorMsg .= '- On line ' . $error->line . ', column ' . $error->column . ': ' . $error->message;
324 324
             }
325 325
 
326 326
             libxml_clear_errors();
327
-            throw new RuntimeException($errorMsg);
327
+            throw new RuntimeException( $errorMsg );
328 328
         }
329 329
 
330
-        libxml_use_internal_errors(false);
330
+        libxml_use_internal_errors( false );
331 331
 
332
-        $ownSniffs      = [];
333
-        $includedSniffs = [];
334
-        $excludedSniffs = [];
332
+        $ownSniffs      = [ ];
333
+        $includedSniffs = [ ];
334
+        $excludedSniffs = [ ];
335 335
 
336
-        $this->paths[]       = $rulesetPath;
337
-        $rulesetDir          = dirname($rulesetPath);
338
-        $this->rulesetDirs[] = $rulesetDir;
336
+        $this->paths[ ]       = $rulesetPath;
337
+        $rulesetDir          = dirname( $rulesetPath );
338
+        $this->rulesetDirs[ ] = $rulesetDir;
339 339
 
340
-        $sniffDir = $rulesetDir.DIRECTORY_SEPARATOR.'Sniffs';
341
-        if (is_dir($sniffDir) === true) {
342
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
343
-                echo str_repeat("\t", $depth);
344
-                echo "\tAdding sniff files from ".Util\Common::stripBasepath($sniffDir, $this->config->basepath).' directory'.PHP_EOL;
340
+        $sniffDir = $rulesetDir . DIRECTORY_SEPARATOR . 'Sniffs';
341
+        if ( is_dir( $sniffDir ) === true ) {
342
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
343
+                echo str_repeat( "\t", $depth );
344
+                echo "\tAdding sniff files from " . Util\Common::stripBasepath( $sniffDir, $this->config->basepath ) . ' directory' . PHP_EOL;
345 345
             }
346 346
 
347
-            $ownSniffs = $this->expandSniffDirectory($sniffDir, $depth);
347
+            $ownSniffs = $this->expandSniffDirectory( $sniffDir, $depth );
348 348
         }
349 349
 
350 350
         // Included custom autoloaders.
351
-        foreach ($ruleset->{'autoload'} as $autoload) {
352
-            if ($this->shouldProcessElement($autoload) === false) {
351
+        foreach ( $ruleset->{'autoload'} as $autoload ) {
352
+            if ( $this->shouldProcessElement( $autoload ) === false ) {
353 353
                 continue;
354 354
             }
355 355
 
356
-            $autoloadPath = (string) $autoload;
357
-            if (is_file($autoloadPath) === false) {
358
-                $autoloadPath = Util\Common::realPath(dirname($rulesetPath).DIRECTORY_SEPARATOR.$autoloadPath);
356
+            $autoloadPath = (string)$autoload;
357
+            if ( is_file( $autoloadPath ) === false ) {
358
+                $autoloadPath = Util\Common::realPath( dirname( $rulesetPath ) . DIRECTORY_SEPARATOR . $autoloadPath );
359 359
             }
360 360
 
361
-            if ($autoloadPath === false) {
362
-                throw new RuntimeException('The specified autoload file "'.$autoload.'" does not exist');
361
+            if ( $autoloadPath === false ) {
362
+                throw new RuntimeException( 'The specified autoload file "' . $autoload . '" does not exist' );
363 363
             }
364 364
 
365 365
             include_once $autoloadPath;
366 366
 
367
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
368
-                echo str_repeat("\t", $depth);
369
-                echo "\t=> included autoloader $autoloadPath".PHP_EOL;
367
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
368
+                echo str_repeat( "\t", $depth );
369
+                echo "\t=> included autoloader $autoloadPath" . PHP_EOL;
370 370
             }
371 371
         }//end foreach
372 372
 
373 373
         // Process custom sniff config settings.
374
-        foreach ($ruleset->{'config'} as $config) {
375
-            if ($this->shouldProcessElement($config) === false) {
374
+        foreach ( $ruleset->{'config'} as $config ) {
375
+            if ( $this->shouldProcessElement( $config ) === false ) {
376 376
                 continue;
377 377
             }
378 378
 
379
-            Config::setConfigData((string) $config['name'], (string) $config['value'], true);
380
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
381
-                echo str_repeat("\t", $depth);
382
-                echo "\t=> set config value ".(string) $config['name'].': '.(string) $config['value'].PHP_EOL;
379
+            Config::setConfigData( (string)$config[ 'name' ], (string)$config[ 'value' ], true );
380
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
381
+                echo str_repeat( "\t", $depth );
382
+                echo "\t=> set config value " . (string)$config[ 'name' ] . ': ' . (string)$config[ 'value' ] . PHP_EOL;
383 383
             }
384 384
         }
385 385
 
386
-        foreach ($ruleset->rule as $rule) {
387
-            if (isset($rule['ref']) === false
388
-                || $this->shouldProcessElement($rule) === false
386
+        foreach ( $ruleset->rule as $rule ) {
387
+            if ( isset( $rule[ 'ref' ] ) === false
388
+                || $this->shouldProcessElement( $rule ) === false
389 389
             ) {
390 390
                 continue;
391 391
             }
392 392
 
393
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
394
-                echo str_repeat("\t", $depth);
395
-                echo "\tProcessing rule \"".$rule['ref'].'"'.PHP_EOL;
393
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
394
+                echo str_repeat( "\t", $depth );
395
+                echo "\tProcessing rule \"" . $rule[ 'ref' ] . '"' . PHP_EOL;
396 396
             }
397 397
 
398
-            $expandedSniffs = $this->expandRulesetReference((string) $rule['ref'], $rulesetDir, $depth);
399
-            $newSniffs      = array_diff($expandedSniffs, $includedSniffs);
400
-            $includedSniffs = array_merge($includedSniffs, $expandedSniffs);
398
+            $expandedSniffs = $this->expandRulesetReference( (string)$rule[ 'ref' ], $rulesetDir, $depth );
399
+            $newSniffs      = array_diff( $expandedSniffs, $includedSniffs );
400
+            $includedSniffs = array_merge( $includedSniffs, $expandedSniffs );
401 401
 
402
-            $parts = explode('.', $rule['ref']);
403
-            if (count($parts) === 4
404
-                && $parts[0] !== ''
405
-                && $parts[1] !== ''
406
-                && $parts[2] !== ''
402
+            $parts = explode( '.', $rule[ 'ref' ] );
403
+            if ( count( $parts ) === 4
404
+                && $parts[ 0 ] !== ''
405
+                && $parts[ 1 ] !== ''
406
+                && $parts[ 2 ] !== ''
407 407
             ) {
408
-                $sniffCode = $parts[0].'.'.$parts[1].'.'.$parts[2];
409
-                if (isset($this->ruleset[$sniffCode]['severity']) === true
410
-                    && $this->ruleset[$sniffCode]['severity'] === 0
408
+                $sniffCode = $parts[ 0 ] . '.' . $parts[ 1 ] . '.' . $parts[ 2 ];
409
+                if ( isset( $this->ruleset[ $sniffCode ][ 'severity' ] ) === true
410
+                    && $this->ruleset[ $sniffCode ][ 'severity' ] === 0
411 411
                 ) {
412 412
                     // This sniff code has already been turned off, but now
413 413
                     // it is being explicitly included again, so turn it back on.
414
-                    $this->ruleset[(string) $rule['ref']]['severity'] = 5;
415
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
416
-                        echo str_repeat("\t", $depth);
417
-                        echo "\t\t* disabling sniff exclusion for specific message code *".PHP_EOL;
418
-                        echo str_repeat("\t", $depth);
419
-                        echo "\t\t=> severity set to 5".PHP_EOL;
414
+                    $this->ruleset[ (string)$rule[ 'ref' ] ][ 'severity' ] = 5;
415
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
416
+                        echo str_repeat( "\t", $depth );
417
+                        echo "\t\t* disabling sniff exclusion for specific message code *" . PHP_EOL;
418
+                        echo str_repeat( "\t", $depth );
419
+                        echo "\t\t=> severity set to 5" . PHP_EOL;
420 420
                     }
421
-                } else if (empty($newSniffs) === false) {
422
-                    $newSniff = $newSniffs[0];
423
-                    if (in_array($newSniff, $ownSniffs, true) === false) {
421
+                } else if ( empty( $newSniffs ) === false ) {
422
+                    $newSniff = $newSniffs[ 0 ];
423
+                    if ( in_array( $newSniff, $ownSniffs, true ) === false ) {
424 424
                         // Including a sniff that hasn't been included higher up, but
425 425
                         // only including a single message from it. So turn off all messages in
426 426
                         // the sniff, except this one.
427
-                        $this->ruleset[$sniffCode]['severity']            = 0;
428
-                        $this->ruleset[(string) $rule['ref']]['severity'] = 5;
429
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
430
-                            echo str_repeat("\t", $depth);
431
-                            echo "\t\tExcluding sniff \"".$sniffCode.'" except for "'.$parts[3].'"'.PHP_EOL;
427
+                        $this->ruleset[ $sniffCode ][ 'severity' ]            = 0;
428
+                        $this->ruleset[ (string)$rule[ 'ref' ] ][ 'severity' ] = 5;
429
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
430
+                            echo str_repeat( "\t", $depth );
431
+                            echo "\t\tExcluding sniff \"" . $sniffCode . '" except for "' . $parts[ 3 ] . '"' . PHP_EOL;
432 432
                         }
433 433
                     }
434 434
                 }//end if
435 435
             }//end if
436 436
 
437
-            if (isset($rule->exclude) === true) {
438
-                foreach ($rule->exclude as $exclude) {
439
-                    if (isset($exclude['name']) === false) {
440
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
441
-                            echo str_repeat("\t", $depth);
442
-                            echo "\t\t* ignoring empty exclude rule *".PHP_EOL;
443
-                            echo "\t\t\t=> ".$exclude->asXML().PHP_EOL;
437
+            if ( isset( $rule->exclude ) === true ) {
438
+                foreach ( $rule->exclude as $exclude ) {
439
+                    if ( isset( $exclude[ 'name' ] ) === false ) {
440
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
441
+                            echo str_repeat( "\t", $depth );
442
+                            echo "\t\t* ignoring empty exclude rule *" . PHP_EOL;
443
+                            echo "\t\t\t=> " . $exclude->asXML() . PHP_EOL;
444 444
                         }
445 445
 
446 446
                         continue;
447 447
                     }
448 448
 
449
-                    if ($this->shouldProcessElement($exclude) === false) {
449
+                    if ( $this->shouldProcessElement( $exclude ) === false ) {
450 450
                         continue;
451 451
                     }
452 452
 
453
-                    if (PHP_CODESNIFFER_VERBOSITY > 1) {
454
-                        echo str_repeat("\t", $depth);
455
-                        echo "\t\tExcluding rule \"".$exclude['name'].'"'.PHP_EOL;
453
+                    if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
454
+                        echo str_repeat( "\t", $depth );
455
+                        echo "\t\tExcluding rule \"" . $exclude[ 'name' ] . '"' . PHP_EOL;
456 456
                     }
457 457
 
458 458
                     // Check if a single code is being excluded, which is a shortcut
459 459
                     // for setting the severity of the message to 0.
460
-                    $parts = explode('.', $exclude['name']);
461
-                    if (count($parts) === 4) {
462
-                        $this->ruleset[(string) $exclude['name']]['severity'] = 0;
463
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
464
-                            echo str_repeat("\t", $depth);
465
-                            echo "\t\t=> severity set to 0".PHP_EOL;
460
+                    $parts = explode( '.', $exclude[ 'name' ] );
461
+                    if ( count( $parts ) === 4 ) {
462
+                        $this->ruleset[ (string)$exclude[ 'name' ] ][ 'severity' ] = 0;
463
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
464
+                            echo str_repeat( "\t", $depth );
465
+                            echo "\t\t=> severity set to 0" . PHP_EOL;
466 466
                         }
467 467
                     } else {
468 468
                         $excludedSniffs = array_merge(
469 469
                             $excludedSniffs,
470
-                            $this->expandRulesetReference((string) $exclude['name'], $rulesetDir, ($depth + 1))
470
+                            $this->expandRulesetReference( (string)$exclude[ 'name' ], $rulesetDir, ( $depth + 1 ) )
471 471
                         );
472 472
                     }
473 473
                 }//end foreach
474 474
             }//end if
475 475
 
476
-            $this->processRule($rule, $newSniffs, $depth);
476
+            $this->processRule( $rule, $newSniffs, $depth );
477 477
         }//end foreach
478 478
 
479 479
         // Process custom command line arguments.
480
-        $cliArgs = [];
481
-        foreach ($ruleset->{'arg'} as $arg) {
482
-            if ($this->shouldProcessElement($arg) === false) {
480
+        $cliArgs = [ ];
481
+        foreach ( $ruleset->{'arg'} as $arg ) {
482
+            if ( $this->shouldProcessElement( $arg ) === false ) {
483 483
                 continue;
484 484
             }
485 485
 
486
-            if (isset($arg['name']) === true) {
487
-                $argString = '--'.(string) $arg['name'];
488
-                if (isset($arg['value']) === true) {
489
-                    $argString .= '='.(string) $arg['value'];
486
+            if ( isset( $arg[ 'name' ] ) === true ) {
487
+                $argString = '--' . (string)$arg[ 'name' ];
488
+                if ( isset( $arg[ 'value' ] ) === true ) {
489
+                    $argString .= '=' . (string)$arg[ 'value' ];
490 490
                 }
491 491
             } else {
492
-                $argString = '-'.(string) $arg['value'];
492
+                $argString = '-' . (string)$arg[ 'value' ];
493 493
             }
494 494
 
495
-            $cliArgs[] = $argString;
495
+            $cliArgs[ ] = $argString;
496 496
 
497
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
498
-                echo str_repeat("\t", $depth);
499
-                echo "\t=> set command line value $argString".PHP_EOL;
497
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
498
+                echo str_repeat( "\t", $depth );
499
+                echo "\t=> set command line value $argString" . PHP_EOL;
500 500
             }
501 501
         }//end foreach
502 502
 
503 503
         // Set custom php ini values as CLI args.
504
-        foreach ($ruleset->{'ini'} as $arg) {
505
-            if ($this->shouldProcessElement($arg) === false) {
504
+        foreach ( $ruleset->{'ini'} as $arg ) {
505
+            if ( $this->shouldProcessElement( $arg ) === false ) {
506 506
                 continue;
507 507
             }
508 508
 
509
-            if (isset($arg['name']) === false) {
509
+            if ( isset( $arg[ 'name' ] ) === false ) {
510 510
                 continue;
511 511
             }
512 512
 
513
-            $name      = (string) $arg['name'];
513
+            $name      = (string)$arg[ 'name' ];
514 514
             $argString = $name;
515
-            if (isset($arg['value']) === true) {
516
-                $value      = (string) $arg['value'];
515
+            if ( isset( $arg[ 'value' ] ) === true ) {
516
+                $value      = (string)$arg[ 'value' ];
517 517
                 $argString .= "=$value";
518 518
             } else {
519 519
                 $value = 'true';
520 520
             }
521 521
 
522
-            $cliArgs[] = '-d';
523
-            $cliArgs[] = $argString;
522
+            $cliArgs[ ] = '-d';
523
+            $cliArgs[ ] = $argString;
524 524
 
525
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
526
-                echo str_repeat("\t", $depth);
527
-                echo "\t=> set PHP ini value $name to $value".PHP_EOL;
525
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
526
+                echo str_repeat( "\t", $depth );
527
+                echo "\t=> set PHP ini value $name to $value" . PHP_EOL;
528 528
             }
529 529
         }//end foreach
530 530
 
531
-        if (empty($this->config->files) === true) {
531
+        if ( empty( $this->config->files ) === true ) {
532 532
             // Process hard-coded file paths.
533
-            foreach ($ruleset->{'file'} as $file) {
534
-                $file      = (string) $file;
535
-                $cliArgs[] = $file;
536
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
537
-                    echo str_repeat("\t", $depth);
538
-                    echo "\t=> added \"$file\" to the file list".PHP_EOL;
533
+            foreach ( $ruleset->{'file'} as $file ) {
534
+                $file      = (string)$file;
535
+                $cliArgs[ ] = $file;
536
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
537
+                    echo str_repeat( "\t", $depth );
538
+                    echo "\t=> added \"$file\" to the file list" . PHP_EOL;
539 539
                 }
540 540
             }
541 541
         }
542 542
 
543
-        if (empty($cliArgs) === false) {
543
+        if ( empty( $cliArgs ) === false ) {
544 544
             // Change the directory so all relative paths are worked
545 545
             // out based on the location of the ruleset instead of
546 546
             // the location of the user.
547
-            $inPhar = Util\Common::isPharFile($rulesetDir);
548
-            if ($inPhar === false) {
547
+            $inPhar = Util\Common::isPharFile( $rulesetDir );
548
+            if ( $inPhar === false ) {
549 549
                 $currentDir = getcwd();
550
-                chdir($rulesetDir);
550
+                chdir( $rulesetDir );
551 551
             }
552 552
 
553
-            $this->config->setCommandLineValues($cliArgs);
553
+            $this->config->setCommandLineValues( $cliArgs );
554 554
 
555
-            if ($inPhar === false) {
556
-                chdir($currentDir);
555
+            if ( $inPhar === false ) {
556
+                chdir( $currentDir );
557 557
             }
558 558
         }
559 559
 
560 560
         // Process custom ignore pattern rules.
561
-        foreach ($ruleset->{'exclude-pattern'} as $pattern) {
562
-            if ($this->shouldProcessElement($pattern) === false) {
561
+        foreach ( $ruleset->{'exclude-pattern'} as $pattern ) {
562
+            if ( $this->shouldProcessElement( $pattern ) === false ) {
563 563
                 continue;
564 564
             }
565 565
 
566
-            if (isset($pattern['type']) === false) {
567
-                $pattern['type'] = 'absolute';
566
+            if ( isset( $pattern[ 'type' ] ) === false ) {
567
+                $pattern[ 'type' ] = 'absolute';
568 568
             }
569 569
 
570
-            $this->ignorePatterns[(string) $pattern] = (string) $pattern['type'];
571
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
572
-                echo str_repeat("\t", $depth);
573
-                echo "\t=> added global ".(string) $pattern['type'].' ignore pattern: '.(string) $pattern.PHP_EOL;
570
+            $this->ignorePatterns[ (string)$pattern ] = (string)$pattern[ 'type' ];
571
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
572
+                echo str_repeat( "\t", $depth );
573
+                echo "\t=> added global " . (string)$pattern[ 'type' ] . ' ignore pattern: ' . (string)$pattern . PHP_EOL;
574 574
             }
575 575
         }
576 576
 
577
-        $includedSniffs = array_unique(array_merge($ownSniffs, $includedSniffs));
578
-        $excludedSniffs = array_unique($excludedSniffs);
577
+        $includedSniffs = array_unique( array_merge( $ownSniffs, $includedSniffs ) );
578
+        $excludedSniffs = array_unique( $excludedSniffs );
579 579
 
580
-        if (PHP_CODESNIFFER_VERBOSITY > 1) {
581
-            $included = count($includedSniffs);
582
-            $excluded = count($excludedSniffs);
583
-            echo str_repeat("\t", $depth);
584
-            echo "=> Ruleset processing complete; included $included sniffs and excluded $excluded".PHP_EOL;
580
+        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
581
+            $included = count( $includedSniffs );
582
+            $excluded = count( $excludedSniffs );
583
+            echo str_repeat( "\t", $depth );
584
+            echo "=> Ruleset processing complete; included $included sniffs and excluded $excluded" . PHP_EOL;
585 585
         }
586 586
 
587 587
         // Merge our own sniff list with our externally included
588 588
         // sniff list, but filter out any excluded sniffs.
589
-        $files = [];
590
-        foreach ($includedSniffs as $sniff) {
591
-            if (in_array($sniff, $excludedSniffs, true) === true) {
589
+        $files = [ ];
590
+        foreach ( $includedSniffs as $sniff ) {
591
+            if ( in_array( $sniff, $excludedSniffs, true ) === true ) {
592 592
                 continue;
593 593
             } else {
594
-                $files[] = Util\Common::realpath($sniff);
594
+                $files[ ] = Util\Common::realpath( $sniff );
595 595
             }
596 596
         }
597 597
 
@@ -609,31 +609,31 @@  discard block
 block discarded – undo
609 609
      *
610 610
      * @return array
611 611
      */
612
-    private function expandSniffDirectory($directory, $depth=0)
612
+    private function expandSniffDirectory( $directory, $depth = 0 )
613 613
     {
614
-        $sniffs = [];
614
+        $sniffs = [ ];
615 615
 
616
-        $rdi = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
617
-        $di  = new \RecursiveIteratorIterator($rdi, 0, \RecursiveIteratorIterator::CATCH_GET_CHILD);
616
+        $rdi = new \RecursiveDirectoryIterator( $directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS );
617
+        $di  = new \RecursiveIteratorIterator( $rdi, 0, \RecursiveIteratorIterator::CATCH_GET_CHILD );
618 618
 
619
-        $dirLen = strlen($directory);
619
+        $dirLen = strlen( $directory );
620 620
 
621
-        foreach ($di as $file) {
621
+        foreach ( $di as $file ) {
622 622
             $filename = $file->getFilename();
623 623
 
624 624
             // Skip hidden files.
625
-            if (substr($filename, 0, 1) === '.') {
625
+            if ( substr( $filename, 0, 1 ) === '.' ) {
626 626
                 continue;
627 627
             }
628 628
 
629 629
             // We are only interested in PHP and sniff files.
630
-            $fileParts = explode('.', $filename);
631
-            if (array_pop($fileParts) !== 'php') {
630
+            $fileParts = explode( '.', $filename );
631
+            if ( array_pop( $fileParts ) !== 'php' ) {
632 632
                 continue;
633 633
             }
634 634
 
635
-            $basename = basename($filename, '.php');
636
-            if (substr($basename, -5) !== 'Sniff') {
635
+            $basename = basename( $filename, '.php' );
636
+            if ( substr( $basename, -5 ) !== 'Sniff' ) {
637 637
                 continue;
638 638
             }
639 639
 
@@ -643,16 +643,16 @@  discard block
 block discarded – undo
643 643
             // standard. We use the offset with strpos() to allow hidden directories
644 644
             // before, valid example:
645 645
             // /home/foo/.composer/vendor/squiz/custom_tool/MyStandard/Sniffs/...
646
-            if (strpos($path, DIRECTORY_SEPARATOR.'.', $dirLen) !== false) {
646
+            if ( strpos( $path, DIRECTORY_SEPARATOR . '.', $dirLen ) !== false ) {
647 647
                 continue;
648 648
             }
649 649
 
650
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
651
-                echo str_repeat("\t", $depth);
652
-                echo "\t\t=> ".Util\Common::stripBasepath($path, $this->config->basepath).PHP_EOL;
650
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
651
+                echo str_repeat( "\t", $depth );
652
+                echo "\t\t=> " . Util\Common::stripBasepath( $path, $this->config->basepath ) . PHP_EOL;
653 653
             }
654 654
 
655
-            $sniffs[] = $path;
655
+            $sniffs[ ] = $path;
656 656
         }//end foreach
657 657
 
658 658
         return $sniffs;
@@ -672,120 +672,120 @@  discard block
 block discarded – undo
672 672
      * @return array
673 673
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the reference is invalid.
674 674
      */
675
-    private function expandRulesetReference($ref, $rulesetDir, $depth=0)
675
+    private function expandRulesetReference( $ref, $rulesetDir, $depth = 0 )
676 676
     {
677 677
         // Ignore internal sniffs codes as they are used to only
678 678
         // hide and change internal messages.
679
-        if (substr($ref, 0, 9) === 'Internal.') {
680
-            if (PHP_CODESNIFFER_VERBOSITY > 1) {
681
-                echo str_repeat("\t", $depth);
682
-                echo "\t\t* ignoring internal sniff code *".PHP_EOL;
679
+        if ( substr( $ref, 0, 9 ) === 'Internal.' ) {
680
+            if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
681
+                echo str_repeat( "\t", $depth );
682
+                echo "\t\t* ignoring internal sniff code *" . PHP_EOL;
683 683
             }
684 684
 
685
-            return [];
685
+            return [ ];
686 686
         }
687 687
 
688 688
         // As sniffs can't begin with a full stop, assume references in
689 689
         // this format are relative paths and attempt to convert them
690 690
         // to absolute paths. If this fails, let the reference run through
691 691
         // the normal checks and have it fail as normal.
692
-        if (substr($ref, 0, 1) === '.') {
693
-            $realpath = Util\Common::realpath($rulesetDir.'/'.$ref);
694
-            if ($realpath !== false) {
692
+        if ( substr( $ref, 0, 1 ) === '.' ) {
693
+            $realpath = Util\Common::realpath( $rulesetDir . '/' . $ref );
694
+            if ( $realpath !== false ) {
695 695
                 $ref = $realpath;
696
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
697
-                    echo str_repeat("\t", $depth);
698
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
696
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
697
+                    echo str_repeat( "\t", $depth );
698
+                    echo "\t\t=> " . Util\Common::stripBasepath( $ref, $this->config->basepath ) . PHP_EOL;
699 699
                 }
700 700
             }
701 701
         }
702 702
 
703 703
         // As sniffs can't begin with a tilde, assume references in
704 704
         // this format are relative to the user's home directory.
705
-        if (substr($ref, 0, 2) === '~/') {
706
-            $realpath = Util\Common::realpath($ref);
707
-            if ($realpath !== false) {
705
+        if ( substr( $ref, 0, 2 ) === '~/' ) {
706
+            $realpath = Util\Common::realpath( $ref );
707
+            if ( $realpath !== false ) {
708 708
                 $ref = $realpath;
709
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
710
-                    echo str_repeat("\t", $depth);
711
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
709
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
710
+                    echo str_repeat( "\t", $depth );
711
+                    echo "\t\t=> " . Util\Common::stripBasepath( $ref, $this->config->basepath ) . PHP_EOL;
712 712
                 }
713 713
             }
714 714
         }
715 715
 
716
-        if (is_file($ref) === true) {
717
-            if (substr($ref, -9) === 'Sniff.php') {
716
+        if ( is_file( $ref ) === true ) {
717
+            if ( substr( $ref, -9 ) === 'Sniff.php' ) {
718 718
                 // A single external sniff.
719
-                $this->rulesetDirs[] = dirname(dirname(dirname($ref)));
720
-                return [$ref];
719
+                $this->rulesetDirs[ ] = dirname( dirname( dirname( $ref ) ) );
720
+                return [ $ref ];
721 721
             }
722 722
         } else {
723 723
             // See if this is a whole standard being referenced.
724
-            $path = Util\Standards::getInstalledStandardPath($ref);
725
-            if (Util\Common::isPharFile($path) === true && strpos($path, 'ruleset.xml') === false) {
724
+            $path = Util\Standards::getInstalledStandardPath( $ref );
725
+            if ( Util\Common::isPharFile( $path ) === true && strpos( $path, 'ruleset.xml' ) === false ) {
726 726
                 // If the ruleset exists inside the phar file, use it.
727
-                if (file_exists($path.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
728
-                    $path .= DIRECTORY_SEPARATOR.'ruleset.xml';
727
+                if ( file_exists( $path . DIRECTORY_SEPARATOR . 'ruleset.xml' ) === true ) {
728
+                    $path .= DIRECTORY_SEPARATOR . 'ruleset.xml';
729 729
                 } else {
730 730
                     $path = null;
731 731
                 }
732 732
             }
733 733
 
734
-            if ($path !== null) {
734
+            if ( $path !== null ) {
735 735
                 $ref = $path;
736
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
737
-                    echo str_repeat("\t", $depth);
738
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
736
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
737
+                    echo str_repeat( "\t", $depth );
738
+                    echo "\t\t=> " . Util\Common::stripBasepath( $ref, $this->config->basepath ) . PHP_EOL;
739 739
                 }
740
-            } else if (is_dir($ref) === false) {
740
+            } else if ( is_dir( $ref ) === false ) {
741 741
                 // Work out the sniff path.
742
-                $sepPos = strpos($ref, DIRECTORY_SEPARATOR);
743
-                if ($sepPos !== false) {
744
-                    $stdName = substr($ref, 0, $sepPos);
745
-                    $path    = substr($ref, $sepPos);
742
+                $sepPos = strpos( $ref, DIRECTORY_SEPARATOR );
743
+                if ( $sepPos !== false ) {
744
+                    $stdName = substr( $ref, 0, $sepPos );
745
+                    $path    = substr( $ref, $sepPos );
746 746
                 } else {
747
-                    $parts   = explode('.', $ref);
748
-                    $stdName = $parts[0];
749
-                    if (count($parts) === 1) {
747
+                    $parts   = explode( '.', $ref );
748
+                    $stdName = $parts[ 0 ];
749
+                    if ( count( $parts ) === 1 ) {
750 750
                         // A whole standard?
751 751
                         $path = '';
752
-                    } else if (count($parts) === 2) {
752
+                    } else if ( count( $parts ) === 2 ) {
753 753
                         // A directory of sniffs?
754
-                        $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1];
754
+                        $path = DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR . $parts[ 1 ];
755 755
                     } else {
756 756
                         // A single sniff?
757
-                        $path = DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR.$parts[1].DIRECTORY_SEPARATOR.$parts[2].'Sniff.php';
757
+                        $path = DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR . $parts[ 1 ] . DIRECTORY_SEPARATOR . $parts[ 2 ] . 'Sniff.php';
758 758
                     }
759 759
                 }
760 760
 
761 761
                 $newRef  = false;
762
-                $stdPath = Util\Standards::getInstalledStandardPath($stdName);
763
-                if ($stdPath !== null && $path !== '') {
764
-                    if (Util\Common::isPharFile($stdPath) === true
765
-                        && strpos($stdPath, 'ruleset.xml') === false
762
+                $stdPath = Util\Standards::getInstalledStandardPath( $stdName );
763
+                if ( $stdPath !== null && $path !== '' ) {
764
+                    if ( Util\Common::isPharFile( $stdPath ) === true
765
+                        && strpos( $stdPath, 'ruleset.xml' ) === false
766 766
                     ) {
767 767
                         // Phar files can only return the directory,
768 768
                         // since ruleset can be omitted if building one standard.
769
-                        $newRef = Util\Common::realpath($stdPath.$path);
769
+                        $newRef = Util\Common::realpath( $stdPath . $path );
770 770
                     } else {
771
-                        $newRef = Util\Common::realpath(dirname($stdPath).$path);
771
+                        $newRef = Util\Common::realpath( dirname( $stdPath ) . $path );
772 772
                     }
773 773
                 }
774 774
 
775
-                if ($newRef === false) {
775
+                if ( $newRef === false ) {
776 776
                     // The sniff is not locally installed, so check if it is being
777 777
                     // referenced as a remote sniff outside the install. We do this
778 778
                     // by looking through all directories where we have found ruleset
779 779
                     // files before, looking for ones for this particular standard,
780 780
                     // and seeing if it is in there.
781
-                    foreach ($this->rulesetDirs as $dir) {
782
-                        if (strtolower(basename($dir)) !== strtolower($stdName)) {
781
+                    foreach ( $this->rulesetDirs as $dir ) {
782
+                        if ( strtolower( basename( $dir ) ) !== strtolower( $stdName ) ) {
783 783
                             continue;
784 784
                         }
785 785
 
786
-                        $newRef = Util\Common::realpath($dir.$path);
786
+                        $newRef = Util\Common::realpath( $dir . $path );
787 787
 
788
-                        if ($newRef !== false) {
788
+                        if ( $newRef !== false ) {
789 789
                             $ref = $newRef;
790 790
                         }
791 791
                     }
@@ -793,50 +793,50 @@  discard block
 block discarded – undo
793 793
                     $ref = $newRef;
794 794
                 }
795 795
 
796
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
797
-                    echo str_repeat("\t", $depth);
798
-                    echo "\t\t=> ".Util\Common::stripBasepath($ref, $this->config->basepath).PHP_EOL;
796
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
797
+                    echo str_repeat( "\t", $depth );
798
+                    echo "\t\t=> " . Util\Common::stripBasepath( $ref, $this->config->basepath ) . PHP_EOL;
799 799
                 }
800 800
             }//end if
801 801
         }//end if
802 802
 
803
-        if (is_dir($ref) === true) {
804
-            if (is_file($ref.DIRECTORY_SEPARATOR.'ruleset.xml') === true) {
803
+        if ( is_dir( $ref ) === true ) {
804
+            if ( is_file( $ref . DIRECTORY_SEPARATOR . 'ruleset.xml' ) === true ) {
805 805
                 // We are referencing an external coding standard.
806
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
807
-                    echo str_repeat("\t", $depth);
808
-                    echo "\t\t* rule is referencing a standard using directory name; processing *".PHP_EOL;
806
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
807
+                    echo str_repeat( "\t", $depth );
808
+                    echo "\t\t* rule is referencing a standard using directory name; processing *" . PHP_EOL;
809 809
                 }
810 810
 
811
-                return $this->processRuleset($ref.DIRECTORY_SEPARATOR.'ruleset.xml', ($depth + 2));
811
+                return $this->processRuleset( $ref . DIRECTORY_SEPARATOR . 'ruleset.xml', ( $depth + 2 ) );
812 812
             } else {
813 813
                 // We are referencing a whole directory of sniffs.
814
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
815
-                    echo str_repeat("\t", $depth);
816
-                    echo "\t\t* rule is referencing a directory of sniffs *".PHP_EOL;
817
-                    echo str_repeat("\t", $depth);
818
-                    echo "\t\tAdding sniff files from directory".PHP_EOL;
814
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
815
+                    echo str_repeat( "\t", $depth );
816
+                    echo "\t\t* rule is referencing a directory of sniffs *" . PHP_EOL;
817
+                    echo str_repeat( "\t", $depth );
818
+                    echo "\t\tAdding sniff files from directory" . PHP_EOL;
819 819
                 }
820 820
 
821
-                return $this->expandSniffDirectory($ref, ($depth + 1));
821
+                return $this->expandSniffDirectory( $ref, ( $depth + 1 ) );
822 822
             }
823 823
         } else {
824
-            if (is_file($ref) === false) {
824
+            if ( is_file( $ref ) === false ) {
825 825
                 $error = "Referenced sniff \"$ref\" does not exist";
826
-                throw new RuntimeException($error);
826
+                throw new RuntimeException( $error );
827 827
             }
828 828
 
829
-            if (substr($ref, -9) === 'Sniff.php') {
829
+            if ( substr( $ref, -9 ) === 'Sniff.php' ) {
830 830
                 // A single sniff.
831
-                return [$ref];
831
+                return [ $ref ];
832 832
             } else {
833 833
                 // Assume an external ruleset.xml file.
834
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
835
-                    echo str_repeat("\t", $depth);
836
-                    echo "\t\t* rule is referencing a standard using ruleset path; processing *".PHP_EOL;
834
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
835
+                    echo str_repeat( "\t", $depth );
836
+                    echo "\t\t* rule is referencing a standard using ruleset path; processing *" . PHP_EOL;
837 837
                 }
838 838
 
839
-                return $this->processRuleset($ref, ($depth + 2));
839
+                return $this->processRuleset( $ref, ( $depth + 2 ) );
840 840
             }
841 841
         }//end if
842 842
 
@@ -854,38 +854,38 @@  discard block
 block discarded – undo
854 854
      * @return void
855 855
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If rule settings are invalid.
856 856
      */
857
-    private function processRule($rule, $newSniffs, $depth=0)
857
+    private function processRule( $rule, $newSniffs, $depth = 0 )
858 858
     {
859
-        $ref  = (string) $rule['ref'];
860
-        $todo = [$ref];
859
+        $ref  = (string)$rule[ 'ref' ];
860
+        $todo = [ $ref ];
861 861
 
862
-        $parts = explode('.', $ref);
863
-        if (count($parts) <= 2) {
862
+        $parts = explode( '.', $ref );
863
+        if ( count( $parts ) <= 2 ) {
864 864
             // We are processing a standard or a category of sniffs.
865
-            foreach ($newSniffs as $sniffFile) {
866
-                $parts         = explode(DIRECTORY_SEPARATOR, $sniffFile);
867
-                $sniffName     = array_pop($parts);
868
-                $sniffCategory = array_pop($parts);
869
-                array_pop($parts);
870
-                $sniffStandard = array_pop($parts);
871
-                $todo[]        = $sniffStandard.'.'.$sniffCategory.'.'.substr($sniffName, 0, -9);
865
+            foreach ( $newSniffs as $sniffFile ) {
866
+                $parts         = explode( DIRECTORY_SEPARATOR, $sniffFile );
867
+                $sniffName     = array_pop( $parts );
868
+                $sniffCategory = array_pop( $parts );
869
+                array_pop( $parts );
870
+                $sniffStandard = array_pop( $parts );
871
+                $todo[ ]        = $sniffStandard . '.' . $sniffCategory . '.' . substr( $sniffName, 0, -9 );
872 872
             }
873 873
         }
874 874
 
875
-        foreach ($todo as $code) {
875
+        foreach ( $todo as $code ) {
876 876
             // Custom severity.
877
-            if (isset($rule->severity) === true
878
-                && $this->shouldProcessElement($rule->severity) === true
877
+            if ( isset( $rule->severity ) === true
878
+                && $this->shouldProcessElement( $rule->severity ) === true
879 879
             ) {
880
-                if (isset($this->ruleset[$code]) === false) {
881
-                    $this->ruleset[$code] = [];
880
+                if ( isset( $this->ruleset[ $code ] ) === false ) {
881
+                    $this->ruleset[ $code ] = [ ];
882 882
                 }
883 883
 
884
-                $this->ruleset[$code]['severity'] = (int) $rule->severity;
885
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
886
-                    echo str_repeat("\t", $depth);
887
-                    echo "\t\t=> severity set to ".(int) $rule->severity;
888
-                    if ($code !== $ref) {
884
+                $this->ruleset[ $code ][ 'severity' ] = (int)$rule->severity;
885
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
886
+                    echo str_repeat( "\t", $depth );
887
+                    echo "\t\t=> severity set to " . (int)$rule->severity;
888
+                    if ( $code !== $ref ) {
889 889
                         echo " for $code";
890 890
                     }
891 891
 
@@ -894,23 +894,23 @@  discard block
 block discarded – undo
894 894
             }
895 895
 
896 896
             // Custom message type.
897
-            if (isset($rule->type) === true
898
-                && $this->shouldProcessElement($rule->type) === true
897
+            if ( isset( $rule->type ) === true
898
+                && $this->shouldProcessElement( $rule->type ) === true
899 899
             ) {
900
-                if (isset($this->ruleset[$code]) === false) {
901
-                    $this->ruleset[$code] = [];
900
+                if ( isset( $this->ruleset[ $code ] ) === false ) {
901
+                    $this->ruleset[ $code ] = [ ];
902 902
                 }
903 903
 
904
-                $type = strtolower((string) $rule->type);
905
-                if ($type !== 'error' && $type !== 'warning') {
906
-                    throw new RuntimeException("Message type \"$type\" is invalid; must be \"error\" or \"warning\"");
904
+                $type = strtolower( (string)$rule->type );
905
+                if ( $type !== 'error' && $type !== 'warning' ) {
906
+                    throw new RuntimeException( "Message type \"$type\" is invalid; must be \"error\" or \"warning\"" );
907 907
                 }
908 908
 
909
-                $this->ruleset[$code]['type'] = $type;
910
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
911
-                    echo str_repeat("\t", $depth);
912
-                    echo "\t\t=> message type set to ".(string) $rule->type;
913
-                    if ($code !== $ref) {
909
+                $this->ruleset[ $code ][ 'type' ] = $type;
910
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
911
+                    echo str_repeat( "\t", $depth );
912
+                    echo "\t\t=> message type set to " . (string)$rule->type;
913
+                    if ( $code !== $ref ) {
914 914
                         echo " for $code";
915 915
                     }
916 916
 
@@ -919,18 +919,18 @@  discard block
 block discarded – undo
919 919
             }//end if
920 920
 
921 921
             // Custom message.
922
-            if (isset($rule->message) === true
923
-                && $this->shouldProcessElement($rule->message) === true
922
+            if ( isset( $rule->message ) === true
923
+                && $this->shouldProcessElement( $rule->message ) === true
924 924
             ) {
925
-                if (isset($this->ruleset[$code]) === false) {
926
-                    $this->ruleset[$code] = [];
925
+                if ( isset( $this->ruleset[ $code ] ) === false ) {
926
+                    $this->ruleset[ $code ] = [ ];
927 927
                 }
928 928
 
929
-                $this->ruleset[$code]['message'] = (string) $rule->message;
930
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
931
-                    echo str_repeat("\t", $depth);
932
-                    echo "\t\t=> message set to ".(string) $rule->message;
933
-                    if ($code !== $ref) {
929
+                $this->ruleset[ $code ][ 'message' ] = (string)$rule->message;
930
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
931
+                    echo str_repeat( "\t", $depth );
932
+                    echo "\t\t=> message set to " . (string)$rule->message;
933
+                    if ( $code !== $ref ) {
934 934
                         echo " for $code";
935 935
                     }
936 936
 
@@ -939,82 +939,82 @@  discard block
 block discarded – undo
939 939
             }
940 940
 
941 941
             // Custom properties.
942
-            if (isset($rule->properties) === true
943
-                && $this->shouldProcessElement($rule->properties) === true
942
+            if ( isset( $rule->properties ) === true
943
+                && $this->shouldProcessElement( $rule->properties ) === true
944 944
             ) {
945
-                foreach ($rule->properties->property as $prop) {
946
-                    if ($this->shouldProcessElement($prop) === false) {
945
+                foreach ( $rule->properties->property as $prop ) {
946
+                    if ( $this->shouldProcessElement( $prop ) === false ) {
947 947
                         continue;
948 948
                     }
949 949
 
950
-                    if (isset($this->ruleset[$code]) === false) {
951
-                        $this->ruleset[$code] = [
952
-                            'properties' => [],
950
+                    if ( isset( $this->ruleset[ $code ] ) === false ) {
951
+                        $this->ruleset[ $code ] = [
952
+                            'properties' => [ ],
953 953
                         ];
954
-                    } else if (isset($this->ruleset[$code]['properties']) === false) {
955
-                        $this->ruleset[$code]['properties'] = [];
954
+                    } else if ( isset( $this->ruleset[ $code ][ 'properties' ] ) === false ) {
955
+                        $this->ruleset[ $code ][ 'properties' ] = [ ];
956 956
                     }
957 957
 
958
-                    $name = (string) $prop['name'];
959
-                    if (isset($prop['type']) === true
960
-                        && (string) $prop['type'] === 'array'
958
+                    $name = (string)$prop[ 'name' ];
959
+                    if ( isset( $prop[ 'type' ] ) === true
960
+                        && (string)$prop[ 'type' ] === 'array'
961 961
                     ) {
962
-                        $values = [];
963
-                        if (isset($prop['extend']) === true
964
-                            && (string) $prop['extend'] === 'true'
965
-                            && isset($this->ruleset[$code]['properties'][$name]) === true
962
+                        $values = [ ];
963
+                        if ( isset( $prop[ 'extend' ] ) === true
964
+                            && (string)$prop[ 'extend' ] === 'true'
965
+                            && isset( $this->ruleset[ $code ][ 'properties' ][ $name ] ) === true
966 966
                         ) {
967
-                            $values = $this->ruleset[$code]['properties'][$name];
967
+                            $values = $this->ruleset[ $code ][ 'properties' ][ $name ];
968 968
                         }
969 969
 
970
-                        if (isset($prop->element) === true) {
970
+                        if ( isset( $prop->element ) === true ) {
971 971
                             $printValue = '';
972
-                            foreach ($prop->element as $element) {
973
-                                if ($this->shouldProcessElement($element) === false) {
972
+                            foreach ( $prop->element as $element ) {
973
+                                if ( $this->shouldProcessElement( $element ) === false ) {
974 974
                                     continue;
975 975
                                 }
976 976
 
977
-                                $value = (string) $element['value'];
978
-                                if (isset($element['key']) === true) {
979
-                                    $key          = (string) $element['key'];
980
-                                    $values[$key] = $value;
981
-                                    $printValue  .= $key.'=>'.$value.',';
977
+                                $value = (string)$element[ 'value' ];
978
+                                if ( isset( $element[ 'key' ] ) === true ) {
979
+                                    $key          = (string)$element[ 'key' ];
980
+                                    $values[ $key ] = $value;
981
+                                    $printValue  .= $key . '=>' . $value . ',';
982 982
                                 } else {
983
-                                    $values[]    = $value;
984
-                                    $printValue .= $value.',';
983
+                                    $values[ ]    = $value;
984
+                                    $printValue .= $value . ',';
985 985
                                 }
986 986
                             }
987 987
 
988
-                            $printValue = rtrim($printValue, ',');
988
+                            $printValue = rtrim( $printValue, ',' );
989 989
                         } else {
990
-                            $value      = (string) $prop['value'];
990
+                            $value      = (string)$prop[ 'value' ];
991 991
                             $printValue = $value;
992
-                            foreach (explode(',', $value) as $val) {
993
-                                list($k, $v) = explode('=>', $val.'=>');
994
-                                if ($v !== '') {
995
-                                    $values[trim($k)] = trim($v);
992
+                            foreach ( explode( ',', $value ) as $val ) {
993
+                                list( $k, $v ) = explode( '=>', $val . '=>' );
994
+                                if ( $v !== '' ) {
995
+                                    $values[ trim( $k ) ] = trim( $v );
996 996
                                 } else {
997
-                                    $values[] = trim($k);
997
+                                    $values[ ] = trim( $k );
998 998
                                 }
999 999
                             }
1000 1000
                         }//end if
1001 1001
 
1002
-                        $this->ruleset[$code]['properties'][$name] = $values;
1003
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1004
-                            echo str_repeat("\t", $depth);
1002
+                        $this->ruleset[ $code ][ 'properties' ][ $name ] = $values;
1003
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1004
+                            echo str_repeat( "\t", $depth );
1005 1005
                             echo "\t\t=> array property \"$name\" set to \"$printValue\"";
1006
-                            if ($code !== $ref) {
1006
+                            if ( $code !== $ref ) {
1007 1007
                                 echo " for $code";
1008 1008
                             }
1009 1009
 
1010 1010
                             echo PHP_EOL;
1011 1011
                         }
1012 1012
                     } else {
1013
-                        $this->ruleset[$code]['properties'][$name] = (string) $prop['value'];
1014
-                        if (PHP_CODESNIFFER_VERBOSITY > 1) {
1015
-                            echo str_repeat("\t", $depth);
1016
-                            echo "\t\t=> property \"$name\" set to \"".(string) $prop['value'].'"';
1017
-                            if ($code !== $ref) {
1013
+                        $this->ruleset[ $code ][ 'properties' ][ $name ] = (string)$prop[ 'value' ];
1014
+                        if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1015
+                            echo str_repeat( "\t", $depth );
1016
+                            echo "\t\t=> property \"$name\" set to \"" . (string)$prop[ 'value' ] . '"';
1017
+                            if ( $code !== $ref ) {
1018 1018
                                 echo " for $code";
1019 1019
                             }
1020 1020
 
@@ -1025,54 +1025,54 @@  discard block
 block discarded – undo
1025 1025
             }//end if
1026 1026
 
1027 1027
             // Ignore patterns.
1028
-            foreach ($rule->{'exclude-pattern'} as $pattern) {
1029
-                if ($this->shouldProcessElement($pattern) === false) {
1028
+            foreach ( $rule->{'exclude-pattern'} as $pattern ) {
1029
+                if ( $this->shouldProcessElement( $pattern ) === false ) {
1030 1030
                     continue;
1031 1031
                 }
1032 1032
 
1033
-                if (isset($this->ignorePatterns[$code]) === false) {
1034
-                    $this->ignorePatterns[$code] = [];
1033
+                if ( isset( $this->ignorePatterns[ $code ] ) === false ) {
1034
+                    $this->ignorePatterns[ $code ] = [ ];
1035 1035
                 }
1036 1036
 
1037
-                if (isset($pattern['type']) === false) {
1038
-                    $pattern['type'] = 'absolute';
1037
+                if ( isset( $pattern[ 'type' ] ) === false ) {
1038
+                    $pattern[ 'type' ] = 'absolute';
1039 1039
                 }
1040 1040
 
1041
-                $this->ignorePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1042
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1043
-                    echo str_repeat("\t", $depth);
1044
-                    echo "\t\t=> added rule-specific ".(string) $pattern['type'].' ignore pattern';
1045
-                    if ($code !== $ref) {
1041
+                $this->ignorePatterns[ $code ][ (string)$pattern ] = (string)$pattern[ 'type' ];
1042
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1043
+                    echo str_repeat( "\t", $depth );
1044
+                    echo "\t\t=> added rule-specific " . (string)$pattern[ 'type' ] . ' ignore pattern';
1045
+                    if ( $code !== $ref ) {
1046 1046
                         echo " for $code";
1047 1047
                     }
1048 1048
 
1049
-                    echo ': '.(string) $pattern.PHP_EOL;
1049
+                    echo ': ' . (string)$pattern . PHP_EOL;
1050 1050
                 }
1051 1051
             }//end foreach
1052 1052
 
1053 1053
             // Include patterns.
1054
-            foreach ($rule->{'include-pattern'} as $pattern) {
1055
-                if ($this->shouldProcessElement($pattern) === false) {
1054
+            foreach ( $rule->{'include-pattern'} as $pattern ) {
1055
+                if ( $this->shouldProcessElement( $pattern ) === false ) {
1056 1056
                     continue;
1057 1057
                 }
1058 1058
 
1059
-                if (isset($this->includePatterns[$code]) === false) {
1060
-                    $this->includePatterns[$code] = [];
1059
+                if ( isset( $this->includePatterns[ $code ] ) === false ) {
1060
+                    $this->includePatterns[ $code ] = [ ];
1061 1061
                 }
1062 1062
 
1063
-                if (isset($pattern['type']) === false) {
1064
-                    $pattern['type'] = 'absolute';
1063
+                if ( isset( $pattern[ 'type' ] ) === false ) {
1064
+                    $pattern[ 'type' ] = 'absolute';
1065 1065
                 }
1066 1066
 
1067
-                $this->includePatterns[$code][(string) $pattern] = (string) $pattern['type'];
1068
-                if (PHP_CODESNIFFER_VERBOSITY > 1) {
1069
-                    echo str_repeat("\t", $depth);
1070
-                    echo "\t\t=> added rule-specific ".(string) $pattern['type'].' include pattern';
1071
-                    if ($code !== $ref) {
1067
+                $this->includePatterns[ $code ][ (string)$pattern ] = (string)$pattern[ 'type' ];
1068
+                if ( PHP_CODESNIFFER_VERBOSITY > 1 ) {
1069
+                    echo str_repeat( "\t", $depth );
1070
+                    echo "\t\t=> added rule-specific " . (string)$pattern[ 'type' ] . ' include pattern';
1071
+                    if ( $code !== $ref ) {
1072 1072
                         echo " for $code";
1073 1073
                     }
1074 1074
 
1075
-                    echo ': '.(string) $pattern.PHP_EOL;
1075
+                    echo ': ' . (string)$pattern . PHP_EOL;
1076 1076
                 }
1077 1077
             }//end foreach
1078 1078
         }//end foreach
@@ -1087,25 +1087,25 @@  discard block
 block discarded – undo
1087 1087
      *
1088 1088
      * @return bool
1089 1089
      */
1090
-    private function shouldProcessElement($element)
1090
+    private function shouldProcessElement( $element )
1091 1091
     {
1092
-        if (isset($element['phpcbf-only']) === false
1093
-            && isset($element['phpcs-only']) === false
1092
+        if ( isset( $element[ 'phpcbf-only' ] ) === false
1093
+            && isset( $element[ 'phpcs-only' ] ) === false
1094 1094
         ) {
1095 1095
             // No exceptions are being made.
1096 1096
             return true;
1097 1097
         }
1098 1098
 
1099
-        if (PHP_CODESNIFFER_CBF === true
1100
-            && isset($element['phpcbf-only']) === true
1101
-            && (string) $element['phpcbf-only'] === 'true'
1099
+        if ( PHP_CODESNIFFER_CBF === true
1100
+            && isset( $element[ 'phpcbf-only' ] ) === true
1101
+            && (string)$element[ 'phpcbf-only' ] === 'true'
1102 1102
         ) {
1103 1103
             return true;
1104 1104
         }
1105 1105
 
1106
-        if (PHP_CODESNIFFER_CBF === false
1107
-            && isset($element['phpcs-only']) === true
1108
-            && (string) $element['phpcs-only'] === 'true'
1106
+        if ( PHP_CODESNIFFER_CBF === false
1107
+            && isset( $element[ 'phpcs-only' ] ) === true
1108
+            && (string)$element[ 'phpcs-only' ] === 'true'
1109 1109
         ) {
1110 1110
             return true;
1111 1111
         }
@@ -1126,52 +1126,52 @@  discard block
 block discarded – undo
1126 1126
      *
1127 1127
      * @return void
1128 1128
      */
1129
-    public function registerSniffs($files, $restrictions, $exclusions)
1129
+    public function registerSniffs( $files, $restrictions, $exclusions )
1130 1130
     {
1131
-        $listeners = [];
1131
+        $listeners = [ ];
1132 1132
 
1133
-        foreach ($files as $file) {
1133
+        foreach ( $files as $file ) {
1134 1134
             // Work out where the position of /StandardName/Sniffs/... is
1135 1135
             // so we can determine what the class will be called.
1136
-            $sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
1137
-            if ($sniffPos === false) {
1136
+            $sniffPos = strrpos( $file, DIRECTORY_SEPARATOR . 'Sniffs' . DIRECTORY_SEPARATOR );
1137
+            if ( $sniffPos === false ) {
1138 1138
                 continue;
1139 1139
             }
1140 1140
 
1141
-            $slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
1142
-            if ($slashPos === false) {
1141
+            $slashPos = strrpos( substr( $file, 0, $sniffPos ), DIRECTORY_SEPARATOR );
1142
+            if ( $slashPos === false ) {
1143 1143
                 continue;
1144 1144
             }
1145 1145
 
1146
-            $className   = Autoload::loadFile($file);
1147
-            $compareName = Util\Common::cleanSniffClass($className);
1146
+            $className   = Autoload::loadFile( $file );
1147
+            $compareName = Util\Common::cleanSniffClass( $className );
1148 1148
 
1149 1149
             // If they have specified a list of sniffs to restrict to, check
1150 1150
             // to see if this sniff is allowed.
1151
-            if (empty($restrictions) === false
1152
-                && isset($restrictions[$compareName]) === false
1151
+            if ( empty( $restrictions ) === false
1152
+                && isset( $restrictions[ $compareName ] ) === false
1153 1153
             ) {
1154 1154
                 continue;
1155 1155
             }
1156 1156
 
1157 1157
             // If they have specified a list of sniffs to exclude, check
1158 1158
             // to see if this sniff is allowed.
1159
-            if (empty($exclusions) === false
1160
-                && isset($exclusions[$compareName]) === true
1159
+            if ( empty( $exclusions ) === false
1160
+                && isset( $exclusions[ $compareName ] ) === true
1161 1161
             ) {
1162 1162
                 continue;
1163 1163
             }
1164 1164
 
1165 1165
             // Skip abstract classes.
1166
-            $reflection = new \ReflectionClass($className);
1167
-            if ($reflection->isAbstract() === true) {
1166
+            $reflection = new \ReflectionClass( $className );
1167
+            if ( $reflection->isAbstract() === true ) {
1168 1168
                 continue;
1169 1169
             }
1170 1170
 
1171
-            $listeners[$className] = $className;
1171
+            $listeners[ $className ] = $className;
1172 1172
 
1173
-            if (PHP_CODESNIFFER_VERBOSITY > 2) {
1174
-                echo "Registered $className".PHP_EOL;
1173
+            if ( PHP_CODESNIFFER_VERBOSITY > 2 ) {
1174
+                echo "Registered $className" . PHP_EOL;
1175 1175
             }
1176 1176
         }//end foreach
1177 1177
 
@@ -1189,67 +1189,67 @@  discard block
 block discarded – undo
1189 1189
     public function populateTokenListeners()
1190 1190
     {
1191 1191
         // Construct a list of listeners indexed by token being listened for.
1192
-        $this->tokenListeners = [];
1192
+        $this->tokenListeners = [ ];
1193 1193
 
1194
-        foreach ($this->sniffs as $sniffClass => $sniffObject) {
1195
-            $this->sniffs[$sniffClass] = null;
1196
-            $this->sniffs[$sniffClass] = new $sniffClass();
1194
+        foreach ( $this->sniffs as $sniffClass => $sniffObject ) {
1195
+            $this->sniffs[ $sniffClass ] = null;
1196
+            $this->sniffs[ $sniffClass ] = new $sniffClass();
1197 1197
 
1198
-            $sniffCode = Util\Common::getSniffCode($sniffClass);
1199
-            $this->sniffCodes[$sniffCode] = $sniffClass;
1198
+            $sniffCode = Util\Common::getSniffCode( $sniffClass );
1199
+            $this->sniffCodes[ $sniffCode ] = $sniffClass;
1200 1200
 
1201 1201
             // Set custom properties.
1202
-            if (isset($this->ruleset[$sniffCode]['properties']) === true) {
1203
-                foreach ($this->ruleset[$sniffCode]['properties'] as $name => $value) {
1204
-                    $this->setSniffProperty($sniffClass, $name, $value);
1202
+            if ( isset( $this->ruleset[ $sniffCode ][ 'properties' ] ) === true ) {
1203
+                foreach ( $this->ruleset[ $sniffCode ][ 'properties' ] as $name => $value ) {
1204
+                    $this->setSniffProperty( $sniffClass, $name, $value );
1205 1205
                 }
1206 1206
             }
1207 1207
 
1208
-            $tokenizers = [];
1209
-            $vars       = get_class_vars($sniffClass);
1210
-            if (isset($vars['supportedTokenizers']) === true) {
1211
-                foreach ($vars['supportedTokenizers'] as $tokenizer) {
1212
-                    $tokenizers[$tokenizer] = $tokenizer;
1208
+            $tokenizers = [ ];
1209
+            $vars       = get_class_vars( $sniffClass );
1210
+            if ( isset( $vars[ 'supportedTokenizers' ] ) === true ) {
1211
+                foreach ( $vars[ 'supportedTokenizers' ] as $tokenizer ) {
1212
+                    $tokenizers[ $tokenizer ] = $tokenizer;
1213 1213
                 }
1214 1214
             } else {
1215
-                $tokenizers = ['PHP' => 'PHP'];
1215
+                $tokenizers = [ 'PHP' => 'PHP' ];
1216 1216
             }
1217 1217
 
1218
-            $tokens = $this->sniffs[$sniffClass]->register();
1219
-            if (is_array($tokens) === false) {
1218
+            $tokens = $this->sniffs[ $sniffClass ]->register();
1219
+            if ( is_array( $tokens ) === false ) {
1220 1220
                 $msg = "Sniff $sniffClass register() method must return an array";
1221
-                throw new RuntimeException($msg);
1221
+                throw new RuntimeException( $msg );
1222 1222
             }
1223 1223
 
1224
-            $ignorePatterns = [];
1225
-            $patterns       = $this->getIgnorePatterns($sniffCode);
1226
-            foreach ($patterns as $pattern => $type) {
1224
+            $ignorePatterns = [ ];
1225
+            $patterns       = $this->getIgnorePatterns( $sniffCode );
1226
+            foreach ( $patterns as $pattern => $type ) {
1227 1227
                 $replacements = [
1228 1228
                     '\\,' => ',',
1229 1229
                     '*'   => '.*',
1230 1230
                 ];
1231 1231
 
1232
-                $ignorePatterns[] = strtr($pattern, $replacements);
1232
+                $ignorePatterns[ ] = strtr( $pattern, $replacements );
1233 1233
             }
1234 1234
 
1235
-            $includePatterns = [];
1236
-            $patterns        = $this->getIncludePatterns($sniffCode);
1237
-            foreach ($patterns as $pattern => $type) {
1235
+            $includePatterns = [ ];
1236
+            $patterns        = $this->getIncludePatterns( $sniffCode );
1237
+            foreach ( $patterns as $pattern => $type ) {
1238 1238
                 $replacements = [
1239 1239
                     '\\,' => ',',
1240 1240
                     '*'   => '.*',
1241 1241
                 ];
1242 1242
 
1243
-                $includePatterns[] = strtr($pattern, $replacements);
1243
+                $includePatterns[ ] = strtr( $pattern, $replacements );
1244 1244
             }
1245 1245
 
1246
-            foreach ($tokens as $token) {
1247
-                if (isset($this->tokenListeners[$token]) === false) {
1248
-                    $this->tokenListeners[$token] = [];
1246
+            foreach ( $tokens as $token ) {
1247
+                if ( isset( $this->tokenListeners[ $token ] ) === false ) {
1248
+                    $this->tokenListeners[ $token ] = [ ];
1249 1249
                 }
1250 1250
 
1251
-                if (isset($this->tokenListeners[$token][$sniffClass]) === false) {
1252
-                    $this->tokenListeners[$token][$sniffClass] = [
1251
+                if ( isset( $this->tokenListeners[ $token ][ $sniffClass ] ) === false ) {
1252
+                    $this->tokenListeners[ $token ][ $sniffClass ] = [
1253 1253
                         'class'      => $sniffClass,
1254 1254
                         'source'     => $sniffCode,
1255 1255
                         'tokenizers' => $tokenizers,
@@ -1272,37 +1272,37 @@  discard block
 block discarded – undo
1272 1272
      *
1273 1273
      * @return void
1274 1274
      */
1275
-    public function setSniffProperty($sniffClass, $name, $value)
1275
+    public function setSniffProperty( $sniffClass, $name, $value )
1276 1276
     {
1277 1277
         // Setting a property for a sniff we are not using.
1278
-        if (isset($this->sniffs[$sniffClass]) === false) {
1278
+        if ( isset( $this->sniffs[ $sniffClass ] ) === false ) {
1279 1279
             return;
1280 1280
         }
1281 1281
 
1282
-        $name = trim($name);
1283
-        if (is_string($value) === true) {
1284
-            $value = trim($value);
1282
+        $name = trim( $name );
1283
+        if ( is_string( $value ) === true ) {
1284
+            $value = trim( $value );
1285 1285
         }
1286 1286
 
1287
-        if ($value === '') {
1287
+        if ( $value === '' ) {
1288 1288
             $value = null;
1289 1289
         }
1290 1290
 
1291 1291
         // Special case for booleans.
1292
-        if ($value === 'true') {
1292
+        if ( $value === 'true' ) {
1293 1293
             $value = true;
1294
-        } else if ($value === 'false') {
1294
+        } else if ( $value === 'false' ) {
1295 1295
             $value = false;
1296
-        } else if (substr($name, -2) === '[]') {
1297
-            $name   = substr($name, 0, -2);
1298
-            $values = [];
1299
-            if ($value !== null) {
1300
-                foreach (explode(',', $value) as $val) {
1301
-                    list($k, $v) = explode('=>', $val.'=>');
1302
-                    if ($v !== '') {
1303
-                        $values[trim($k)] = trim($v);
1296
+        } else if ( substr( $name, -2 ) === '[]' ) {
1297
+            $name   = substr( $name, 0, -2 );
1298
+            $values = [ ];
1299
+            if ( $value !== null ) {
1300
+                foreach ( explode( ',', $value ) as $val ) {
1301
+                    list( $k, $v ) = explode( '=>', $val . '=>' );
1302
+                    if ( $v !== '' ) {
1303
+                        $values[ trim( $k ) ] = trim( $v );
1304 1304
                     } else {
1305
-                        $values[] = trim($k);
1305
+                        $values[ ] = trim( $k );
1306 1306
                     }
1307 1307
                 }
1308 1308
             }
@@ -1310,7 +1310,7 @@  discard block
 block discarded – undo
1310 1310
             $value = $values;
1311 1311
         }
1312 1312
 
1313
-        $this->sniffs[$sniffClass]->$name = $value;
1313
+        $this->sniffs[ $sniffClass ]->$name = $value;
1314 1314
 
1315 1315
     }//end setSniffProperty()
1316 1316
 
@@ -1326,17 +1326,17 @@  discard block
 block discarded – undo
1326 1326
      *
1327 1327
      * @return array
1328 1328
      */
1329
-    public function getIgnorePatterns($listener=null)
1329
+    public function getIgnorePatterns( $listener = null )
1330 1330
     {
1331
-        if ($listener === null) {
1331
+        if ( $listener === null ) {
1332 1332
             return $this->ignorePatterns;
1333 1333
         }
1334 1334
 
1335
-        if (isset($this->ignorePatterns[$listener]) === true) {
1336
-            return $this->ignorePatterns[$listener];
1335
+        if ( isset( $this->ignorePatterns[ $listener ] ) === true ) {
1336
+            return $this->ignorePatterns[ $listener ];
1337 1337
         }
1338 1338
 
1339
-        return [];
1339
+        return [ ];
1340 1340
 
1341 1341
     }//end getIgnorePatterns()
1342 1342
 
@@ -1352,17 +1352,17 @@  discard block
 block discarded – undo
1352 1352
      *
1353 1353
      * @return array
1354 1354
      */
1355
-    public function getIncludePatterns($listener=null)
1355
+    public function getIncludePatterns( $listener = null )
1356 1356
     {
1357
-        if ($listener === null) {
1357
+        if ( $listener === null ) {
1358 1358
             return $this->includePatterns;
1359 1359
         }
1360 1360
 
1361
-        if (isset($this->includePatterns[$listener]) === true) {
1362
-            return $this->includePatterns[$listener];
1361
+        if ( isset( $this->includePatterns[ $listener ] ) === true ) {
1362
+            return $this->includePatterns[ $listener ];
1363 1363
         }
1364 1364
 
1365
-        return [];
1365
+        return [ ];
1366 1366
 
1367 1367
     }//end getIncludePatterns()
1368 1368
 
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -14,8 +14,7 @@  discard block
 block discarded – undo
14 14
 use PHP_CodeSniffer\Util;
15 15
 use PHP_CodeSniffer\Exceptions\RuntimeException;
16 16
 
17
-class Ruleset
18
-{
17
+class Ruleset {
19 18
 
20 19
     /**
21 20
      * The name of the coding standard being used.
@@ -123,8 +122,7 @@  discard block
 block discarded – undo
123 122
      *
124 123
      * @return void
125 124
      */
126
-    public function __construct(Config $config)
127
-    {
125
+    public function __construct(Config $config) {
128 126
         // Ignore sniff restrictions if caching is on.
129 127
         $restrictions = [];
130 128
         $exclusions   = [];
@@ -233,8 +231,7 @@  discard block
 block discarded – undo
233 231
      *
234 232
      * @return void
235 233
      */
236
-    public function explain()
237
-    {
234
+    public function explain() {
238 235
         $sniffs = array_keys($this->sniffCodes);
239 236
         sort($sniffs);
240 237
 
@@ -306,8 +303,7 @@  discard block
 block discarded – undo
306 303
      * @return string[]
307 304
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid.
308 305
      */
309
-    public function processRuleset($rulesetPath, $depth=0)
310
-    {
306
+    public function processRuleset($rulesetPath, $depth=0) {
311 307
         $rulesetPath = Util\Common::realpath($rulesetPath);
312 308
         if (PHP_CODESNIFFER_VERBOSITY > 1) {
313 309
             echo str_repeat("\t", $depth);
@@ -609,8 +605,7 @@  discard block
 block discarded – undo
609 605
      *
610 606
      * @return array
611 607
      */
612
-    private function expandSniffDirectory($directory, $depth=0)
613
-    {
608
+    private function expandSniffDirectory($directory, $depth=0) {
614 609
         $sniffs = [];
615 610
 
616 611
         $rdi = new \RecursiveDirectoryIterator($directory, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
@@ -672,8 +667,7 @@  discard block
 block discarded – undo
672 667
      * @return array
673 668
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the reference is invalid.
674 669
      */
675
-    private function expandRulesetReference($ref, $rulesetDir, $depth=0)
676
-    {
670
+    private function expandRulesetReference($ref, $rulesetDir, $depth=0) {
677 671
         // Ignore internal sniffs codes as they are used to only
678 672
         // hide and change internal messages.
679 673
         if (substr($ref, 0, 9) === 'Internal.') {
@@ -854,8 +848,7 @@  discard block
 block discarded – undo
854 848
      * @return void
855 849
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If rule settings are invalid.
856 850
      */
857
-    private function processRule($rule, $newSniffs, $depth=0)
858
-    {
851
+    private function processRule($rule, $newSniffs, $depth=0) {
859 852
         $ref  = (string) $rule['ref'];
860 853
         $todo = [$ref];
861 854
 
@@ -1087,8 +1080,7 @@  discard block
 block discarded – undo
1087 1080
      *
1088 1081
      * @return bool
1089 1082
      */
1090
-    private function shouldProcessElement($element)
1091
-    {
1083
+    private function shouldProcessElement($element) {
1092 1084
         if (isset($element['phpcbf-only']) === false
1093 1085
             && isset($element['phpcs-only']) === false
1094 1086
         ) {
@@ -1126,8 +1118,7 @@  discard block
 block discarded – undo
1126 1118
      *
1127 1119
      * @return void
1128 1120
      */
1129
-    public function registerSniffs($files, $restrictions, $exclusions)
1130
-    {
1121
+    public function registerSniffs($files, $restrictions, $exclusions) {
1131 1122
         $listeners = [];
1132 1123
 
1133 1124
         foreach ($files as $file) {
@@ -1186,8 +1177,7 @@  discard block
 block discarded – undo
1186 1177
      * @return void
1187 1178
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If sniff registration fails.
1188 1179
      */
1189
-    public function populateTokenListeners()
1190
-    {
1180
+    public function populateTokenListeners() {
1191 1181
         // Construct a list of listeners indexed by token being listened for.
1192 1182
         $this->tokenListeners = [];
1193 1183
 
@@ -1272,8 +1262,7 @@  discard block
 block discarded – undo
1272 1262
      *
1273 1263
      * @return void
1274 1264
      */
1275
-    public function setSniffProperty($sniffClass, $name, $value)
1276
-    {
1265
+    public function setSniffProperty($sniffClass, $name, $value) {
1277 1266
         // Setting a property for a sniff we are not using.
1278 1267
         if (isset($this->sniffs[$sniffClass]) === false) {
1279 1268
             return;
@@ -1326,8 +1315,7 @@  discard block
 block discarded – undo
1326 1315
      *
1327 1316
      * @return array
1328 1317
      */
1329
-    public function getIgnorePatterns($listener=null)
1330
-    {
1318
+    public function getIgnorePatterns($listener=null) {
1331 1319
         if ($listener === null) {
1332 1320
             return $this->ignorePatterns;
1333 1321
         }
@@ -1352,8 +1340,7 @@  discard block
 block discarded – undo
1352 1340
      *
1353 1341
      * @return array
1354 1342
      */
1355
-    public function getIncludePatterns($listener=null)
1356
-    {
1343
+    public function getIncludePatterns($listener=null) {
1357 1344
         if ($listener === null) {
1358 1345
             return $this->includePatterns;
1359 1346
         }
Please login to merge, or discard this patch.
Upper-Lower-Casing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
         // one last time and clear the output buffer.
249 249
         $sniffs[] = '';
250 250
 
251
-        echo PHP_EOL."The $this->name standard contains $sniffCount sniffs".PHP_EOL;
251
+        echo PHP_EOL."the $this->name standard contains $sniffCount sniffs".PHP_EOL;
252 252
 
253 253
         ob_start();
254 254
 
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
         libxml_use_internal_errors(true);
318 318
         $ruleset = simplexml_load_string(file_get_contents($rulesetPath));
319 319
         if ($ruleset === false) {
320
-            $errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL;
320
+            $errorMsg = "ruleset $rulesetPath is not valid".PHP_EOL;
321 321
             $errors   = libxml_get_errors();
322 322
             foreach ($errors as $error) {
323 323
                 $errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message;
@@ -1171,7 +1171,7 @@  discard block
 block discarded – undo
1171 1171
             $listeners[$className] = $className;
1172 1172
 
1173 1173
             if (PHP_CODESNIFFER_VERBOSITY > 2) {
1174
-                echo "Registered $className".PHP_EOL;
1174
+                echo "registered $className".PHP_EOL;
1175 1175
             }
1176 1176
         }//end foreach
1177 1177
 
@@ -1217,7 +1217,7 @@  discard block
 block discarded – undo
1217 1217
 
1218 1218
             $tokens = $this->sniffs[$sniffClass]->register();
1219 1219
             if (is_array($tokens) === false) {
1220
-                $msg = "Sniff $sniffClass register() method must return an array";
1220
+                $msg = "sniff $sniffClass register() method must return an array";
1221 1221
                 throw new RuntimeException($msg);
1222 1222
             }
1223 1223
 
Please login to merge, or discard this patch.
vendor/squizlabs/php_codesniffer/src/Config.php 4 patches
Indentation   +1691 added lines, -1691 removed lines patch added patch discarded remove patch
@@ -18,1697 +18,1697 @@
 block discarded – undo
18 18
 class Config
19 19
 {
20 20
 
21
-    /**
22
-     * The current version.
23
-     *
24
-     * @var string
25
-     */
26
-    const VERSION = '3.4.2';
27
-
28
-    /**
29
-     * Package stability; either stable, beta or alpha.
30
-     *
31
-     * @var string
32
-     */
33
-    const STABILITY = 'stable';
34
-
35
-    /**
36
-     * An array of settings that PHPCS and PHPCBF accept.
37
-     *
38
-     * This array is not meant to be accessed directly. Instead, use the settings
39
-     * as if they are class member vars so the __get() and __set() magic methods
40
-     * can be used to validate the values. For example, to set the verbosity level to
41
-     * level 2, use $this->verbosity = 2; instead of accessing this property directly.
42
-     *
43
-     * The list of settings are:
44
-     *
45
-     * string[] files           The files and directories to check.
46
-     * string[] standards       The standards being used for checking.
47
-     * int      verbosity       How verbose the output should be.
48
-     *                          0: no unnecessary output
49
-     *                          1: basic output for files being checked
50
-     *                          2: ruleset and file parsing output
51
-     *                          3: sniff execution output
52
-     * bool     interactive     Enable interactive checking mode.
53
-     * bool     parallel        Check files in parallel.
54
-     * bool     cache           Enable the use of the file cache.
55
-     * bool     cacheFile       A file where the cache data should be written
56
-     * bool     colors          Display colours in output.
57
-     * bool     explain         Explain the coding standards.
58
-     * bool     local           Process local files in directories only (no recursion).
59
-     * bool     showSources     Show sniff source codes in report output.
60
-     * bool     showProgress    Show basic progress information while running.
61
-     * bool     quiet           Quiet mode; disables progress and verbose output.
62
-     * bool     annotations     Process phpcs: annotations.
63
-     * int      tabWidth        How many spaces each tab is worth.
64
-     * string   encoding        The encoding of the files being checked.
65
-     * string[] sniffs          The sniffs that should be used for checking.
66
-     *                          If empty, all sniffs in the supplied standards will be used.
67
-     * string[] exclude         The sniffs that should be excluded from checking.
68
-     *                          If empty, all sniffs in the supplied standards will be used.
69
-     * string[] ignored         Regular expressions used to ignore files and folders during checking.
70
-     * string   reportFile      A file where the report output should be written.
71
-     * string   generator       The documentation generator to use.
72
-     * string   filter          The filter to use for the run.
73
-     * string[] bootstrap       One of more files to include before the run begins.
74
-     * int      reportWidth     The maximum number of columns that reports should use for output.
75
-     *                          Set to "auto" for have this value changed to the width of the terminal.
76
-     * int      errorSeverity   The minimum severity an error must have to be displayed.
77
-     * int      warningSeverity The minimum severity a warning must have to be displayed.
78
-     * bool     recordErrors    Record the content of error messages as well as error counts.
79
-     * string   suffix          A suffix to add to fixed files.
80
-     * string   basepath        A file system location to strip from the paths of files shown in reports.
81
-     * bool     stdin           Read content from STDIN instead of supplied files.
82
-     * string   stdinContent    Content passed directly to PHPCS on STDIN.
83
-     * string   stdinPath       The path to use for content passed on STDIN.
84
-     *
85
-     * array<string, string>      extensions File extensions that should be checked, and what tokenizer to use.
86
-     *                                       E.g., array('inc' => 'PHP');
87
-     * array<string, string|null> reports    The reports to use for printing output after the run.
88
-     *                                       The format of the array is:
89
-     *                                           array(
90
-     *                                            'reportName1' => 'outputFile',
91
-     *                                            'reportName2' => null,
92
-     *                                           );
93
-     *                                       If the array value is NULL, the report will be written to the screen.
94
-     *
95
-     * string[] unknown Any arguments gathered on the command line that are unknown to us.
96
-     *                  E.g., using `phpcs -c` will give array('c');
97
-     *
98
-     * @var array<string, mixed>
99
-     */
100
-    private $settings = [
101
-        'files'           => null,
102
-        'standards'       => null,
103
-        'verbosity'       => null,
104
-        'interactive'     => null,
105
-        'parallel'        => null,
106
-        'cache'           => null,
107
-        'cacheFile'       => null,
108
-        'colors'          => null,
109
-        'explain'         => null,
110
-        'local'           => null,
111
-        'showSources'     => null,
112
-        'showProgress'    => null,
113
-        'quiet'           => null,
114
-        'annotations'     => null,
115
-        'tabWidth'        => null,
116
-        'encoding'        => null,
117
-        'extensions'      => null,
118
-        'sniffs'          => null,
119
-        'exclude'         => null,
120
-        'ignored'         => null,
121
-        'reportFile'      => null,
122
-        'generator'       => null,
123
-        'filter'          => null,
124
-        'bootstrap'       => null,
125
-        'reports'         => null,
126
-        'basepath'        => null,
127
-        'reportWidth'     => null,
128
-        'errorSeverity'   => null,
129
-        'warningSeverity' => null,
130
-        'recordErrors'    => null,
131
-        'suffix'          => null,
132
-        'stdin'           => null,
133
-        'stdinContent'    => null,
134
-        'stdinPath'       => null,
135
-        'unknown'         => null,
136
-    ];
137
-
138
-    /**
139
-     * Whether or not to kill the process when an unknown command line arg is found.
140
-     *
141
-     * If FALSE, arguments that are not command line options or file/directory paths
142
-     * will be ignored and execution will continue. These values will be stored in
143
-     * $this->unknown.
144
-     *
145
-     * @var boolean
146
-     */
147
-    public $dieOnUnknownArg;
148
-
149
-    /**
150
-     * The current command line arguments we are processing.
151
-     *
152
-     * @var string[]
153
-     */
154
-    private $cliArgs = [];
155
-
156
-    /**
157
-     * Command line values that the user has supplied directly.
158
-     *
159
-     * @var array<string, TRUE>
160
-     */
161
-    private static $overriddenDefaults = [];
162
-
163
-    /**
164
-     * Config file data that has been loaded for the run.
165
-     *
166
-     * @var array<string, string>
167
-     */
168
-    private static $configData = null;
169
-
170
-    /**
171
-     * The full path to the config data file that has been loaded.
172
-     *
173
-     * @var string
174
-     */
175
-    private static $configDataFile = null;
176
-
177
-    /**
178
-     * Automatically discovered executable utility paths.
179
-     *
180
-     * @var array<string, string>
181
-     */
182
-    private static $executablePaths = [];
183
-
184
-
185
-    /**
186
-     * Get the value of an inaccessible property.
187
-     *
188
-     * @param string $name The name of the property.
189
-     *
190
-     * @return mixed
191
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
192
-     */
193
-    public function __get($name)
194
-    {
195
-        if (array_key_exists($name, $this->settings) === false) {
196
-            throw new RuntimeException("ERROR: unable to get value of property \"$name\"");
197
-        }
198
-
199
-        return $this->settings[$name];
200
-
201
-    }//end __get()
202
-
203
-
204
-    /**
205
-     * Set the value of an inaccessible property.
206
-     *
207
-     * @param string $name  The name of the property.
208
-     * @param mixed  $value The value of the property.
209
-     *
210
-     * @return void
211
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
212
-     */
213
-    public function __set($name, $value)
214
-    {
215
-        if (array_key_exists($name, $this->settings) === false) {
216
-            throw new RuntimeException("Can't __set() $name; setting doesn't exist");
217
-        }
218
-
219
-        switch ($name) {
220
-        case 'reportWidth' :
221
-            // Support auto terminal width.
222
-            if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
223
-                $value = (int) $matches[1];
224
-            } else {
225
-                $value = (int) $value;
226
-            }
227
-            break;
228
-        case 'standards' :
229
-            $cleaned = [];
230
-
231
-            // Check if the standard name is valid, or if the case is invalid.
232
-            $installedStandards = Util\Standards::getInstalledStandards();
233
-            foreach ($value as $standard) {
234
-                foreach ($installedStandards as $validStandard) {
235
-                    if (strtolower($standard) === strtolower($validStandard)) {
236
-                        $standard = $validStandard;
237
-                        break;
238
-                    }
239
-                }
240
-
241
-                $cleaned[] = $standard;
242
-            }
243
-
244
-            $value = $cleaned;
245
-            break;
246
-        default :
247
-            // No validation required.
248
-            break;
249
-        }//end switch
250
-
251
-        $this->settings[$name] = $value;
252
-
253
-    }//end __set()
254
-
255
-
256
-    /**
257
-     * Check if the value of an inaccessible property is set.
258
-     *
259
-     * @param string $name The name of the property.
260
-     *
261
-     * @return bool
262
-     */
263
-    public function __isset($name)
264
-    {
265
-        return isset($this->settings[$name]);
266
-
267
-    }//end __isset()
268
-
269
-
270
-    /**
271
-     * Unset the value of an inaccessible property.
272
-     *
273
-     * @param string $name The name of the property.
274
-     *
275
-     * @return void
276
-     */
277
-    public function __unset($name)
278
-    {
279
-        $this->settings[$name] = null;
280
-
281
-    }//end __unset()
282
-
283
-
284
-    /**
285
-     * Get the array of all config settings.
286
-     *
287
-     * @return array<string, mixed>
288
-     */
289
-    public function getSettings()
290
-    {
291
-        return $this->settings;
292
-
293
-    }//end getSettings()
294
-
295
-
296
-    /**
297
-     * Set the array of all config settings.
298
-     *
299
-     * @param array<string, mixed> $settings The array of config settings.
300
-     *
301
-     * @return void
302
-     */
303
-    public function setSettings($settings)
304
-    {
305
-        return $this->settings = $settings;
306
-
307
-    }//end setSettings()
308
-
309
-
310
-    /**
311
-     * Creates a Config object and populates it with command line values.
312
-     *
313
-     * @param array $cliArgs         An array of values gathered from CLI args.
314
-     * @param bool  $dieOnUnknownArg Whether or not to kill the process when an
315
-     *                               unknown command line arg is found.
316
-     *
317
-     * @return void
318
-     */
319
-    public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
320
-    {
321
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
322
-            // Let everything through during testing so that we can
323
-            // make use of PHPUnit command line arguments as well.
324
-            $this->dieOnUnknownArg = false;
325
-        } else {
326
-            $this->dieOnUnknownArg = $dieOnUnknownArg;
327
-        }
328
-
329
-        if (empty($cliArgs) === true) {
330
-            $cliArgs = $_SERVER['argv'];
331
-            array_shift($cliArgs);
332
-        }
333
-
334
-        $this->restoreDefaults();
335
-        $this->setCommandLineValues($cliArgs);
336
-
337
-        if (isset(self::$overriddenDefaults['standards']) === false) {
338
-            // They did not supply a standard to use.
339
-            // Look for a default ruleset in the current directory or higher.
340
-            $currentDir = getcwd();
341
-
342
-            $defaultFiles = [
343
-                '.phpcs.xml',
344
-                'phpcs.xml',
345
-                '.phpcs.xml.dist',
346
-                'phpcs.xml.dist',
347
-            ];
348
-
349
-            do {
350
-                foreach ($defaultFiles as $defaultFilename) {
351
-                    $default = $currentDir.DIRECTORY_SEPARATOR.$defaultFilename;
352
-                    if (is_file($default) === true) {
353
-                        $this->standards = [$default];
354
-                        break(2);
355
-                    }
356
-                }
357
-
358
-                $lastDir    = $currentDir;
359
-                $currentDir = dirname($currentDir);
360
-            } while ($currentDir !== '.' && $currentDir !== $lastDir);
361
-        }//end if
362
-
363
-        if (defined('STDIN') === false
364
-            || strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'
365
-        ) {
366
-            return;
367
-        }
368
-
369
-        $handle = fopen('php://stdin', 'r');
370
-
371
-        // Check for content on STDIN.
372
-        if ($this->stdin === true
373
-            || (Util\Common::isStdinATTY() === false
374
-            && feof($handle) === false)
375
-        ) {
376
-            $readStreams = [$handle];
377
-            $writeSteams = null;
378
-
379
-            $fileContents = '';
380
-            while (is_resource($handle) === true && feof($handle) === false) {
381
-                // Set a timeout of 200ms.
382
-                if (stream_select($readStreams, $writeSteams, $writeSteams, 0, 200000) === 0) {
383
-                    break;
384
-                }
385
-
386
-                $fileContents .= fgets($handle);
387
-            }
388
-
389
-            if (trim($fileContents) !== '') {
390
-                $this->stdin        = true;
391
-                $this->stdinContent = $fileContents;
392
-                self::$overriddenDefaults['stdin']        = true;
393
-                self::$overriddenDefaults['stdinContent'] = true;
394
-            }
395
-        }//end if
396
-
397
-        fclose($handle);
398
-
399
-    }//end __construct()
400
-
401
-
402
-    /**
403
-     * Set the command line values.
404
-     *
405
-     * @param array $args An array of command line arguments to set.
406
-     *
407
-     * @return void
408
-     */
409
-    public function setCommandLineValues($args)
410
-    {
411
-        $this->cliArgs = $args;
412
-        $numArgs       = count($args);
413
-
414
-        for ($i = 0; $i < $numArgs; $i++) {
415
-            $arg = $this->cliArgs[$i];
416
-            if ($arg === '') {
417
-                continue;
418
-            }
419
-
420
-            if ($arg{0} === '-') {
421
-                if ($arg === '-') {
422
-                    // Asking to read from STDIN.
423
-                    $this->stdin = true;
424
-                    self::$overriddenDefaults['stdin'] = true;
425
-                    continue;
426
-                }
427
-
428
-                if ($arg === '--') {
429
-                    // Empty argument, ignore it.
430
-                    continue;
431
-                }
432
-
433
-                if ($arg{1} === '-') {
434
-                    $this->processLongArgument(substr($arg, 2), $i);
435
-                } else {
436
-                    $switches = str_split($arg);
437
-                    foreach ($switches as $switch) {
438
-                        if ($switch === '-') {
439
-                            continue;
440
-                        }
441
-
442
-                        $this->processShortArgument($switch, $i);
443
-                    }
444
-                }
445
-            } else {
446
-                $this->processUnknownArgument($arg, $i);
447
-            }//end if
448
-        }//end for
449
-
450
-    }//end setCommandLineValues()
451
-
452
-
453
-    /**
454
-     * Restore default values for all possible command line arguments.
455
-     *
456
-     * @return array
457
-     */
458
-    public function restoreDefaults()
459
-    {
460
-        $this->files           = [];
461
-        $this->standards       = ['PEAR'];
462
-        $this->verbosity       = 0;
463
-        $this->interactive     = false;
464
-        $this->cache           = false;
465
-        $this->cacheFile       = null;
466
-        $this->colors          = false;
467
-        $this->explain         = false;
468
-        $this->local           = false;
469
-        $this->showSources     = false;
470
-        $this->showProgress    = false;
471
-        $this->quiet           = false;
472
-        $this->annotations     = true;
473
-        $this->parallel        = 1;
474
-        $this->tabWidth        = 0;
475
-        $this->encoding        = 'utf-8';
476
-        $this->extensions      = [
477
-            'php' => 'PHP',
478
-            'inc' => 'PHP',
479
-            'js'  => 'JS',
480
-            'css' => 'CSS',
481
-        ];
482
-        $this->sniffs          = [];
483
-        $this->exclude         = [];
484
-        $this->ignored         = [];
485
-        $this->reportFile      = null;
486
-        $this->generator       = null;
487
-        $this->filter          = null;
488
-        $this->bootstrap       = [];
489
-        $this->basepath        = null;
490
-        $this->reports         = ['full' => null];
491
-        $this->reportWidth     = 'auto';
492
-        $this->errorSeverity   = 5;
493
-        $this->warningSeverity = 5;
494
-        $this->recordErrors    = true;
495
-        $this->suffix          = '';
496
-        $this->stdin           = false;
497
-        $this->stdinContent    = null;
498
-        $this->stdinPath       = null;
499
-        $this->unknown         = [];
500
-
501
-        $standard = self::getConfigData('default_standard');
502
-        if ($standard !== null) {
503
-            $this->standards = explode(',', $standard);
504
-        }
505
-
506
-        $reportFormat = self::getConfigData('report_format');
507
-        if ($reportFormat !== null) {
508
-            $this->reports = [$reportFormat => null];
509
-        }
510
-
511
-        $tabWidth = self::getConfigData('tab_width');
512
-        if ($tabWidth !== null) {
513
-            $this->tabWidth = (int) $tabWidth;
514
-        }
515
-
516
-        $encoding = self::getConfigData('encoding');
517
-        if ($encoding !== null) {
518
-            $this->encoding = strtolower($encoding);
519
-        }
520
-
521
-        $severity = self::getConfigData('severity');
522
-        if ($severity !== null) {
523
-            $this->errorSeverity   = (int) $severity;
524
-            $this->warningSeverity = (int) $severity;
525
-        }
526
-
527
-        $severity = self::getConfigData('error_severity');
528
-        if ($severity !== null) {
529
-            $this->errorSeverity = (int) $severity;
530
-        }
531
-
532
-        $severity = self::getConfigData('warning_severity');
533
-        if ($severity !== null) {
534
-            $this->warningSeverity = (int) $severity;
535
-        }
536
-
537
-        $showWarnings = self::getConfigData('show_warnings');
538
-        if ($showWarnings !== null) {
539
-            $showWarnings = (bool) $showWarnings;
540
-            if ($showWarnings === false) {
541
-                $this->warningSeverity = 0;
542
-            }
543
-        }
544
-
545
-        $reportWidth = self::getConfigData('report_width');
546
-        if ($reportWidth !== null) {
547
-            $this->reportWidth = $reportWidth;
548
-        }
549
-
550
-        $showProgress = self::getConfigData('show_progress');
551
-        if ($showProgress !== null) {
552
-            $this->showProgress = (bool) $showProgress;
553
-        }
554
-
555
-        $quiet = self::getConfigData('quiet');
556
-        if ($quiet !== null) {
557
-            $this->quiet = (bool) $quiet;
558
-        }
559
-
560
-        $colors = self::getConfigData('colors');
561
-        if ($colors !== null) {
562
-            $this->colors = (bool) $colors;
563
-        }
564
-
565
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
566
-            $cache = self::getConfigData('cache');
567
-            if ($cache !== null) {
568
-                $this->cache = (bool) $cache;
569
-            }
570
-
571
-            $parallel = self::getConfigData('parallel');
572
-            if ($parallel !== null) {
573
-                $this->parallel = max((int) $parallel, 1);
574
-            }
575
-        }
576
-
577
-    }//end restoreDefaults()
578
-
579
-
580
-    /**
581
-     * Processes a short (-e) command line argument.
582
-     *
583
-     * @param string $arg The command line argument.
584
-     * @param int    $pos The position of the argument on the command line.
585
-     *
586
-     * @return void
587
-     */
588
-    public function processShortArgument($arg, $pos)
589
-    {
590
-        switch ($arg) {
591
-        case 'h':
592
-        case '?':
593
-            ob_start();
594
-            $this->printUsage();
595
-            $output = ob_get_contents();
596
-            ob_end_clean();
597
-            throw new DeepExitException($output, 0);
598
-        case 'i' :
599
-            ob_start();
600
-            Util\Standards::printInstalledStandards();
601
-            $output = ob_get_contents();
602
-            ob_end_clean();
603
-            throw new DeepExitException($output, 0);
604
-        case 'v' :
605
-            if ($this->quiet === true) {
606
-                // Ignore when quiet mode is enabled.
607
-                break;
608
-            }
609
-
610
-            $this->verbosity++;
611
-            self::$overriddenDefaults['verbosity'] = true;
612
-            break;
613
-        case 'l' :
614
-            $this->local = true;
615
-            self::$overriddenDefaults['local'] = true;
616
-            break;
617
-        case 's' :
618
-            $this->showSources = true;
619
-            self::$overriddenDefaults['showSources'] = true;
620
-            break;
621
-        case 'a' :
622
-            $this->interactive = true;
623
-            self::$overriddenDefaults['interactive'] = true;
624
-            break;
625
-        case 'e':
626
-            $this->explain = true;
627
-            self::$overriddenDefaults['explain'] = true;
628
-            break;
629
-        case 'p' :
630
-            if ($this->quiet === true) {
631
-                // Ignore when quiet mode is enabled.
632
-                break;
633
-            }
634
-
635
-            $this->showProgress = true;
636
-            self::$overriddenDefaults['showProgress'] = true;
637
-            break;
638
-        case 'q' :
639
-            // Quiet mode disables a few other settings as well.
640
-            $this->quiet        = true;
641
-            $this->showProgress = false;
642
-            $this->verbosity    = 0;
643
-
644
-            self::$overriddenDefaults['quiet'] = true;
645
-            break;
646
-        case 'm' :
647
-            $this->recordErrors = false;
648
-            self::$overriddenDefaults['recordErrors'] = true;
649
-            break;
650
-        case 'd' :
651
-            $ini = explode('=', $this->cliArgs[($pos + 1)]);
652
-            $this->cliArgs[($pos + 1)] = '';
653
-            if (isset($ini[1]) === true) {
654
-                ini_set($ini[0], $ini[1]);
655
-            } else {
656
-                ini_set($ini[0], true);
657
-            }
658
-            break;
659
-        case 'n' :
660
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
661
-                $this->warningSeverity = 0;
662
-                self::$overriddenDefaults['warningSeverity'] = true;
663
-            }
664
-            break;
665
-        case 'w' :
666
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
667
-                $this->warningSeverity = $this->errorSeverity;
668
-                self::$overriddenDefaults['warningSeverity'] = true;
669
-            }
670
-            break;
671
-        default:
672
-            if ($this->dieOnUnknownArg === false) {
673
-                $unknown       = $this->unknown;
674
-                $unknown[]     = $arg;
675
-                $this->unknown = $unknown;
676
-            } else {
677
-                $this->processUnknownArgument('-'.$arg, $pos);
678
-            }
679
-        }//end switch
680
-
681
-    }//end processShortArgument()
682
-
683
-
684
-    /**
685
-     * Processes a long (--example) command line argument.
686
-     *
687
-     * @param string $arg The command line argument.
688
-     * @param int    $pos The position of the argument on the command line.
689
-     *
690
-     * @return void
691
-     */
692
-    public function processLongArgument($arg, $pos)
693
-    {
694
-        switch ($arg) {
695
-        case 'help':
696
-            ob_start();
697
-            $this->printUsage();
698
-            $output = ob_get_contents();
699
-            ob_end_clean();
700
-            throw new DeepExitException($output, 0);
701
-        case 'version':
702
-            $output  = 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') ';
703
-            $output .= 'by Squiz (http://www.squiz.net)'.PHP_EOL;
704
-            throw new DeepExitException($output, 0);
705
-        case 'colors':
706
-            if (isset(self::$overriddenDefaults['colors']) === true) {
707
-                break;
708
-            }
709
-
710
-            $this->colors = true;
711
-            self::$overriddenDefaults['colors'] = true;
712
-            break;
713
-        case 'no-colors':
714
-            if (isset(self::$overriddenDefaults['colors']) === true) {
715
-                break;
716
-            }
717
-
718
-            $this->colors = false;
719
-            self::$overriddenDefaults['colors'] = true;
720
-            break;
721
-        case 'cache':
722
-            if (isset(self::$overriddenDefaults['cache']) === true) {
723
-                break;
724
-            }
725
-
726
-            if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
727
-                $this->cache = true;
728
-                self::$overriddenDefaults['cache'] = true;
729
-            }
730
-            break;
731
-        case 'no-cache':
732
-            if (isset(self::$overriddenDefaults['cache']) === true) {
733
-                break;
734
-            }
735
-
736
-            $this->cache = false;
737
-            self::$overriddenDefaults['cache'] = true;
738
-            break;
739
-        case 'ignore-annotations':
740
-            if (isset(self::$overriddenDefaults['annotations']) === true) {
741
-                break;
742
-            }
743
-
744
-            $this->annotations = false;
745
-            self::$overriddenDefaults['annotations'] = true;
746
-            break;
747
-        case 'config-set':
748
-            if (isset($this->cliArgs[($pos + 1)]) === false
749
-                || isset($this->cliArgs[($pos + 2)]) === false
750
-            ) {
751
-                $error  = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
752
-                $error .= $this->printShortUsage(true);
753
-                throw new DeepExitException($error, 3);
754
-            }
755
-
756
-            $key     = $this->cliArgs[($pos + 1)];
757
-            $value   = $this->cliArgs[($pos + 2)];
758
-            $current = self::getConfigData($key);
759
-
760
-            try {
761
-                $this->setConfigData($key, $value);
762
-            } catch (\Exception $e) {
763
-                throw new DeepExitException($e->getMessage().PHP_EOL, 3);
764
-            }
765
-
766
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
767
-
768
-            if ($current === null) {
769
-                $output .= "Config value \"$key\" added successfully".PHP_EOL;
770
-            } else {
771
-                $output .= "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL;
772
-            }
773
-            throw new DeepExitException($output, 0);
774
-        case 'config-delete':
775
-            if (isset($this->cliArgs[($pos + 1)]) === false) {
776
-                $error  = 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL;
777
-                $error .= $this->printShortUsage(true);
778
-                throw new DeepExitException($error, 3);
779
-            }
780
-
781
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
782
-
783
-            $key     = $this->cliArgs[($pos + 1)];
784
-            $current = self::getConfigData($key);
785
-            if ($current === null) {
786
-                $output .= "Config value \"$key\" has not been set".PHP_EOL;
787
-            } else {
788
-                try {
789
-                    $this->setConfigData($key, null);
790
-                } catch (\Exception $e) {
791
-                    throw new DeepExitException($e->getMessage().PHP_EOL, 3);
792
-                }
793
-
794
-                $output .= "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL;
795
-            }
796
-            throw new DeepExitException($output, 0);
797
-        case 'config-show':
798
-            ob_start();
799
-            $data = self::getAllConfigData();
800
-            echo 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
801
-            $this->printConfigData($data);
802
-            $output = ob_get_contents();
803
-            ob_end_clean();
804
-            throw new DeepExitException($output, 0);
805
-        case 'runtime-set':
806
-            if (isset($this->cliArgs[($pos + 1)]) === false
807
-                || isset($this->cliArgs[($pos + 2)]) === false
808
-            ) {
809
-                $error  = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
810
-                $error .= $this->printShortUsage(true);
811
-                throw new DeepExitException($error, 3);
812
-            }
813
-
814
-            $key   = $this->cliArgs[($pos + 1)];
815
-            $value = $this->cliArgs[($pos + 2)];
816
-            $this->cliArgs[($pos + 1)] = '';
817
-            $this->cliArgs[($pos + 2)] = '';
818
-            self::setConfigData($key, $value, true);
819
-            if (isset(self::$overriddenDefaults['runtime-set']) === false) {
820
-                self::$overriddenDefaults['runtime-set'] = [];
821
-            }
822
-
823
-            self::$overriddenDefaults['runtime-set'][$key] = true;
824
-            break;
825
-        default:
826
-            if (substr($arg, 0, 7) === 'sniffs=') {
827
-                if (isset(self::$overriddenDefaults['sniffs']) === true) {
828
-                    break;
829
-                }
830
-
831
-                $sniffs = explode(',', substr($arg, 7));
832
-                foreach ($sniffs as $sniff) {
833
-                    if (substr_count($sniff, '.') !== 2) {
834
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
835
-                        $error .= $this->printShortUsage(true);
836
-                        throw new DeepExitException($error, 3);
837
-                    }
838
-                }
839
-
840
-                $this->sniffs = $sniffs;
841
-                self::$overriddenDefaults['sniffs'] = true;
842
-            } else if (substr($arg, 0, 8) === 'exclude=') {
843
-                if (isset(self::$overriddenDefaults['exclude']) === true) {
844
-                    break;
845
-                }
846
-
847
-                $sniffs = explode(',', substr($arg, 8));
848
-                foreach ($sniffs as $sniff) {
849
-                    if (substr_count($sniff, '.') !== 2) {
850
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
851
-                        $error .= $this->printShortUsage(true);
852
-                        throw new DeepExitException($error, 3);
853
-                    }
854
-                }
855
-
856
-                $this->exclude = $sniffs;
857
-                self::$overriddenDefaults['exclude'] = true;
858
-            } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
859
-                && substr($arg, 0, 6) === 'cache='
860
-            ) {
861
-                if ((isset(self::$overriddenDefaults['cache']) === true
862
-                    && $this->cache === false)
863
-                    || isset(self::$overriddenDefaults['cacheFile']) === true
864
-                ) {
865
-                    break;
866
-                }
867
-
868
-                // Turn caching on.
869
-                $this->cache = true;
870
-                self::$overriddenDefaults['cache'] = true;
871
-
872
-                $this->cacheFile = Util\Common::realpath(substr($arg, 6));
873
-
874
-                // It may not exist and return false instead.
875
-                if ($this->cacheFile === false) {
876
-                    $this->cacheFile = substr($arg, 6);
877
-
878
-                    $dir = dirname($this->cacheFile);
879
-                    if (is_dir($dir) === false) {
880
-                        $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
881
-                        $error .= $this->printShortUsage(true);
882
-                        throw new DeepExitException($error, 3);
883
-                    }
884
-
885
-                    if ($dir === '.') {
886
-                        // Passed cache file is a file in the current directory.
887
-                        $this->cacheFile = getcwd().'/'.basename($this->cacheFile);
888
-                    } else {
889
-                        if ($dir{0} === '/') {
890
-                            // An absolute path.
891
-                            $dir = Util\Common::realpath($dir);
892
-                        } else {
893
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
894
-                        }
895
-
896
-                        if ($dir !== false) {
897
-                            // Cache file path is relative.
898
-                            $this->cacheFile = $dir.'/'.basename($this->cacheFile);
899
-                        }
900
-                    }
901
-                }//end if
902
-
903
-                self::$overriddenDefaults['cacheFile'] = true;
904
-
905
-                if (is_dir($this->cacheFile) === true) {
906
-                    $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL;
907
-                    $error .= $this->printShortUsage(true);
908
-                    throw new DeepExitException($error, 3);
909
-                }
910
-            } else if (substr($arg, 0, 10) === 'bootstrap=') {
911
-                $files     = explode(',', substr($arg, 10));
912
-                $bootstrap = [];
913
-                foreach ($files as $file) {
914
-                    $path = Util\Common::realpath($file);
915
-                    if ($path === false) {
916
-                        $error  = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
917
-                        $error .= $this->printShortUsage(true);
918
-                        throw new DeepExitException($error, 3);
919
-                    }
920
-
921
-                    $bootstrap[] = $path;
922
-                }
923
-
924
-                $this->bootstrap = array_merge($this->bootstrap, $bootstrap);
925
-                self::$overriddenDefaults['bootstrap'] = true;
926
-            } else if (substr($arg, 0, 10) === 'file-list=') {
927
-                $fileList = substr($arg, 10);
928
-                $path     = Util\Common::realpath($fileList);
929
-                if ($path === false) {
930
-                    $error  = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
931
-                    $error .= $this->printShortUsage(true);
932
-                    throw new DeepExitException($error, 3);
933
-                }
934
-
935
-                $files = file($path);
936
-                foreach ($files as $inputFile) {
937
-                    $inputFile = trim($inputFile);
938
-
939
-                    // Skip empty lines.
940
-                    if ($inputFile === '') {
941
-                        continue;
942
-                    }
943
-
944
-                    $this->processFilePath($inputFile);
945
-                }
946
-            } else if (substr($arg, 0, 11) === 'stdin-path=') {
947
-                if (isset(self::$overriddenDefaults['stdinPath']) === true) {
948
-                    break;
949
-                }
950
-
951
-                $this->stdinPath = Util\Common::realpath(substr($arg, 11));
952
-
953
-                // It may not exist and return false instead, so use whatever they gave us.
954
-                if ($this->stdinPath === false) {
955
-                    $this->stdinPath = trim(substr($arg, 11));
956
-                }
957
-
958
-                self::$overriddenDefaults['stdinPath'] = true;
959
-            } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
960
-                if (isset(self::$overriddenDefaults['reportFile']) === true) {
961
-                    break;
962
-                }
963
-
964
-                $this->reportFile = Util\Common::realpath(substr($arg, 12));
965
-
966
-                // It may not exist and return false instead.
967
-                if ($this->reportFile === false) {
968
-                    $this->reportFile = substr($arg, 12);
969
-
970
-                    $dir = dirname($this->reportFile);
971
-                    if (is_dir($dir) === false) {
972
-                        $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
973
-                        $error .= $this->printShortUsage(true);
974
-                        throw new DeepExitException($error, 3);
975
-                    }
976
-
977
-                    if ($dir === '.') {
978
-                        // Passed report file is a file in the current directory.
979
-                        $this->reportFile = getcwd().'/'.basename($this->reportFile);
980
-                    } else {
981
-                        if ($dir{0} === '/') {
982
-                            // An absolute path.
983
-                            $dir = Util\Common::realpath($dir);
984
-                        } else {
985
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
986
-                        }
987
-
988
-                        if ($dir !== false) {
989
-                            // Report file path is relative.
990
-                            $this->reportFile = $dir.'/'.basename($this->reportFile);
991
-                        }
992
-                    }
993
-                }//end if
994
-
995
-                self::$overriddenDefaults['reportFile'] = true;
996
-
997
-                if (is_dir($this->reportFile) === true) {
998
-                    $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL;
999
-                    $error .= $this->printShortUsage(true);
1000
-                    throw new DeepExitException($error, 3);
1001
-                }
1002
-            } else if (substr($arg, 0, 13) === 'report-width=') {
1003
-                if (isset(self::$overriddenDefaults['reportWidth']) === true) {
1004
-                    break;
1005
-                }
1006
-
1007
-                $this->reportWidth = substr($arg, 13);
1008
-                self::$overriddenDefaults['reportWidth'] = true;
1009
-            } else if (substr($arg, 0, 9) === 'basepath=') {
1010
-                if (isset(self::$overriddenDefaults['basepath']) === true) {
1011
-                    break;
1012
-                }
1013
-
1014
-                self::$overriddenDefaults['basepath'] = true;
1015
-
1016
-                if (substr($arg, 9) === '') {
1017
-                    $this->basepath = null;
1018
-                    break;
1019
-                }
1020
-
1021
-                $this->basepath = Util\Common::realpath(substr($arg, 9));
1022
-
1023
-                // It may not exist and return false instead.
1024
-                if ($this->basepath === false) {
1025
-                    $this->basepath = substr($arg, 9);
1026
-                }
1027
-
1028
-                if (is_dir($this->basepath) === false) {
1029
-                    $error  = 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1030
-                    $error .= $this->printShortUsage(true);
1031
-                    throw new DeepExitException($error, 3);
1032
-                }
1033
-            } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) {
1034
-                $reports = [];
1035
-
1036
-                if ($arg[6] === '-') {
1037
-                    // This is a report with file output.
1038
-                    $split = strpos($arg, '=');
1039
-                    if ($split === false) {
1040
-                        $report = substr($arg, 7);
1041
-                        $output = null;
1042
-                    } else {
1043
-                        $report = substr($arg, 7, ($split - 7));
1044
-                        $output = substr($arg, ($split + 1));
1045
-                        if ($output === false) {
1046
-                            $output = null;
1047
-                        } else {
1048
-                            $dir = dirname($output);
1049
-                            if (is_dir($dir) === false) {
1050
-                                $error  = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1051
-                                $error .= $this->printShortUsage(true);
1052
-                                throw new DeepExitException($error, 3);
1053
-                            }
1054
-
1055
-                            if ($dir === '.') {
1056
-                                // Passed report file is a filename in the current directory.
1057
-                                $output = getcwd().'/'.basename($output);
1058
-                            } else {
1059
-                                if ($dir{0} === '/') {
1060
-                                    // An absolute path.
1061
-                                    $dir = Util\Common::realpath($dir);
1062
-                                } else {
1063
-                                    $dir = Util\Common::realpath(getcwd().'/'.$dir);
1064
-                                }
1065
-
1066
-                                if ($dir !== false) {
1067
-                                    // Report file path is relative.
1068
-                                    $output = $dir.'/'.basename($output);
1069
-                                }
1070
-                            }
1071
-                        }//end if
1072
-                    }//end if
1073
-
1074
-                    $reports[$report] = $output;
1075
-                } else {
1076
-                    // This is a single report.
1077
-                    if (isset(self::$overriddenDefaults['reports']) === true) {
1078
-                        break;
1079
-                    }
1080
-
1081
-                    $reportNames = explode(',', substr($arg, 7));
1082
-                    foreach ($reportNames as $report) {
1083
-                        $reports[$report] = null;
1084
-                    }
1085
-                }//end if
1086
-
1087
-                // Remove the default value so the CLI value overrides it.
1088
-                if (isset(self::$overriddenDefaults['reports']) === false) {
1089
-                    $this->reports = $reports;
1090
-                } else {
1091
-                    $this->reports = array_merge($this->reports, $reports);
1092
-                }
1093
-
1094
-                self::$overriddenDefaults['reports'] = true;
1095
-            } else if (substr($arg, 0, 7) === 'filter=') {
1096
-                if (isset(self::$overriddenDefaults['filter']) === true) {
1097
-                    break;
1098
-                }
1099
-
1100
-                $this->filter = substr($arg, 7);
1101
-                self::$overriddenDefaults['filter'] = true;
1102
-            } else if (substr($arg, 0, 9) === 'standard=') {
1103
-                $standards = trim(substr($arg, 9));
1104
-                if ($standards !== '') {
1105
-                    $this->standards = explode(',', $standards);
1106
-                }
1107
-
1108
-                self::$overriddenDefaults['standards'] = true;
1109
-            } else if (substr($arg, 0, 11) === 'extensions=') {
1110
-                if (isset(self::$overriddenDefaults['extensions']) === true) {
1111
-                    break;
1112
-                }
1113
-
1114
-                $extensions    = explode(',', substr($arg, 11));
1115
-                $newExtensions = [];
1116
-                foreach ($extensions as $ext) {
1117
-                    $slash = strpos($ext, '/');
1118
-                    if ($slash !== false) {
1119
-                        // They specified the tokenizer too.
1120
-                        list($ext, $tokenizer) = explode('/', $ext);
1121
-                        $newExtensions[$ext]   = strtoupper($tokenizer);
1122
-                        continue;
1123
-                    }
1124
-
1125
-                    if (isset($this->extensions[$ext]) === true) {
1126
-                        $newExtensions[$ext] = $this->extensions[$ext];
1127
-                    } else {
1128
-                        $newExtensions[$ext] = 'PHP';
1129
-                    }
1130
-                }
1131
-
1132
-                $this->extensions = $newExtensions;
1133
-                self::$overriddenDefaults['extensions'] = true;
1134
-            } else if (substr($arg, 0, 7) === 'suffix=') {
1135
-                if (isset(self::$overriddenDefaults['suffix']) === true) {
1136
-                    break;
1137
-                }
1138
-
1139
-                $this->suffix = substr($arg, 7);
1140
-                self::$overriddenDefaults['suffix'] = true;
1141
-            } else if (substr($arg, 0, 9) === 'parallel=') {
1142
-                if (isset(self::$overriddenDefaults['parallel']) === true) {
1143
-                    break;
1144
-                }
1145
-
1146
-                $this->parallel = max((int) substr($arg, 9), 1);
1147
-                self::$overriddenDefaults['parallel'] = true;
1148
-            } else if (substr($arg, 0, 9) === 'severity=') {
1149
-                $this->errorSeverity   = (int) substr($arg, 9);
1150
-                $this->warningSeverity = $this->errorSeverity;
1151
-                if (isset(self::$overriddenDefaults['errorSeverity']) === false) {
1152
-                    self::$overriddenDefaults['errorSeverity'] = true;
1153
-                }
1154
-
1155
-                if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
1156
-                    self::$overriddenDefaults['warningSeverity'] = true;
1157
-                }
1158
-            } else if (substr($arg, 0, 15) === 'error-severity=') {
1159
-                if (isset(self::$overriddenDefaults['errorSeverity']) === true) {
1160
-                    break;
1161
-                }
1162
-
1163
-                $this->errorSeverity = (int) substr($arg, 15);
1164
-                self::$overriddenDefaults['errorSeverity'] = true;
1165
-            } else if (substr($arg, 0, 17) === 'warning-severity=') {
1166
-                if (isset(self::$overriddenDefaults['warningSeverity']) === true) {
1167
-                    break;
1168
-                }
1169
-
1170
-                $this->warningSeverity = (int) substr($arg, 17);
1171
-                self::$overriddenDefaults['warningSeverity'] = true;
1172
-            } else if (substr($arg, 0, 7) === 'ignore=') {
1173
-                if (isset(self::$overriddenDefaults['ignored']) === true) {
1174
-                    break;
1175
-                }
1176
-
1177
-                // Split the ignore string on commas, unless the comma is escaped
1178
-                // using 1 or 3 slashes (\, or \\\,).
1179
-                $patterns = preg_split(
1180
-                    '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
1181
-                    substr($arg, 7)
1182
-                );
1183
-
1184
-                $ignored = [];
1185
-                foreach ($patterns as $pattern) {
1186
-                    $pattern = trim($pattern);
1187
-                    if ($pattern === '') {
1188
-                        continue;
1189
-                    }
1190
-
1191
-                    $ignored[$pattern] = 'absolute';
1192
-                }
1193
-
1194
-                $this->ignored = $ignored;
1195
-                self::$overriddenDefaults['ignored'] = true;
1196
-            } else if (substr($arg, 0, 10) === 'generator='
1197
-                && PHP_CODESNIFFER_CBF === false
1198
-            ) {
1199
-                if (isset(self::$overriddenDefaults['generator']) === true) {
1200
-                    break;
1201
-                }
1202
-
1203
-                $this->generator = substr($arg, 10);
1204
-                self::$overriddenDefaults['generator'] = true;
1205
-            } else if (substr($arg, 0, 9) === 'encoding=') {
1206
-                if (isset(self::$overriddenDefaults['encoding']) === true) {
1207
-                    break;
1208
-                }
1209
-
1210
-                $this->encoding = strtolower(substr($arg, 9));
1211
-                self::$overriddenDefaults['encoding'] = true;
1212
-            } else if (substr($arg, 0, 10) === 'tab-width=') {
1213
-                if (isset(self::$overriddenDefaults['tabWidth']) === true) {
1214
-                    break;
1215
-                }
1216
-
1217
-                $this->tabWidth = (int) substr($arg, 10);
1218
-                self::$overriddenDefaults['tabWidth'] = true;
1219
-            } else {
1220
-                if ($this->dieOnUnknownArg === false) {
1221
-                    $eqPos = strpos($arg, '=');
1222
-                    try {
1223
-                        if ($eqPos === false) {
1224
-                            $this->values[$arg] = $arg;
1225
-                        } else {
1226
-                            $value = substr($arg, ($eqPos + 1));
1227
-                            $arg   = substr($arg, 0, $eqPos);
1228
-                            $this->values[$arg] = $value;
1229
-                        }
1230
-                    } catch (RuntimeException $e) {
1231
-                        // Value is not valid, so just ignore it.
1232
-                    }
1233
-                } else {
1234
-                    $this->processUnknownArgument('--'.$arg, $pos);
1235
-                }
1236
-            }//end if
1237
-            break;
1238
-        }//end switch
1239
-
1240
-    }//end processLongArgument()
1241
-
1242
-
1243
-    /**
1244
-     * Processes an unknown command line argument.
1245
-     *
1246
-     * Assumes all unknown arguments are files and folders to check.
1247
-     *
1248
-     * @param string $arg The command line argument.
1249
-     * @param int    $pos The position of the argument on the command line.
1250
-     *
1251
-     * @return void
1252
-     */
1253
-    public function processUnknownArgument($arg, $pos)
1254
-    {
1255
-        // We don't know about any additional switches; just files.
1256
-        if ($arg{0} === '-') {
1257
-            if ($this->dieOnUnknownArg === false) {
1258
-                return;
1259
-            }
1260
-
1261
-            $error  = "ERROR: option \"$arg\" not known".PHP_EOL.PHP_EOL;
1262
-            $error .= $this->printShortUsage(true);
1263
-            throw new DeepExitException($error, 3);
1264
-        }
1265
-
1266
-        $this->processFilePath($arg);
1267
-
1268
-    }//end processUnknownArgument()
1269
-
1270
-
1271
-    /**
1272
-     * Processes a file path and add it to the file list.
1273
-     *
1274
-     * @param string $path The path to the file to add.
1275
-     *
1276
-     * @return void
1277
-     */
1278
-    public function processFilePath($path)
1279
-    {
1280
-        // If we are processing STDIN, don't record any files to check.
1281
-        if ($this->stdin === true) {
1282
-            return;
1283
-        }
1284
-
1285
-        $file = Util\Common::realpath($path);
1286
-        if (file_exists($file) === false) {
1287
-            if ($this->dieOnUnknownArg === false) {
1288
-                return;
1289
-            }
1290
-
1291
-            $error  = 'ERROR: The file "'.$path.'" does not exist.'.PHP_EOL.PHP_EOL;
1292
-            $error .= $this->printShortUsage(true);
1293
-            throw new DeepExitException($error, 3);
1294
-        } else {
1295
-            // Can't modify the files array directly because it's not a real
1296
-            // class member, so need to use this little get/modify/set trick.
1297
-            $files       = $this->files;
1298
-            $files[]     = $file;
1299
-            $this->files = $files;
1300
-            self::$overriddenDefaults['files'] = true;
1301
-        }
1302
-
1303
-    }//end processFilePath()
1304
-
1305
-
1306
-    /**
1307
-     * Prints out the usage information for this script.
1308
-     *
1309
-     * @return void
1310
-     */
1311
-    public function printUsage()
1312
-    {
1313
-        echo PHP_EOL;
1314
-
1315
-        if (PHP_CODESNIFFER_CBF === true) {
1316
-            $this->printPHPCBFUsage();
1317
-        } else {
1318
-            $this->printPHPCSUsage();
1319
-        }
1320
-
1321
-        echo PHP_EOL;
1322
-
1323
-    }//end printUsage()
1324
-
1325
-
1326
-    /**
1327
-     * Prints out the short usage information for this script.
1328
-     *
1329
-     * @param bool $return If TRUE, the usage string is returned
1330
-     *                     instead of output to screen.
1331
-     *
1332
-     * @return string|void
1333
-     */
1334
-    public function printShortUsage($return=false)
1335
-    {
1336
-        if (PHP_CODESNIFFER_CBF === true) {
1337
-            $usage = 'Run "phpcbf --help" for usage information';
1338
-        } else {
1339
-            $usage = 'Run "phpcs --help" for usage information';
1340
-        }
1341
-
1342
-        $usage .= PHP_EOL.PHP_EOL;
1343
-
1344
-        if ($return === true) {
1345
-            return $usage;
1346
-        }
1347
-
1348
-        echo $usage;
1349
-
1350
-    }//end printShortUsage()
1351
-
1352
-
1353
-    /**
1354
-     * Prints out the usage information for PHPCS.
1355
-     *
1356
-     * @return void
1357
-     */
1358
-    public function printPHPCSUsage()
1359
-    {
1360
-        echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]'.PHP_EOL;
1361
-        echo '  [--cache[=<cacheFile>]] [--no-cache] [--tab-width=<tabWidth>]'.PHP_EOL;
1362
-        echo '  [--report=<report>] [--report-file=<reportFile>] [--report-<report>=<reportFile>]'.PHP_EOL;
1363
-        echo '  [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]'.PHP_EOL;
1364
-        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1365
-        echo '  [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
1366
-        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]'.PHP_EOL;
1367
-        echo '  [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]'.PHP_EOL;
1368
-        echo '  [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]'.PHP_EOL;
1369
-        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1370
-        echo PHP_EOL;
1371
-        echo ' -     Check STDIN instead of local files and directories'.PHP_EOL;
1372
-        echo ' -n    Do not print warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1373
-        echo ' -w    Print both warnings and errors (this is the default)'.PHP_EOL;
1374
-        echo ' -l    Local directory only, no recursion'.PHP_EOL;
1375
-        echo ' -s    Show sniff codes in all reports'.PHP_EOL;
1376
-        echo ' -a    Run interactively'.PHP_EOL;
1377
-        echo ' -e    Explain a standard by showing the sniffs it includes'.PHP_EOL;
1378
-        echo ' -p    Show progress of the run'.PHP_EOL;
1379
-        echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1380
-        echo ' -m    Stop error messages from being recorded'.PHP_EOL;
1381
-        echo '       (saves a lot of memory, but stops many reports from being used)'.PHP_EOL;
1382
-        echo ' -v    Print processed files'.PHP_EOL;
1383
-        echo ' -vv   Print ruleset and token output'.PHP_EOL;
1384
-        echo ' -vvv  Print sniff processing information'.PHP_EOL;
1385
-        echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1386
-        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1387
-        echo PHP_EOL;
1388
-        echo ' --help                Print this help message'.PHP_EOL;
1389
-        echo ' --version             Print version information'.PHP_EOL;
1390
-        echo ' --colors              Use colors in output'.PHP_EOL;
1391
-        echo ' --no-colors           Do not use colors in output (this is the default)'.PHP_EOL;
1392
-        echo ' --cache               Cache results between runs'.PHP_EOL;
1393
-        echo ' --no-cache            Do not cache results between runs (this is the default)'.PHP_EOL;
1394
-        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1395
-        echo PHP_EOL;
1396
-        echo ' <cacheFile>    Use a specific file for caching (uses a temporary file by default)'.PHP_EOL;
1397
-        echo ' <basepath>     A path to strip from the front of file paths inside reports'.PHP_EOL;
1398
-        echo ' <bootstrap>    A comma separated list of files to run before processing begins'.PHP_EOL;
1399
-        echo ' <encoding>     The encoding of the files being checked (default is utf-8)'.PHP_EOL;
1400
-        echo ' <extensions>   A comma separated list of file extensions to check'.PHP_EOL;
1401
-        echo '                The type of the file can be specified using: ext/type'.PHP_EOL;
1402
-        echo '                e.g., module/php,es/js'.PHP_EOL;
1403
-        echo ' <file>         One or more files and/or directories to check'.PHP_EOL;
1404
-        echo ' <fileList>     A file containing a list of files and/or directories to check (one per line)'.PHP_EOL;
1405
-        echo ' <filter>       Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1406
-        echo ' <generator>    Uses either the "HTML", "Markdown" or "Text" generator'.PHP_EOL;
1407
-        echo '                (forces documentation generation instead of checking)'.PHP_EOL;
1408
-        echo ' <patterns>     A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1409
-        echo ' <processes>    How many files should be checked simultaneously (default is 1)'.PHP_EOL;
1410
-        echo ' <report>       Print either the "full", "xml", "checkstyle", "csv"'.PHP_EOL;
1411
-        echo '                "json", "junit", "emacs", "source", "summary", "diff"'.PHP_EOL;
1412
-        echo '                "svnblame", "gitblame", "hgblame" or "notifysend" report,'.PHP_EOL;
1413
-        echo '                or specify the path to a custom report class'.PHP_EOL;
1414
-        echo '                (the "full" report is printed by default)'.PHP_EOL;
1415
-        echo ' <reportFile>   Write the report to the specified file path'.PHP_EOL;
1416
-        echo ' <reportWidth>  How many columns wide screen reports should be printed'.PHP_EOL;
1417
-        echo '                or set to "auto" to use current screen width, where supported'.PHP_EOL;
1418
-        echo ' <severity>     The minimum severity required to display an error or warning'.PHP_EOL;
1419
-        echo ' <sniffs>       A comma separated list of sniff codes to include or exclude from checking'.PHP_EOL;
1420
-        echo '                (all sniffs must be part of the specified standard)'.PHP_EOL;
1421
-        echo ' <standard>     The name or path of the coding standard to use'.PHP_EOL;
1422
-        echo ' <stdinPath>    If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1423
-        echo ' <tabWidth>     The number of spaces each tab represents'.PHP_EOL;
1424
-
1425
-    }//end printPHPCSUsage()
1426
-
1427
-
1428
-    /**
1429
-     * Prints out the usage information for PHPCBF.
1430
-     *
1431
-     * @return void
1432
-     */
1433
-    public function printPHPCBFUsage()
1434
-    {
1435
-        echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--ignore-annotations] [--bootstrap=<bootstrap>]'.PHP_EOL;
1436
-        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--suffix=<suffix>]'.PHP_EOL;
1437
-        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1438
-        echo '  [--tab-width=<tabWidth>] [--encoding=<encoding>] [--parallel=<processes>]'.PHP_EOL;
1439
-        echo '  [--basepath=<basepath>] [--extensions=<extensions>] [--ignore=<patterns>]'.PHP_EOL;
1440
-        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1441
-        echo PHP_EOL;
1442
-        echo ' -     Fix STDIN instead of local files and directories'.PHP_EOL;
1443
-        echo ' -n    Do not fix warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1444
-        echo ' -w    Fix both warnings and errors (on by default)'.PHP_EOL;
1445
-        echo ' -l    Local directory only, no recursion'.PHP_EOL;
1446
-        echo ' -p    Show progress of the run'.PHP_EOL;
1447
-        echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1448
-        echo ' -v    Print processed files'.PHP_EOL;
1449
-        echo ' -vv   Print ruleset and token output'.PHP_EOL;
1450
-        echo ' -vvv  Print sniff processing information'.PHP_EOL;
1451
-        echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1452
-        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1453
-        echo PHP_EOL;
1454
-        echo ' --help                Print this help message'.PHP_EOL;
1455
-        echo ' --version             Print version information'.PHP_EOL;
1456
-        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1457
-        echo PHP_EOL;
1458
-        echo ' <basepath>    A path to strip from the front of file paths inside reports'.PHP_EOL;
1459
-        echo ' <bootstrap>   A comma separated list of files to run before processing begins'.PHP_EOL;
1460
-        echo ' <encoding>    The encoding of the files being fixed (default is utf-8)'.PHP_EOL;
1461
-        echo ' <extensions>  A comma separated list of file extensions to fix'.PHP_EOL;
1462
-        echo '               The type of the file can be specified using: ext/type'.PHP_EOL;
1463
-        echo '               e.g., module/php,es/js'.PHP_EOL;
1464
-        echo ' <file>        One or more files and/or directories to fix'.PHP_EOL;
1465
-        echo ' <fileList>    A file containing a list of files and/or directories to fix (one per line)'.PHP_EOL;
1466
-        echo ' <filter>      Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1467
-        echo ' <patterns>    A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1468
-        echo ' <processes>   How many files should be fixed simultaneously (default is 1)'.PHP_EOL;
1469
-        echo ' <severity>    The minimum severity required to fix an error or warning'.PHP_EOL;
1470
-        echo ' <sniffs>      A comma separated list of sniff codes to include or exclude from fixing'.PHP_EOL;
1471
-        echo '               (all sniffs must be part of the specified standard)'.PHP_EOL;
1472
-        echo ' <standard>    The name or path of the coding standard to use'.PHP_EOL;
1473
-        echo ' <stdinPath>   If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1474
-        echo ' <suffix>      Write modified files to a filename using this suffix'.PHP_EOL;
1475
-        echo '               ("diff" and "patch" are not used in this mode)'.PHP_EOL;
1476
-        echo ' <tabWidth>    The number of spaces each tab represents'.PHP_EOL;
1477
-
1478
-    }//end printPHPCBFUsage()
1479
-
1480
-
1481
-    /**
1482
-     * Get a single config value.
1483
-     *
1484
-     * @param string $key The name of the config value.
1485
-     *
1486
-     * @return string|null
1487
-     * @see    setConfigData()
1488
-     * @see    getAllConfigData()
1489
-     */
1490
-    public static function getConfigData($key)
1491
-    {
1492
-        $phpCodeSnifferConfig = self::getAllConfigData();
1493
-
1494
-        if ($phpCodeSnifferConfig === null) {
1495
-            return null;
1496
-        }
1497
-
1498
-        if (isset($phpCodeSnifferConfig[$key]) === false) {
1499
-            return null;
1500
-        }
1501
-
1502
-        return $phpCodeSnifferConfig[$key];
1503
-
1504
-    }//end getConfigData()
1505
-
1506
-
1507
-    /**
1508
-     * Get the path to an executable utility.
1509
-     *
1510
-     * @param string $name The name of the executable utility.
1511
-     *
1512
-     * @return string|null
1513
-     * @see    getConfigData()
1514
-     */
1515
-    public static function getExecutablePath($name)
1516
-    {
1517
-        $data = self::getConfigData($name.'_path');
1518
-        if ($data !== null) {
1519
-            return $data;
1520
-        }
1521
-
1522
-        if ($name === "php") {
1523
-            // For php, we know the executable path. There's no need to look it up.
1524
-            return PHP_BINARY;
1525
-        }
1526
-
1527
-        if (array_key_exists($name, self::$executablePaths) === true) {
1528
-            return self::$executablePaths[$name];
1529
-        }
1530
-
1531
-        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1532
-            $cmd = 'where '.escapeshellarg($name).' 2> nul';
1533
-        } else {
1534
-            $cmd = 'which '.escapeshellarg($name).' 2> /dev/null';
1535
-        }
1536
-
1537
-        $result = exec($cmd, $output, $retVal);
1538
-        if ($retVal !== 0) {
1539
-            $result = null;
1540
-        }
1541
-
1542
-        self::$executablePaths[$name] = $result;
1543
-        return $result;
1544
-
1545
-    }//end getExecutablePath()
1546
-
1547
-
1548
-    /**
1549
-     * Set a single config value.
1550
-     *
1551
-     * @param string      $key   The name of the config value.
1552
-     * @param string|null $value The value to set. If null, the config
1553
-     *                           entry is deleted, reverting it to the
1554
-     *                           default value.
1555
-     * @param boolean     $temp  Set this config data temporarily for this
1556
-     *                           script run. This will not write the config
1557
-     *                           data to the config file.
1558
-     *
1559
-     * @return bool
1560
-     * @see    getConfigData()
1561
-     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the config file can not be written.
1562
-     */
1563
-    public static function setConfigData($key, $value, $temp=false)
1564
-    {
1565
-        if (isset(self::$overriddenDefaults['runtime-set']) === true
1566
-            && isset(self::$overriddenDefaults['runtime-set'][$key]) === true
1567
-        ) {
1568
-            return false;
1569
-        }
1570
-
1571
-        if ($temp === false) {
1572
-            $path = '';
1573
-            if (is_callable('\Phar::running') === true) {
1574
-                $path = \Phar::running(false);
1575
-            }
1576
-
1577
-            if ($path !== '') {
1578
-                $configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1579
-            } else {
1580
-                $configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1581
-                if (is_file($configFile) === false
1582
-                    && strpos('@data_dir@', '@data_dir') === false
1583
-                ) {
1584
-                    // If data_dir was replaced, this is a PEAR install and we can
1585
-                    // use the PEAR data dir to store the conf file.
1586
-                    $configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
1587
-                }
1588
-            }
1589
-
1590
-            if (is_file($configFile) === true
1591
-                && is_writable($configFile) === false
1592
-            ) {
1593
-                $error = 'ERROR: Config file '.$configFile.' is not writable'.PHP_EOL.PHP_EOL;
1594
-                throw new DeepExitException($error, 3);
1595
-            }
1596
-        }//end if
1597
-
1598
-        $phpCodeSnifferConfig = self::getAllConfigData();
1599
-
1600
-        if ($value === null) {
1601
-            if (isset($phpCodeSnifferConfig[$key]) === true) {
1602
-                unset($phpCodeSnifferConfig[$key]);
1603
-            }
1604
-        } else {
1605
-            $phpCodeSnifferConfig[$key] = $value;
1606
-        }
1607
-
1608
-        if ($temp === false) {
1609
-            $output  = '<'.'?php'."\n".' $phpCodeSnifferConfig = ';
1610
-            $output .= var_export($phpCodeSnifferConfig, true);
1611
-            $output .= "\n?".'>';
1612
-
1613
-            if (file_put_contents($configFile, $output) === false) {
1614
-                $error = 'ERROR: Config file '.$configFile.' could not be written'.PHP_EOL.PHP_EOL;
1615
-                throw new DeepExitException($error, 3);
1616
-            }
1617
-
1618
-            self::$configDataFile = $configFile;
1619
-        }
1620
-
1621
-        self::$configData = $phpCodeSnifferConfig;
1622
-
1623
-        // If the installed paths are being set, make sure all known
1624
-        // standards paths are added to the autoloader.
1625
-        if ($key === 'installed_paths') {
1626
-            $installedStandards = Util\Standards::getInstalledStandardDetails();
1627
-            foreach ($installedStandards as $name => $details) {
1628
-                Autoload::addSearchPath($details['path'], $details['namespace']);
1629
-            }
1630
-        }
1631
-
1632
-        return true;
1633
-
1634
-    }//end setConfigData()
1635
-
1636
-
1637
-    /**
1638
-     * Get all config data.
1639
-     *
1640
-     * @return array<string, string>
1641
-     * @see    getConfigData()
1642
-     */
1643
-    public static function getAllConfigData()
1644
-    {
1645
-        if (self::$configData !== null) {
1646
-            return self::$configData;
1647
-        }
1648
-
1649
-        $path = '';
1650
-        if (is_callable('\Phar::running') === true) {
1651
-            $path = \Phar::running(false);
1652
-        }
1653
-
1654
-        if ($path !== '') {
1655
-            $configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1656
-        } else {
1657
-            $configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1658
-            if (is_file($configFile) === false
1659
-                && strpos('@data_dir@', '@data_dir') === false
1660
-            ) {
1661
-                $configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
1662
-            }
1663
-        }
1664
-
1665
-        if (is_file($configFile) === false) {
1666
-            self::$configData = [];
1667
-            return [];
1668
-        }
1669
-
1670
-        if (is_readable($configFile) === false) {
1671
-            $error = 'ERROR: Config file '.$configFile.' is not readable'.PHP_EOL.PHP_EOL;
1672
-            throw new DeepExitException($error, 3);
1673
-        }
1674
-
1675
-        include $configFile;
1676
-        self::$configDataFile = $configFile;
1677
-        self::$configData     = $phpCodeSnifferConfig;
1678
-        return self::$configData;
1679
-
1680
-    }//end getAllConfigData()
1681
-
1682
-
1683
-    /**
1684
-     * Prints out the gathered config data.
1685
-     *
1686
-     * @param array $data The config data to print.
1687
-     *
1688
-     * @return void
1689
-     */
1690
-    public function printConfigData($data)
1691
-    {
1692
-        $max  = 0;
1693
-        $keys = array_keys($data);
1694
-        foreach ($keys as $key) {
1695
-            $len = strlen($key);
1696
-            if (strlen($key) > $max) {
1697
-                $max = $len;
1698
-            }
1699
-        }
1700
-
1701
-        if ($max === 0) {
1702
-            return;
1703
-        }
1704
-
1705
-        $max += 2;
1706
-        ksort($data);
1707
-        foreach ($data as $name => $value) {
1708
-            echo str_pad($name.': ', $max).$value.PHP_EOL;
1709
-        }
1710
-
1711
-    }//end printConfigData()
21
+	/**
22
+	 * The current version.
23
+	 *
24
+	 * @var string
25
+	 */
26
+	const VERSION = '3.4.2';
27
+
28
+	/**
29
+	 * Package stability; either stable, beta or alpha.
30
+	 *
31
+	 * @var string
32
+	 */
33
+	const STABILITY = 'stable';
34
+
35
+	/**
36
+	 * An array of settings that PHPCS and PHPCBF accept.
37
+	 *
38
+	 * This array is not meant to be accessed directly. Instead, use the settings
39
+	 * as if they are class member vars so the __get() and __set() magic methods
40
+	 * can be used to validate the values. For example, to set the verbosity level to
41
+	 * level 2, use $this->verbosity = 2; instead of accessing this property directly.
42
+	 *
43
+	 * The list of settings are:
44
+	 *
45
+	 * string[] files           The files and directories to check.
46
+	 * string[] standards       The standards being used for checking.
47
+	 * int      verbosity       How verbose the output should be.
48
+	 *                          0: no unnecessary output
49
+	 *                          1: basic output for files being checked
50
+	 *                          2: ruleset and file parsing output
51
+	 *                          3: sniff execution output
52
+	 * bool     interactive     Enable interactive checking mode.
53
+	 * bool     parallel        Check files in parallel.
54
+	 * bool     cache           Enable the use of the file cache.
55
+	 * bool     cacheFile       A file where the cache data should be written
56
+	 * bool     colors          Display colours in output.
57
+	 * bool     explain         Explain the coding standards.
58
+	 * bool     local           Process local files in directories only (no recursion).
59
+	 * bool     showSources     Show sniff source codes in report output.
60
+	 * bool     showProgress    Show basic progress information while running.
61
+	 * bool     quiet           Quiet mode; disables progress and verbose output.
62
+	 * bool     annotations     Process phpcs: annotations.
63
+	 * int      tabWidth        How many spaces each tab is worth.
64
+	 * string   encoding        The encoding of the files being checked.
65
+	 * string[] sniffs          The sniffs that should be used for checking.
66
+	 *                          If empty, all sniffs in the supplied standards will be used.
67
+	 * string[] exclude         The sniffs that should be excluded from checking.
68
+	 *                          If empty, all sniffs in the supplied standards will be used.
69
+	 * string[] ignored         Regular expressions used to ignore files and folders during checking.
70
+	 * string   reportFile      A file where the report output should be written.
71
+	 * string   generator       The documentation generator to use.
72
+	 * string   filter          The filter to use for the run.
73
+	 * string[] bootstrap       One of more files to include before the run begins.
74
+	 * int      reportWidth     The maximum number of columns that reports should use for output.
75
+	 *                          Set to "auto" for have this value changed to the width of the terminal.
76
+	 * int      errorSeverity   The minimum severity an error must have to be displayed.
77
+	 * int      warningSeverity The minimum severity a warning must have to be displayed.
78
+	 * bool     recordErrors    Record the content of error messages as well as error counts.
79
+	 * string   suffix          A suffix to add to fixed files.
80
+	 * string   basepath        A file system location to strip from the paths of files shown in reports.
81
+	 * bool     stdin           Read content from STDIN instead of supplied files.
82
+	 * string   stdinContent    Content passed directly to PHPCS on STDIN.
83
+	 * string   stdinPath       The path to use for content passed on STDIN.
84
+	 *
85
+	 * array<string, string>      extensions File extensions that should be checked, and what tokenizer to use.
86
+	 *                                       E.g., array('inc' => 'PHP');
87
+	 * array<string, string|null> reports    The reports to use for printing output after the run.
88
+	 *                                       The format of the array is:
89
+	 *                                           array(
90
+	 *                                            'reportName1' => 'outputFile',
91
+	 *                                            'reportName2' => null,
92
+	 *                                           );
93
+	 *                                       If the array value is NULL, the report will be written to the screen.
94
+	 *
95
+	 * string[] unknown Any arguments gathered on the command line that are unknown to us.
96
+	 *                  E.g., using `phpcs -c` will give array('c');
97
+	 *
98
+	 * @var array<string, mixed>
99
+	 */
100
+	private $settings = [
101
+		'files'           => null,
102
+		'standards'       => null,
103
+		'verbosity'       => null,
104
+		'interactive'     => null,
105
+		'parallel'        => null,
106
+		'cache'           => null,
107
+		'cacheFile'       => null,
108
+		'colors'          => null,
109
+		'explain'         => null,
110
+		'local'           => null,
111
+		'showSources'     => null,
112
+		'showProgress'    => null,
113
+		'quiet'           => null,
114
+		'annotations'     => null,
115
+		'tabWidth'        => null,
116
+		'encoding'        => null,
117
+		'extensions'      => null,
118
+		'sniffs'          => null,
119
+		'exclude'         => null,
120
+		'ignored'         => null,
121
+		'reportFile'      => null,
122
+		'generator'       => null,
123
+		'filter'          => null,
124
+		'bootstrap'       => null,
125
+		'reports'         => null,
126
+		'basepath'        => null,
127
+		'reportWidth'     => null,
128
+		'errorSeverity'   => null,
129
+		'warningSeverity' => null,
130
+		'recordErrors'    => null,
131
+		'suffix'          => null,
132
+		'stdin'           => null,
133
+		'stdinContent'    => null,
134
+		'stdinPath'       => null,
135
+		'unknown'         => null,
136
+	];
137
+
138
+	/**
139
+	 * Whether or not to kill the process when an unknown command line arg is found.
140
+	 *
141
+	 * If FALSE, arguments that are not command line options or file/directory paths
142
+	 * will be ignored and execution will continue. These values will be stored in
143
+	 * $this->unknown.
144
+	 *
145
+	 * @var boolean
146
+	 */
147
+	public $dieOnUnknownArg;
148
+
149
+	/**
150
+	 * The current command line arguments we are processing.
151
+	 *
152
+	 * @var string[]
153
+	 */
154
+	private $cliArgs = [];
155
+
156
+	/**
157
+	 * Command line values that the user has supplied directly.
158
+	 *
159
+	 * @var array<string, TRUE>
160
+	 */
161
+	private static $overriddenDefaults = [];
162
+
163
+	/**
164
+	 * Config file data that has been loaded for the run.
165
+	 *
166
+	 * @var array<string, string>
167
+	 */
168
+	private static $configData = null;
169
+
170
+	/**
171
+	 * The full path to the config data file that has been loaded.
172
+	 *
173
+	 * @var string
174
+	 */
175
+	private static $configDataFile = null;
176
+
177
+	/**
178
+	 * Automatically discovered executable utility paths.
179
+	 *
180
+	 * @var array<string, string>
181
+	 */
182
+	private static $executablePaths = [];
183
+
184
+
185
+	/**
186
+	 * Get the value of an inaccessible property.
187
+	 *
188
+	 * @param string $name The name of the property.
189
+	 *
190
+	 * @return mixed
191
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
192
+	 */
193
+	public function __get($name)
194
+	{
195
+		if (array_key_exists($name, $this->settings) === false) {
196
+			throw new RuntimeException("ERROR: unable to get value of property \"$name\"");
197
+		}
198
+
199
+		return $this->settings[$name];
200
+
201
+	}//end __get()
202
+
203
+
204
+	/**
205
+	 * Set the value of an inaccessible property.
206
+	 *
207
+	 * @param string $name  The name of the property.
208
+	 * @param mixed  $value The value of the property.
209
+	 *
210
+	 * @return void
211
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
212
+	 */
213
+	public function __set($name, $value)
214
+	{
215
+		if (array_key_exists($name, $this->settings) === false) {
216
+			throw new RuntimeException("Can't __set() $name; setting doesn't exist");
217
+		}
218
+
219
+		switch ($name) {
220
+		case 'reportWidth' :
221
+			// Support auto terminal width.
222
+			if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
223
+				$value = (int) $matches[1];
224
+			} else {
225
+				$value = (int) $value;
226
+			}
227
+			break;
228
+		case 'standards' :
229
+			$cleaned = [];
230
+
231
+			// Check if the standard name is valid, or if the case is invalid.
232
+			$installedStandards = Util\Standards::getInstalledStandards();
233
+			foreach ($value as $standard) {
234
+				foreach ($installedStandards as $validStandard) {
235
+					if (strtolower($standard) === strtolower($validStandard)) {
236
+						$standard = $validStandard;
237
+						break;
238
+					}
239
+				}
240
+
241
+				$cleaned[] = $standard;
242
+			}
243
+
244
+			$value = $cleaned;
245
+			break;
246
+		default :
247
+			// No validation required.
248
+			break;
249
+		}//end switch
250
+
251
+		$this->settings[$name] = $value;
252
+
253
+	}//end __set()
254
+
255
+
256
+	/**
257
+	 * Check if the value of an inaccessible property is set.
258
+	 *
259
+	 * @param string $name The name of the property.
260
+	 *
261
+	 * @return bool
262
+	 */
263
+	public function __isset($name)
264
+	{
265
+		return isset($this->settings[$name]);
266
+
267
+	}//end __isset()
268
+
269
+
270
+	/**
271
+	 * Unset the value of an inaccessible property.
272
+	 *
273
+	 * @param string $name The name of the property.
274
+	 *
275
+	 * @return void
276
+	 */
277
+	public function __unset($name)
278
+	{
279
+		$this->settings[$name] = null;
280
+
281
+	}//end __unset()
282
+
283
+
284
+	/**
285
+	 * Get the array of all config settings.
286
+	 *
287
+	 * @return array<string, mixed>
288
+	 */
289
+	public function getSettings()
290
+	{
291
+		return $this->settings;
292
+
293
+	}//end getSettings()
294
+
295
+
296
+	/**
297
+	 * Set the array of all config settings.
298
+	 *
299
+	 * @param array<string, mixed> $settings The array of config settings.
300
+	 *
301
+	 * @return void
302
+	 */
303
+	public function setSettings($settings)
304
+	{
305
+		return $this->settings = $settings;
306
+
307
+	}//end setSettings()
308
+
309
+
310
+	/**
311
+	 * Creates a Config object and populates it with command line values.
312
+	 *
313
+	 * @param array $cliArgs         An array of values gathered from CLI args.
314
+	 * @param bool  $dieOnUnknownArg Whether or not to kill the process when an
315
+	 *                               unknown command line arg is found.
316
+	 *
317
+	 * @return void
318
+	 */
319
+	public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
320
+	{
321
+		if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
322
+			// Let everything through during testing so that we can
323
+			// make use of PHPUnit command line arguments as well.
324
+			$this->dieOnUnknownArg = false;
325
+		} else {
326
+			$this->dieOnUnknownArg = $dieOnUnknownArg;
327
+		}
328
+
329
+		if (empty($cliArgs) === true) {
330
+			$cliArgs = $_SERVER['argv'];
331
+			array_shift($cliArgs);
332
+		}
333
+
334
+		$this->restoreDefaults();
335
+		$this->setCommandLineValues($cliArgs);
336
+
337
+		if (isset(self::$overriddenDefaults['standards']) === false) {
338
+			// They did not supply a standard to use.
339
+			// Look for a default ruleset in the current directory or higher.
340
+			$currentDir = getcwd();
341
+
342
+			$defaultFiles = [
343
+				'.phpcs.xml',
344
+				'phpcs.xml',
345
+				'.phpcs.xml.dist',
346
+				'phpcs.xml.dist',
347
+			];
348
+
349
+			do {
350
+				foreach ($defaultFiles as $defaultFilename) {
351
+					$default = $currentDir.DIRECTORY_SEPARATOR.$defaultFilename;
352
+					if (is_file($default) === true) {
353
+						$this->standards = [$default];
354
+						break(2);
355
+					}
356
+				}
357
+
358
+				$lastDir    = $currentDir;
359
+				$currentDir = dirname($currentDir);
360
+			} while ($currentDir !== '.' && $currentDir !== $lastDir);
361
+		}//end if
362
+
363
+		if (defined('STDIN') === false
364
+			|| strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'
365
+		) {
366
+			return;
367
+		}
368
+
369
+		$handle = fopen('php://stdin', 'r');
370
+
371
+		// Check for content on STDIN.
372
+		if ($this->stdin === true
373
+			|| (Util\Common::isStdinATTY() === false
374
+			&& feof($handle) === false)
375
+		) {
376
+			$readStreams = [$handle];
377
+			$writeSteams = null;
378
+
379
+			$fileContents = '';
380
+			while (is_resource($handle) === true && feof($handle) === false) {
381
+				// Set a timeout of 200ms.
382
+				if (stream_select($readStreams, $writeSteams, $writeSteams, 0, 200000) === 0) {
383
+					break;
384
+				}
385
+
386
+				$fileContents .= fgets($handle);
387
+			}
388
+
389
+			if (trim($fileContents) !== '') {
390
+				$this->stdin        = true;
391
+				$this->stdinContent = $fileContents;
392
+				self::$overriddenDefaults['stdin']        = true;
393
+				self::$overriddenDefaults['stdinContent'] = true;
394
+			}
395
+		}//end if
396
+
397
+		fclose($handle);
398
+
399
+	}//end __construct()
400
+
401
+
402
+	/**
403
+	 * Set the command line values.
404
+	 *
405
+	 * @param array $args An array of command line arguments to set.
406
+	 *
407
+	 * @return void
408
+	 */
409
+	public function setCommandLineValues($args)
410
+	{
411
+		$this->cliArgs = $args;
412
+		$numArgs       = count($args);
413
+
414
+		for ($i = 0; $i < $numArgs; $i++) {
415
+			$arg = $this->cliArgs[$i];
416
+			if ($arg === '') {
417
+				continue;
418
+			}
419
+
420
+			if ($arg{0} === '-') {
421
+				if ($arg === '-') {
422
+					// Asking to read from STDIN.
423
+					$this->stdin = true;
424
+					self::$overriddenDefaults['stdin'] = true;
425
+					continue;
426
+				}
427
+
428
+				if ($arg === '--') {
429
+					// Empty argument, ignore it.
430
+					continue;
431
+				}
432
+
433
+				if ($arg{1} === '-') {
434
+					$this->processLongArgument(substr($arg, 2), $i);
435
+				} else {
436
+					$switches = str_split($arg);
437
+					foreach ($switches as $switch) {
438
+						if ($switch === '-') {
439
+							continue;
440
+						}
441
+
442
+						$this->processShortArgument($switch, $i);
443
+					}
444
+				}
445
+			} else {
446
+				$this->processUnknownArgument($arg, $i);
447
+			}//end if
448
+		}//end for
449
+
450
+	}//end setCommandLineValues()
451
+
452
+
453
+	/**
454
+	 * Restore default values for all possible command line arguments.
455
+	 *
456
+	 * @return array
457
+	 */
458
+	public function restoreDefaults()
459
+	{
460
+		$this->files           = [];
461
+		$this->standards       = ['PEAR'];
462
+		$this->verbosity       = 0;
463
+		$this->interactive     = false;
464
+		$this->cache           = false;
465
+		$this->cacheFile       = null;
466
+		$this->colors          = false;
467
+		$this->explain         = false;
468
+		$this->local           = false;
469
+		$this->showSources     = false;
470
+		$this->showProgress    = false;
471
+		$this->quiet           = false;
472
+		$this->annotations     = true;
473
+		$this->parallel        = 1;
474
+		$this->tabWidth        = 0;
475
+		$this->encoding        = 'utf-8';
476
+		$this->extensions      = [
477
+			'php' => 'PHP',
478
+			'inc' => 'PHP',
479
+			'js'  => 'JS',
480
+			'css' => 'CSS',
481
+		];
482
+		$this->sniffs          = [];
483
+		$this->exclude         = [];
484
+		$this->ignored         = [];
485
+		$this->reportFile      = null;
486
+		$this->generator       = null;
487
+		$this->filter          = null;
488
+		$this->bootstrap       = [];
489
+		$this->basepath        = null;
490
+		$this->reports         = ['full' => null];
491
+		$this->reportWidth     = 'auto';
492
+		$this->errorSeverity   = 5;
493
+		$this->warningSeverity = 5;
494
+		$this->recordErrors    = true;
495
+		$this->suffix          = '';
496
+		$this->stdin           = false;
497
+		$this->stdinContent    = null;
498
+		$this->stdinPath       = null;
499
+		$this->unknown         = [];
500
+
501
+		$standard = self::getConfigData('default_standard');
502
+		if ($standard !== null) {
503
+			$this->standards = explode(',', $standard);
504
+		}
505
+
506
+		$reportFormat = self::getConfigData('report_format');
507
+		if ($reportFormat !== null) {
508
+			$this->reports = [$reportFormat => null];
509
+		}
510
+
511
+		$tabWidth = self::getConfigData('tab_width');
512
+		if ($tabWidth !== null) {
513
+			$this->tabWidth = (int) $tabWidth;
514
+		}
515
+
516
+		$encoding = self::getConfigData('encoding');
517
+		if ($encoding !== null) {
518
+			$this->encoding = strtolower($encoding);
519
+		}
520
+
521
+		$severity = self::getConfigData('severity');
522
+		if ($severity !== null) {
523
+			$this->errorSeverity   = (int) $severity;
524
+			$this->warningSeverity = (int) $severity;
525
+		}
526
+
527
+		$severity = self::getConfigData('error_severity');
528
+		if ($severity !== null) {
529
+			$this->errorSeverity = (int) $severity;
530
+		}
531
+
532
+		$severity = self::getConfigData('warning_severity');
533
+		if ($severity !== null) {
534
+			$this->warningSeverity = (int) $severity;
535
+		}
536
+
537
+		$showWarnings = self::getConfigData('show_warnings');
538
+		if ($showWarnings !== null) {
539
+			$showWarnings = (bool) $showWarnings;
540
+			if ($showWarnings === false) {
541
+				$this->warningSeverity = 0;
542
+			}
543
+		}
544
+
545
+		$reportWidth = self::getConfigData('report_width');
546
+		if ($reportWidth !== null) {
547
+			$this->reportWidth = $reportWidth;
548
+		}
549
+
550
+		$showProgress = self::getConfigData('show_progress');
551
+		if ($showProgress !== null) {
552
+			$this->showProgress = (bool) $showProgress;
553
+		}
554
+
555
+		$quiet = self::getConfigData('quiet');
556
+		if ($quiet !== null) {
557
+			$this->quiet = (bool) $quiet;
558
+		}
559
+
560
+		$colors = self::getConfigData('colors');
561
+		if ($colors !== null) {
562
+			$this->colors = (bool) $colors;
563
+		}
564
+
565
+		if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
566
+			$cache = self::getConfigData('cache');
567
+			if ($cache !== null) {
568
+				$this->cache = (bool) $cache;
569
+			}
570
+
571
+			$parallel = self::getConfigData('parallel');
572
+			if ($parallel !== null) {
573
+				$this->parallel = max((int) $parallel, 1);
574
+			}
575
+		}
576
+
577
+	}//end restoreDefaults()
578
+
579
+
580
+	/**
581
+	 * Processes a short (-e) command line argument.
582
+	 *
583
+	 * @param string $arg The command line argument.
584
+	 * @param int    $pos The position of the argument on the command line.
585
+	 *
586
+	 * @return void
587
+	 */
588
+	public function processShortArgument($arg, $pos)
589
+	{
590
+		switch ($arg) {
591
+		case 'h':
592
+		case '?':
593
+			ob_start();
594
+			$this->printUsage();
595
+			$output = ob_get_contents();
596
+			ob_end_clean();
597
+			throw new DeepExitException($output, 0);
598
+		case 'i' :
599
+			ob_start();
600
+			Util\Standards::printInstalledStandards();
601
+			$output = ob_get_contents();
602
+			ob_end_clean();
603
+			throw new DeepExitException($output, 0);
604
+		case 'v' :
605
+			if ($this->quiet === true) {
606
+				// Ignore when quiet mode is enabled.
607
+				break;
608
+			}
609
+
610
+			$this->verbosity++;
611
+			self::$overriddenDefaults['verbosity'] = true;
612
+			break;
613
+		case 'l' :
614
+			$this->local = true;
615
+			self::$overriddenDefaults['local'] = true;
616
+			break;
617
+		case 's' :
618
+			$this->showSources = true;
619
+			self::$overriddenDefaults['showSources'] = true;
620
+			break;
621
+		case 'a' :
622
+			$this->interactive = true;
623
+			self::$overriddenDefaults['interactive'] = true;
624
+			break;
625
+		case 'e':
626
+			$this->explain = true;
627
+			self::$overriddenDefaults['explain'] = true;
628
+			break;
629
+		case 'p' :
630
+			if ($this->quiet === true) {
631
+				// Ignore when quiet mode is enabled.
632
+				break;
633
+			}
634
+
635
+			$this->showProgress = true;
636
+			self::$overriddenDefaults['showProgress'] = true;
637
+			break;
638
+		case 'q' :
639
+			// Quiet mode disables a few other settings as well.
640
+			$this->quiet        = true;
641
+			$this->showProgress = false;
642
+			$this->verbosity    = 0;
643
+
644
+			self::$overriddenDefaults['quiet'] = true;
645
+			break;
646
+		case 'm' :
647
+			$this->recordErrors = false;
648
+			self::$overriddenDefaults['recordErrors'] = true;
649
+			break;
650
+		case 'd' :
651
+			$ini = explode('=', $this->cliArgs[($pos + 1)]);
652
+			$this->cliArgs[($pos + 1)] = '';
653
+			if (isset($ini[1]) === true) {
654
+				ini_set($ini[0], $ini[1]);
655
+			} else {
656
+				ini_set($ini[0], true);
657
+			}
658
+			break;
659
+		case 'n' :
660
+			if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
661
+				$this->warningSeverity = 0;
662
+				self::$overriddenDefaults['warningSeverity'] = true;
663
+			}
664
+			break;
665
+		case 'w' :
666
+			if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
667
+				$this->warningSeverity = $this->errorSeverity;
668
+				self::$overriddenDefaults['warningSeverity'] = true;
669
+			}
670
+			break;
671
+		default:
672
+			if ($this->dieOnUnknownArg === false) {
673
+				$unknown       = $this->unknown;
674
+				$unknown[]     = $arg;
675
+				$this->unknown = $unknown;
676
+			} else {
677
+				$this->processUnknownArgument('-'.$arg, $pos);
678
+			}
679
+		}//end switch
680
+
681
+	}//end processShortArgument()
682
+
683
+
684
+	/**
685
+	 * Processes a long (--example) command line argument.
686
+	 *
687
+	 * @param string $arg The command line argument.
688
+	 * @param int    $pos The position of the argument on the command line.
689
+	 *
690
+	 * @return void
691
+	 */
692
+	public function processLongArgument($arg, $pos)
693
+	{
694
+		switch ($arg) {
695
+		case 'help':
696
+			ob_start();
697
+			$this->printUsage();
698
+			$output = ob_get_contents();
699
+			ob_end_clean();
700
+			throw new DeepExitException($output, 0);
701
+		case 'version':
702
+			$output  = 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') ';
703
+			$output .= 'by Squiz (http://www.squiz.net)'.PHP_EOL;
704
+			throw new DeepExitException($output, 0);
705
+		case 'colors':
706
+			if (isset(self::$overriddenDefaults['colors']) === true) {
707
+				break;
708
+			}
709
+
710
+			$this->colors = true;
711
+			self::$overriddenDefaults['colors'] = true;
712
+			break;
713
+		case 'no-colors':
714
+			if (isset(self::$overriddenDefaults['colors']) === true) {
715
+				break;
716
+			}
717
+
718
+			$this->colors = false;
719
+			self::$overriddenDefaults['colors'] = true;
720
+			break;
721
+		case 'cache':
722
+			if (isset(self::$overriddenDefaults['cache']) === true) {
723
+				break;
724
+			}
725
+
726
+			if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
727
+				$this->cache = true;
728
+				self::$overriddenDefaults['cache'] = true;
729
+			}
730
+			break;
731
+		case 'no-cache':
732
+			if (isset(self::$overriddenDefaults['cache']) === true) {
733
+				break;
734
+			}
735
+
736
+			$this->cache = false;
737
+			self::$overriddenDefaults['cache'] = true;
738
+			break;
739
+		case 'ignore-annotations':
740
+			if (isset(self::$overriddenDefaults['annotations']) === true) {
741
+				break;
742
+			}
743
+
744
+			$this->annotations = false;
745
+			self::$overriddenDefaults['annotations'] = true;
746
+			break;
747
+		case 'config-set':
748
+			if (isset($this->cliArgs[($pos + 1)]) === false
749
+				|| isset($this->cliArgs[($pos + 2)]) === false
750
+			) {
751
+				$error  = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
752
+				$error .= $this->printShortUsage(true);
753
+				throw new DeepExitException($error, 3);
754
+			}
755
+
756
+			$key     = $this->cliArgs[($pos + 1)];
757
+			$value   = $this->cliArgs[($pos + 2)];
758
+			$current = self::getConfigData($key);
759
+
760
+			try {
761
+				$this->setConfigData($key, $value);
762
+			} catch (\Exception $e) {
763
+				throw new DeepExitException($e->getMessage().PHP_EOL, 3);
764
+			}
765
+
766
+			$output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
767
+
768
+			if ($current === null) {
769
+				$output .= "Config value \"$key\" added successfully".PHP_EOL;
770
+			} else {
771
+				$output .= "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL;
772
+			}
773
+			throw new DeepExitException($output, 0);
774
+		case 'config-delete':
775
+			if (isset($this->cliArgs[($pos + 1)]) === false) {
776
+				$error  = 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL;
777
+				$error .= $this->printShortUsage(true);
778
+				throw new DeepExitException($error, 3);
779
+			}
780
+
781
+			$output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
782
+
783
+			$key     = $this->cliArgs[($pos + 1)];
784
+			$current = self::getConfigData($key);
785
+			if ($current === null) {
786
+				$output .= "Config value \"$key\" has not been set".PHP_EOL;
787
+			} else {
788
+				try {
789
+					$this->setConfigData($key, null);
790
+				} catch (\Exception $e) {
791
+					throw new DeepExitException($e->getMessage().PHP_EOL, 3);
792
+				}
793
+
794
+				$output .= "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL;
795
+			}
796
+			throw new DeepExitException($output, 0);
797
+		case 'config-show':
798
+			ob_start();
799
+			$data = self::getAllConfigData();
800
+			echo 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
801
+			$this->printConfigData($data);
802
+			$output = ob_get_contents();
803
+			ob_end_clean();
804
+			throw new DeepExitException($output, 0);
805
+		case 'runtime-set':
806
+			if (isset($this->cliArgs[($pos + 1)]) === false
807
+				|| isset($this->cliArgs[($pos + 2)]) === false
808
+			) {
809
+				$error  = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
810
+				$error .= $this->printShortUsage(true);
811
+				throw new DeepExitException($error, 3);
812
+			}
813
+
814
+			$key   = $this->cliArgs[($pos + 1)];
815
+			$value = $this->cliArgs[($pos + 2)];
816
+			$this->cliArgs[($pos + 1)] = '';
817
+			$this->cliArgs[($pos + 2)] = '';
818
+			self::setConfigData($key, $value, true);
819
+			if (isset(self::$overriddenDefaults['runtime-set']) === false) {
820
+				self::$overriddenDefaults['runtime-set'] = [];
821
+			}
822
+
823
+			self::$overriddenDefaults['runtime-set'][$key] = true;
824
+			break;
825
+		default:
826
+			if (substr($arg, 0, 7) === 'sniffs=') {
827
+				if (isset(self::$overriddenDefaults['sniffs']) === true) {
828
+					break;
829
+				}
830
+
831
+				$sniffs = explode(',', substr($arg, 7));
832
+				foreach ($sniffs as $sniff) {
833
+					if (substr_count($sniff, '.') !== 2) {
834
+						$error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
835
+						$error .= $this->printShortUsage(true);
836
+						throw new DeepExitException($error, 3);
837
+					}
838
+				}
839
+
840
+				$this->sniffs = $sniffs;
841
+				self::$overriddenDefaults['sniffs'] = true;
842
+			} else if (substr($arg, 0, 8) === 'exclude=') {
843
+				if (isset(self::$overriddenDefaults['exclude']) === true) {
844
+					break;
845
+				}
846
+
847
+				$sniffs = explode(',', substr($arg, 8));
848
+				foreach ($sniffs as $sniff) {
849
+					if (substr_count($sniff, '.') !== 2) {
850
+						$error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
851
+						$error .= $this->printShortUsage(true);
852
+						throw new DeepExitException($error, 3);
853
+					}
854
+				}
855
+
856
+				$this->exclude = $sniffs;
857
+				self::$overriddenDefaults['exclude'] = true;
858
+			} else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
859
+				&& substr($arg, 0, 6) === 'cache='
860
+			) {
861
+				if ((isset(self::$overriddenDefaults['cache']) === true
862
+					&& $this->cache === false)
863
+					|| isset(self::$overriddenDefaults['cacheFile']) === true
864
+				) {
865
+					break;
866
+				}
867
+
868
+				// Turn caching on.
869
+				$this->cache = true;
870
+				self::$overriddenDefaults['cache'] = true;
871
+
872
+				$this->cacheFile = Util\Common::realpath(substr($arg, 6));
873
+
874
+				// It may not exist and return false instead.
875
+				if ($this->cacheFile === false) {
876
+					$this->cacheFile = substr($arg, 6);
877
+
878
+					$dir = dirname($this->cacheFile);
879
+					if (is_dir($dir) === false) {
880
+						$error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
881
+						$error .= $this->printShortUsage(true);
882
+						throw new DeepExitException($error, 3);
883
+					}
884
+
885
+					if ($dir === '.') {
886
+						// Passed cache file is a file in the current directory.
887
+						$this->cacheFile = getcwd().'/'.basename($this->cacheFile);
888
+					} else {
889
+						if ($dir{0} === '/') {
890
+							// An absolute path.
891
+							$dir = Util\Common::realpath($dir);
892
+						} else {
893
+							$dir = Util\Common::realpath(getcwd().'/'.$dir);
894
+						}
895
+
896
+						if ($dir !== false) {
897
+							// Cache file path is relative.
898
+							$this->cacheFile = $dir.'/'.basename($this->cacheFile);
899
+						}
900
+					}
901
+				}//end if
902
+
903
+				self::$overriddenDefaults['cacheFile'] = true;
904
+
905
+				if (is_dir($this->cacheFile) === true) {
906
+					$error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL;
907
+					$error .= $this->printShortUsage(true);
908
+					throw new DeepExitException($error, 3);
909
+				}
910
+			} else if (substr($arg, 0, 10) === 'bootstrap=') {
911
+				$files     = explode(',', substr($arg, 10));
912
+				$bootstrap = [];
913
+				foreach ($files as $file) {
914
+					$path = Util\Common::realpath($file);
915
+					if ($path === false) {
916
+						$error  = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
917
+						$error .= $this->printShortUsage(true);
918
+						throw new DeepExitException($error, 3);
919
+					}
920
+
921
+					$bootstrap[] = $path;
922
+				}
923
+
924
+				$this->bootstrap = array_merge($this->bootstrap, $bootstrap);
925
+				self::$overriddenDefaults['bootstrap'] = true;
926
+			} else if (substr($arg, 0, 10) === 'file-list=') {
927
+				$fileList = substr($arg, 10);
928
+				$path     = Util\Common::realpath($fileList);
929
+				if ($path === false) {
930
+					$error  = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
931
+					$error .= $this->printShortUsage(true);
932
+					throw new DeepExitException($error, 3);
933
+				}
934
+
935
+				$files = file($path);
936
+				foreach ($files as $inputFile) {
937
+					$inputFile = trim($inputFile);
938
+
939
+					// Skip empty lines.
940
+					if ($inputFile === '') {
941
+						continue;
942
+					}
943
+
944
+					$this->processFilePath($inputFile);
945
+				}
946
+			} else if (substr($arg, 0, 11) === 'stdin-path=') {
947
+				if (isset(self::$overriddenDefaults['stdinPath']) === true) {
948
+					break;
949
+				}
950
+
951
+				$this->stdinPath = Util\Common::realpath(substr($arg, 11));
952
+
953
+				// It may not exist and return false instead, so use whatever they gave us.
954
+				if ($this->stdinPath === false) {
955
+					$this->stdinPath = trim(substr($arg, 11));
956
+				}
957
+
958
+				self::$overriddenDefaults['stdinPath'] = true;
959
+			} else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
960
+				if (isset(self::$overriddenDefaults['reportFile']) === true) {
961
+					break;
962
+				}
963
+
964
+				$this->reportFile = Util\Common::realpath(substr($arg, 12));
965
+
966
+				// It may not exist and return false instead.
967
+				if ($this->reportFile === false) {
968
+					$this->reportFile = substr($arg, 12);
969
+
970
+					$dir = dirname($this->reportFile);
971
+					if (is_dir($dir) === false) {
972
+						$error  = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
973
+						$error .= $this->printShortUsage(true);
974
+						throw new DeepExitException($error, 3);
975
+					}
976
+
977
+					if ($dir === '.') {
978
+						// Passed report file is a file in the current directory.
979
+						$this->reportFile = getcwd().'/'.basename($this->reportFile);
980
+					} else {
981
+						if ($dir{0} === '/') {
982
+							// An absolute path.
983
+							$dir = Util\Common::realpath($dir);
984
+						} else {
985
+							$dir = Util\Common::realpath(getcwd().'/'.$dir);
986
+						}
987
+
988
+						if ($dir !== false) {
989
+							// Report file path is relative.
990
+							$this->reportFile = $dir.'/'.basename($this->reportFile);
991
+						}
992
+					}
993
+				}//end if
994
+
995
+				self::$overriddenDefaults['reportFile'] = true;
996
+
997
+				if (is_dir($this->reportFile) === true) {
998
+					$error  = 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL;
999
+					$error .= $this->printShortUsage(true);
1000
+					throw new DeepExitException($error, 3);
1001
+				}
1002
+			} else if (substr($arg, 0, 13) === 'report-width=') {
1003
+				if (isset(self::$overriddenDefaults['reportWidth']) === true) {
1004
+					break;
1005
+				}
1006
+
1007
+				$this->reportWidth = substr($arg, 13);
1008
+				self::$overriddenDefaults['reportWidth'] = true;
1009
+			} else if (substr($arg, 0, 9) === 'basepath=') {
1010
+				if (isset(self::$overriddenDefaults['basepath']) === true) {
1011
+					break;
1012
+				}
1013
+
1014
+				self::$overriddenDefaults['basepath'] = true;
1015
+
1016
+				if (substr($arg, 9) === '') {
1017
+					$this->basepath = null;
1018
+					break;
1019
+				}
1020
+
1021
+				$this->basepath = Util\Common::realpath(substr($arg, 9));
1022
+
1023
+				// It may not exist and return false instead.
1024
+				if ($this->basepath === false) {
1025
+					$this->basepath = substr($arg, 9);
1026
+				}
1027
+
1028
+				if (is_dir($this->basepath) === false) {
1029
+					$error  = 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1030
+					$error .= $this->printShortUsage(true);
1031
+					throw new DeepExitException($error, 3);
1032
+				}
1033
+			} else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) {
1034
+				$reports = [];
1035
+
1036
+				if ($arg[6] === '-') {
1037
+					// This is a report with file output.
1038
+					$split = strpos($arg, '=');
1039
+					if ($split === false) {
1040
+						$report = substr($arg, 7);
1041
+						$output = null;
1042
+					} else {
1043
+						$report = substr($arg, 7, ($split - 7));
1044
+						$output = substr($arg, ($split + 1));
1045
+						if ($output === false) {
1046
+							$output = null;
1047
+						} else {
1048
+							$dir = dirname($output);
1049
+							if (is_dir($dir) === false) {
1050
+								$error  = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1051
+								$error .= $this->printShortUsage(true);
1052
+								throw new DeepExitException($error, 3);
1053
+							}
1054
+
1055
+							if ($dir === '.') {
1056
+								// Passed report file is a filename in the current directory.
1057
+								$output = getcwd().'/'.basename($output);
1058
+							} else {
1059
+								if ($dir{0} === '/') {
1060
+									// An absolute path.
1061
+									$dir = Util\Common::realpath($dir);
1062
+								} else {
1063
+									$dir = Util\Common::realpath(getcwd().'/'.$dir);
1064
+								}
1065
+
1066
+								if ($dir !== false) {
1067
+									// Report file path is relative.
1068
+									$output = $dir.'/'.basename($output);
1069
+								}
1070
+							}
1071
+						}//end if
1072
+					}//end if
1073
+
1074
+					$reports[$report] = $output;
1075
+				} else {
1076
+					// This is a single report.
1077
+					if (isset(self::$overriddenDefaults['reports']) === true) {
1078
+						break;
1079
+					}
1080
+
1081
+					$reportNames = explode(',', substr($arg, 7));
1082
+					foreach ($reportNames as $report) {
1083
+						$reports[$report] = null;
1084
+					}
1085
+				}//end if
1086
+
1087
+				// Remove the default value so the CLI value overrides it.
1088
+				if (isset(self::$overriddenDefaults['reports']) === false) {
1089
+					$this->reports = $reports;
1090
+				} else {
1091
+					$this->reports = array_merge($this->reports, $reports);
1092
+				}
1093
+
1094
+				self::$overriddenDefaults['reports'] = true;
1095
+			} else if (substr($arg, 0, 7) === 'filter=') {
1096
+				if (isset(self::$overriddenDefaults['filter']) === true) {
1097
+					break;
1098
+				}
1099
+
1100
+				$this->filter = substr($arg, 7);
1101
+				self::$overriddenDefaults['filter'] = true;
1102
+			} else if (substr($arg, 0, 9) === 'standard=') {
1103
+				$standards = trim(substr($arg, 9));
1104
+				if ($standards !== '') {
1105
+					$this->standards = explode(',', $standards);
1106
+				}
1107
+
1108
+				self::$overriddenDefaults['standards'] = true;
1109
+			} else if (substr($arg, 0, 11) === 'extensions=') {
1110
+				if (isset(self::$overriddenDefaults['extensions']) === true) {
1111
+					break;
1112
+				}
1113
+
1114
+				$extensions    = explode(',', substr($arg, 11));
1115
+				$newExtensions = [];
1116
+				foreach ($extensions as $ext) {
1117
+					$slash = strpos($ext, '/');
1118
+					if ($slash !== false) {
1119
+						// They specified the tokenizer too.
1120
+						list($ext, $tokenizer) = explode('/', $ext);
1121
+						$newExtensions[$ext]   = strtoupper($tokenizer);
1122
+						continue;
1123
+					}
1124
+
1125
+					if (isset($this->extensions[$ext]) === true) {
1126
+						$newExtensions[$ext] = $this->extensions[$ext];
1127
+					} else {
1128
+						$newExtensions[$ext] = 'PHP';
1129
+					}
1130
+				}
1131
+
1132
+				$this->extensions = $newExtensions;
1133
+				self::$overriddenDefaults['extensions'] = true;
1134
+			} else if (substr($arg, 0, 7) === 'suffix=') {
1135
+				if (isset(self::$overriddenDefaults['suffix']) === true) {
1136
+					break;
1137
+				}
1138
+
1139
+				$this->suffix = substr($arg, 7);
1140
+				self::$overriddenDefaults['suffix'] = true;
1141
+			} else if (substr($arg, 0, 9) === 'parallel=') {
1142
+				if (isset(self::$overriddenDefaults['parallel']) === true) {
1143
+					break;
1144
+				}
1145
+
1146
+				$this->parallel = max((int) substr($arg, 9), 1);
1147
+				self::$overriddenDefaults['parallel'] = true;
1148
+			} else if (substr($arg, 0, 9) === 'severity=') {
1149
+				$this->errorSeverity   = (int) substr($arg, 9);
1150
+				$this->warningSeverity = $this->errorSeverity;
1151
+				if (isset(self::$overriddenDefaults['errorSeverity']) === false) {
1152
+					self::$overriddenDefaults['errorSeverity'] = true;
1153
+				}
1154
+
1155
+				if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
1156
+					self::$overriddenDefaults['warningSeverity'] = true;
1157
+				}
1158
+			} else if (substr($arg, 0, 15) === 'error-severity=') {
1159
+				if (isset(self::$overriddenDefaults['errorSeverity']) === true) {
1160
+					break;
1161
+				}
1162
+
1163
+				$this->errorSeverity = (int) substr($arg, 15);
1164
+				self::$overriddenDefaults['errorSeverity'] = true;
1165
+			} else if (substr($arg, 0, 17) === 'warning-severity=') {
1166
+				if (isset(self::$overriddenDefaults['warningSeverity']) === true) {
1167
+					break;
1168
+				}
1169
+
1170
+				$this->warningSeverity = (int) substr($arg, 17);
1171
+				self::$overriddenDefaults['warningSeverity'] = true;
1172
+			} else if (substr($arg, 0, 7) === 'ignore=') {
1173
+				if (isset(self::$overriddenDefaults['ignored']) === true) {
1174
+					break;
1175
+				}
1176
+
1177
+				// Split the ignore string on commas, unless the comma is escaped
1178
+				// using 1 or 3 slashes (\, or \\\,).
1179
+				$patterns = preg_split(
1180
+					'/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
1181
+					substr($arg, 7)
1182
+				);
1183
+
1184
+				$ignored = [];
1185
+				foreach ($patterns as $pattern) {
1186
+					$pattern = trim($pattern);
1187
+					if ($pattern === '') {
1188
+						continue;
1189
+					}
1190
+
1191
+					$ignored[$pattern] = 'absolute';
1192
+				}
1193
+
1194
+				$this->ignored = $ignored;
1195
+				self::$overriddenDefaults['ignored'] = true;
1196
+			} else if (substr($arg, 0, 10) === 'generator='
1197
+				&& PHP_CODESNIFFER_CBF === false
1198
+			) {
1199
+				if (isset(self::$overriddenDefaults['generator']) === true) {
1200
+					break;
1201
+				}
1202
+
1203
+				$this->generator = substr($arg, 10);
1204
+				self::$overriddenDefaults['generator'] = true;
1205
+			} else if (substr($arg, 0, 9) === 'encoding=') {
1206
+				if (isset(self::$overriddenDefaults['encoding']) === true) {
1207
+					break;
1208
+				}
1209
+
1210
+				$this->encoding = strtolower(substr($arg, 9));
1211
+				self::$overriddenDefaults['encoding'] = true;
1212
+			} else if (substr($arg, 0, 10) === 'tab-width=') {
1213
+				if (isset(self::$overriddenDefaults['tabWidth']) === true) {
1214
+					break;
1215
+				}
1216
+
1217
+				$this->tabWidth = (int) substr($arg, 10);
1218
+				self::$overriddenDefaults['tabWidth'] = true;
1219
+			} else {
1220
+				if ($this->dieOnUnknownArg === false) {
1221
+					$eqPos = strpos($arg, '=');
1222
+					try {
1223
+						if ($eqPos === false) {
1224
+							$this->values[$arg] = $arg;
1225
+						} else {
1226
+							$value = substr($arg, ($eqPos + 1));
1227
+							$arg   = substr($arg, 0, $eqPos);
1228
+							$this->values[$arg] = $value;
1229
+						}
1230
+					} catch (RuntimeException $e) {
1231
+						// Value is not valid, so just ignore it.
1232
+					}
1233
+				} else {
1234
+					$this->processUnknownArgument('--'.$arg, $pos);
1235
+				}
1236
+			}//end if
1237
+			break;
1238
+		}//end switch
1239
+
1240
+	}//end processLongArgument()
1241
+
1242
+
1243
+	/**
1244
+	 * Processes an unknown command line argument.
1245
+	 *
1246
+	 * Assumes all unknown arguments are files and folders to check.
1247
+	 *
1248
+	 * @param string $arg The command line argument.
1249
+	 * @param int    $pos The position of the argument on the command line.
1250
+	 *
1251
+	 * @return void
1252
+	 */
1253
+	public function processUnknownArgument($arg, $pos)
1254
+	{
1255
+		// We don't know about any additional switches; just files.
1256
+		if ($arg{0} === '-') {
1257
+			if ($this->dieOnUnknownArg === false) {
1258
+				return;
1259
+			}
1260
+
1261
+			$error  = "ERROR: option \"$arg\" not known".PHP_EOL.PHP_EOL;
1262
+			$error .= $this->printShortUsage(true);
1263
+			throw new DeepExitException($error, 3);
1264
+		}
1265
+
1266
+		$this->processFilePath($arg);
1267
+
1268
+	}//end processUnknownArgument()
1269
+
1270
+
1271
+	/**
1272
+	 * Processes a file path and add it to the file list.
1273
+	 *
1274
+	 * @param string $path The path to the file to add.
1275
+	 *
1276
+	 * @return void
1277
+	 */
1278
+	public function processFilePath($path)
1279
+	{
1280
+		// If we are processing STDIN, don't record any files to check.
1281
+		if ($this->stdin === true) {
1282
+			return;
1283
+		}
1284
+
1285
+		$file = Util\Common::realpath($path);
1286
+		if (file_exists($file) === false) {
1287
+			if ($this->dieOnUnknownArg === false) {
1288
+				return;
1289
+			}
1290
+
1291
+			$error  = 'ERROR: The file "'.$path.'" does not exist.'.PHP_EOL.PHP_EOL;
1292
+			$error .= $this->printShortUsage(true);
1293
+			throw new DeepExitException($error, 3);
1294
+		} else {
1295
+			// Can't modify the files array directly because it's not a real
1296
+			// class member, so need to use this little get/modify/set trick.
1297
+			$files       = $this->files;
1298
+			$files[]     = $file;
1299
+			$this->files = $files;
1300
+			self::$overriddenDefaults['files'] = true;
1301
+		}
1302
+
1303
+	}//end processFilePath()
1304
+
1305
+
1306
+	/**
1307
+	 * Prints out the usage information for this script.
1308
+	 *
1309
+	 * @return void
1310
+	 */
1311
+	public function printUsage()
1312
+	{
1313
+		echo PHP_EOL;
1314
+
1315
+		if (PHP_CODESNIFFER_CBF === true) {
1316
+			$this->printPHPCBFUsage();
1317
+		} else {
1318
+			$this->printPHPCSUsage();
1319
+		}
1320
+
1321
+		echo PHP_EOL;
1322
+
1323
+	}//end printUsage()
1324
+
1325
+
1326
+	/**
1327
+	 * Prints out the short usage information for this script.
1328
+	 *
1329
+	 * @param bool $return If TRUE, the usage string is returned
1330
+	 *                     instead of output to screen.
1331
+	 *
1332
+	 * @return string|void
1333
+	 */
1334
+	public function printShortUsage($return=false)
1335
+	{
1336
+		if (PHP_CODESNIFFER_CBF === true) {
1337
+			$usage = 'Run "phpcbf --help" for usage information';
1338
+		} else {
1339
+			$usage = 'Run "phpcs --help" for usage information';
1340
+		}
1341
+
1342
+		$usage .= PHP_EOL.PHP_EOL;
1343
+
1344
+		if ($return === true) {
1345
+			return $usage;
1346
+		}
1347
+
1348
+		echo $usage;
1349
+
1350
+	}//end printShortUsage()
1351
+
1352
+
1353
+	/**
1354
+	 * Prints out the usage information for PHPCS.
1355
+	 *
1356
+	 * @return void
1357
+	 */
1358
+	public function printPHPCSUsage()
1359
+	{
1360
+		echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]'.PHP_EOL;
1361
+		echo '  [--cache[=<cacheFile>]] [--no-cache] [--tab-width=<tabWidth>]'.PHP_EOL;
1362
+		echo '  [--report=<report>] [--report-file=<reportFile>] [--report-<report>=<reportFile>]'.PHP_EOL;
1363
+		echo '  [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]'.PHP_EOL;
1364
+		echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1365
+		echo '  [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
1366
+		echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]'.PHP_EOL;
1367
+		echo '  [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]'.PHP_EOL;
1368
+		echo '  [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]'.PHP_EOL;
1369
+		echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1370
+		echo PHP_EOL;
1371
+		echo ' -     Check STDIN instead of local files and directories'.PHP_EOL;
1372
+		echo ' -n    Do not print warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1373
+		echo ' -w    Print both warnings and errors (this is the default)'.PHP_EOL;
1374
+		echo ' -l    Local directory only, no recursion'.PHP_EOL;
1375
+		echo ' -s    Show sniff codes in all reports'.PHP_EOL;
1376
+		echo ' -a    Run interactively'.PHP_EOL;
1377
+		echo ' -e    Explain a standard by showing the sniffs it includes'.PHP_EOL;
1378
+		echo ' -p    Show progress of the run'.PHP_EOL;
1379
+		echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1380
+		echo ' -m    Stop error messages from being recorded'.PHP_EOL;
1381
+		echo '       (saves a lot of memory, but stops many reports from being used)'.PHP_EOL;
1382
+		echo ' -v    Print processed files'.PHP_EOL;
1383
+		echo ' -vv   Print ruleset and token output'.PHP_EOL;
1384
+		echo ' -vvv  Print sniff processing information'.PHP_EOL;
1385
+		echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1386
+		echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1387
+		echo PHP_EOL;
1388
+		echo ' --help                Print this help message'.PHP_EOL;
1389
+		echo ' --version             Print version information'.PHP_EOL;
1390
+		echo ' --colors              Use colors in output'.PHP_EOL;
1391
+		echo ' --no-colors           Do not use colors in output (this is the default)'.PHP_EOL;
1392
+		echo ' --cache               Cache results between runs'.PHP_EOL;
1393
+		echo ' --no-cache            Do not cache results between runs (this is the default)'.PHP_EOL;
1394
+		echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1395
+		echo PHP_EOL;
1396
+		echo ' <cacheFile>    Use a specific file for caching (uses a temporary file by default)'.PHP_EOL;
1397
+		echo ' <basepath>     A path to strip from the front of file paths inside reports'.PHP_EOL;
1398
+		echo ' <bootstrap>    A comma separated list of files to run before processing begins'.PHP_EOL;
1399
+		echo ' <encoding>     The encoding of the files being checked (default is utf-8)'.PHP_EOL;
1400
+		echo ' <extensions>   A comma separated list of file extensions to check'.PHP_EOL;
1401
+		echo '                The type of the file can be specified using: ext/type'.PHP_EOL;
1402
+		echo '                e.g., module/php,es/js'.PHP_EOL;
1403
+		echo ' <file>         One or more files and/or directories to check'.PHP_EOL;
1404
+		echo ' <fileList>     A file containing a list of files and/or directories to check (one per line)'.PHP_EOL;
1405
+		echo ' <filter>       Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1406
+		echo ' <generator>    Uses either the "HTML", "Markdown" or "Text" generator'.PHP_EOL;
1407
+		echo '                (forces documentation generation instead of checking)'.PHP_EOL;
1408
+		echo ' <patterns>     A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1409
+		echo ' <processes>    How many files should be checked simultaneously (default is 1)'.PHP_EOL;
1410
+		echo ' <report>       Print either the "full", "xml", "checkstyle", "csv"'.PHP_EOL;
1411
+		echo '                "json", "junit", "emacs", "source", "summary", "diff"'.PHP_EOL;
1412
+		echo '                "svnblame", "gitblame", "hgblame" or "notifysend" report,'.PHP_EOL;
1413
+		echo '                or specify the path to a custom report class'.PHP_EOL;
1414
+		echo '                (the "full" report is printed by default)'.PHP_EOL;
1415
+		echo ' <reportFile>   Write the report to the specified file path'.PHP_EOL;
1416
+		echo ' <reportWidth>  How many columns wide screen reports should be printed'.PHP_EOL;
1417
+		echo '                or set to "auto" to use current screen width, where supported'.PHP_EOL;
1418
+		echo ' <severity>     The minimum severity required to display an error or warning'.PHP_EOL;
1419
+		echo ' <sniffs>       A comma separated list of sniff codes to include or exclude from checking'.PHP_EOL;
1420
+		echo '                (all sniffs must be part of the specified standard)'.PHP_EOL;
1421
+		echo ' <standard>     The name or path of the coding standard to use'.PHP_EOL;
1422
+		echo ' <stdinPath>    If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1423
+		echo ' <tabWidth>     The number of spaces each tab represents'.PHP_EOL;
1424
+
1425
+	}//end printPHPCSUsage()
1426
+
1427
+
1428
+	/**
1429
+	 * Prints out the usage information for PHPCBF.
1430
+	 *
1431
+	 * @return void
1432
+	 */
1433
+	public function printPHPCBFUsage()
1434
+	{
1435
+		echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--ignore-annotations] [--bootstrap=<bootstrap>]'.PHP_EOL;
1436
+		echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--suffix=<suffix>]'.PHP_EOL;
1437
+		echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1438
+		echo '  [--tab-width=<tabWidth>] [--encoding=<encoding>] [--parallel=<processes>]'.PHP_EOL;
1439
+		echo '  [--basepath=<basepath>] [--extensions=<extensions>] [--ignore=<patterns>]'.PHP_EOL;
1440
+		echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1441
+		echo PHP_EOL;
1442
+		echo ' -     Fix STDIN instead of local files and directories'.PHP_EOL;
1443
+		echo ' -n    Do not fix warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1444
+		echo ' -w    Fix both warnings and errors (on by default)'.PHP_EOL;
1445
+		echo ' -l    Local directory only, no recursion'.PHP_EOL;
1446
+		echo ' -p    Show progress of the run'.PHP_EOL;
1447
+		echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1448
+		echo ' -v    Print processed files'.PHP_EOL;
1449
+		echo ' -vv   Print ruleset and token output'.PHP_EOL;
1450
+		echo ' -vvv  Print sniff processing information'.PHP_EOL;
1451
+		echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1452
+		echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1453
+		echo PHP_EOL;
1454
+		echo ' --help                Print this help message'.PHP_EOL;
1455
+		echo ' --version             Print version information'.PHP_EOL;
1456
+		echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1457
+		echo PHP_EOL;
1458
+		echo ' <basepath>    A path to strip from the front of file paths inside reports'.PHP_EOL;
1459
+		echo ' <bootstrap>   A comma separated list of files to run before processing begins'.PHP_EOL;
1460
+		echo ' <encoding>    The encoding of the files being fixed (default is utf-8)'.PHP_EOL;
1461
+		echo ' <extensions>  A comma separated list of file extensions to fix'.PHP_EOL;
1462
+		echo '               The type of the file can be specified using: ext/type'.PHP_EOL;
1463
+		echo '               e.g., module/php,es/js'.PHP_EOL;
1464
+		echo ' <file>        One or more files and/or directories to fix'.PHP_EOL;
1465
+		echo ' <fileList>    A file containing a list of files and/or directories to fix (one per line)'.PHP_EOL;
1466
+		echo ' <filter>      Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1467
+		echo ' <patterns>    A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1468
+		echo ' <processes>   How many files should be fixed simultaneously (default is 1)'.PHP_EOL;
1469
+		echo ' <severity>    The minimum severity required to fix an error or warning'.PHP_EOL;
1470
+		echo ' <sniffs>      A comma separated list of sniff codes to include or exclude from fixing'.PHP_EOL;
1471
+		echo '               (all sniffs must be part of the specified standard)'.PHP_EOL;
1472
+		echo ' <standard>    The name or path of the coding standard to use'.PHP_EOL;
1473
+		echo ' <stdinPath>   If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1474
+		echo ' <suffix>      Write modified files to a filename using this suffix'.PHP_EOL;
1475
+		echo '               ("diff" and "patch" are not used in this mode)'.PHP_EOL;
1476
+		echo ' <tabWidth>    The number of spaces each tab represents'.PHP_EOL;
1477
+
1478
+	}//end printPHPCBFUsage()
1479
+
1480
+
1481
+	/**
1482
+	 * Get a single config value.
1483
+	 *
1484
+	 * @param string $key The name of the config value.
1485
+	 *
1486
+	 * @return string|null
1487
+	 * @see    setConfigData()
1488
+	 * @see    getAllConfigData()
1489
+	 */
1490
+	public static function getConfigData($key)
1491
+	{
1492
+		$phpCodeSnifferConfig = self::getAllConfigData();
1493
+
1494
+		if ($phpCodeSnifferConfig === null) {
1495
+			return null;
1496
+		}
1497
+
1498
+		if (isset($phpCodeSnifferConfig[$key]) === false) {
1499
+			return null;
1500
+		}
1501
+
1502
+		return $phpCodeSnifferConfig[$key];
1503
+
1504
+	}//end getConfigData()
1505
+
1506
+
1507
+	/**
1508
+	 * Get the path to an executable utility.
1509
+	 *
1510
+	 * @param string $name The name of the executable utility.
1511
+	 *
1512
+	 * @return string|null
1513
+	 * @see    getConfigData()
1514
+	 */
1515
+	public static function getExecutablePath($name)
1516
+	{
1517
+		$data = self::getConfigData($name.'_path');
1518
+		if ($data !== null) {
1519
+			return $data;
1520
+		}
1521
+
1522
+		if ($name === "php") {
1523
+			// For php, we know the executable path. There's no need to look it up.
1524
+			return PHP_BINARY;
1525
+		}
1526
+
1527
+		if (array_key_exists($name, self::$executablePaths) === true) {
1528
+			return self::$executablePaths[$name];
1529
+		}
1530
+
1531
+		if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1532
+			$cmd = 'where '.escapeshellarg($name).' 2> nul';
1533
+		} else {
1534
+			$cmd = 'which '.escapeshellarg($name).' 2> /dev/null';
1535
+		}
1536
+
1537
+		$result = exec($cmd, $output, $retVal);
1538
+		if ($retVal !== 0) {
1539
+			$result = null;
1540
+		}
1541
+
1542
+		self::$executablePaths[$name] = $result;
1543
+		return $result;
1544
+
1545
+	}//end getExecutablePath()
1546
+
1547
+
1548
+	/**
1549
+	 * Set a single config value.
1550
+	 *
1551
+	 * @param string      $key   The name of the config value.
1552
+	 * @param string|null $value The value to set. If null, the config
1553
+	 *                           entry is deleted, reverting it to the
1554
+	 *                           default value.
1555
+	 * @param boolean     $temp  Set this config data temporarily for this
1556
+	 *                           script run. This will not write the config
1557
+	 *                           data to the config file.
1558
+	 *
1559
+	 * @return bool
1560
+	 * @see    getConfigData()
1561
+	 * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the config file can not be written.
1562
+	 */
1563
+	public static function setConfigData($key, $value, $temp=false)
1564
+	{
1565
+		if (isset(self::$overriddenDefaults['runtime-set']) === true
1566
+			&& isset(self::$overriddenDefaults['runtime-set'][$key]) === true
1567
+		) {
1568
+			return false;
1569
+		}
1570
+
1571
+		if ($temp === false) {
1572
+			$path = '';
1573
+			if (is_callable('\Phar::running') === true) {
1574
+				$path = \Phar::running(false);
1575
+			}
1576
+
1577
+			if ($path !== '') {
1578
+				$configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1579
+			} else {
1580
+				$configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1581
+				if (is_file($configFile) === false
1582
+					&& strpos('@data_dir@', '@data_dir') === false
1583
+				) {
1584
+					// If data_dir was replaced, this is a PEAR install and we can
1585
+					// use the PEAR data dir to store the conf file.
1586
+					$configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
1587
+				}
1588
+			}
1589
+
1590
+			if (is_file($configFile) === true
1591
+				&& is_writable($configFile) === false
1592
+			) {
1593
+				$error = 'ERROR: Config file '.$configFile.' is not writable'.PHP_EOL.PHP_EOL;
1594
+				throw new DeepExitException($error, 3);
1595
+			}
1596
+		}//end if
1597
+
1598
+		$phpCodeSnifferConfig = self::getAllConfigData();
1599
+
1600
+		if ($value === null) {
1601
+			if (isset($phpCodeSnifferConfig[$key]) === true) {
1602
+				unset($phpCodeSnifferConfig[$key]);
1603
+			}
1604
+		} else {
1605
+			$phpCodeSnifferConfig[$key] = $value;
1606
+		}
1607
+
1608
+		if ($temp === false) {
1609
+			$output  = '<'.'?php'."\n".' $phpCodeSnifferConfig = ';
1610
+			$output .= var_export($phpCodeSnifferConfig, true);
1611
+			$output .= "\n?".'>';
1612
+
1613
+			if (file_put_contents($configFile, $output) === false) {
1614
+				$error = 'ERROR: Config file '.$configFile.' could not be written'.PHP_EOL.PHP_EOL;
1615
+				throw new DeepExitException($error, 3);
1616
+			}
1617
+
1618
+			self::$configDataFile = $configFile;
1619
+		}
1620
+
1621
+		self::$configData = $phpCodeSnifferConfig;
1622
+
1623
+		// If the installed paths are being set, make sure all known
1624
+		// standards paths are added to the autoloader.
1625
+		if ($key === 'installed_paths') {
1626
+			$installedStandards = Util\Standards::getInstalledStandardDetails();
1627
+			foreach ($installedStandards as $name => $details) {
1628
+				Autoload::addSearchPath($details['path'], $details['namespace']);
1629
+			}
1630
+		}
1631
+
1632
+		return true;
1633
+
1634
+	}//end setConfigData()
1635
+
1636
+
1637
+	/**
1638
+	 * Get all config data.
1639
+	 *
1640
+	 * @return array<string, string>
1641
+	 * @see    getConfigData()
1642
+	 */
1643
+	public static function getAllConfigData()
1644
+	{
1645
+		if (self::$configData !== null) {
1646
+			return self::$configData;
1647
+		}
1648
+
1649
+		$path = '';
1650
+		if (is_callable('\Phar::running') === true) {
1651
+			$path = \Phar::running(false);
1652
+		}
1653
+
1654
+		if ($path !== '') {
1655
+			$configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1656
+		} else {
1657
+			$configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1658
+			if (is_file($configFile) === false
1659
+				&& strpos('@data_dir@', '@data_dir') === false
1660
+			) {
1661
+				$configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
1662
+			}
1663
+		}
1664
+
1665
+		if (is_file($configFile) === false) {
1666
+			self::$configData = [];
1667
+			return [];
1668
+		}
1669
+
1670
+		if (is_readable($configFile) === false) {
1671
+			$error = 'ERROR: Config file '.$configFile.' is not readable'.PHP_EOL.PHP_EOL;
1672
+			throw new DeepExitException($error, 3);
1673
+		}
1674
+
1675
+		include $configFile;
1676
+		self::$configDataFile = $configFile;
1677
+		self::$configData     = $phpCodeSnifferConfig;
1678
+		return self::$configData;
1679
+
1680
+	}//end getAllConfigData()
1681
+
1682
+
1683
+	/**
1684
+	 * Prints out the gathered config data.
1685
+	 *
1686
+	 * @param array $data The config data to print.
1687
+	 *
1688
+	 * @return void
1689
+	 */
1690
+	public function printConfigData($data)
1691
+	{
1692
+		$max  = 0;
1693
+		$keys = array_keys($data);
1694
+		foreach ($keys as $key) {
1695
+			$len = strlen($key);
1696
+			if (strlen($key) > $max) {
1697
+				$max = $len;
1698
+			}
1699
+		}
1700
+
1701
+		if ($max === 0) {
1702
+			return;
1703
+		}
1704
+
1705
+		$max += 2;
1706
+		ksort($data);
1707
+		foreach ($data as $name => $value) {
1708
+			echo str_pad($name.': ', $max).$value.PHP_EOL;
1709
+		}
1710
+
1711
+	}//end printConfigData()
1712 1712
 
1713 1713
 
1714 1714
 }//end class
Please login to merge, or discard this patch.
Switch Indentation   +660 added lines, -660 removed lines patch added patch discarded remove patch
@@ -217,35 +217,35 @@  discard block
 block discarded – undo
217 217
         }
218 218
 
219 219
         switch ($name) {
220
-        case 'reportWidth' :
221
-            // Support auto terminal width.
222
-            if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
223
-                $value = (int) $matches[1];
224
-            } else {
225
-                $value = (int) $value;
226
-            }
227
-            break;
228
-        case 'standards' :
229
-            $cleaned = [];
230
-
231
-            // Check if the standard name is valid, or if the case is invalid.
232
-            $installedStandards = Util\Standards::getInstalledStandards();
233
-            foreach ($value as $standard) {
234
-                foreach ($installedStandards as $validStandard) {
235
-                    if (strtolower($standard) === strtolower($validStandard)) {
236
-                        $standard = $validStandard;
237
-                        break;
238
-                    }
239
-                }
240
-
241
-                $cleaned[] = $standard;
242
-            }
243
-
244
-            $value = $cleaned;
245
-            break;
246
-        default :
247
-            // No validation required.
248
-            break;
220
+        	case 'reportWidth' :
221
+            	// Support auto terminal width.
222
+            	if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
223
+                	$value = (int) $matches[1];
224
+            	} else {
225
+                	$value = (int) $value;
226
+            	}
227
+            	break;
228
+        	case 'standards' :
229
+            	$cleaned = [];
230
+
231
+            	// Check if the standard name is valid, or if the case is invalid.
232
+            	$installedStandards = Util\Standards::getInstalledStandards();
233
+            	foreach ($value as $standard) {
234
+                	foreach ($installedStandards as $validStandard) {
235
+                    	if (strtolower($standard) === strtolower($validStandard)) {
236
+                        	$standard = $validStandard;
237
+                        	break;
238
+                    	}
239
+                	}
240
+
241
+                	$cleaned[] = $standard;
242
+            	}
243
+
244
+            	$value = $cleaned;
245
+            	break;
246
+        	default :
247
+            	// No validation required.
248
+            	break;
249 249
         }//end switch
250 250
 
251 251
         $this->settings[$name] = $value;
@@ -588,94 +588,94 @@  discard block
 block discarded – undo
588 588
     public function processShortArgument($arg, $pos)
589 589
     {
590 590
         switch ($arg) {
591
-        case 'h':
592
-        case '?':
593
-            ob_start();
594
-            $this->printUsage();
595
-            $output = ob_get_contents();
596
-            ob_end_clean();
597
-            throw new DeepExitException($output, 0);
598
-        case 'i' :
599
-            ob_start();
600
-            Util\Standards::printInstalledStandards();
601
-            $output = ob_get_contents();
602
-            ob_end_clean();
603
-            throw new DeepExitException($output, 0);
604
-        case 'v' :
605
-            if ($this->quiet === true) {
606
-                // Ignore when quiet mode is enabled.
607
-                break;
608
-            }
609
-
610
-            $this->verbosity++;
611
-            self::$overriddenDefaults['verbosity'] = true;
612
-            break;
613
-        case 'l' :
614
-            $this->local = true;
615
-            self::$overriddenDefaults['local'] = true;
616
-            break;
617
-        case 's' :
618
-            $this->showSources = true;
619
-            self::$overriddenDefaults['showSources'] = true;
620
-            break;
621
-        case 'a' :
622
-            $this->interactive = true;
623
-            self::$overriddenDefaults['interactive'] = true;
624
-            break;
625
-        case 'e':
626
-            $this->explain = true;
627
-            self::$overriddenDefaults['explain'] = true;
628
-            break;
629
-        case 'p' :
630
-            if ($this->quiet === true) {
631
-                // Ignore when quiet mode is enabled.
632
-                break;
633
-            }
634
-
635
-            $this->showProgress = true;
636
-            self::$overriddenDefaults['showProgress'] = true;
637
-            break;
638
-        case 'q' :
639
-            // Quiet mode disables a few other settings as well.
640
-            $this->quiet        = true;
641
-            $this->showProgress = false;
642
-            $this->verbosity    = 0;
643
-
644
-            self::$overriddenDefaults['quiet'] = true;
645
-            break;
646
-        case 'm' :
647
-            $this->recordErrors = false;
648
-            self::$overriddenDefaults['recordErrors'] = true;
649
-            break;
650
-        case 'd' :
651
-            $ini = explode('=', $this->cliArgs[($pos + 1)]);
652
-            $this->cliArgs[($pos + 1)] = '';
653
-            if (isset($ini[1]) === true) {
654
-                ini_set($ini[0], $ini[1]);
655
-            } else {
656
-                ini_set($ini[0], true);
657
-            }
658
-            break;
659
-        case 'n' :
660
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
661
-                $this->warningSeverity = 0;
662
-                self::$overriddenDefaults['warningSeverity'] = true;
663
-            }
664
-            break;
665
-        case 'w' :
666
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
667
-                $this->warningSeverity = $this->errorSeverity;
668
-                self::$overriddenDefaults['warningSeverity'] = true;
669
-            }
670
-            break;
671
-        default:
672
-            if ($this->dieOnUnknownArg === false) {
673
-                $unknown       = $this->unknown;
674
-                $unknown[]     = $arg;
675
-                $this->unknown = $unknown;
676
-            } else {
677
-                $this->processUnknownArgument('-'.$arg, $pos);
678
-            }
591
+        	case 'h':
592
+        	case '?':
593
+            	ob_start();
594
+            	$this->printUsage();
595
+            	$output = ob_get_contents();
596
+            	ob_end_clean();
597
+            	throw new DeepExitException($output, 0);
598
+        	case 'i' :
599
+            	ob_start();
600
+            	Util\Standards::printInstalledStandards();
601
+            	$output = ob_get_contents();
602
+            	ob_end_clean();
603
+            	throw new DeepExitException($output, 0);
604
+        	case 'v' :
605
+            	if ($this->quiet === true) {
606
+                	// Ignore when quiet mode is enabled.
607
+                	break;
608
+            	}
609
+
610
+            	$this->verbosity++;
611
+            	self::$overriddenDefaults['verbosity'] = true;
612
+            	break;
613
+        	case 'l' :
614
+            	$this->local = true;
615
+            	self::$overriddenDefaults['local'] = true;
616
+            	break;
617
+        	case 's' :
618
+            	$this->showSources = true;
619
+            	self::$overriddenDefaults['showSources'] = true;
620
+            	break;
621
+        	case 'a' :
622
+            	$this->interactive = true;
623
+            	self::$overriddenDefaults['interactive'] = true;
624
+            	break;
625
+        	case 'e':
626
+            	$this->explain = true;
627
+            	self::$overriddenDefaults['explain'] = true;
628
+            	break;
629
+        	case 'p' :
630
+            	if ($this->quiet === true) {
631
+                	// Ignore when quiet mode is enabled.
632
+                	break;
633
+            	}
634
+
635
+            	$this->showProgress = true;
636
+            	self::$overriddenDefaults['showProgress'] = true;
637
+            	break;
638
+        	case 'q' :
639
+            	// Quiet mode disables a few other settings as well.
640
+            	$this->quiet        = true;
641
+            	$this->showProgress = false;
642
+            	$this->verbosity    = 0;
643
+
644
+            	self::$overriddenDefaults['quiet'] = true;
645
+            	break;
646
+        	case 'm' :
647
+            	$this->recordErrors = false;
648
+            	self::$overriddenDefaults['recordErrors'] = true;
649
+            	break;
650
+        	case 'd' :
651
+            	$ini = explode('=', $this->cliArgs[($pos + 1)]);
652
+            	$this->cliArgs[($pos + 1)] = '';
653
+            	if (isset($ini[1]) === true) {
654
+                	ini_set($ini[0], $ini[1]);
655
+            	} else {
656
+                	ini_set($ini[0], true);
657
+            	}
658
+            	break;
659
+        	case 'n' :
660
+            	if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
661
+                	$this->warningSeverity = 0;
662
+                	self::$overriddenDefaults['warningSeverity'] = true;
663
+            	}
664
+            	break;
665
+        	case 'w' :
666
+            	if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
667
+                	$this->warningSeverity = $this->errorSeverity;
668
+                	self::$overriddenDefaults['warningSeverity'] = true;
669
+            	}
670
+            	break;
671
+        	default:
672
+            	if ($this->dieOnUnknownArg === false) {
673
+                	$unknown       = $this->unknown;
674
+                	$unknown[]     = $arg;
675
+                	$this->unknown = $unknown;
676
+            	} else {
677
+                	$this->processUnknownArgument('-'.$arg, $pos);
678
+            	}
679 679
         }//end switch
680 680
 
681 681
     }//end processShortArgument()
@@ -692,549 +692,549 @@  discard block
 block discarded – undo
692 692
     public function processLongArgument($arg, $pos)
693 693
     {
694 694
         switch ($arg) {
695
-        case 'help':
696
-            ob_start();
697
-            $this->printUsage();
698
-            $output = ob_get_contents();
699
-            ob_end_clean();
700
-            throw new DeepExitException($output, 0);
701
-        case 'version':
702
-            $output  = 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') ';
703
-            $output .= 'by Squiz (http://www.squiz.net)'.PHP_EOL;
704
-            throw new DeepExitException($output, 0);
705
-        case 'colors':
706
-            if (isset(self::$overriddenDefaults['colors']) === true) {
707
-                break;
708
-            }
709
-
710
-            $this->colors = true;
711
-            self::$overriddenDefaults['colors'] = true;
712
-            break;
713
-        case 'no-colors':
714
-            if (isset(self::$overriddenDefaults['colors']) === true) {
715
-                break;
716
-            }
717
-
718
-            $this->colors = false;
719
-            self::$overriddenDefaults['colors'] = true;
720
-            break;
721
-        case 'cache':
722
-            if (isset(self::$overriddenDefaults['cache']) === true) {
723
-                break;
724
-            }
725
-
726
-            if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
727
-                $this->cache = true;
728
-                self::$overriddenDefaults['cache'] = true;
729
-            }
730
-            break;
731
-        case 'no-cache':
732
-            if (isset(self::$overriddenDefaults['cache']) === true) {
733
-                break;
734
-            }
735
-
736
-            $this->cache = false;
737
-            self::$overriddenDefaults['cache'] = true;
738
-            break;
739
-        case 'ignore-annotations':
740
-            if (isset(self::$overriddenDefaults['annotations']) === true) {
741
-                break;
742
-            }
743
-
744
-            $this->annotations = false;
745
-            self::$overriddenDefaults['annotations'] = true;
746
-            break;
747
-        case 'config-set':
748
-            if (isset($this->cliArgs[($pos + 1)]) === false
749
-                || isset($this->cliArgs[($pos + 2)]) === false
750
-            ) {
751
-                $error  = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
752
-                $error .= $this->printShortUsage(true);
753
-                throw new DeepExitException($error, 3);
754
-            }
755
-
756
-            $key     = $this->cliArgs[($pos + 1)];
757
-            $value   = $this->cliArgs[($pos + 2)];
758
-            $current = self::getConfigData($key);
759
-
760
-            try {
761
-                $this->setConfigData($key, $value);
762
-            } catch (\Exception $e) {
763
-                throw new DeepExitException($e->getMessage().PHP_EOL, 3);
764
-            }
765
-
766
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
767
-
768
-            if ($current === null) {
769
-                $output .= "Config value \"$key\" added successfully".PHP_EOL;
770
-            } else {
771
-                $output .= "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL;
772
-            }
773
-            throw new DeepExitException($output, 0);
774
-        case 'config-delete':
775
-            if (isset($this->cliArgs[($pos + 1)]) === false) {
776
-                $error  = 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL;
777
-                $error .= $this->printShortUsage(true);
778
-                throw new DeepExitException($error, 3);
779
-            }
780
-
781
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
782
-
783
-            $key     = $this->cliArgs[($pos + 1)];
784
-            $current = self::getConfigData($key);
785
-            if ($current === null) {
786
-                $output .= "Config value \"$key\" has not been set".PHP_EOL;
787
-            } else {
788
-                try {
789
-                    $this->setConfigData($key, null);
790
-                } catch (\Exception $e) {
791
-                    throw new DeepExitException($e->getMessage().PHP_EOL, 3);
792
-                }
793
-
794
-                $output .= "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL;
795
-            }
796
-            throw new DeepExitException($output, 0);
797
-        case 'config-show':
798
-            ob_start();
799
-            $data = self::getAllConfigData();
800
-            echo 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
801
-            $this->printConfigData($data);
802
-            $output = ob_get_contents();
803
-            ob_end_clean();
804
-            throw new DeepExitException($output, 0);
805
-        case 'runtime-set':
806
-            if (isset($this->cliArgs[($pos + 1)]) === false
807
-                || isset($this->cliArgs[($pos + 2)]) === false
808
-            ) {
809
-                $error  = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
810
-                $error .= $this->printShortUsage(true);
811
-                throw new DeepExitException($error, 3);
812
-            }
813
-
814
-            $key   = $this->cliArgs[($pos + 1)];
815
-            $value = $this->cliArgs[($pos + 2)];
816
-            $this->cliArgs[($pos + 1)] = '';
817
-            $this->cliArgs[($pos + 2)] = '';
818
-            self::setConfigData($key, $value, true);
819
-            if (isset(self::$overriddenDefaults['runtime-set']) === false) {
820
-                self::$overriddenDefaults['runtime-set'] = [];
821
-            }
822
-
823
-            self::$overriddenDefaults['runtime-set'][$key] = true;
824
-            break;
825
-        default:
826
-            if (substr($arg, 0, 7) === 'sniffs=') {
827
-                if (isset(self::$overriddenDefaults['sniffs']) === true) {
828
-                    break;
829
-                }
830
-
831
-                $sniffs = explode(',', substr($arg, 7));
832
-                foreach ($sniffs as $sniff) {
833
-                    if (substr_count($sniff, '.') !== 2) {
834
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
835
-                        $error .= $this->printShortUsage(true);
836
-                        throw new DeepExitException($error, 3);
837
-                    }
838
-                }
839
-
840
-                $this->sniffs = $sniffs;
841
-                self::$overriddenDefaults['sniffs'] = true;
842
-            } else if (substr($arg, 0, 8) === 'exclude=') {
843
-                if (isset(self::$overriddenDefaults['exclude']) === true) {
844
-                    break;
845
-                }
846
-
847
-                $sniffs = explode(',', substr($arg, 8));
848
-                foreach ($sniffs as $sniff) {
849
-                    if (substr_count($sniff, '.') !== 2) {
850
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
851
-                        $error .= $this->printShortUsage(true);
852
-                        throw new DeepExitException($error, 3);
853
-                    }
854
-                }
855
-
856
-                $this->exclude = $sniffs;
857
-                self::$overriddenDefaults['exclude'] = true;
858
-            } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
859
-                && substr($arg, 0, 6) === 'cache='
860
-            ) {
861
-                if ((isset(self::$overriddenDefaults['cache']) === true
862
-                    && $this->cache === false)
863
-                    || isset(self::$overriddenDefaults['cacheFile']) === true
864
-                ) {
865
-                    break;
866
-                }
867
-
868
-                // Turn caching on.
869
-                $this->cache = true;
870
-                self::$overriddenDefaults['cache'] = true;
871
-
872
-                $this->cacheFile = Util\Common::realpath(substr($arg, 6));
873
-
874
-                // It may not exist and return false instead.
875
-                if ($this->cacheFile === false) {
876
-                    $this->cacheFile = substr($arg, 6);
877
-
878
-                    $dir = dirname($this->cacheFile);
879
-                    if (is_dir($dir) === false) {
880
-                        $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
881
-                        $error .= $this->printShortUsage(true);
882
-                        throw new DeepExitException($error, 3);
883
-                    }
884
-
885
-                    if ($dir === '.') {
886
-                        // Passed cache file is a file in the current directory.
887
-                        $this->cacheFile = getcwd().'/'.basename($this->cacheFile);
888
-                    } else {
889
-                        if ($dir{0} === '/') {
890
-                            // An absolute path.
891
-                            $dir = Util\Common::realpath($dir);
892
-                        } else {
893
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
894
-                        }
895
-
896
-                        if ($dir !== false) {
897
-                            // Cache file path is relative.
898
-                            $this->cacheFile = $dir.'/'.basename($this->cacheFile);
899
-                        }
900
-                    }
901
-                }//end if
902
-
903
-                self::$overriddenDefaults['cacheFile'] = true;
904
-
905
-                if (is_dir($this->cacheFile) === true) {
906
-                    $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL;
907
-                    $error .= $this->printShortUsage(true);
908
-                    throw new DeepExitException($error, 3);
909
-                }
910
-            } else if (substr($arg, 0, 10) === 'bootstrap=') {
911
-                $files     = explode(',', substr($arg, 10));
912
-                $bootstrap = [];
913
-                foreach ($files as $file) {
914
-                    $path = Util\Common::realpath($file);
915
-                    if ($path === false) {
916
-                        $error  = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
917
-                        $error .= $this->printShortUsage(true);
918
-                        throw new DeepExitException($error, 3);
919
-                    }
920
-
921
-                    $bootstrap[] = $path;
922
-                }
923
-
924
-                $this->bootstrap = array_merge($this->bootstrap, $bootstrap);
925
-                self::$overriddenDefaults['bootstrap'] = true;
926
-            } else if (substr($arg, 0, 10) === 'file-list=') {
927
-                $fileList = substr($arg, 10);
928
-                $path     = Util\Common::realpath($fileList);
929
-                if ($path === false) {
930
-                    $error  = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
931
-                    $error .= $this->printShortUsage(true);
932
-                    throw new DeepExitException($error, 3);
933
-                }
934
-
935
-                $files = file($path);
936
-                foreach ($files as $inputFile) {
937
-                    $inputFile = trim($inputFile);
938
-
939
-                    // Skip empty lines.
940
-                    if ($inputFile === '') {
941
-                        continue;
942
-                    }
943
-
944
-                    $this->processFilePath($inputFile);
945
-                }
946
-            } else if (substr($arg, 0, 11) === 'stdin-path=') {
947
-                if (isset(self::$overriddenDefaults['stdinPath']) === true) {
948
-                    break;
949
-                }
950
-
951
-                $this->stdinPath = Util\Common::realpath(substr($arg, 11));
952
-
953
-                // It may not exist and return false instead, so use whatever they gave us.
954
-                if ($this->stdinPath === false) {
955
-                    $this->stdinPath = trim(substr($arg, 11));
956
-                }
957
-
958
-                self::$overriddenDefaults['stdinPath'] = true;
959
-            } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
960
-                if (isset(self::$overriddenDefaults['reportFile']) === true) {
961
-                    break;
962
-                }
963
-
964
-                $this->reportFile = Util\Common::realpath(substr($arg, 12));
965
-
966
-                // It may not exist and return false instead.
967
-                if ($this->reportFile === false) {
968
-                    $this->reportFile = substr($arg, 12);
969
-
970
-                    $dir = dirname($this->reportFile);
971
-                    if (is_dir($dir) === false) {
972
-                        $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
973
-                        $error .= $this->printShortUsage(true);
974
-                        throw new DeepExitException($error, 3);
975
-                    }
976
-
977
-                    if ($dir === '.') {
978
-                        // Passed report file is a file in the current directory.
979
-                        $this->reportFile = getcwd().'/'.basename($this->reportFile);
980
-                    } else {
981
-                        if ($dir{0} === '/') {
982
-                            // An absolute path.
983
-                            $dir = Util\Common::realpath($dir);
984
-                        } else {
985
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
986
-                        }
987
-
988
-                        if ($dir !== false) {
989
-                            // Report file path is relative.
990
-                            $this->reportFile = $dir.'/'.basename($this->reportFile);
991
-                        }
992
-                    }
993
-                }//end if
994
-
995
-                self::$overriddenDefaults['reportFile'] = true;
996
-
997
-                if (is_dir($this->reportFile) === true) {
998
-                    $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL;
999
-                    $error .= $this->printShortUsage(true);
1000
-                    throw new DeepExitException($error, 3);
1001
-                }
1002
-            } else if (substr($arg, 0, 13) === 'report-width=') {
1003
-                if (isset(self::$overriddenDefaults['reportWidth']) === true) {
1004
-                    break;
1005
-                }
1006
-
1007
-                $this->reportWidth = substr($arg, 13);
1008
-                self::$overriddenDefaults['reportWidth'] = true;
1009
-            } else if (substr($arg, 0, 9) === 'basepath=') {
1010
-                if (isset(self::$overriddenDefaults['basepath']) === true) {
1011
-                    break;
1012
-                }
1013
-
1014
-                self::$overriddenDefaults['basepath'] = true;
1015
-
1016
-                if (substr($arg, 9) === '') {
1017
-                    $this->basepath = null;
1018
-                    break;
1019
-                }
1020
-
1021
-                $this->basepath = Util\Common::realpath(substr($arg, 9));
1022
-
1023
-                // It may not exist and return false instead.
1024
-                if ($this->basepath === false) {
1025
-                    $this->basepath = substr($arg, 9);
1026
-                }
1027
-
1028
-                if (is_dir($this->basepath) === false) {
1029
-                    $error  = 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1030
-                    $error .= $this->printShortUsage(true);
1031
-                    throw new DeepExitException($error, 3);
1032
-                }
1033
-            } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) {
1034
-                $reports = [];
1035
-
1036
-                if ($arg[6] === '-') {
1037
-                    // This is a report with file output.
1038
-                    $split = strpos($arg, '=');
1039
-                    if ($split === false) {
1040
-                        $report = substr($arg, 7);
1041
-                        $output = null;
1042
-                    } else {
1043
-                        $report = substr($arg, 7, ($split - 7));
1044
-                        $output = substr($arg, ($split + 1));
1045
-                        if ($output === false) {
1046
-                            $output = null;
1047
-                        } else {
1048
-                            $dir = dirname($output);
1049
-                            if (is_dir($dir) === false) {
1050
-                                $error  = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1051
-                                $error .= $this->printShortUsage(true);
1052
-                                throw new DeepExitException($error, 3);
1053
-                            }
1054
-
1055
-                            if ($dir === '.') {
1056
-                                // Passed report file is a filename in the current directory.
1057
-                                $output = getcwd().'/'.basename($output);
1058
-                            } else {
1059
-                                if ($dir{0} === '/') {
1060
-                                    // An absolute path.
1061
-                                    $dir = Util\Common::realpath($dir);
1062
-                                } else {
1063
-                                    $dir = Util\Common::realpath(getcwd().'/'.$dir);
1064
-                                }
1065
-
1066
-                                if ($dir !== false) {
1067
-                                    // Report file path is relative.
1068
-                                    $output = $dir.'/'.basename($output);
1069
-                                }
1070
-                            }
1071
-                        }//end if
1072
-                    }//end if
1073
-
1074
-                    $reports[$report] = $output;
1075
-                } else {
1076
-                    // This is a single report.
1077
-                    if (isset(self::$overriddenDefaults['reports']) === true) {
1078
-                        break;
1079
-                    }
1080
-
1081
-                    $reportNames = explode(',', substr($arg, 7));
1082
-                    foreach ($reportNames as $report) {
1083
-                        $reports[$report] = null;
1084
-                    }
1085
-                }//end if
1086
-
1087
-                // Remove the default value so the CLI value overrides it.
1088
-                if (isset(self::$overriddenDefaults['reports']) === false) {
1089
-                    $this->reports = $reports;
1090
-                } else {
1091
-                    $this->reports = array_merge($this->reports, $reports);
1092
-                }
1093
-
1094
-                self::$overriddenDefaults['reports'] = true;
1095
-            } else if (substr($arg, 0, 7) === 'filter=') {
1096
-                if (isset(self::$overriddenDefaults['filter']) === true) {
1097
-                    break;
1098
-                }
1099
-
1100
-                $this->filter = substr($arg, 7);
1101
-                self::$overriddenDefaults['filter'] = true;
1102
-            } else if (substr($arg, 0, 9) === 'standard=') {
1103
-                $standards = trim(substr($arg, 9));
1104
-                if ($standards !== '') {
1105
-                    $this->standards = explode(',', $standards);
1106
-                }
1107
-
1108
-                self::$overriddenDefaults['standards'] = true;
1109
-            } else if (substr($arg, 0, 11) === 'extensions=') {
1110
-                if (isset(self::$overriddenDefaults['extensions']) === true) {
1111
-                    break;
1112
-                }
1113
-
1114
-                $extensions    = explode(',', substr($arg, 11));
1115
-                $newExtensions = [];
1116
-                foreach ($extensions as $ext) {
1117
-                    $slash = strpos($ext, '/');
1118
-                    if ($slash !== false) {
1119
-                        // They specified the tokenizer too.
1120
-                        list($ext, $tokenizer) = explode('/', $ext);
1121
-                        $newExtensions[$ext]   = strtoupper($tokenizer);
1122
-                        continue;
1123
-                    }
1124
-
1125
-                    if (isset($this->extensions[$ext]) === true) {
1126
-                        $newExtensions[$ext] = $this->extensions[$ext];
1127
-                    } else {
1128
-                        $newExtensions[$ext] = 'PHP';
1129
-                    }
1130
-                }
1131
-
1132
-                $this->extensions = $newExtensions;
1133
-                self::$overriddenDefaults['extensions'] = true;
1134
-            } else if (substr($arg, 0, 7) === 'suffix=') {
1135
-                if (isset(self::$overriddenDefaults['suffix']) === true) {
1136
-                    break;
1137
-                }
1138
-
1139
-                $this->suffix = substr($arg, 7);
1140
-                self::$overriddenDefaults['suffix'] = true;
1141
-            } else if (substr($arg, 0, 9) === 'parallel=') {
1142
-                if (isset(self::$overriddenDefaults['parallel']) === true) {
1143
-                    break;
1144
-                }
1145
-
1146
-                $this->parallel = max((int) substr($arg, 9), 1);
1147
-                self::$overriddenDefaults['parallel'] = true;
1148
-            } else if (substr($arg, 0, 9) === 'severity=') {
1149
-                $this->errorSeverity   = (int) substr($arg, 9);
1150
-                $this->warningSeverity = $this->errorSeverity;
1151
-                if (isset(self::$overriddenDefaults['errorSeverity']) === false) {
1152
-                    self::$overriddenDefaults['errorSeverity'] = true;
1153
-                }
1154
-
1155
-                if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
1156
-                    self::$overriddenDefaults['warningSeverity'] = true;
1157
-                }
1158
-            } else if (substr($arg, 0, 15) === 'error-severity=') {
1159
-                if (isset(self::$overriddenDefaults['errorSeverity']) === true) {
1160
-                    break;
1161
-                }
1162
-
1163
-                $this->errorSeverity = (int) substr($arg, 15);
1164
-                self::$overriddenDefaults['errorSeverity'] = true;
1165
-            } else if (substr($arg, 0, 17) === 'warning-severity=') {
1166
-                if (isset(self::$overriddenDefaults['warningSeverity']) === true) {
1167
-                    break;
1168
-                }
1169
-
1170
-                $this->warningSeverity = (int) substr($arg, 17);
1171
-                self::$overriddenDefaults['warningSeverity'] = true;
1172
-            } else if (substr($arg, 0, 7) === 'ignore=') {
1173
-                if (isset(self::$overriddenDefaults['ignored']) === true) {
1174
-                    break;
1175
-                }
1176
-
1177
-                // Split the ignore string on commas, unless the comma is escaped
1178
-                // using 1 or 3 slashes (\, or \\\,).
1179
-                $patterns = preg_split(
1180
-                    '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
1181
-                    substr($arg, 7)
1182
-                );
1183
-
1184
-                $ignored = [];
1185
-                foreach ($patterns as $pattern) {
1186
-                    $pattern = trim($pattern);
1187
-                    if ($pattern === '') {
1188
-                        continue;
1189
-                    }
1190
-
1191
-                    $ignored[$pattern] = 'absolute';
1192
-                }
1193
-
1194
-                $this->ignored = $ignored;
1195
-                self::$overriddenDefaults['ignored'] = true;
1196
-            } else if (substr($arg, 0, 10) === 'generator='
1197
-                && PHP_CODESNIFFER_CBF === false
1198
-            ) {
1199
-                if (isset(self::$overriddenDefaults['generator']) === true) {
1200
-                    break;
1201
-                }
1202
-
1203
-                $this->generator = substr($arg, 10);
1204
-                self::$overriddenDefaults['generator'] = true;
1205
-            } else if (substr($arg, 0, 9) === 'encoding=') {
1206
-                if (isset(self::$overriddenDefaults['encoding']) === true) {
1207
-                    break;
1208
-                }
1209
-
1210
-                $this->encoding = strtolower(substr($arg, 9));
1211
-                self::$overriddenDefaults['encoding'] = true;
1212
-            } else if (substr($arg, 0, 10) === 'tab-width=') {
1213
-                if (isset(self::$overriddenDefaults['tabWidth']) === true) {
1214
-                    break;
1215
-                }
1216
-
1217
-                $this->tabWidth = (int) substr($arg, 10);
1218
-                self::$overriddenDefaults['tabWidth'] = true;
1219
-            } else {
1220
-                if ($this->dieOnUnknownArg === false) {
1221
-                    $eqPos = strpos($arg, '=');
1222
-                    try {
1223
-                        if ($eqPos === false) {
1224
-                            $this->values[$arg] = $arg;
1225
-                        } else {
1226
-                            $value = substr($arg, ($eqPos + 1));
1227
-                            $arg   = substr($arg, 0, $eqPos);
1228
-                            $this->values[$arg] = $value;
1229
-                        }
1230
-                    } catch (RuntimeException $e) {
1231
-                        // Value is not valid, so just ignore it.
1232
-                    }
1233
-                } else {
1234
-                    $this->processUnknownArgument('--'.$arg, $pos);
1235
-                }
1236
-            }//end if
1237
-            break;
695
+        	case 'help':
696
+            	ob_start();
697
+            	$this->printUsage();
698
+            	$output = ob_get_contents();
699
+            	ob_end_clean();
700
+            	throw new DeepExitException($output, 0);
701
+        	case 'version':
702
+            	$output  = 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') ';
703
+            	$output .= 'by Squiz (http://www.squiz.net)'.PHP_EOL;
704
+            	throw new DeepExitException($output, 0);
705
+        	case 'colors':
706
+            	if (isset(self::$overriddenDefaults['colors']) === true) {
707
+                	break;
708
+            	}
709
+
710
+            	$this->colors = true;
711
+            	self::$overriddenDefaults['colors'] = true;
712
+            	break;
713
+        	case 'no-colors':
714
+            	if (isset(self::$overriddenDefaults['colors']) === true) {
715
+                	break;
716
+            	}
717
+
718
+            	$this->colors = false;
719
+            	self::$overriddenDefaults['colors'] = true;
720
+            	break;
721
+        	case 'cache':
722
+            	if (isset(self::$overriddenDefaults['cache']) === true) {
723
+                	break;
724
+            	}
725
+
726
+            	if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
727
+                	$this->cache = true;
728
+                	self::$overriddenDefaults['cache'] = true;
729
+            	}
730
+            	break;
731
+        	case 'no-cache':
732
+            	if (isset(self::$overriddenDefaults['cache']) === true) {
733
+                	break;
734
+            	}
735
+
736
+            	$this->cache = false;
737
+            	self::$overriddenDefaults['cache'] = true;
738
+            	break;
739
+        	case 'ignore-annotations':
740
+            	if (isset(self::$overriddenDefaults['annotations']) === true) {
741
+                	break;
742
+            	}
743
+
744
+            	$this->annotations = false;
745
+            	self::$overriddenDefaults['annotations'] = true;
746
+            	break;
747
+        	case 'config-set':
748
+            	if (isset($this->cliArgs[($pos + 1)]) === false
749
+                	|| isset($this->cliArgs[($pos + 2)]) === false
750
+            	) {
751
+                	$error  = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
752
+                	$error .= $this->printShortUsage(true);
753
+                	throw new DeepExitException($error, 3);
754
+            	}
755
+
756
+            	$key     = $this->cliArgs[($pos + 1)];
757
+            	$value   = $this->cliArgs[($pos + 2)];
758
+            	$current = self::getConfigData($key);
759
+
760
+            	try {
761
+                	$this->setConfigData($key, $value);
762
+            	} catch (\Exception $e) {
763
+                	throw new DeepExitException($e->getMessage().PHP_EOL, 3);
764
+            	}
765
+
766
+            	$output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
767
+
768
+            	if ($current === null) {
769
+                	$output .= "Config value \"$key\" added successfully".PHP_EOL;
770
+            	} else {
771
+                	$output .= "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL;
772
+            	}
773
+            	throw new DeepExitException($output, 0);
774
+        	case 'config-delete':
775
+            	if (isset($this->cliArgs[($pos + 1)]) === false) {
776
+                	$error  = 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL;
777
+                	$error .= $this->printShortUsage(true);
778
+                	throw new DeepExitException($error, 3);
779
+            	}
780
+
781
+            	$output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
782
+
783
+            	$key     = $this->cliArgs[($pos + 1)];
784
+            	$current = self::getConfigData($key);
785
+            	if ($current === null) {
786
+                	$output .= "Config value \"$key\" has not been set".PHP_EOL;
787
+            	} else {
788
+                	try {
789
+                    	$this->setConfigData($key, null);
790
+                	} catch (\Exception $e) {
791
+                    	throw new DeepExitException($e->getMessage().PHP_EOL, 3);
792
+                	}
793
+
794
+                	$output .= "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL;
795
+            	}
796
+            	throw new DeepExitException($output, 0);
797
+        	case 'config-show':
798
+            	ob_start();
799
+            	$data = self::getAllConfigData();
800
+            	echo 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
801
+            	$this->printConfigData($data);
802
+            	$output = ob_get_contents();
803
+            	ob_end_clean();
804
+            	throw new DeepExitException($output, 0);
805
+        	case 'runtime-set':
806
+            	if (isset($this->cliArgs[($pos + 1)]) === false
807
+                	|| isset($this->cliArgs[($pos + 2)]) === false
808
+            	) {
809
+                	$error  = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
810
+                	$error .= $this->printShortUsage(true);
811
+                	throw new DeepExitException($error, 3);
812
+            	}
813
+
814
+            	$key   = $this->cliArgs[($pos + 1)];
815
+            	$value = $this->cliArgs[($pos + 2)];
816
+            	$this->cliArgs[($pos + 1)] = '';
817
+            	$this->cliArgs[($pos + 2)] = '';
818
+            	self::setConfigData($key, $value, true);
819
+            	if (isset(self::$overriddenDefaults['runtime-set']) === false) {
820
+                	self::$overriddenDefaults['runtime-set'] = [];
821
+            	}
822
+
823
+            	self::$overriddenDefaults['runtime-set'][$key] = true;
824
+            	break;
825
+        	default:
826
+            	if (substr($arg, 0, 7) === 'sniffs=') {
827
+                	if (isset(self::$overriddenDefaults['sniffs']) === true) {
828
+                    	break;
829
+                	}
830
+
831
+                	$sniffs = explode(',', substr($arg, 7));
832
+                	foreach ($sniffs as $sniff) {
833
+                    	if (substr_count($sniff, '.') !== 2) {
834
+                        	$error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
835
+                        	$error .= $this->printShortUsage(true);
836
+                        	throw new DeepExitException($error, 3);
837
+                    	}
838
+                	}
839
+
840
+                	$this->sniffs = $sniffs;
841
+                	self::$overriddenDefaults['sniffs'] = true;
842
+            	} else if (substr($arg, 0, 8) === 'exclude=') {
843
+                	if (isset(self::$overriddenDefaults['exclude']) === true) {
844
+                    	break;
845
+                	}
846
+
847
+                	$sniffs = explode(',', substr($arg, 8));
848
+                	foreach ($sniffs as $sniff) {
849
+                    	if (substr_count($sniff, '.') !== 2) {
850
+                        	$error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
851
+                        	$error .= $this->printShortUsage(true);
852
+                        	throw new DeepExitException($error, 3);
853
+                    	}
854
+                	}
855
+
856
+                	$this->exclude = $sniffs;
857
+                	self::$overriddenDefaults['exclude'] = true;
858
+            	} else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
859
+                	&& substr($arg, 0, 6) === 'cache='
860
+            	) {
861
+                	if ((isset(self::$overriddenDefaults['cache']) === true
862
+                    	&& $this->cache === false)
863
+                    	|| isset(self::$overriddenDefaults['cacheFile']) === true
864
+                	) {
865
+                    	break;
866
+                	}
867
+
868
+                	// Turn caching on.
869
+                	$this->cache = true;
870
+                	self::$overriddenDefaults['cache'] = true;
871
+
872
+                	$this->cacheFile = Util\Common::realpath(substr($arg, 6));
873
+
874
+                	// It may not exist and return false instead.
875
+                	if ($this->cacheFile === false) {
876
+                    	$this->cacheFile = substr($arg, 6);
877
+
878
+                    	$dir = dirname($this->cacheFile);
879
+                    	if (is_dir($dir) === false) {
880
+                        	$error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
881
+                        	$error .= $this->printShortUsage(true);
882
+                        	throw new DeepExitException($error, 3);
883
+                    	}
884
+
885
+                    	if ($dir === '.') {
886
+                        	// Passed cache file is a file in the current directory.
887
+                        	$this->cacheFile = getcwd().'/'.basename($this->cacheFile);
888
+                    	} else {
889
+                        	if ($dir{0} === '/') {
890
+                            	// An absolute path.
891
+                            	$dir = Util\Common::realpath($dir);
892
+                        	} else {
893
+                            	$dir = Util\Common::realpath(getcwd().'/'.$dir);
894
+                        	}
895
+
896
+                        	if ($dir !== false) {
897
+                            	// Cache file path is relative.
898
+                            	$this->cacheFile = $dir.'/'.basename($this->cacheFile);
899
+                        	}
900
+                    	}
901
+                	}//end if
902
+
903
+                	self::$overriddenDefaults['cacheFile'] = true;
904
+
905
+                	if (is_dir($this->cacheFile) === true) {
906
+                    	$error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL;
907
+                    	$error .= $this->printShortUsage(true);
908
+                    	throw new DeepExitException($error, 3);
909
+                	}
910
+            	} else if (substr($arg, 0, 10) === 'bootstrap=') {
911
+                	$files     = explode(',', substr($arg, 10));
912
+                	$bootstrap = [];
913
+                	foreach ($files as $file) {
914
+                    	$path = Util\Common::realpath($file);
915
+                    	if ($path === false) {
916
+                        	$error  = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
917
+                        	$error .= $this->printShortUsage(true);
918
+                        	throw new DeepExitException($error, 3);
919
+                    	}
920
+
921
+                    	$bootstrap[] = $path;
922
+                	}
923
+
924
+                	$this->bootstrap = array_merge($this->bootstrap, $bootstrap);
925
+                	self::$overriddenDefaults['bootstrap'] = true;
926
+            	} else if (substr($arg, 0, 10) === 'file-list=') {
927
+                	$fileList = substr($arg, 10);
928
+                	$path     = Util\Common::realpath($fileList);
929
+                	if ($path === false) {
930
+                    	$error  = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
931
+                    	$error .= $this->printShortUsage(true);
932
+                    	throw new DeepExitException($error, 3);
933
+                	}
934
+
935
+                	$files = file($path);
936
+                	foreach ($files as $inputFile) {
937
+                    	$inputFile = trim($inputFile);
938
+
939
+                    	// Skip empty lines.
940
+                    	if ($inputFile === '') {
941
+                        	continue;
942
+                    	}
943
+
944
+                    	$this->processFilePath($inputFile);
945
+                	}
946
+            	} else if (substr($arg, 0, 11) === 'stdin-path=') {
947
+                	if (isset(self::$overriddenDefaults['stdinPath']) === true) {
948
+                    	break;
949
+                	}
950
+
951
+                	$this->stdinPath = Util\Common::realpath(substr($arg, 11));
952
+
953
+                	// It may not exist and return false instead, so use whatever they gave us.
954
+                	if ($this->stdinPath === false) {
955
+                    	$this->stdinPath = trim(substr($arg, 11));
956
+                	}
957
+
958
+                	self::$overriddenDefaults['stdinPath'] = true;
959
+            	} else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
960
+                	if (isset(self::$overriddenDefaults['reportFile']) === true) {
961
+                    	break;
962
+                	}
963
+
964
+                	$this->reportFile = Util\Common::realpath(substr($arg, 12));
965
+
966
+                	// It may not exist and return false instead.
967
+                	if ($this->reportFile === false) {
968
+                    	$this->reportFile = substr($arg, 12);
969
+
970
+                    	$dir = dirname($this->reportFile);
971
+                    	if (is_dir($dir) === false) {
972
+                        	$error  = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
973
+                        	$error .= $this->printShortUsage(true);
974
+                        	throw new DeepExitException($error, 3);
975
+                    	}
976
+
977
+                    	if ($dir === '.') {
978
+                        	// Passed report file is a file in the current directory.
979
+                        	$this->reportFile = getcwd().'/'.basename($this->reportFile);
980
+                    	} else {
981
+                        	if ($dir{0} === '/') {
982
+                            	// An absolute path.
983
+                            	$dir = Util\Common::realpath($dir);
984
+                        	} else {
985
+                            	$dir = Util\Common::realpath(getcwd().'/'.$dir);
986
+                        	}
987
+
988
+                        	if ($dir !== false) {
989
+                            	// Report file path is relative.
990
+                            	$this->reportFile = $dir.'/'.basename($this->reportFile);
991
+                        	}
992
+                    	}
993
+                	}//end if
994
+
995
+                	self::$overriddenDefaults['reportFile'] = true;
996
+
997
+                	if (is_dir($this->reportFile) === true) {
998
+                    	$error  = 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL;
999
+                    	$error .= $this->printShortUsage(true);
1000
+                    	throw new DeepExitException($error, 3);
1001
+                	}
1002
+            	} else if (substr($arg, 0, 13) === 'report-width=') {
1003
+                	if (isset(self::$overriddenDefaults['reportWidth']) === true) {
1004
+                    	break;
1005
+                	}
1006
+
1007
+                	$this->reportWidth = substr($arg, 13);
1008
+                	self::$overriddenDefaults['reportWidth'] = true;
1009
+            	} else if (substr($arg, 0, 9) === 'basepath=') {
1010
+                	if (isset(self::$overriddenDefaults['basepath']) === true) {
1011
+                    	break;
1012
+                	}
1013
+
1014
+                	self::$overriddenDefaults['basepath'] = true;
1015
+
1016
+                	if (substr($arg, 9) === '') {
1017
+                    	$this->basepath = null;
1018
+                    	break;
1019
+                	}
1020
+
1021
+                	$this->basepath = Util\Common::realpath(substr($arg, 9));
1022
+
1023
+                	// It may not exist and return false instead.
1024
+                	if ($this->basepath === false) {
1025
+                    	$this->basepath = substr($arg, 9);
1026
+                	}
1027
+
1028
+                	if (is_dir($this->basepath) === false) {
1029
+                    	$error  = 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1030
+                    	$error .= $this->printShortUsage(true);
1031
+                    	throw new DeepExitException($error, 3);
1032
+                	}
1033
+            	} else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) {
1034
+                	$reports = [];
1035
+
1036
+                	if ($arg[6] === '-') {
1037
+                    	// This is a report with file output.
1038
+                    	$split = strpos($arg, '=');
1039
+                    	if ($split === false) {
1040
+                        	$report = substr($arg, 7);
1041
+                        	$output = null;
1042
+                    	} else {
1043
+                        	$report = substr($arg, 7, ($split - 7));
1044
+                        	$output = substr($arg, ($split + 1));
1045
+                        	if ($output === false) {
1046
+                            	$output = null;
1047
+                        	} else {
1048
+                            	$dir = dirname($output);
1049
+                            	if (is_dir($dir) === false) {
1050
+                                	$error  = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1051
+                                	$error .= $this->printShortUsage(true);
1052
+                                	throw new DeepExitException($error, 3);
1053
+                            	}
1054
+
1055
+                            	if ($dir === '.') {
1056
+                                	// Passed report file is a filename in the current directory.
1057
+                                	$output = getcwd().'/'.basename($output);
1058
+                            	} else {
1059
+                                	if ($dir{0} === '/') {
1060
+                                    	// An absolute path.
1061
+                                    	$dir = Util\Common::realpath($dir);
1062
+                                	} else {
1063
+                                    	$dir = Util\Common::realpath(getcwd().'/'.$dir);
1064
+                                	}
1065
+
1066
+                                	if ($dir !== false) {
1067
+                                    	// Report file path is relative.
1068
+                                    	$output = $dir.'/'.basename($output);
1069
+                                	}
1070
+                            	}
1071
+                        	}//end if
1072
+                    	}//end if
1073
+
1074
+                    	$reports[$report] = $output;
1075
+                	} else {
1076
+                    	// This is a single report.
1077
+                    	if (isset(self::$overriddenDefaults['reports']) === true) {
1078
+                        	break;
1079
+                    	}
1080
+
1081
+                    	$reportNames = explode(',', substr($arg, 7));
1082
+                    	foreach ($reportNames as $report) {
1083
+                        	$reports[$report] = null;
1084
+                    	}
1085
+                	}//end if
1086
+
1087
+                	// Remove the default value so the CLI value overrides it.
1088
+                	if (isset(self::$overriddenDefaults['reports']) === false) {
1089
+                    	$this->reports = $reports;
1090
+                	} else {
1091
+                    	$this->reports = array_merge($this->reports, $reports);
1092
+                	}
1093
+
1094
+                	self::$overriddenDefaults['reports'] = true;
1095
+            	} else if (substr($arg, 0, 7) === 'filter=') {
1096
+                	if (isset(self::$overriddenDefaults['filter']) === true) {
1097
+                    	break;
1098
+                	}
1099
+
1100
+                	$this->filter = substr($arg, 7);
1101
+                	self::$overriddenDefaults['filter'] = true;
1102
+            	} else if (substr($arg, 0, 9) === 'standard=') {
1103
+                	$standards = trim(substr($arg, 9));
1104
+                	if ($standards !== '') {
1105
+                    	$this->standards = explode(',', $standards);
1106
+                	}
1107
+
1108
+                	self::$overriddenDefaults['standards'] = true;
1109
+            	} else if (substr($arg, 0, 11) === 'extensions=') {
1110
+                	if (isset(self::$overriddenDefaults['extensions']) === true) {
1111
+                    	break;
1112
+                	}
1113
+
1114
+                	$extensions    = explode(',', substr($arg, 11));
1115
+                	$newExtensions = [];
1116
+                	foreach ($extensions as $ext) {
1117
+                    	$slash = strpos($ext, '/');
1118
+                    	if ($slash !== false) {
1119
+                        	// They specified the tokenizer too.
1120
+                        	list($ext, $tokenizer) = explode('/', $ext);
1121
+                        	$newExtensions[$ext]   = strtoupper($tokenizer);
1122
+                        	continue;
1123
+                    	}
1124
+
1125
+                    	if (isset($this->extensions[$ext]) === true) {
1126
+                        	$newExtensions[$ext] = $this->extensions[$ext];
1127
+                    	} else {
1128
+                        	$newExtensions[$ext] = 'PHP';
1129
+                    	}
1130
+                	}
1131
+
1132
+                	$this->extensions = $newExtensions;
1133
+                	self::$overriddenDefaults['extensions'] = true;
1134
+            	} else if (substr($arg, 0, 7) === 'suffix=') {
1135
+                	if (isset(self::$overriddenDefaults['suffix']) === true) {
1136
+                    	break;
1137
+                	}
1138
+
1139
+                	$this->suffix = substr($arg, 7);
1140
+                	self::$overriddenDefaults['suffix'] = true;
1141
+            	} else if (substr($arg, 0, 9) === 'parallel=') {
1142
+                	if (isset(self::$overriddenDefaults['parallel']) === true) {
1143
+                    	break;
1144
+                	}
1145
+
1146
+                	$this->parallel = max((int) substr($arg, 9), 1);
1147
+                	self::$overriddenDefaults['parallel'] = true;
1148
+            	} else if (substr($arg, 0, 9) === 'severity=') {
1149
+                	$this->errorSeverity   = (int) substr($arg, 9);
1150
+                	$this->warningSeverity = $this->errorSeverity;
1151
+                	if (isset(self::$overriddenDefaults['errorSeverity']) === false) {
1152
+                    	self::$overriddenDefaults['errorSeverity'] = true;
1153
+                	}
1154
+
1155
+                	if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
1156
+                    	self::$overriddenDefaults['warningSeverity'] = true;
1157
+                	}
1158
+            	} else if (substr($arg, 0, 15) === 'error-severity=') {
1159
+                	if (isset(self::$overriddenDefaults['errorSeverity']) === true) {
1160
+                    	break;
1161
+                	}
1162
+
1163
+                	$this->errorSeverity = (int) substr($arg, 15);
1164
+                	self::$overriddenDefaults['errorSeverity'] = true;
1165
+            	} else if (substr($arg, 0, 17) === 'warning-severity=') {
1166
+                	if (isset(self::$overriddenDefaults['warningSeverity']) === true) {
1167
+                    	break;
1168
+                	}
1169
+
1170
+                	$this->warningSeverity = (int) substr($arg, 17);
1171
+                	self::$overriddenDefaults['warningSeverity'] = true;
1172
+            	} else if (substr($arg, 0, 7) === 'ignore=') {
1173
+                	if (isset(self::$overriddenDefaults['ignored']) === true) {
1174
+                    	break;
1175
+                	}
1176
+
1177
+                	// Split the ignore string on commas, unless the comma is escaped
1178
+                	// using 1 or 3 slashes (\, or \\\,).
1179
+                	$patterns = preg_split(
1180
+                    	'/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
1181
+                    	substr($arg, 7)
1182
+                	);
1183
+
1184
+                	$ignored = [];
1185
+                	foreach ($patterns as $pattern) {
1186
+                    	$pattern = trim($pattern);
1187
+                    	if ($pattern === '') {
1188
+                        	continue;
1189
+                    	}
1190
+
1191
+                    	$ignored[$pattern] = 'absolute';
1192
+                	}
1193
+
1194
+                	$this->ignored = $ignored;
1195
+                	self::$overriddenDefaults['ignored'] = true;
1196
+            	} else if (substr($arg, 0, 10) === 'generator='
1197
+                	&& PHP_CODESNIFFER_CBF === false
1198
+            	) {
1199
+                	if (isset(self::$overriddenDefaults['generator']) === true) {
1200
+                    	break;
1201
+                	}
1202
+
1203
+                	$this->generator = substr($arg, 10);
1204
+                	self::$overriddenDefaults['generator'] = true;
1205
+            	} else if (substr($arg, 0, 9) === 'encoding=') {
1206
+                	if (isset(self::$overriddenDefaults['encoding']) === true) {
1207
+                    	break;
1208
+                	}
1209
+
1210
+                	$this->encoding = strtolower(substr($arg, 9));
1211
+                	self::$overriddenDefaults['encoding'] = true;
1212
+            	} else if (substr($arg, 0, 10) === 'tab-width=') {
1213
+                	if (isset(self::$overriddenDefaults['tabWidth']) === true) {
1214
+                    	break;
1215
+                	}
1216
+
1217
+                	$this->tabWidth = (int) substr($arg, 10);
1218
+                	self::$overriddenDefaults['tabWidth'] = true;
1219
+            	} else {
1220
+                	if ($this->dieOnUnknownArg === false) {
1221
+                    	$eqPos = strpos($arg, '=');
1222
+                    	try {
1223
+                        	if ($eqPos === false) {
1224
+                            	$this->values[$arg] = $arg;
1225
+                        	} else {
1226
+                            	$value = substr($arg, ($eqPos + 1));
1227
+                            	$arg   = substr($arg, 0, $eqPos);
1228
+                            	$this->values[$arg] = $value;
1229
+                        	}
1230
+                    	} catch (RuntimeException $e) {
1231
+                        	// Value is not valid, so just ignore it.
1232
+                    	}
1233
+                	} else {
1234
+                    	$this->processUnknownArgument('--'.$arg, $pos);
1235
+                	}
1236
+            	}//end if
1237
+            	break;
1238 1238
         }//end switch
1239 1239
 
1240 1240
     }//end processLongArgument()
Please login to merge, or discard this patch.
Spacing   +616 added lines, -616 removed lines patch added patch discarded remove patch
@@ -151,14 +151,14 @@  discard block
 block discarded – undo
151 151
      *
152 152
      * @var string[]
153 153
      */
154
-    private $cliArgs = [];
154
+    private $cliArgs = [ ];
155 155
 
156 156
     /**
157 157
      * Command line values that the user has supplied directly.
158 158
      *
159 159
      * @var array<string, TRUE>
160 160
      */
161
-    private static $overriddenDefaults = [];
161
+    private static $overriddenDefaults = [ ];
162 162
 
163 163
     /**
164 164
      * Config file data that has been loaded for the run.
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
      *
180 180
      * @var array<string, string>
181 181
      */
182
-    private static $executablePaths = [];
182
+    private static $executablePaths = [ ];
183 183
 
184 184
 
185 185
     /**
@@ -190,13 +190,13 @@  discard block
 block discarded – undo
190 190
      * @return mixed
191 191
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
192 192
      */
193
-    public function __get($name)
193
+    public function __get( $name )
194 194
     {
195
-        if (array_key_exists($name, $this->settings) === false) {
196
-            throw new RuntimeException("ERROR: unable to get value of property \"$name\"");
195
+        if ( array_key_exists( $name, $this->settings ) === false ) {
196
+            throw new RuntimeException( "ERROR: unable to get value of property \"$name\"" );
197 197
         }
198 198
 
199
-        return $this->settings[$name];
199
+        return $this->settings[ $name ];
200 200
 
201 201
     }//end __get()
202 202
 
@@ -210,35 +210,35 @@  discard block
 block discarded – undo
210 210
      * @return void
211 211
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
212 212
      */
213
-    public function __set($name, $value)
213
+    public function __set( $name, $value )
214 214
     {
215
-        if (array_key_exists($name, $this->settings) === false) {
216
-            throw new RuntimeException("Can't __set() $name; setting doesn't exist");
215
+        if ( array_key_exists( $name, $this->settings ) === false ) {
216
+            throw new RuntimeException( "Can't __set() $name; setting doesn't exist" );
217 217
         }
218 218
 
219
-        switch ($name) {
219
+        switch ( $name ) {
220 220
         case 'reportWidth' :
221 221
             // Support auto terminal width.
222
-            if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
223
-                $value = (int) $matches[1];
222
+            if ( $value === 'auto' && preg_match( '|\d+ (\d+)|', shell_exec( 'stty size 2>&1' ), $matches ) === 1 ) {
223
+                $value = (int)$matches[ 1 ];
224 224
             } else {
225
-                $value = (int) $value;
225
+                $value = (int)$value;
226 226
             }
227 227
             break;
228 228
         case 'standards' :
229
-            $cleaned = [];
229
+            $cleaned = [ ];
230 230
 
231 231
             // Check if the standard name is valid, or if the case is invalid.
232 232
             $installedStandards = Util\Standards::getInstalledStandards();
233
-            foreach ($value as $standard) {
234
-                foreach ($installedStandards as $validStandard) {
235
-                    if (strtolower($standard) === strtolower($validStandard)) {
233
+            foreach ( $value as $standard ) {
234
+                foreach ( $installedStandards as $validStandard ) {
235
+                    if ( strtolower( $standard ) === strtolower( $validStandard ) ) {
236 236
                         $standard = $validStandard;
237 237
                         break;
238 238
                     }
239 239
                 }
240 240
 
241
-                $cleaned[] = $standard;
241
+                $cleaned[ ] = $standard;
242 242
             }
243 243
 
244 244
             $value = $cleaned;
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
             break;
249 249
         }//end switch
250 250
 
251
-        $this->settings[$name] = $value;
251
+        $this->settings[ $name ] = $value;
252 252
 
253 253
     }//end __set()
254 254
 
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
      *
261 261
      * @return bool
262 262
      */
263
-    public function __isset($name)
263
+    public function __isset( $name )
264 264
     {
265
-        return isset($this->settings[$name]);
265
+        return isset( $this->settings[ $name ] );
266 266
 
267 267
     }//end __isset()
268 268
 
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
      *
275 275
      * @return void
276 276
      */
277
-    public function __unset($name)
277
+    public function __unset( $name )
278 278
     {
279
-        $this->settings[$name] = null;
279
+        $this->settings[ $name ] = null;
280 280
 
281 281
     }//end __unset()
282 282
 
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      *
301 301
      * @return void
302 302
      */
303
-    public function setSettings($settings)
303
+    public function setSettings( $settings )
304 304
     {
305 305
         return $this->settings = $settings;
306 306
 
@@ -316,9 +316,9 @@  discard block
 block discarded – undo
316 316
      *
317 317
      * @return void
318 318
      */
319
-    public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
319
+    public function __construct( array $cliArgs = [ ], $dieOnUnknownArg = true )
320 320
     {
321
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
321
+        if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === true ) {
322 322
             // Let everything through during testing so that we can
323 323
             // make use of PHPUnit command line arguments as well.
324 324
             $this->dieOnUnknownArg = false;
@@ -326,15 +326,15 @@  discard block
 block discarded – undo
326 326
             $this->dieOnUnknownArg = $dieOnUnknownArg;
327 327
         }
328 328
 
329
-        if (empty($cliArgs) === true) {
330
-            $cliArgs = $_SERVER['argv'];
331
-            array_shift($cliArgs);
329
+        if ( empty( $cliArgs ) === true ) {
330
+            $cliArgs = $_SERVER[ 'argv' ];
331
+            array_shift( $cliArgs );
332 332
         }
333 333
 
334 334
         $this->restoreDefaults();
335
-        $this->setCommandLineValues($cliArgs);
335
+        $this->setCommandLineValues( $cliArgs );
336 336
 
337
-        if (isset(self::$overriddenDefaults['standards']) === false) {
337
+        if ( isset( self::$overriddenDefaults[ 'standards' ] ) === false ) {
338 338
             // They did not supply a standard to use.
339 339
             // Look for a default ruleset in the current directory or higher.
340 340
             $currentDir = getcwd();
@@ -347,54 +347,54 @@  discard block
 block discarded – undo
347 347
             ];
348 348
 
349 349
             do {
350
-                foreach ($defaultFiles as $defaultFilename) {
351
-                    $default = $currentDir.DIRECTORY_SEPARATOR.$defaultFilename;
352
-                    if (is_file($default) === true) {
353
-                        $this->standards = [$default];
354
-                        break(2);
350
+                foreach ( $defaultFiles as $defaultFilename ) {
351
+                    $default = $currentDir . DIRECTORY_SEPARATOR . $defaultFilename;
352
+                    if ( is_file( $default ) === true ) {
353
+                        $this->standards = [ $default ];
354
+                        break( 2 );
355 355
                     }
356 356
                 }
357 357
 
358 358
                 $lastDir    = $currentDir;
359
-                $currentDir = dirname($currentDir);
360
-            } while ($currentDir !== '.' && $currentDir !== $lastDir);
359
+                $currentDir = dirname( $currentDir );
360
+            } while ( $currentDir !== '.' && $currentDir !== $lastDir );
361 361
         }//end if
362 362
 
363
-        if (defined('STDIN') === false
364
-            || strtoupper(substr(PHP_OS, 0, 3)) === 'WIN'
363
+        if ( defined( 'STDIN' ) === false
364
+            || strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN'
365 365
         ) {
366 366
             return;
367 367
         }
368 368
 
369
-        $handle = fopen('php://stdin', 'r');
369
+        $handle = fopen( 'php://stdin', 'r' );
370 370
 
371 371
         // Check for content on STDIN.
372
-        if ($this->stdin === true
373
-            || (Util\Common::isStdinATTY() === false
374
-            && feof($handle) === false)
372
+        if ( $this->stdin === true
373
+            || ( Util\Common::isStdinATTY() === false
374
+            && feof( $handle ) === false )
375 375
         ) {
376
-            $readStreams = [$handle];
376
+            $readStreams = [ $handle ];
377 377
             $writeSteams = null;
378 378
 
379 379
             $fileContents = '';
380
-            while (is_resource($handle) === true && feof($handle) === false) {
380
+            while ( is_resource( $handle ) === true && feof( $handle ) === false ) {
381 381
                 // Set a timeout of 200ms.
382
-                if (stream_select($readStreams, $writeSteams, $writeSteams, 0, 200000) === 0) {
382
+                if ( stream_select( $readStreams, $writeSteams, $writeSteams, 0, 200000 ) === 0 ) {
383 383
                     break;
384 384
                 }
385 385
 
386
-                $fileContents .= fgets($handle);
386
+                $fileContents .= fgets( $handle );
387 387
             }
388 388
 
389
-            if (trim($fileContents) !== '') {
389
+            if ( trim( $fileContents ) !== '' ) {
390 390
                 $this->stdin        = true;
391 391
                 $this->stdinContent = $fileContents;
392
-                self::$overriddenDefaults['stdin']        = true;
393
-                self::$overriddenDefaults['stdinContent'] = true;
392
+                self::$overriddenDefaults[ 'stdin' ]        = true;
393
+                self::$overriddenDefaults[ 'stdinContent' ] = true;
394 394
             }
395 395
         }//end if
396 396
 
397
-        fclose($handle);
397
+        fclose( $handle );
398 398
 
399 399
     }//end __construct()
400 400
 
@@ -406,44 +406,44 @@  discard block
 block discarded – undo
406 406
      *
407 407
      * @return void
408 408
      */
409
-    public function setCommandLineValues($args)
409
+    public function setCommandLineValues( $args )
410 410
     {
411 411
         $this->cliArgs = $args;
412
-        $numArgs       = count($args);
412
+        $numArgs       = count( $args );
413 413
 
414
-        for ($i = 0; $i < $numArgs; $i++) {
415
-            $arg = $this->cliArgs[$i];
416
-            if ($arg === '') {
414
+        for ( $i = 0; $i < $numArgs; $i++ ) {
415
+            $arg = $this->cliArgs[ $i ];
416
+            if ( $arg === '' ) {
417 417
                 continue;
418 418
             }
419 419
 
420
-            if ($arg{0} === '-') {
421
-                if ($arg === '-') {
420
+            if ( $arg{0} === '-' ) {
421
+                if ( $arg === '-' ) {
422 422
                     // Asking to read from STDIN.
423 423
                     $this->stdin = true;
424
-                    self::$overriddenDefaults['stdin'] = true;
424
+                    self::$overriddenDefaults[ 'stdin' ] = true;
425 425
                     continue;
426 426
                 }
427 427
 
428
-                if ($arg === '--') {
428
+                if ( $arg === '--' ) {
429 429
                     // Empty argument, ignore it.
430 430
                     continue;
431 431
                 }
432 432
 
433
-                if ($arg{1} === '-') {
434
-                    $this->processLongArgument(substr($arg, 2), $i);
433
+                if ( $arg{1} === '-' ) {
434
+                    $this->processLongArgument( substr( $arg, 2 ), $i );
435 435
                 } else {
436
-                    $switches = str_split($arg);
437
-                    foreach ($switches as $switch) {
438
-                        if ($switch === '-') {
436
+                    $switches = str_split( $arg );
437
+                    foreach ( $switches as $switch ) {
438
+                        if ( $switch === '-' ) {
439 439
                             continue;
440 440
                         }
441 441
 
442
-                        $this->processShortArgument($switch, $i);
442
+                        $this->processShortArgument( $switch, $i );
443 443
                     }
444 444
                 }
445 445
             } else {
446
-                $this->processUnknownArgument($arg, $i);
446
+                $this->processUnknownArgument( $arg, $i );
447 447
             }//end if
448 448
         }//end for
449 449
 
@@ -457,8 +457,8 @@  discard block
 block discarded – undo
457 457
      */
458 458
     public function restoreDefaults()
459 459
     {
460
-        $this->files           = [];
461
-        $this->standards       = ['PEAR'];
460
+        $this->files           = [ ];
461
+        $this->standards       = [ 'PEAR' ];
462 462
         $this->verbosity       = 0;
463 463
         $this->interactive     = false;
464 464
         $this->cache           = false;
@@ -479,15 +479,15 @@  discard block
 block discarded – undo
479 479
             'js'  => 'JS',
480 480
             'css' => 'CSS',
481 481
         ];
482
-        $this->sniffs          = [];
483
-        $this->exclude         = [];
484
-        $this->ignored         = [];
482
+        $this->sniffs          = [ ];
483
+        $this->exclude         = [ ];
484
+        $this->ignored         = [ ];
485 485
         $this->reportFile      = null;
486 486
         $this->generator       = null;
487 487
         $this->filter          = null;
488
-        $this->bootstrap       = [];
488
+        $this->bootstrap       = [ ];
489 489
         $this->basepath        = null;
490
-        $this->reports         = ['full' => null];
490
+        $this->reports         = [ 'full' => null ];
491 491
         $this->reportWidth     = 'auto';
492 492
         $this->errorSeverity   = 5;
493 493
         $this->warningSeverity = 5;
@@ -496,81 +496,81 @@  discard block
 block discarded – undo
496 496
         $this->stdin           = false;
497 497
         $this->stdinContent    = null;
498 498
         $this->stdinPath       = null;
499
-        $this->unknown         = [];
499
+        $this->unknown         = [ ];
500 500
 
501
-        $standard = self::getConfigData('default_standard');
502
-        if ($standard !== null) {
503
-            $this->standards = explode(',', $standard);
501
+        $standard = self::getConfigData( 'default_standard' );
502
+        if ( $standard !== null ) {
503
+            $this->standards = explode( ',', $standard );
504 504
         }
505 505
 
506
-        $reportFormat = self::getConfigData('report_format');
507
-        if ($reportFormat !== null) {
508
-            $this->reports = [$reportFormat => null];
506
+        $reportFormat = self::getConfigData( 'report_format' );
507
+        if ( $reportFormat !== null ) {
508
+            $this->reports = [ $reportFormat => null ];
509 509
         }
510 510
 
511
-        $tabWidth = self::getConfigData('tab_width');
512
-        if ($tabWidth !== null) {
513
-            $this->tabWidth = (int) $tabWidth;
511
+        $tabWidth = self::getConfigData( 'tab_width' );
512
+        if ( $tabWidth !== null ) {
513
+            $this->tabWidth = (int)$tabWidth;
514 514
         }
515 515
 
516
-        $encoding = self::getConfigData('encoding');
517
-        if ($encoding !== null) {
518
-            $this->encoding = strtolower($encoding);
516
+        $encoding = self::getConfigData( 'encoding' );
517
+        if ( $encoding !== null ) {
518
+            $this->encoding = strtolower( $encoding );
519 519
         }
520 520
 
521
-        $severity = self::getConfigData('severity');
522
-        if ($severity !== null) {
523
-            $this->errorSeverity   = (int) $severity;
524
-            $this->warningSeverity = (int) $severity;
521
+        $severity = self::getConfigData( 'severity' );
522
+        if ( $severity !== null ) {
523
+            $this->errorSeverity   = (int)$severity;
524
+            $this->warningSeverity = (int)$severity;
525 525
         }
526 526
 
527
-        $severity = self::getConfigData('error_severity');
528
-        if ($severity !== null) {
529
-            $this->errorSeverity = (int) $severity;
527
+        $severity = self::getConfigData( 'error_severity' );
528
+        if ( $severity !== null ) {
529
+            $this->errorSeverity = (int)$severity;
530 530
         }
531 531
 
532
-        $severity = self::getConfigData('warning_severity');
533
-        if ($severity !== null) {
534
-            $this->warningSeverity = (int) $severity;
532
+        $severity = self::getConfigData( 'warning_severity' );
533
+        if ( $severity !== null ) {
534
+            $this->warningSeverity = (int)$severity;
535 535
         }
536 536
 
537
-        $showWarnings = self::getConfigData('show_warnings');
538
-        if ($showWarnings !== null) {
539
-            $showWarnings = (bool) $showWarnings;
540
-            if ($showWarnings === false) {
537
+        $showWarnings = self::getConfigData( 'show_warnings' );
538
+        if ( $showWarnings !== null ) {
539
+            $showWarnings = (bool)$showWarnings;
540
+            if ( $showWarnings === false ) {
541 541
                 $this->warningSeverity = 0;
542 542
             }
543 543
         }
544 544
 
545
-        $reportWidth = self::getConfigData('report_width');
546
-        if ($reportWidth !== null) {
545
+        $reportWidth = self::getConfigData( 'report_width' );
546
+        if ( $reportWidth !== null ) {
547 547
             $this->reportWidth = $reportWidth;
548 548
         }
549 549
 
550
-        $showProgress = self::getConfigData('show_progress');
551
-        if ($showProgress !== null) {
552
-            $this->showProgress = (bool) $showProgress;
550
+        $showProgress = self::getConfigData( 'show_progress' );
551
+        if ( $showProgress !== null ) {
552
+            $this->showProgress = (bool)$showProgress;
553 553
         }
554 554
 
555
-        $quiet = self::getConfigData('quiet');
556
-        if ($quiet !== null) {
557
-            $this->quiet = (bool) $quiet;
555
+        $quiet = self::getConfigData( 'quiet' );
556
+        if ( $quiet !== null ) {
557
+            $this->quiet = (bool)$quiet;
558 558
         }
559 559
 
560
-        $colors = self::getConfigData('colors');
561
-        if ($colors !== null) {
562
-            $this->colors = (bool) $colors;
560
+        $colors = self::getConfigData( 'colors' );
561
+        if ( $colors !== null ) {
562
+            $this->colors = (bool)$colors;
563 563
         }
564 564
 
565
-        if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
566
-            $cache = self::getConfigData('cache');
567
-            if ($cache !== null) {
568
-                $this->cache = (bool) $cache;
565
+        if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === false ) {
566
+            $cache = self::getConfigData( 'cache' );
567
+            if ( $cache !== null ) {
568
+                $this->cache = (bool)$cache;
569 569
             }
570 570
 
571
-            $parallel = self::getConfigData('parallel');
572
-            if ($parallel !== null) {
573
-                $this->parallel = max((int) $parallel, 1);
571
+            $parallel = self::getConfigData( 'parallel' );
572
+            if ( $parallel !== null ) {
573
+                $this->parallel = max( (int)$parallel, 1 );
574 574
             }
575 575
         }
576 576
 
@@ -585,55 +585,55 @@  discard block
 block discarded – undo
585 585
      *
586 586
      * @return void
587 587
      */
588
-    public function processShortArgument($arg, $pos)
588
+    public function processShortArgument( $arg, $pos )
589 589
     {
590
-        switch ($arg) {
590
+        switch ( $arg ) {
591 591
         case 'h':
592 592
         case '?':
593 593
             ob_start();
594 594
             $this->printUsage();
595 595
             $output = ob_get_contents();
596 596
             ob_end_clean();
597
-            throw new DeepExitException($output, 0);
597
+            throw new DeepExitException( $output, 0 );
598 598
         case 'i' :
599 599
             ob_start();
600 600
             Util\Standards::printInstalledStandards();
601 601
             $output = ob_get_contents();
602 602
             ob_end_clean();
603
-            throw new DeepExitException($output, 0);
603
+            throw new DeepExitException( $output, 0 );
604 604
         case 'v' :
605
-            if ($this->quiet === true) {
605
+            if ( $this->quiet === true ) {
606 606
                 // Ignore when quiet mode is enabled.
607 607
                 break;
608 608
             }
609 609
 
610 610
             $this->verbosity++;
611
-            self::$overriddenDefaults['verbosity'] = true;
611
+            self::$overriddenDefaults[ 'verbosity' ] = true;
612 612
             break;
613 613
         case 'l' :
614 614
             $this->local = true;
615
-            self::$overriddenDefaults['local'] = true;
615
+            self::$overriddenDefaults[ 'local' ] = true;
616 616
             break;
617 617
         case 's' :
618 618
             $this->showSources = true;
619
-            self::$overriddenDefaults['showSources'] = true;
619
+            self::$overriddenDefaults[ 'showSources' ] = true;
620 620
             break;
621 621
         case 'a' :
622 622
             $this->interactive = true;
623
-            self::$overriddenDefaults['interactive'] = true;
623
+            self::$overriddenDefaults[ 'interactive' ] = true;
624 624
             break;
625 625
         case 'e':
626 626
             $this->explain = true;
627
-            self::$overriddenDefaults['explain'] = true;
627
+            self::$overriddenDefaults[ 'explain' ] = true;
628 628
             break;
629 629
         case 'p' :
630
-            if ($this->quiet === true) {
630
+            if ( $this->quiet === true ) {
631 631
                 // Ignore when quiet mode is enabled.
632 632
                 break;
633 633
             }
634 634
 
635 635
             $this->showProgress = true;
636
-            self::$overriddenDefaults['showProgress'] = true;
636
+            self::$overriddenDefaults[ 'showProgress' ] = true;
637 637
             break;
638 638
         case 'q' :
639 639
             // Quiet mode disables a few other settings as well.
@@ -641,40 +641,40 @@  discard block
 block discarded – undo
641 641
             $this->showProgress = false;
642 642
             $this->verbosity    = 0;
643 643
 
644
-            self::$overriddenDefaults['quiet'] = true;
644
+            self::$overriddenDefaults[ 'quiet' ] = true;
645 645
             break;
646 646
         case 'm' :
647 647
             $this->recordErrors = false;
648
-            self::$overriddenDefaults['recordErrors'] = true;
648
+            self::$overriddenDefaults[ 'recordErrors' ] = true;
649 649
             break;
650 650
         case 'd' :
651
-            $ini = explode('=', $this->cliArgs[($pos + 1)]);
652
-            $this->cliArgs[($pos + 1)] = '';
653
-            if (isset($ini[1]) === true) {
654
-                ini_set($ini[0], $ini[1]);
651
+            $ini = explode( '=', $this->cliArgs[ ( $pos + 1 ) ] );
652
+            $this->cliArgs[ ( $pos + 1 ) ] = '';
653
+            if ( isset( $ini[ 1 ] ) === true ) {
654
+                ini_set( $ini[ 0 ], $ini[ 1 ] );
655 655
             } else {
656
-                ini_set($ini[0], true);
656
+                ini_set( $ini[ 0 ], true );
657 657
             }
658 658
             break;
659 659
         case 'n' :
660
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
660
+            if ( isset( self::$overriddenDefaults[ 'warningSeverity' ] ) === false ) {
661 661
                 $this->warningSeverity = 0;
662
-                self::$overriddenDefaults['warningSeverity'] = true;
662
+                self::$overriddenDefaults[ 'warningSeverity' ] = true;
663 663
             }
664 664
             break;
665 665
         case 'w' :
666
-            if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
666
+            if ( isset( self::$overriddenDefaults[ 'warningSeverity' ] ) === false ) {
667 667
                 $this->warningSeverity = $this->errorSeverity;
668
-                self::$overriddenDefaults['warningSeverity'] = true;
668
+                self::$overriddenDefaults[ 'warningSeverity' ] = true;
669 669
             }
670 670
             break;
671 671
         default:
672
-            if ($this->dieOnUnknownArg === false) {
672
+            if ( $this->dieOnUnknownArg === false ) {
673 673
                 $unknown       = $this->unknown;
674
-                $unknown[]     = $arg;
674
+                $unknown[ ]     = $arg;
675 675
                 $this->unknown = $unknown;
676 676
             } else {
677
-                $this->processUnknownArgument('-'.$arg, $pos);
677
+                $this->processUnknownArgument( '-' . $arg, $pos );
678 678
             }
679 679
         }//end switch
680 680
 
@@ -689,488 +689,488 @@  discard block
 block discarded – undo
689 689
      *
690 690
      * @return void
691 691
      */
692
-    public function processLongArgument($arg, $pos)
692
+    public function processLongArgument( $arg, $pos )
693 693
     {
694
-        switch ($arg) {
694
+        switch ( $arg ) {
695 695
         case 'help':
696 696
             ob_start();
697 697
             $this->printUsage();
698 698
             $output = ob_get_contents();
699 699
             ob_end_clean();
700
-            throw new DeepExitException($output, 0);
700
+            throw new DeepExitException( $output, 0 );
701 701
         case 'version':
702
-            $output  = 'PHP_CodeSniffer version '.self::VERSION.' ('.self::STABILITY.') ';
703
-            $output .= 'by Squiz (http://www.squiz.net)'.PHP_EOL;
704
-            throw new DeepExitException($output, 0);
702
+            $output  = 'PHP_CodeSniffer version ' . self::VERSION . ' (' . self::STABILITY . ') ';
703
+            $output .= 'by Squiz (http://www.squiz.net)' . PHP_EOL;
704
+            throw new DeepExitException( $output, 0 );
705 705
         case 'colors':
706
-            if (isset(self::$overriddenDefaults['colors']) === true) {
706
+            if ( isset( self::$overriddenDefaults[ 'colors' ] ) === true ) {
707 707
                 break;
708 708
             }
709 709
 
710 710
             $this->colors = true;
711
-            self::$overriddenDefaults['colors'] = true;
711
+            self::$overriddenDefaults[ 'colors' ] = true;
712 712
             break;
713 713
         case 'no-colors':
714
-            if (isset(self::$overriddenDefaults['colors']) === true) {
714
+            if ( isset( self::$overriddenDefaults[ 'colors' ] ) === true ) {
715 715
                 break;
716 716
             }
717 717
 
718 718
             $this->colors = false;
719
-            self::$overriddenDefaults['colors'] = true;
719
+            self::$overriddenDefaults[ 'colors' ] = true;
720 720
             break;
721 721
         case 'cache':
722
-            if (isset(self::$overriddenDefaults['cache']) === true) {
722
+            if ( isset( self::$overriddenDefaults[ 'cache' ] ) === true ) {
723 723
                 break;
724 724
             }
725 725
 
726
-            if (defined('PHP_CODESNIFFER_IN_TESTS') === false) {
726
+            if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === false ) {
727 727
                 $this->cache = true;
728
-                self::$overriddenDefaults['cache'] = true;
728
+                self::$overriddenDefaults[ 'cache' ] = true;
729 729
             }
730 730
             break;
731 731
         case 'no-cache':
732
-            if (isset(self::$overriddenDefaults['cache']) === true) {
732
+            if ( isset( self::$overriddenDefaults[ 'cache' ] ) === true ) {
733 733
                 break;
734 734
             }
735 735
 
736 736
             $this->cache = false;
737
-            self::$overriddenDefaults['cache'] = true;
737
+            self::$overriddenDefaults[ 'cache' ] = true;
738 738
             break;
739 739
         case 'ignore-annotations':
740
-            if (isset(self::$overriddenDefaults['annotations']) === true) {
740
+            if ( isset( self::$overriddenDefaults[ 'annotations' ] ) === true ) {
741 741
                 break;
742 742
             }
743 743
 
744 744
             $this->annotations = false;
745
-            self::$overriddenDefaults['annotations'] = true;
745
+            self::$overriddenDefaults[ 'annotations' ] = true;
746 746
             break;
747 747
         case 'config-set':
748
-            if (isset($this->cliArgs[($pos + 1)]) === false
749
-                || isset($this->cliArgs[($pos + 2)]) === false
748
+            if ( isset( $this->cliArgs[ ( $pos + 1 ) ] ) === false
749
+                || isset( $this->cliArgs[ ( $pos + 2 ) ] ) === false
750 750
             ) {
751
-                $error  = 'ERROR: Setting a config option requires a name and value'.PHP_EOL.PHP_EOL;
752
-                $error .= $this->printShortUsage(true);
753
-                throw new DeepExitException($error, 3);
751
+                $error  = 'ERROR: Setting a config option requires a name and value' . PHP_EOL . PHP_EOL;
752
+                $error .= $this->printShortUsage( true );
753
+                throw new DeepExitException( $error, 3 );
754 754
             }
755 755
 
756
-            $key     = $this->cliArgs[($pos + 1)];
757
-            $value   = $this->cliArgs[($pos + 2)];
758
-            $current = self::getConfigData($key);
756
+            $key     = $this->cliArgs[ ( $pos + 1 ) ];
757
+            $value   = $this->cliArgs[ ( $pos + 2 ) ];
758
+            $current = self::getConfigData( $key );
759 759
 
760 760
             try {
761
-                $this->setConfigData($key, $value);
762
-            } catch (\Exception $e) {
763
-                throw new DeepExitException($e->getMessage().PHP_EOL, 3);
761
+                $this->setConfigData( $key, $value );
762
+            } catch ( \Exception $e ) {
763
+                throw new DeepExitException( $e->getMessage() . PHP_EOL, 3 );
764 764
             }
765 765
 
766
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
766
+            $output = 'Using config file: ' . self::$configDataFile . PHP_EOL . PHP_EOL;
767 767
 
768
-            if ($current === null) {
769
-                $output .= "Config value \"$key\" added successfully".PHP_EOL;
768
+            if ( $current === null ) {
769
+                $output .= "Config value \"$key\" added successfully" . PHP_EOL;
770 770
             } else {
771
-                $output .= "Config value \"$key\" updated successfully; old value was \"$current\"".PHP_EOL;
771
+                $output .= "Config value \"$key\" updated successfully; old value was \"$current\"" . PHP_EOL;
772 772
             }
773
-            throw new DeepExitException($output, 0);
773
+            throw new DeepExitException( $output, 0 );
774 774
         case 'config-delete':
775
-            if (isset($this->cliArgs[($pos + 1)]) === false) {
776
-                $error  = 'ERROR: Deleting a config option requires the name of the option'.PHP_EOL.PHP_EOL;
777
-                $error .= $this->printShortUsage(true);
778
-                throw new DeepExitException($error, 3);
775
+            if ( isset( $this->cliArgs[ ( $pos + 1 ) ] ) === false ) {
776
+                $error  = 'ERROR: Deleting a config option requires the name of the option' . PHP_EOL . PHP_EOL;
777
+                $error .= $this->printShortUsage( true );
778
+                throw new DeepExitException( $error, 3 );
779 779
             }
780 780
 
781
-            $output = 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
781
+            $output = 'Using config file: ' . self::$configDataFile . PHP_EOL . PHP_EOL;
782 782
 
783
-            $key     = $this->cliArgs[($pos + 1)];
784
-            $current = self::getConfigData($key);
785
-            if ($current === null) {
786
-                $output .= "Config value \"$key\" has not been set".PHP_EOL;
783
+            $key     = $this->cliArgs[ ( $pos + 1 ) ];
784
+            $current = self::getConfigData( $key );
785
+            if ( $current === null ) {
786
+                $output .= "Config value \"$key\" has not been set" . PHP_EOL;
787 787
             } else {
788 788
                 try {
789
-                    $this->setConfigData($key, null);
790
-                } catch (\Exception $e) {
791
-                    throw new DeepExitException($e->getMessage().PHP_EOL, 3);
789
+                    $this->setConfigData( $key, null );
790
+                } catch ( \Exception $e ) {
791
+                    throw new DeepExitException( $e->getMessage() . PHP_EOL, 3 );
792 792
                 }
793 793
 
794
-                $output .= "Config value \"$key\" removed successfully; old value was \"$current\"".PHP_EOL;
794
+                $output .= "Config value \"$key\" removed successfully; old value was \"$current\"" . PHP_EOL;
795 795
             }
796
-            throw new DeepExitException($output, 0);
796
+            throw new DeepExitException( $output, 0 );
797 797
         case 'config-show':
798 798
             ob_start();
799 799
             $data = self::getAllConfigData();
800
-            echo 'Using config file: '.self::$configDataFile.PHP_EOL.PHP_EOL;
801
-            $this->printConfigData($data);
800
+            echo 'Using config file: ' . self::$configDataFile . PHP_EOL . PHP_EOL;
801
+            $this->printConfigData( $data );
802 802
             $output = ob_get_contents();
803 803
             ob_end_clean();
804
-            throw new DeepExitException($output, 0);
804
+            throw new DeepExitException( $output, 0 );
805 805
         case 'runtime-set':
806
-            if (isset($this->cliArgs[($pos + 1)]) === false
807
-                || isset($this->cliArgs[($pos + 2)]) === false
806
+            if ( isset( $this->cliArgs[ ( $pos + 1 ) ] ) === false
807
+                || isset( $this->cliArgs[ ( $pos + 2 ) ] ) === false
808 808
             ) {
809
-                $error  = 'ERROR: Setting a runtime config option requires a name and value'.PHP_EOL.PHP_EOL;
810
-                $error .= $this->printShortUsage(true);
811
-                throw new DeepExitException($error, 3);
809
+                $error  = 'ERROR: Setting a runtime config option requires a name and value' . PHP_EOL . PHP_EOL;
810
+                $error .= $this->printShortUsage( true );
811
+                throw new DeepExitException( $error, 3 );
812 812
             }
813 813
 
814
-            $key   = $this->cliArgs[($pos + 1)];
815
-            $value = $this->cliArgs[($pos + 2)];
816
-            $this->cliArgs[($pos + 1)] = '';
817
-            $this->cliArgs[($pos + 2)] = '';
818
-            self::setConfigData($key, $value, true);
819
-            if (isset(self::$overriddenDefaults['runtime-set']) === false) {
820
-                self::$overriddenDefaults['runtime-set'] = [];
814
+            $key   = $this->cliArgs[ ( $pos + 1 ) ];
815
+            $value = $this->cliArgs[ ( $pos + 2 ) ];
816
+            $this->cliArgs[ ( $pos + 1 ) ] = '';
817
+            $this->cliArgs[ ( $pos + 2 ) ] = '';
818
+            self::setConfigData( $key, $value, true );
819
+            if ( isset( self::$overriddenDefaults[ 'runtime-set' ] ) === false ) {
820
+                self::$overriddenDefaults[ 'runtime-set' ] = [ ];
821 821
             }
822 822
 
823
-            self::$overriddenDefaults['runtime-set'][$key] = true;
823
+            self::$overriddenDefaults[ 'runtime-set' ][ $key ] = true;
824 824
             break;
825 825
         default:
826
-            if (substr($arg, 0, 7) === 'sniffs=') {
827
-                if (isset(self::$overriddenDefaults['sniffs']) === true) {
826
+            if ( substr( $arg, 0, 7 ) === 'sniffs=' ) {
827
+                if ( isset( self::$overriddenDefaults[ 'sniffs' ] ) === true ) {
828 828
                     break;
829 829
                 }
830 830
 
831
-                $sniffs = explode(',', substr($arg, 7));
832
-                foreach ($sniffs as $sniff) {
833
-                    if (substr_count($sniff, '.') !== 2) {
834
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
835
-                        $error .= $this->printShortUsage(true);
836
-                        throw new DeepExitException($error, 3);
831
+                $sniffs = explode( ',', substr( $arg, 7 ) );
832
+                foreach ( $sniffs as $sniff ) {
833
+                    if ( substr_count( $sniff, '.' ) !== 2 ) {
834
+                        $error  = 'ERROR: The specified sniff code "' . $sniff . '" is invalid' . PHP_EOL . PHP_EOL;
835
+                        $error .= $this->printShortUsage( true );
836
+                        throw new DeepExitException( $error, 3 );
837 837
                     }
838 838
                 }
839 839
 
840 840
                 $this->sniffs = $sniffs;
841
-                self::$overriddenDefaults['sniffs'] = true;
842
-            } else if (substr($arg, 0, 8) === 'exclude=') {
843
-                if (isset(self::$overriddenDefaults['exclude']) === true) {
841
+                self::$overriddenDefaults[ 'sniffs' ] = true;
842
+            } else if ( substr( $arg, 0, 8 ) === 'exclude=' ) {
843
+                if ( isset( self::$overriddenDefaults[ 'exclude' ] ) === true ) {
844 844
                     break;
845 845
                 }
846 846
 
847
-                $sniffs = explode(',', substr($arg, 8));
848
-                foreach ($sniffs as $sniff) {
849
-                    if (substr_count($sniff, '.') !== 2) {
850
-                        $error  = 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
851
-                        $error .= $this->printShortUsage(true);
852
-                        throw new DeepExitException($error, 3);
847
+                $sniffs = explode( ',', substr( $arg, 8 ) );
848
+                foreach ( $sniffs as $sniff ) {
849
+                    if ( substr_count( $sniff, '.' ) !== 2 ) {
850
+                        $error  = 'ERROR: The specified sniff code "' . $sniff . '" is invalid' . PHP_EOL . PHP_EOL;
851
+                        $error .= $this->printShortUsage( true );
852
+                        throw new DeepExitException( $error, 3 );
853 853
                     }
854 854
                 }
855 855
 
856 856
                 $this->exclude = $sniffs;
857
-                self::$overriddenDefaults['exclude'] = true;
858
-            } else if (defined('PHP_CODESNIFFER_IN_TESTS') === false
859
-                && substr($arg, 0, 6) === 'cache='
857
+                self::$overriddenDefaults[ 'exclude' ] = true;
858
+            } else if ( defined( 'PHP_CODESNIFFER_IN_TESTS' ) === false
859
+                && substr( $arg, 0, 6 ) === 'cache='
860 860
             ) {
861
-                if ((isset(self::$overriddenDefaults['cache']) === true
862
-                    && $this->cache === false)
863
-                    || isset(self::$overriddenDefaults['cacheFile']) === true
861
+                if ( ( isset( self::$overriddenDefaults[ 'cache' ] ) === true
862
+                    && $this->cache === false )
863
+                    || isset( self::$overriddenDefaults[ 'cacheFile' ] ) === true
864 864
                 ) {
865 865
                     break;
866 866
                 }
867 867
 
868 868
                 // Turn caching on.
869 869
                 $this->cache = true;
870
-                self::$overriddenDefaults['cache'] = true;
870
+                self::$overriddenDefaults[ 'cache' ] = true;
871 871
 
872
-                $this->cacheFile = Util\Common::realpath(substr($arg, 6));
872
+                $this->cacheFile = Util\Common::realpath( substr( $arg, 6 ) );
873 873
 
874 874
                 // It may not exist and return false instead.
875
-                if ($this->cacheFile === false) {
876
-                    $this->cacheFile = substr($arg, 6);
877
-
878
-                    $dir = dirname($this->cacheFile);
879
-                    if (is_dir($dir) === false) {
880
-                        $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
881
-                        $error .= $this->printShortUsage(true);
882
-                        throw new DeepExitException($error, 3);
875
+                if ( $this->cacheFile === false ) {
876
+                    $this->cacheFile = substr( $arg, 6 );
877
+
878
+                    $dir = dirname( $this->cacheFile );
879
+                    if ( is_dir( $dir ) === false ) {
880
+                        $error  = 'ERROR: The specified cache file path "' . $this->cacheFile . '" points to a non-existent directory' . PHP_EOL . PHP_EOL;
881
+                        $error .= $this->printShortUsage( true );
882
+                        throw new DeepExitException( $error, 3 );
883 883
                     }
884 884
 
885
-                    if ($dir === '.') {
885
+                    if ( $dir === '.' ) {
886 886
                         // Passed cache file is a file in the current directory.
887
-                        $this->cacheFile = getcwd().'/'.basename($this->cacheFile);
887
+                        $this->cacheFile = getcwd() . '/' . basename( $this->cacheFile );
888 888
                     } else {
889
-                        if ($dir{0} === '/') {
889
+                        if ( $dir{0} === '/' ) {
890 890
                             // An absolute path.
891
-                            $dir = Util\Common::realpath($dir);
891
+                            $dir = Util\Common::realpath( $dir );
892 892
                         } else {
893
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
893
+                            $dir = Util\Common::realpath( getcwd() . '/' . $dir );
894 894
                         }
895 895
 
896
-                        if ($dir !== false) {
896
+                        if ( $dir !== false ) {
897 897
                             // Cache file path is relative.
898
-                            $this->cacheFile = $dir.'/'.basename($this->cacheFile);
898
+                            $this->cacheFile = $dir . '/' . basename( $this->cacheFile );
899 899
                         }
900 900
                     }
901 901
                 }//end if
902 902
 
903
-                self::$overriddenDefaults['cacheFile'] = true;
903
+                self::$overriddenDefaults[ 'cacheFile' ] = true;
904 904
 
905
-                if (is_dir($this->cacheFile) === true) {
906
-                    $error  = 'ERROR: The specified cache file path "'.$this->cacheFile.'" is a directory'.PHP_EOL.PHP_EOL;
907
-                    $error .= $this->printShortUsage(true);
908
-                    throw new DeepExitException($error, 3);
905
+                if ( is_dir( $this->cacheFile ) === true ) {
906
+                    $error  = 'ERROR: The specified cache file path "' . $this->cacheFile . '" is a directory' . PHP_EOL . PHP_EOL;
907
+                    $error .= $this->printShortUsage( true );
908
+                    throw new DeepExitException( $error, 3 );
909 909
                 }
910
-            } else if (substr($arg, 0, 10) === 'bootstrap=') {
911
-                $files     = explode(',', substr($arg, 10));
912
-                $bootstrap = [];
913
-                foreach ($files as $file) {
914
-                    $path = Util\Common::realpath($file);
915
-                    if ($path === false) {
916
-                        $error  = 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
917
-                        $error .= $this->printShortUsage(true);
918
-                        throw new DeepExitException($error, 3);
910
+            } else if ( substr( $arg, 0, 10 ) === 'bootstrap=' ) {
911
+                $files     = explode( ',', substr( $arg, 10 ) );
912
+                $bootstrap = [ ];
913
+                foreach ( $files as $file ) {
914
+                    $path = Util\Common::realpath( $file );
915
+                    if ( $path === false ) {
916
+                        $error  = 'ERROR: The specified bootstrap file "' . $file . '" does not exist' . PHP_EOL . PHP_EOL;
917
+                        $error .= $this->printShortUsage( true );
918
+                        throw new DeepExitException( $error, 3 );
919 919
                     }
920 920
 
921
-                    $bootstrap[] = $path;
921
+                    $bootstrap[ ] = $path;
922 922
                 }
923 923
 
924
-                $this->bootstrap = array_merge($this->bootstrap, $bootstrap);
925
-                self::$overriddenDefaults['bootstrap'] = true;
926
-            } else if (substr($arg, 0, 10) === 'file-list=') {
927
-                $fileList = substr($arg, 10);
928
-                $path     = Util\Common::realpath($fileList);
929
-                if ($path === false) {
930
-                    $error  = 'ERROR: The specified file list "'.$fileList.'" does not exist'.PHP_EOL.PHP_EOL;
931
-                    $error .= $this->printShortUsage(true);
932
-                    throw new DeepExitException($error, 3);
924
+                $this->bootstrap = array_merge( $this->bootstrap, $bootstrap );
925
+                self::$overriddenDefaults[ 'bootstrap' ] = true;
926
+            } else if ( substr( $arg, 0, 10 ) === 'file-list=' ) {
927
+                $fileList = substr( $arg, 10 );
928
+                $path     = Util\Common::realpath( $fileList );
929
+                if ( $path === false ) {
930
+                    $error  = 'ERROR: The specified file list "' . $fileList . '" does not exist' . PHP_EOL . PHP_EOL;
931
+                    $error .= $this->printShortUsage( true );
932
+                    throw new DeepExitException( $error, 3 );
933 933
                 }
934 934
 
935
-                $files = file($path);
936
-                foreach ($files as $inputFile) {
937
-                    $inputFile = trim($inputFile);
935
+                $files = file( $path );
936
+                foreach ( $files as $inputFile ) {
937
+                    $inputFile = trim( $inputFile );
938 938
 
939 939
                     // Skip empty lines.
940
-                    if ($inputFile === '') {
940
+                    if ( $inputFile === '' ) {
941 941
                         continue;
942 942
                     }
943 943
 
944
-                    $this->processFilePath($inputFile);
944
+                    $this->processFilePath( $inputFile );
945 945
                 }
946
-            } else if (substr($arg, 0, 11) === 'stdin-path=') {
947
-                if (isset(self::$overriddenDefaults['stdinPath']) === true) {
946
+            } else if ( substr( $arg, 0, 11 ) === 'stdin-path=' ) {
947
+                if ( isset( self::$overriddenDefaults[ 'stdinPath' ] ) === true ) {
948 948
                     break;
949 949
                 }
950 950
 
951
-                $this->stdinPath = Util\Common::realpath(substr($arg, 11));
951
+                $this->stdinPath = Util\Common::realpath( substr( $arg, 11 ) );
952 952
 
953 953
                 // It may not exist and return false instead, so use whatever they gave us.
954
-                if ($this->stdinPath === false) {
955
-                    $this->stdinPath = trim(substr($arg, 11));
954
+                if ( $this->stdinPath === false ) {
955
+                    $this->stdinPath = trim( substr( $arg, 11 ) );
956 956
                 }
957 957
 
958
-                self::$overriddenDefaults['stdinPath'] = true;
959
-            } else if (PHP_CODESNIFFER_CBF === false && substr($arg, 0, 12) === 'report-file=') {
960
-                if (isset(self::$overriddenDefaults['reportFile']) === true) {
958
+                self::$overriddenDefaults[ 'stdinPath' ] = true;
959
+            } else if ( PHP_CODESNIFFER_CBF === false && substr( $arg, 0, 12 ) === 'report-file=' ) {
960
+                if ( isset( self::$overriddenDefaults[ 'reportFile' ] ) === true ) {
961 961
                     break;
962 962
                 }
963 963
 
964
-                $this->reportFile = Util\Common::realpath(substr($arg, 12));
964
+                $this->reportFile = Util\Common::realpath( substr( $arg, 12 ) );
965 965
 
966 966
                 // It may not exist and return false instead.
967
-                if ($this->reportFile === false) {
968
-                    $this->reportFile = substr($arg, 12);
969
-
970
-                    $dir = dirname($this->reportFile);
971
-                    if (is_dir($dir) === false) {
972
-                        $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
973
-                        $error .= $this->printShortUsage(true);
974
-                        throw new DeepExitException($error, 3);
967
+                if ( $this->reportFile === false ) {
968
+                    $this->reportFile = substr( $arg, 12 );
969
+
970
+                    $dir = dirname( $this->reportFile );
971
+                    if ( is_dir( $dir ) === false ) {
972
+                        $error  = 'ERROR: The specified report file path "' . $this->reportFile . '" points to a non-existent directory' . PHP_EOL . PHP_EOL;
973
+                        $error .= $this->printShortUsage( true );
974
+                        throw new DeepExitException( $error, 3 );
975 975
                     }
976 976
 
977
-                    if ($dir === '.') {
977
+                    if ( $dir === '.' ) {
978 978
                         // Passed report file is a file in the current directory.
979
-                        $this->reportFile = getcwd().'/'.basename($this->reportFile);
979
+                        $this->reportFile = getcwd() . '/' . basename( $this->reportFile );
980 980
                     } else {
981
-                        if ($dir{0} === '/') {
981
+                        if ( $dir{0} === '/' ) {
982 982
                             // An absolute path.
983
-                            $dir = Util\Common::realpath($dir);
983
+                            $dir = Util\Common::realpath( $dir );
984 984
                         } else {
985
-                            $dir = Util\Common::realpath(getcwd().'/'.$dir);
985
+                            $dir = Util\Common::realpath( getcwd() . '/' . $dir );
986 986
                         }
987 987
 
988
-                        if ($dir !== false) {
988
+                        if ( $dir !== false ) {
989 989
                             // Report file path is relative.
990
-                            $this->reportFile = $dir.'/'.basename($this->reportFile);
990
+                            $this->reportFile = $dir . '/' . basename( $this->reportFile );
991 991
                         }
992 992
                     }
993 993
                 }//end if
994 994
 
995
-                self::$overriddenDefaults['reportFile'] = true;
995
+                self::$overriddenDefaults[ 'reportFile' ] = true;
996 996
 
997
-                if (is_dir($this->reportFile) === true) {
998
-                    $error  = 'ERROR: The specified report file path "'.$this->reportFile.'" is a directory'.PHP_EOL.PHP_EOL;
999
-                    $error .= $this->printShortUsage(true);
1000
-                    throw new DeepExitException($error, 3);
997
+                if ( is_dir( $this->reportFile ) === true ) {
998
+                    $error  = 'ERROR: The specified report file path "' . $this->reportFile . '" is a directory' . PHP_EOL . PHP_EOL;
999
+                    $error .= $this->printShortUsage( true );
1000
+                    throw new DeepExitException( $error, 3 );
1001 1001
                 }
1002
-            } else if (substr($arg, 0, 13) === 'report-width=') {
1003
-                if (isset(self::$overriddenDefaults['reportWidth']) === true) {
1002
+            } else if ( substr( $arg, 0, 13 ) === 'report-width=' ) {
1003
+                if ( isset( self::$overriddenDefaults[ 'reportWidth' ] ) === true ) {
1004 1004
                     break;
1005 1005
                 }
1006 1006
 
1007
-                $this->reportWidth = substr($arg, 13);
1008
-                self::$overriddenDefaults['reportWidth'] = true;
1009
-            } else if (substr($arg, 0, 9) === 'basepath=') {
1010
-                if (isset(self::$overriddenDefaults['basepath']) === true) {
1007
+                $this->reportWidth = substr( $arg, 13 );
1008
+                self::$overriddenDefaults[ 'reportWidth' ] = true;
1009
+            } else if ( substr( $arg, 0, 9 ) === 'basepath=' ) {
1010
+                if ( isset( self::$overriddenDefaults[ 'basepath' ] ) === true ) {
1011 1011
                     break;
1012 1012
                 }
1013 1013
 
1014
-                self::$overriddenDefaults['basepath'] = true;
1014
+                self::$overriddenDefaults[ 'basepath' ] = true;
1015 1015
 
1016
-                if (substr($arg, 9) === '') {
1016
+                if ( substr( $arg, 9 ) === '' ) {
1017 1017
                     $this->basepath = null;
1018 1018
                     break;
1019 1019
                 }
1020 1020
 
1021
-                $this->basepath = Util\Common::realpath(substr($arg, 9));
1021
+                $this->basepath = Util\Common::realpath( substr( $arg, 9 ) );
1022 1022
 
1023 1023
                 // It may not exist and return false instead.
1024
-                if ($this->basepath === false) {
1025
-                    $this->basepath = substr($arg, 9);
1024
+                if ( $this->basepath === false ) {
1025
+                    $this->basepath = substr( $arg, 9 );
1026 1026
                 }
1027 1027
 
1028
-                if (is_dir($this->basepath) === false) {
1029
-                    $error  = 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1030
-                    $error .= $this->printShortUsage(true);
1031
-                    throw new DeepExitException($error, 3);
1028
+                if ( is_dir( $this->basepath ) === false ) {
1029
+                    $error  = 'ERROR: The specified basepath "' . $this->basepath . '" points to a non-existent directory' . PHP_EOL . PHP_EOL;
1030
+                    $error .= $this->printShortUsage( true );
1031
+                    throw new DeepExitException( $error, 3 );
1032 1032
                 }
1033
-            } else if ((substr($arg, 0, 7) === 'report=' || substr($arg, 0, 7) === 'report-')) {
1034
-                $reports = [];
1033
+            } else if ( ( substr( $arg, 0, 7 ) === 'report=' || substr( $arg, 0, 7 ) === 'report-' ) ) {
1034
+                $reports = [ ];
1035 1035
 
1036
-                if ($arg[6] === '-') {
1036
+                if ( $arg[ 6 ] === '-' ) {
1037 1037
                     // This is a report with file output.
1038
-                    $split = strpos($arg, '=');
1039
-                    if ($split === false) {
1040
-                        $report = substr($arg, 7);
1038
+                    $split = strpos( $arg, '=' );
1039
+                    if ( $split === false ) {
1040
+                        $report = substr( $arg, 7 );
1041 1041
                         $output = null;
1042 1042
                     } else {
1043
-                        $report = substr($arg, 7, ($split - 7));
1044
-                        $output = substr($arg, ($split + 1));
1045
-                        if ($output === false) {
1043
+                        $report = substr( $arg, 7, ( $split - 7 ) );
1044
+                        $output = substr( $arg, ( $split + 1 ) );
1045
+                        if ( $output === false ) {
1046 1046
                             $output = null;
1047 1047
                         } else {
1048
-                            $dir = dirname($output);
1049
-                            if (is_dir($dir) === false) {
1050
-                                $error  = 'ERROR: The specified '.$report.' report file path "'.$output.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
1051
-                                $error .= $this->printShortUsage(true);
1052
-                                throw new DeepExitException($error, 3);
1048
+                            $dir = dirname( $output );
1049
+                            if ( is_dir( $dir ) === false ) {
1050
+                                $error  = 'ERROR: The specified ' . $report . ' report file path "' . $output . '" points to a non-existent directory' . PHP_EOL . PHP_EOL;
1051
+                                $error .= $this->printShortUsage( true );
1052
+                                throw new DeepExitException( $error, 3 );
1053 1053
                             }
1054 1054
 
1055
-                            if ($dir === '.') {
1055
+                            if ( $dir === '.' ) {
1056 1056
                                 // Passed report file is a filename in the current directory.
1057
-                                $output = getcwd().'/'.basename($output);
1057
+                                $output = getcwd() . '/' . basename( $output );
1058 1058
                             } else {
1059
-                                if ($dir{0} === '/') {
1059
+                                if ( $dir{0} === '/' ) {
1060 1060
                                     // An absolute path.
1061
-                                    $dir = Util\Common::realpath($dir);
1061
+                                    $dir = Util\Common::realpath( $dir );
1062 1062
                                 } else {
1063
-                                    $dir = Util\Common::realpath(getcwd().'/'.$dir);
1063
+                                    $dir = Util\Common::realpath( getcwd() . '/' . $dir );
1064 1064
                                 }
1065 1065
 
1066
-                                if ($dir !== false) {
1066
+                                if ( $dir !== false ) {
1067 1067
                                     // Report file path is relative.
1068
-                                    $output = $dir.'/'.basename($output);
1068
+                                    $output = $dir . '/' . basename( $output );
1069 1069
                                 }
1070 1070
                             }
1071 1071
                         }//end if
1072 1072
                     }//end if
1073 1073
 
1074
-                    $reports[$report] = $output;
1074
+                    $reports[ $report ] = $output;
1075 1075
                 } else {
1076 1076
                     // This is a single report.
1077
-                    if (isset(self::$overriddenDefaults['reports']) === true) {
1077
+                    if ( isset( self::$overriddenDefaults[ 'reports' ] ) === true ) {
1078 1078
                         break;
1079 1079
                     }
1080 1080
 
1081
-                    $reportNames = explode(',', substr($arg, 7));
1082
-                    foreach ($reportNames as $report) {
1083
-                        $reports[$report] = null;
1081
+                    $reportNames = explode( ',', substr( $arg, 7 ) );
1082
+                    foreach ( $reportNames as $report ) {
1083
+                        $reports[ $report ] = null;
1084 1084
                     }
1085 1085
                 }//end if
1086 1086
 
1087 1087
                 // Remove the default value so the CLI value overrides it.
1088
-                if (isset(self::$overriddenDefaults['reports']) === false) {
1088
+                if ( isset( self::$overriddenDefaults[ 'reports' ] ) === false ) {
1089 1089
                     $this->reports = $reports;
1090 1090
                 } else {
1091
-                    $this->reports = array_merge($this->reports, $reports);
1091
+                    $this->reports = array_merge( $this->reports, $reports );
1092 1092
                 }
1093 1093
 
1094
-                self::$overriddenDefaults['reports'] = true;
1095
-            } else if (substr($arg, 0, 7) === 'filter=') {
1096
-                if (isset(self::$overriddenDefaults['filter']) === true) {
1094
+                self::$overriddenDefaults[ 'reports' ] = true;
1095
+            } else if ( substr( $arg, 0, 7 ) === 'filter=' ) {
1096
+                if ( isset( self::$overriddenDefaults[ 'filter' ] ) === true ) {
1097 1097
                     break;
1098 1098
                 }
1099 1099
 
1100
-                $this->filter = substr($arg, 7);
1101
-                self::$overriddenDefaults['filter'] = true;
1102
-            } else if (substr($arg, 0, 9) === 'standard=') {
1103
-                $standards = trim(substr($arg, 9));
1104
-                if ($standards !== '') {
1105
-                    $this->standards = explode(',', $standards);
1100
+                $this->filter = substr( $arg, 7 );
1101
+                self::$overriddenDefaults[ 'filter' ] = true;
1102
+            } else if ( substr( $arg, 0, 9 ) === 'standard=' ) {
1103
+                $standards = trim( substr( $arg, 9 ) );
1104
+                if ( $standards !== '' ) {
1105
+                    $this->standards = explode( ',', $standards );
1106 1106
                 }
1107 1107
 
1108
-                self::$overriddenDefaults['standards'] = true;
1109
-            } else if (substr($arg, 0, 11) === 'extensions=') {
1110
-                if (isset(self::$overriddenDefaults['extensions']) === true) {
1108
+                self::$overriddenDefaults[ 'standards' ] = true;
1109
+            } else if ( substr( $arg, 0, 11 ) === 'extensions=' ) {
1110
+                if ( isset( self::$overriddenDefaults[ 'extensions' ] ) === true ) {
1111 1111
                     break;
1112 1112
                 }
1113 1113
 
1114
-                $extensions    = explode(',', substr($arg, 11));
1115
-                $newExtensions = [];
1116
-                foreach ($extensions as $ext) {
1117
-                    $slash = strpos($ext, '/');
1118
-                    if ($slash !== false) {
1114
+                $extensions    = explode( ',', substr( $arg, 11 ) );
1115
+                $newExtensions = [ ];
1116
+                foreach ( $extensions as $ext ) {
1117
+                    $slash = strpos( $ext, '/' );
1118
+                    if ( $slash !== false ) {
1119 1119
                         // They specified the tokenizer too.
1120
-                        list($ext, $tokenizer) = explode('/', $ext);
1121
-                        $newExtensions[$ext]   = strtoupper($tokenizer);
1120
+                        list( $ext, $tokenizer ) = explode( '/', $ext );
1121
+                        $newExtensions[ $ext ]   = strtoupper( $tokenizer );
1122 1122
                         continue;
1123 1123
                     }
1124 1124
 
1125
-                    if (isset($this->extensions[$ext]) === true) {
1126
-                        $newExtensions[$ext] = $this->extensions[$ext];
1125
+                    if ( isset( $this->extensions[ $ext ] ) === true ) {
1126
+                        $newExtensions[ $ext ] = $this->extensions[ $ext ];
1127 1127
                     } else {
1128
-                        $newExtensions[$ext] = 'PHP';
1128
+                        $newExtensions[ $ext ] = 'PHP';
1129 1129
                     }
1130 1130
                 }
1131 1131
 
1132 1132
                 $this->extensions = $newExtensions;
1133
-                self::$overriddenDefaults['extensions'] = true;
1134
-            } else if (substr($arg, 0, 7) === 'suffix=') {
1135
-                if (isset(self::$overriddenDefaults['suffix']) === true) {
1133
+                self::$overriddenDefaults[ 'extensions' ] = true;
1134
+            } else if ( substr( $arg, 0, 7 ) === 'suffix=' ) {
1135
+                if ( isset( self::$overriddenDefaults[ 'suffix' ] ) === true ) {
1136 1136
                     break;
1137 1137
                 }
1138 1138
 
1139
-                $this->suffix = substr($arg, 7);
1140
-                self::$overriddenDefaults['suffix'] = true;
1141
-            } else if (substr($arg, 0, 9) === 'parallel=') {
1142
-                if (isset(self::$overriddenDefaults['parallel']) === true) {
1139
+                $this->suffix = substr( $arg, 7 );
1140
+                self::$overriddenDefaults[ 'suffix' ] = true;
1141
+            } else if ( substr( $arg, 0, 9 ) === 'parallel=' ) {
1142
+                if ( isset( self::$overriddenDefaults[ 'parallel' ] ) === true ) {
1143 1143
                     break;
1144 1144
                 }
1145 1145
 
1146
-                $this->parallel = max((int) substr($arg, 9), 1);
1147
-                self::$overriddenDefaults['parallel'] = true;
1148
-            } else if (substr($arg, 0, 9) === 'severity=') {
1149
-                $this->errorSeverity   = (int) substr($arg, 9);
1146
+                $this->parallel = max( (int)substr( $arg, 9 ), 1 );
1147
+                self::$overriddenDefaults[ 'parallel' ] = true;
1148
+            } else if ( substr( $arg, 0, 9 ) === 'severity=' ) {
1149
+                $this->errorSeverity   = (int)substr( $arg, 9 );
1150 1150
                 $this->warningSeverity = $this->errorSeverity;
1151
-                if (isset(self::$overriddenDefaults['errorSeverity']) === false) {
1152
-                    self::$overriddenDefaults['errorSeverity'] = true;
1151
+                if ( isset( self::$overriddenDefaults[ 'errorSeverity' ] ) === false ) {
1152
+                    self::$overriddenDefaults[ 'errorSeverity' ] = true;
1153 1153
                 }
1154 1154
 
1155
-                if (isset(self::$overriddenDefaults['warningSeverity']) === false) {
1156
-                    self::$overriddenDefaults['warningSeverity'] = true;
1155
+                if ( isset( self::$overriddenDefaults[ 'warningSeverity' ] ) === false ) {
1156
+                    self::$overriddenDefaults[ 'warningSeverity' ] = true;
1157 1157
                 }
1158
-            } else if (substr($arg, 0, 15) === 'error-severity=') {
1159
-                if (isset(self::$overriddenDefaults['errorSeverity']) === true) {
1158
+            } else if ( substr( $arg, 0, 15 ) === 'error-severity=' ) {
1159
+                if ( isset( self::$overriddenDefaults[ 'errorSeverity' ] ) === true ) {
1160 1160
                     break;
1161 1161
                 }
1162 1162
 
1163
-                $this->errorSeverity = (int) substr($arg, 15);
1164
-                self::$overriddenDefaults['errorSeverity'] = true;
1165
-            } else if (substr($arg, 0, 17) === 'warning-severity=') {
1166
-                if (isset(self::$overriddenDefaults['warningSeverity']) === true) {
1163
+                $this->errorSeverity = (int)substr( $arg, 15 );
1164
+                self::$overriddenDefaults[ 'errorSeverity' ] = true;
1165
+            } else if ( substr( $arg, 0, 17 ) === 'warning-severity=' ) {
1166
+                if ( isset( self::$overriddenDefaults[ 'warningSeverity' ] ) === true ) {
1167 1167
                     break;
1168 1168
                 }
1169 1169
 
1170
-                $this->warningSeverity = (int) substr($arg, 17);
1171
-                self::$overriddenDefaults['warningSeverity'] = true;
1172
-            } else if (substr($arg, 0, 7) === 'ignore=') {
1173
-                if (isset(self::$overriddenDefaults['ignored']) === true) {
1170
+                $this->warningSeverity = (int)substr( $arg, 17 );
1171
+                self::$overriddenDefaults[ 'warningSeverity' ] = true;
1172
+            } else if ( substr( $arg, 0, 7 ) === 'ignore=' ) {
1173
+                if ( isset( self::$overriddenDefaults[ 'ignored' ] ) === true ) {
1174 1174
                     break;
1175 1175
                 }
1176 1176
 
@@ -1178,60 +1178,60 @@  discard block
 block discarded – undo
1178 1178
                 // using 1 or 3 slashes (\, or \\\,).
1179 1179
                 $patterns = preg_split(
1180 1180
                     '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
1181
-                    substr($arg, 7)
1181
+                    substr( $arg, 7 )
1182 1182
                 );
1183 1183
 
1184
-                $ignored = [];
1185
-                foreach ($patterns as $pattern) {
1186
-                    $pattern = trim($pattern);
1187
-                    if ($pattern === '') {
1184
+                $ignored = [ ];
1185
+                foreach ( $patterns as $pattern ) {
1186
+                    $pattern = trim( $pattern );
1187
+                    if ( $pattern === '' ) {
1188 1188
                         continue;
1189 1189
                     }
1190 1190
 
1191
-                    $ignored[$pattern] = 'absolute';
1191
+                    $ignored[ $pattern ] = 'absolute';
1192 1192
                 }
1193 1193
 
1194 1194
                 $this->ignored = $ignored;
1195
-                self::$overriddenDefaults['ignored'] = true;
1196
-            } else if (substr($arg, 0, 10) === 'generator='
1195
+                self::$overriddenDefaults[ 'ignored' ] = true;
1196
+            } else if ( substr( $arg, 0, 10 ) === 'generator='
1197 1197
                 && PHP_CODESNIFFER_CBF === false
1198 1198
             ) {
1199
-                if (isset(self::$overriddenDefaults['generator']) === true) {
1199
+                if ( isset( self::$overriddenDefaults[ 'generator' ] ) === true ) {
1200 1200
                     break;
1201 1201
                 }
1202 1202
 
1203
-                $this->generator = substr($arg, 10);
1204
-                self::$overriddenDefaults['generator'] = true;
1205
-            } else if (substr($arg, 0, 9) === 'encoding=') {
1206
-                if (isset(self::$overriddenDefaults['encoding']) === true) {
1203
+                $this->generator = substr( $arg, 10 );
1204
+                self::$overriddenDefaults[ 'generator' ] = true;
1205
+            } else if ( substr( $arg, 0, 9 ) === 'encoding=' ) {
1206
+                if ( isset( self::$overriddenDefaults[ 'encoding' ] ) === true ) {
1207 1207
                     break;
1208 1208
                 }
1209 1209
 
1210
-                $this->encoding = strtolower(substr($arg, 9));
1211
-                self::$overriddenDefaults['encoding'] = true;
1212
-            } else if (substr($arg, 0, 10) === 'tab-width=') {
1213
-                if (isset(self::$overriddenDefaults['tabWidth']) === true) {
1210
+                $this->encoding = strtolower( substr( $arg, 9 ) );
1211
+                self::$overriddenDefaults[ 'encoding' ] = true;
1212
+            } else if ( substr( $arg, 0, 10 ) === 'tab-width=' ) {
1213
+                if ( isset( self::$overriddenDefaults[ 'tabWidth' ] ) === true ) {
1214 1214
                     break;
1215 1215
                 }
1216 1216
 
1217
-                $this->tabWidth = (int) substr($arg, 10);
1218
-                self::$overriddenDefaults['tabWidth'] = true;
1217
+                $this->tabWidth = (int)substr( $arg, 10 );
1218
+                self::$overriddenDefaults[ 'tabWidth' ] = true;
1219 1219
             } else {
1220
-                if ($this->dieOnUnknownArg === false) {
1221
-                    $eqPos = strpos($arg, '=');
1220
+                if ( $this->dieOnUnknownArg === false ) {
1221
+                    $eqPos = strpos( $arg, '=' );
1222 1222
                     try {
1223
-                        if ($eqPos === false) {
1224
-                            $this->values[$arg] = $arg;
1223
+                        if ( $eqPos === false ) {
1224
+                            $this->values[ $arg ] = $arg;
1225 1225
                         } else {
1226
-                            $value = substr($arg, ($eqPos + 1));
1227
-                            $arg   = substr($arg, 0, $eqPos);
1228
-                            $this->values[$arg] = $value;
1226
+                            $value = substr( $arg, ( $eqPos + 1 ) );
1227
+                            $arg   = substr( $arg, 0, $eqPos );
1228
+                            $this->values[ $arg ] = $value;
1229 1229
                         }
1230
-                    } catch (RuntimeException $e) {
1230
+                    } catch ( RuntimeException $e ) {
1231 1231
                         // Value is not valid, so just ignore it.
1232 1232
                     }
1233 1233
                 } else {
1234
-                    $this->processUnknownArgument('--'.$arg, $pos);
1234
+                    $this->processUnknownArgument( '--' . $arg, $pos );
1235 1235
                 }
1236 1236
             }//end if
1237 1237
             break;
@@ -1250,20 +1250,20 @@  discard block
 block discarded – undo
1250 1250
      *
1251 1251
      * @return void
1252 1252
      */
1253
-    public function processUnknownArgument($arg, $pos)
1253
+    public function processUnknownArgument( $arg, $pos )
1254 1254
     {
1255 1255
         // We don't know about any additional switches; just files.
1256
-        if ($arg{0} === '-') {
1257
-            if ($this->dieOnUnknownArg === false) {
1256
+        if ( $arg{0} === '-' ) {
1257
+            if ( $this->dieOnUnknownArg === false ) {
1258 1258
                 return;
1259 1259
             }
1260 1260
 
1261
-            $error  = "ERROR: option \"$arg\" not known".PHP_EOL.PHP_EOL;
1262
-            $error .= $this->printShortUsage(true);
1263
-            throw new DeepExitException($error, 3);
1261
+            $error  = "ERROR: option \"$arg\" not known" . PHP_EOL . PHP_EOL;
1262
+            $error .= $this->printShortUsage( true );
1263
+            throw new DeepExitException( $error, 3 );
1264 1264
         }
1265 1265
 
1266
-        $this->processFilePath($arg);
1266
+        $this->processFilePath( $arg );
1267 1267
 
1268 1268
     }//end processUnknownArgument()
1269 1269
 
@@ -1275,29 +1275,29 @@  discard block
 block discarded – undo
1275 1275
      *
1276 1276
      * @return void
1277 1277
      */
1278
-    public function processFilePath($path)
1278
+    public function processFilePath( $path )
1279 1279
     {
1280 1280
         // If we are processing STDIN, don't record any files to check.
1281
-        if ($this->stdin === true) {
1281
+        if ( $this->stdin === true ) {
1282 1282
             return;
1283 1283
         }
1284 1284
 
1285
-        $file = Util\Common::realpath($path);
1286
-        if (file_exists($file) === false) {
1287
-            if ($this->dieOnUnknownArg === false) {
1285
+        $file = Util\Common::realpath( $path );
1286
+        if ( file_exists( $file ) === false ) {
1287
+            if ( $this->dieOnUnknownArg === false ) {
1288 1288
                 return;
1289 1289
             }
1290 1290
 
1291
-            $error  = 'ERROR: The file "'.$path.'" does not exist.'.PHP_EOL.PHP_EOL;
1292
-            $error .= $this->printShortUsage(true);
1293
-            throw new DeepExitException($error, 3);
1291
+            $error  = 'ERROR: The file "' . $path . '" does not exist.' . PHP_EOL . PHP_EOL;
1292
+            $error .= $this->printShortUsage( true );
1293
+            throw new DeepExitException( $error, 3 );
1294 1294
         } else {
1295 1295
             // Can't modify the files array directly because it's not a real
1296 1296
             // class member, so need to use this little get/modify/set trick.
1297 1297
             $files       = $this->files;
1298
-            $files[]     = $file;
1298
+            $files[ ]     = $file;
1299 1299
             $this->files = $files;
1300
-            self::$overriddenDefaults['files'] = true;
1300
+            self::$overriddenDefaults[ 'files' ] = true;
1301 1301
         }
1302 1302
 
1303 1303
     }//end processFilePath()
@@ -1312,7 +1312,7 @@  discard block
 block discarded – undo
1312 1312
     {
1313 1313
         echo PHP_EOL;
1314 1314
 
1315
-        if (PHP_CODESNIFFER_CBF === true) {
1315
+        if ( PHP_CODESNIFFER_CBF === true ) {
1316 1316
             $this->printPHPCBFUsage();
1317 1317
         } else {
1318 1318
             $this->printPHPCSUsage();
@@ -1331,17 +1331,17 @@  discard block
 block discarded – undo
1331 1331
      *
1332 1332
      * @return string|void
1333 1333
      */
1334
-    public function printShortUsage($return=false)
1334
+    public function printShortUsage( $return = false )
1335 1335
     {
1336
-        if (PHP_CODESNIFFER_CBF === true) {
1336
+        if ( PHP_CODESNIFFER_CBF === true ) {
1337 1337
             $usage = 'Run "phpcbf --help" for usage information';
1338 1338
         } else {
1339 1339
             $usage = 'Run "phpcs --help" for usage information';
1340 1340
         }
1341 1341
 
1342
-        $usage .= PHP_EOL.PHP_EOL;
1342
+        $usage .= PHP_EOL . PHP_EOL;
1343 1343
 
1344
-        if ($return === true) {
1344
+        if ( $return === true ) {
1345 1345
             return $usage;
1346 1346
         }
1347 1347
 
@@ -1357,70 +1357,70 @@  discard block
 block discarded – undo
1357 1357
      */
1358 1358
     public function printPHPCSUsage()
1359 1359
     {
1360
-        echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]'.PHP_EOL;
1361
-        echo '  [--cache[=<cacheFile>]] [--no-cache] [--tab-width=<tabWidth>]'.PHP_EOL;
1362
-        echo '  [--report=<report>] [--report-file=<reportFile>] [--report-<report>=<reportFile>]'.PHP_EOL;
1363
-        echo '  [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]'.PHP_EOL;
1364
-        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1365
-        echo '  [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]'.PHP_EOL;
1366
-        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]'.PHP_EOL;
1367
-        echo '  [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]'.PHP_EOL;
1368
-        echo '  [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]'.PHP_EOL;
1369
-        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1360
+        echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]' . PHP_EOL;
1361
+        echo '  [--cache[=<cacheFile>]] [--no-cache] [--tab-width=<tabWidth>]' . PHP_EOL;
1362
+        echo '  [--report=<report>] [--report-file=<reportFile>] [--report-<report>=<reportFile>]' . PHP_EOL;
1363
+        echo '  [--report-width=<reportWidth>] [--basepath=<basepath>] [--bootstrap=<bootstrap>]' . PHP_EOL;
1364
+        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]' . PHP_EOL;
1365
+        echo '  [--runtime-set key value] [--config-set key value] [--config-delete key] [--config-show]' . PHP_EOL;
1366
+        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>]' . PHP_EOL;
1367
+        echo '  [--encoding=<encoding>] [--parallel=<processes>] [--generator=<generator>]' . PHP_EOL;
1368
+        echo '  [--extensions=<extensions>] [--ignore=<patterns>] [--ignore-annotations]' . PHP_EOL;
1369
+        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...' . PHP_EOL;
1370 1370
         echo PHP_EOL;
1371
-        echo ' -     Check STDIN instead of local files and directories'.PHP_EOL;
1372
-        echo ' -n    Do not print warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1373
-        echo ' -w    Print both warnings and errors (this is the default)'.PHP_EOL;
1374
-        echo ' -l    Local directory only, no recursion'.PHP_EOL;
1375
-        echo ' -s    Show sniff codes in all reports'.PHP_EOL;
1376
-        echo ' -a    Run interactively'.PHP_EOL;
1377
-        echo ' -e    Explain a standard by showing the sniffs it includes'.PHP_EOL;
1378
-        echo ' -p    Show progress of the run'.PHP_EOL;
1379
-        echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1380
-        echo ' -m    Stop error messages from being recorded'.PHP_EOL;
1381
-        echo '       (saves a lot of memory, but stops many reports from being used)'.PHP_EOL;
1382
-        echo ' -v    Print processed files'.PHP_EOL;
1383
-        echo ' -vv   Print ruleset and token output'.PHP_EOL;
1384
-        echo ' -vvv  Print sniff processing information'.PHP_EOL;
1385
-        echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1386
-        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1371
+        echo ' -     Check STDIN instead of local files and directories' . PHP_EOL;
1372
+        echo ' -n    Do not print warnings (shortcut for --warning-severity=0)' . PHP_EOL;
1373
+        echo ' -w    Print both warnings and errors (this is the default)' . PHP_EOL;
1374
+        echo ' -l    Local directory only, no recursion' . PHP_EOL;
1375
+        echo ' -s    Show sniff codes in all reports' . PHP_EOL;
1376
+        echo ' -a    Run interactively' . PHP_EOL;
1377
+        echo ' -e    Explain a standard by showing the sniffs it includes' . PHP_EOL;
1378
+        echo ' -p    Show progress of the run' . PHP_EOL;
1379
+        echo ' -q    Quiet mode; disables progress and verbose output' . PHP_EOL;
1380
+        echo ' -m    Stop error messages from being recorded' . PHP_EOL;
1381
+        echo '       (saves a lot of memory, but stops many reports from being used)' . PHP_EOL;
1382
+        echo ' -v    Print processed files' . PHP_EOL;
1383
+        echo ' -vv   Print ruleset and token output' . PHP_EOL;
1384
+        echo ' -vvv  Print sniff processing information' . PHP_EOL;
1385
+        echo ' -i    Show a list of installed coding standards' . PHP_EOL;
1386
+        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted' . PHP_EOL;
1387 1387
         echo PHP_EOL;
1388
-        echo ' --help                Print this help message'.PHP_EOL;
1389
-        echo ' --version             Print version information'.PHP_EOL;
1390
-        echo ' --colors              Use colors in output'.PHP_EOL;
1391
-        echo ' --no-colors           Do not use colors in output (this is the default)'.PHP_EOL;
1392
-        echo ' --cache               Cache results between runs'.PHP_EOL;
1393
-        echo ' --no-cache            Do not cache results between runs (this is the default)'.PHP_EOL;
1394
-        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1388
+        echo ' --help                Print this help message' . PHP_EOL;
1389
+        echo ' --version             Print version information' . PHP_EOL;
1390
+        echo ' --colors              Use colors in output' . PHP_EOL;
1391
+        echo ' --no-colors           Do not use colors in output (this is the default)' . PHP_EOL;
1392
+        echo ' --cache               Cache results between runs' . PHP_EOL;
1393
+        echo ' --no-cache            Do not cache results between runs (this is the default)' . PHP_EOL;
1394
+        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments' . PHP_EOL;
1395 1395
         echo PHP_EOL;
1396
-        echo ' <cacheFile>    Use a specific file for caching (uses a temporary file by default)'.PHP_EOL;
1397
-        echo ' <basepath>     A path to strip from the front of file paths inside reports'.PHP_EOL;
1398
-        echo ' <bootstrap>    A comma separated list of files to run before processing begins'.PHP_EOL;
1399
-        echo ' <encoding>     The encoding of the files being checked (default is utf-8)'.PHP_EOL;
1400
-        echo ' <extensions>   A comma separated list of file extensions to check'.PHP_EOL;
1401
-        echo '                The type of the file can be specified using: ext/type'.PHP_EOL;
1402
-        echo '                e.g., module/php,es/js'.PHP_EOL;
1403
-        echo ' <file>         One or more files and/or directories to check'.PHP_EOL;
1404
-        echo ' <fileList>     A file containing a list of files and/or directories to check (one per line)'.PHP_EOL;
1405
-        echo ' <filter>       Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1406
-        echo ' <generator>    Uses either the "HTML", "Markdown" or "Text" generator'.PHP_EOL;
1407
-        echo '                (forces documentation generation instead of checking)'.PHP_EOL;
1408
-        echo ' <patterns>     A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1409
-        echo ' <processes>    How many files should be checked simultaneously (default is 1)'.PHP_EOL;
1410
-        echo ' <report>       Print either the "full", "xml", "checkstyle", "csv"'.PHP_EOL;
1411
-        echo '                "json", "junit", "emacs", "source", "summary", "diff"'.PHP_EOL;
1412
-        echo '                "svnblame", "gitblame", "hgblame" or "notifysend" report,'.PHP_EOL;
1413
-        echo '                or specify the path to a custom report class'.PHP_EOL;
1414
-        echo '                (the "full" report is printed by default)'.PHP_EOL;
1415
-        echo ' <reportFile>   Write the report to the specified file path'.PHP_EOL;
1416
-        echo ' <reportWidth>  How many columns wide screen reports should be printed'.PHP_EOL;
1417
-        echo '                or set to "auto" to use current screen width, where supported'.PHP_EOL;
1418
-        echo ' <severity>     The minimum severity required to display an error or warning'.PHP_EOL;
1419
-        echo ' <sniffs>       A comma separated list of sniff codes to include or exclude from checking'.PHP_EOL;
1420
-        echo '                (all sniffs must be part of the specified standard)'.PHP_EOL;
1421
-        echo ' <standard>     The name or path of the coding standard to use'.PHP_EOL;
1422
-        echo ' <stdinPath>    If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1423
-        echo ' <tabWidth>     The number of spaces each tab represents'.PHP_EOL;
1396
+        echo ' <cacheFile>    Use a specific file for caching (uses a temporary file by default)' . PHP_EOL;
1397
+        echo ' <basepath>     A path to strip from the front of file paths inside reports' . PHP_EOL;
1398
+        echo ' <bootstrap>    A comma separated list of files to run before processing begins' . PHP_EOL;
1399
+        echo ' <encoding>     The encoding of the files being checked (default is utf-8)' . PHP_EOL;
1400
+        echo ' <extensions>   A comma separated list of file extensions to check' . PHP_EOL;
1401
+        echo '                The type of the file can be specified using: ext/type' . PHP_EOL;
1402
+        echo '                e.g., module/php,es/js' . PHP_EOL;
1403
+        echo ' <file>         One or more files and/or directories to check' . PHP_EOL;
1404
+        echo ' <fileList>     A file containing a list of files and/or directories to check (one per line)' . PHP_EOL;
1405
+        echo ' <filter>       Use the "gitmodified" filter, or specify the path to a custom filter class' . PHP_EOL;
1406
+        echo ' <generator>    Uses either the "HTML", "Markdown" or "Text" generator' . PHP_EOL;
1407
+        echo '                (forces documentation generation instead of checking)' . PHP_EOL;
1408
+        echo ' <patterns>     A comma separated list of patterns to ignore files and directories' . PHP_EOL;
1409
+        echo ' <processes>    How many files should be checked simultaneously (default is 1)' . PHP_EOL;
1410
+        echo ' <report>       Print either the "full", "xml", "checkstyle", "csv"' . PHP_EOL;
1411
+        echo '                "json", "junit", "emacs", "source", "summary", "diff"' . PHP_EOL;
1412
+        echo '                "svnblame", "gitblame", "hgblame" or "notifysend" report,' . PHP_EOL;
1413
+        echo '                or specify the path to a custom report class' . PHP_EOL;
1414
+        echo '                (the "full" report is printed by default)' . PHP_EOL;
1415
+        echo ' <reportFile>   Write the report to the specified file path' . PHP_EOL;
1416
+        echo ' <reportWidth>  How many columns wide screen reports should be printed' . PHP_EOL;
1417
+        echo '                or set to "auto" to use current screen width, where supported' . PHP_EOL;
1418
+        echo ' <severity>     The minimum severity required to display an error or warning' . PHP_EOL;
1419
+        echo ' <sniffs>       A comma separated list of sniff codes to include or exclude from checking' . PHP_EOL;
1420
+        echo '                (all sniffs must be part of the specified standard)' . PHP_EOL;
1421
+        echo ' <standard>     The name or path of the coding standard to use' . PHP_EOL;
1422
+        echo ' <stdinPath>    If processing STDIN, the file path that STDIN will be processed as' . PHP_EOL;
1423
+        echo ' <tabWidth>     The number of spaces each tab represents' . PHP_EOL;
1424 1424
 
1425 1425
     }//end printPHPCSUsage()
1426 1426
 
@@ -1432,48 +1432,48 @@  discard block
 block discarded – undo
1432 1432
      */
1433 1433
     public function printPHPCBFUsage()
1434 1434
     {
1435
-        echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--ignore-annotations] [--bootstrap=<bootstrap>]'.PHP_EOL;
1436
-        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--suffix=<suffix>]'.PHP_EOL;
1437
-        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
1438
-        echo '  [--tab-width=<tabWidth>] [--encoding=<encoding>] [--parallel=<processes>]'.PHP_EOL;
1439
-        echo '  [--basepath=<basepath>] [--extensions=<extensions>] [--ignore=<patterns>]'.PHP_EOL;
1440
-        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...'.PHP_EOL;
1435
+        echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--ignore-annotations] [--bootstrap=<bootstrap>]' . PHP_EOL;
1436
+        echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--suffix=<suffix>]' . PHP_EOL;
1437
+        echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]' . PHP_EOL;
1438
+        echo '  [--tab-width=<tabWidth>] [--encoding=<encoding>] [--parallel=<processes>]' . PHP_EOL;
1439
+        echo '  [--basepath=<basepath>] [--extensions=<extensions>] [--ignore=<patterns>]' . PHP_EOL;
1440
+        echo '  [--stdin-path=<stdinPath>] [--file-list=<fileList>] [--filter=<filter>] <file> - ...' . PHP_EOL;
1441 1441
         echo PHP_EOL;
1442
-        echo ' -     Fix STDIN instead of local files and directories'.PHP_EOL;
1443
-        echo ' -n    Do not fix warnings (shortcut for --warning-severity=0)'.PHP_EOL;
1444
-        echo ' -w    Fix both warnings and errors (on by default)'.PHP_EOL;
1445
-        echo ' -l    Local directory only, no recursion'.PHP_EOL;
1446
-        echo ' -p    Show progress of the run'.PHP_EOL;
1447
-        echo ' -q    Quiet mode; disables progress and verbose output'.PHP_EOL;
1448
-        echo ' -v    Print processed files'.PHP_EOL;
1449
-        echo ' -vv   Print ruleset and token output'.PHP_EOL;
1450
-        echo ' -vvv  Print sniff processing information'.PHP_EOL;
1451
-        echo ' -i    Show a list of installed coding standards'.PHP_EOL;
1452
-        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted'.PHP_EOL;
1442
+        echo ' -     Fix STDIN instead of local files and directories' . PHP_EOL;
1443
+        echo ' -n    Do not fix warnings (shortcut for --warning-severity=0)' . PHP_EOL;
1444
+        echo ' -w    Fix both warnings and errors (on by default)' . PHP_EOL;
1445
+        echo ' -l    Local directory only, no recursion' . PHP_EOL;
1446
+        echo ' -p    Show progress of the run' . PHP_EOL;
1447
+        echo ' -q    Quiet mode; disables progress and verbose output' . PHP_EOL;
1448
+        echo ' -v    Print processed files' . PHP_EOL;
1449
+        echo ' -vv   Print ruleset and token output' . PHP_EOL;
1450
+        echo ' -vvv  Print sniff processing information' . PHP_EOL;
1451
+        echo ' -i    Show a list of installed coding standards' . PHP_EOL;
1452
+        echo ' -d    Set the [key] php.ini value to [value] or [true] if value is omitted' . PHP_EOL;
1453 1453
         echo PHP_EOL;
1454
-        echo ' --help                Print this help message'.PHP_EOL;
1455
-        echo ' --version             Print version information'.PHP_EOL;
1456
-        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments'.PHP_EOL;
1454
+        echo ' --help                Print this help message' . PHP_EOL;
1455
+        echo ' --version             Print version information' . PHP_EOL;
1456
+        echo ' --ignore-annotations  Ignore all phpcs: annotations in code comments' . PHP_EOL;
1457 1457
         echo PHP_EOL;
1458
-        echo ' <basepath>    A path to strip from the front of file paths inside reports'.PHP_EOL;
1459
-        echo ' <bootstrap>   A comma separated list of files to run before processing begins'.PHP_EOL;
1460
-        echo ' <encoding>    The encoding of the files being fixed (default is utf-8)'.PHP_EOL;
1461
-        echo ' <extensions>  A comma separated list of file extensions to fix'.PHP_EOL;
1462
-        echo '               The type of the file can be specified using: ext/type'.PHP_EOL;
1463
-        echo '               e.g., module/php,es/js'.PHP_EOL;
1464
-        echo ' <file>        One or more files and/or directories to fix'.PHP_EOL;
1465
-        echo ' <fileList>    A file containing a list of files and/or directories to fix (one per line)'.PHP_EOL;
1466
-        echo ' <filter>      Use the "gitmodified" filter, or specify the path to a custom filter class'.PHP_EOL;
1467
-        echo ' <patterns>    A comma separated list of patterns to ignore files and directories'.PHP_EOL;
1468
-        echo ' <processes>   How many files should be fixed simultaneously (default is 1)'.PHP_EOL;
1469
-        echo ' <severity>    The minimum severity required to fix an error or warning'.PHP_EOL;
1470
-        echo ' <sniffs>      A comma separated list of sniff codes to include or exclude from fixing'.PHP_EOL;
1471
-        echo '               (all sniffs must be part of the specified standard)'.PHP_EOL;
1472
-        echo ' <standard>    The name or path of the coding standard to use'.PHP_EOL;
1473
-        echo ' <stdinPath>   If processing STDIN, the file path that STDIN will be processed as'.PHP_EOL;
1474
-        echo ' <suffix>      Write modified files to a filename using this suffix'.PHP_EOL;
1475
-        echo '               ("diff" and "patch" are not used in this mode)'.PHP_EOL;
1476
-        echo ' <tabWidth>    The number of spaces each tab represents'.PHP_EOL;
1458
+        echo ' <basepath>    A path to strip from the front of file paths inside reports' . PHP_EOL;
1459
+        echo ' <bootstrap>   A comma separated list of files to run before processing begins' . PHP_EOL;
1460
+        echo ' <encoding>    The encoding of the files being fixed (default is utf-8)' . PHP_EOL;
1461
+        echo ' <extensions>  A comma separated list of file extensions to fix' . PHP_EOL;
1462
+        echo '               The type of the file can be specified using: ext/type' . PHP_EOL;
1463
+        echo '               e.g., module/php,es/js' . PHP_EOL;
1464
+        echo ' <file>        One or more files and/or directories to fix' . PHP_EOL;
1465
+        echo ' <fileList>    A file containing a list of files and/or directories to fix (one per line)' . PHP_EOL;
1466
+        echo ' <filter>      Use the "gitmodified" filter, or specify the path to a custom filter class' . PHP_EOL;
1467
+        echo ' <patterns>    A comma separated list of patterns to ignore files and directories' . PHP_EOL;
1468
+        echo ' <processes>   How many files should be fixed simultaneously (default is 1)' . PHP_EOL;
1469
+        echo ' <severity>    The minimum severity required to fix an error or warning' . PHP_EOL;
1470
+        echo ' <sniffs>      A comma separated list of sniff codes to include or exclude from fixing' . PHP_EOL;
1471
+        echo '               (all sniffs must be part of the specified standard)' . PHP_EOL;
1472
+        echo ' <standard>    The name or path of the coding standard to use' . PHP_EOL;
1473
+        echo ' <stdinPath>   If processing STDIN, the file path that STDIN will be processed as' . PHP_EOL;
1474
+        echo ' <suffix>      Write modified files to a filename using this suffix' . PHP_EOL;
1475
+        echo '               ("diff" and "patch" are not used in this mode)' . PHP_EOL;
1476
+        echo ' <tabWidth>    The number of spaces each tab represents' . PHP_EOL;
1477 1477
 
1478 1478
     }//end printPHPCBFUsage()
1479 1479
 
@@ -1487,19 +1487,19 @@  discard block
 block discarded – undo
1487 1487
      * @see    setConfigData()
1488 1488
      * @see    getAllConfigData()
1489 1489
      */
1490
-    public static function getConfigData($key)
1490
+    public static function getConfigData( $key )
1491 1491
     {
1492 1492
         $phpCodeSnifferConfig = self::getAllConfigData();
1493 1493
 
1494
-        if ($phpCodeSnifferConfig === null) {
1494
+        if ( $phpCodeSnifferConfig === null ) {
1495 1495
             return null;
1496 1496
         }
1497 1497
 
1498
-        if (isset($phpCodeSnifferConfig[$key]) === false) {
1498
+        if ( isset( $phpCodeSnifferConfig[ $key ] ) === false ) {
1499 1499
             return null;
1500 1500
         }
1501 1501
 
1502
-        return $phpCodeSnifferConfig[$key];
1502
+        return $phpCodeSnifferConfig[ $key ];
1503 1503
 
1504 1504
     }//end getConfigData()
1505 1505
 
@@ -1512,34 +1512,34 @@  discard block
 block discarded – undo
1512 1512
      * @return string|null
1513 1513
      * @see    getConfigData()
1514 1514
      */
1515
-    public static function getExecutablePath($name)
1515
+    public static function getExecutablePath( $name )
1516 1516
     {
1517
-        $data = self::getConfigData($name.'_path');
1518
-        if ($data !== null) {
1517
+        $data = self::getConfigData( $name . '_path' );
1518
+        if ( $data !== null ) {
1519 1519
             return $data;
1520 1520
         }
1521 1521
 
1522
-        if ($name === "php") {
1522
+        if ( $name === "php" ) {
1523 1523
             // For php, we know the executable path. There's no need to look it up.
1524 1524
             return PHP_BINARY;
1525 1525
         }
1526 1526
 
1527
-        if (array_key_exists($name, self::$executablePaths) === true) {
1528
-            return self::$executablePaths[$name];
1527
+        if ( array_key_exists( $name, self::$executablePaths ) === true ) {
1528
+            return self::$executablePaths[ $name ];
1529 1529
         }
1530 1530
 
1531
-        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
1532
-            $cmd = 'where '.escapeshellarg($name).' 2> nul';
1531
+        if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
1532
+            $cmd = 'where ' . escapeshellarg( $name ) . ' 2> nul';
1533 1533
         } else {
1534
-            $cmd = 'which '.escapeshellarg($name).' 2> /dev/null';
1534
+            $cmd = 'which ' . escapeshellarg( $name ) . ' 2> /dev/null';
1535 1535
         }
1536 1536
 
1537
-        $result = exec($cmd, $output, $retVal);
1538
-        if ($retVal !== 0) {
1537
+        $result = exec( $cmd, $output, $retVal );
1538
+        if ( $retVal !== 0 ) {
1539 1539
             $result = null;
1540 1540
         }
1541 1541
 
1542
-        self::$executablePaths[$name] = $result;
1542
+        self::$executablePaths[ $name ] = $result;
1543 1543
         return $result;
1544 1544
 
1545 1545
     }//end getExecutablePath()
@@ -1560,26 +1560,26 @@  discard block
 block discarded – undo
1560 1560
      * @see    getConfigData()
1561 1561
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the config file can not be written.
1562 1562
      */
1563
-    public static function setConfigData($key, $value, $temp=false)
1563
+    public static function setConfigData( $key, $value, $temp = false )
1564 1564
     {
1565
-        if (isset(self::$overriddenDefaults['runtime-set']) === true
1566
-            && isset(self::$overriddenDefaults['runtime-set'][$key]) === true
1565
+        if ( isset( self::$overriddenDefaults[ 'runtime-set' ] ) === true
1566
+            && isset( self::$overriddenDefaults[ 'runtime-set' ][ $key ] ) === true
1567 1567
         ) {
1568 1568
             return false;
1569 1569
         }
1570 1570
 
1571
-        if ($temp === false) {
1571
+        if ( $temp === false ) {
1572 1572
             $path = '';
1573
-            if (is_callable('\Phar::running') === true) {
1574
-                $path = \Phar::running(false);
1573
+            if ( is_callable( '\Phar::running' ) === true ) {
1574
+                $path = \Phar::running( false );
1575 1575
             }
1576 1576
 
1577
-            if ($path !== '') {
1578
-                $configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1577
+            if ( $path !== '' ) {
1578
+                $configFile = dirname( $path ) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
1579 1579
             } else {
1580
-                $configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1581
-                if (is_file($configFile) === false
1582
-                    && strpos('@data_dir@', '@data_dir') === false
1580
+                $configFile = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
1581
+                if ( is_file( $configFile ) === false
1582
+                    && strpos( '@data_dir@', '@data_dir' ) === false
1583 1583
                 ) {
1584 1584
                     // If data_dir was replaced, this is a PEAR install and we can
1585 1585
                     // use the PEAR data dir to store the conf file.
@@ -1587,32 +1587,32 @@  discard block
 block discarded – undo
1587 1587
                 }
1588 1588
             }
1589 1589
 
1590
-            if (is_file($configFile) === true
1591
-                && is_writable($configFile) === false
1590
+            if ( is_file( $configFile ) === true
1591
+                && is_writable( $configFile ) === false
1592 1592
             ) {
1593
-                $error = 'ERROR: Config file '.$configFile.' is not writable'.PHP_EOL.PHP_EOL;
1594
-                throw new DeepExitException($error, 3);
1593
+                $error = 'ERROR: Config file ' . $configFile . ' is not writable' . PHP_EOL . PHP_EOL;
1594
+                throw new DeepExitException( $error, 3 );
1595 1595
             }
1596 1596
         }//end if
1597 1597
 
1598 1598
         $phpCodeSnifferConfig = self::getAllConfigData();
1599 1599
 
1600
-        if ($value === null) {
1601
-            if (isset($phpCodeSnifferConfig[$key]) === true) {
1602
-                unset($phpCodeSnifferConfig[$key]);
1600
+        if ( $value === null ) {
1601
+            if ( isset( $phpCodeSnifferConfig[ $key ] ) === true ) {
1602
+                unset( $phpCodeSnifferConfig[ $key ] );
1603 1603
             }
1604 1604
         } else {
1605
-            $phpCodeSnifferConfig[$key] = $value;
1605
+            $phpCodeSnifferConfig[ $key ] = $value;
1606 1606
         }
1607 1607
 
1608
-        if ($temp === false) {
1609
-            $output  = '<'.'?php'."\n".' $phpCodeSnifferConfig = ';
1610
-            $output .= var_export($phpCodeSnifferConfig, true);
1611
-            $output .= "\n?".'>';
1608
+        if ( $temp === false ) {
1609
+            $output  = '<' . '?php' . "\n" . ' $phpCodeSnifferConfig = ';
1610
+            $output .= var_export( $phpCodeSnifferConfig, true );
1611
+            $output .= "\n?" . '>';
1612 1612
 
1613
-            if (file_put_contents($configFile, $output) === false) {
1614
-                $error = 'ERROR: Config file '.$configFile.' could not be written'.PHP_EOL.PHP_EOL;
1615
-                throw new DeepExitException($error, 3);
1613
+            if ( file_put_contents( $configFile, $output ) === false ) {
1614
+                $error = 'ERROR: Config file ' . $configFile . ' could not be written' . PHP_EOL . PHP_EOL;
1615
+                throw new DeepExitException( $error, 3 );
1616 1616
             }
1617 1617
 
1618 1618
             self::$configDataFile = $configFile;
@@ -1622,10 +1622,10 @@  discard block
 block discarded – undo
1622 1622
 
1623 1623
         // If the installed paths are being set, make sure all known
1624 1624
         // standards paths are added to the autoloader.
1625
-        if ($key === 'installed_paths') {
1625
+        if ( $key === 'installed_paths' ) {
1626 1626
             $installedStandards = Util\Standards::getInstalledStandardDetails();
1627
-            foreach ($installedStandards as $name => $details) {
1628
-                Autoload::addSearchPath($details['path'], $details['namespace']);
1627
+            foreach ( $installedStandards as $name => $details ) {
1628
+                Autoload::addSearchPath( $details[ 'path' ], $details[ 'namespace' ] );
1629 1629
             }
1630 1630
         }
1631 1631
 
@@ -1642,34 +1642,34 @@  discard block
 block discarded – undo
1642 1642
      */
1643 1643
     public static function getAllConfigData()
1644 1644
     {
1645
-        if (self::$configData !== null) {
1645
+        if ( self::$configData !== null ) {
1646 1646
             return self::$configData;
1647 1647
         }
1648 1648
 
1649 1649
         $path = '';
1650
-        if (is_callable('\Phar::running') === true) {
1651
-            $path = \Phar::running(false);
1650
+        if ( is_callable( '\Phar::running' ) === true ) {
1651
+            $path = \Phar::running( false );
1652 1652
         }
1653 1653
 
1654
-        if ($path !== '') {
1655
-            $configFile = dirname($path).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1654
+        if ( $path !== '' ) {
1655
+            $configFile = dirname( $path ) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
1656 1656
         } else {
1657
-            $configFile = dirname(__DIR__).DIRECTORY_SEPARATOR.'CodeSniffer.conf';
1658
-            if (is_file($configFile) === false
1659
-                && strpos('@data_dir@', '@data_dir') === false
1657
+            $configFile = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'CodeSniffer.conf';
1658
+            if ( is_file( $configFile ) === false
1659
+                && strpos( '@data_dir@', '@data_dir' ) === false
1660 1660
             ) {
1661 1661
                 $configFile = '@data_dir@/PHP_CodeSniffer/CodeSniffer.conf';
1662 1662
             }
1663 1663
         }
1664 1664
 
1665
-        if (is_file($configFile) === false) {
1666
-            self::$configData = [];
1667
-            return [];
1665
+        if ( is_file( $configFile ) === false ) {
1666
+            self::$configData = [ ];
1667
+            return [ ];
1668 1668
         }
1669 1669
 
1670
-        if (is_readable($configFile) === false) {
1671
-            $error = 'ERROR: Config file '.$configFile.' is not readable'.PHP_EOL.PHP_EOL;
1672
-            throw new DeepExitException($error, 3);
1670
+        if ( is_readable( $configFile ) === false ) {
1671
+            $error = 'ERROR: Config file ' . $configFile . ' is not readable' . PHP_EOL . PHP_EOL;
1672
+            throw new DeepExitException( $error, 3 );
1673 1673
         }
1674 1674
 
1675 1675
         include $configFile;
@@ -1687,25 +1687,25 @@  discard block
 block discarded – undo
1687 1687
      *
1688 1688
      * @return void
1689 1689
      */
1690
-    public function printConfigData($data)
1690
+    public function printConfigData( $data )
1691 1691
     {
1692 1692
         $max  = 0;
1693
-        $keys = array_keys($data);
1694
-        foreach ($keys as $key) {
1695
-            $len = strlen($key);
1696
-            if (strlen($key) > $max) {
1693
+        $keys = array_keys( $data );
1694
+        foreach ( $keys as $key ) {
1695
+            $len = strlen( $key );
1696
+            if ( strlen( $key ) > $max ) {
1697 1697
                 $max = $len;
1698 1698
             }
1699 1699
         }
1700 1700
 
1701
-        if ($max === 0) {
1701
+        if ( $max === 0 ) {
1702 1702
             return;
1703 1703
         }
1704 1704
 
1705 1705
         $max += 2;
1706
-        ksort($data);
1707
-        foreach ($data as $name => $value) {
1708
-            echo str_pad($name.': ', $max).$value.PHP_EOL;
1706
+        ksort( $data );
1707
+        foreach ( $data as $name => $value ) {
1708
+            echo str_pad( $name . ': ', $max ) . $value . PHP_EOL;
1709 1709
         }
1710 1710
 
1711 1711
     }//end printConfigData()
Please login to merge, or discard this patch.
Braces   +23 added lines, -46 removed lines patch added patch discarded remove patch
@@ -15,8 +15,7 @@  discard block
 block discarded – undo
15 15
 use PHP_CodeSniffer\Exceptions\RuntimeException;
16 16
 use PHP_CodeSniffer\Exceptions\DeepExitException;
17 17
 
18
-class Config
19
-{
18
+class Config {
20 19
 
21 20
     /**
22 21
      * The current version.
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
      * @return mixed
191 190
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
192 191
      */
193
-    public function __get($name)
194
-    {
192
+    public function __get($name) {
195 193
         if (array_key_exists($name, $this->settings) === false) {
196 194
             throw new RuntimeException("ERROR: unable to get value of property \"$name\"");
197 195
         }
@@ -210,8 +208,7 @@  discard block
 block discarded – undo
210 208
      * @return void
211 209
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the setting name is invalid.
212 210
      */
213
-    public function __set($name, $value)
214
-    {
211
+    public function __set($name, $value) {
215 212
         if (array_key_exists($name, $this->settings) === false) {
216 213
             throw new RuntimeException("Can't __set() $name; setting doesn't exist");
217 214
         }
@@ -260,8 +257,7 @@  discard block
 block discarded – undo
260 257
      *
261 258
      * @return bool
262 259
      */
263
-    public function __isset($name)
264
-    {
260
+    public function __isset($name) {
265 261
         return isset($this->settings[$name]);
266 262
 
267 263
     }//end __isset()
@@ -274,8 +270,7 @@  discard block
 block discarded – undo
274 270
      *
275 271
      * @return void
276 272
      */
277
-    public function __unset($name)
278
-    {
273
+    public function __unset($name) {
279 274
         $this->settings[$name] = null;
280 275
 
281 276
     }//end __unset()
@@ -286,8 +281,7 @@  discard block
 block discarded – undo
286 281
      *
287 282
      * @return array<string, mixed>
288 283
      */
289
-    public function getSettings()
290
-    {
284
+    public function getSettings() {
291 285
         return $this->settings;
292 286
 
293 287
     }//end getSettings()
@@ -300,8 +294,7 @@  discard block
 block discarded – undo
300 294
      *
301 295
      * @return void
302 296
      */
303
-    public function setSettings($settings)
304
-    {
297
+    public function setSettings($settings) {
305 298
         return $this->settings = $settings;
306 299
 
307 300
     }//end setSettings()
@@ -316,8 +309,7 @@  discard block
 block discarded – undo
316 309
      *
317 310
      * @return void
318 311
      */
319
-    public function __construct(array $cliArgs=[], $dieOnUnknownArg=true)
320
-    {
312
+    public function __construct(array $cliArgs=[], $dieOnUnknownArg=true) {
321 313
         if (defined('PHP_CODESNIFFER_IN_TESTS') === true) {
322 314
             // Let everything through during testing so that we can
323 315
             // make use of PHPUnit command line arguments as well.
@@ -406,8 +398,7 @@  discard block
 block discarded – undo
406 398
      *
407 399
      * @return void
408 400
      */
409
-    public function setCommandLineValues($args)
410
-    {
401
+    public function setCommandLineValues($args) {
411 402
         $this->cliArgs = $args;
412 403
         $numArgs       = count($args);
413 404
 
@@ -455,8 +446,7 @@  discard block
 block discarded – undo
455 446
      *
456 447
      * @return array
457 448
      */
458
-    public function restoreDefaults()
459
-    {
449
+    public function restoreDefaults() {
460 450
         $this->files           = [];
461 451
         $this->standards       = ['PEAR'];
462 452
         $this->verbosity       = 0;
@@ -585,8 +575,7 @@  discard block
 block discarded – undo
585 575
      *
586 576
      * @return void
587 577
      */
588
-    public function processShortArgument($arg, $pos)
589
-    {
578
+    public function processShortArgument($arg, $pos) {
590 579
         switch ($arg) {
591 580
         case 'h':
592 581
         case '?':
@@ -689,8 +678,7 @@  discard block
 block discarded – undo
689 678
      *
690 679
      * @return void
691 680
      */
692
-    public function processLongArgument($arg, $pos)
693
-    {
681
+    public function processLongArgument($arg, $pos) {
694 682
         switch ($arg) {
695 683
         case 'help':
696 684
             ob_start();
@@ -1250,8 +1238,7 @@  discard block
 block discarded – undo
1250 1238
      *
1251 1239
      * @return void
1252 1240
      */
1253
-    public function processUnknownArgument($arg, $pos)
1254
-    {
1241
+    public function processUnknownArgument($arg, $pos) {
1255 1242
         // We don't know about any additional switches; just files.
1256 1243
         if ($arg{0} === '-') {
1257 1244
             if ($this->dieOnUnknownArg === false) {
@@ -1275,8 +1262,7 @@  discard block
 block discarded – undo
1275 1262
      *
1276 1263
      * @return void
1277 1264
      */
1278
-    public function processFilePath($path)
1279
-    {
1265
+    public function processFilePath($path) {
1280 1266
         // If we are processing STDIN, don't record any files to check.
1281 1267
         if ($this->stdin === true) {
1282 1268
             return;
@@ -1308,8 +1294,7 @@  discard block
 block discarded – undo
1308 1294
      *
1309 1295
      * @return void
1310 1296
      */
1311
-    public function printUsage()
1312
-    {
1297
+    public function printUsage() {
1313 1298
         echo PHP_EOL;
1314 1299
 
1315 1300
         if (PHP_CODESNIFFER_CBF === true) {
@@ -1331,8 +1316,7 @@  discard block
 block discarded – undo
1331 1316
      *
1332 1317
      * @return string|void
1333 1318
      */
1334
-    public function printShortUsage($return=false)
1335
-    {
1319
+    public function printShortUsage($return=false) {
1336 1320
         if (PHP_CODESNIFFER_CBF === true) {
1337 1321
             $usage = 'Run "phpcbf --help" for usage information';
1338 1322
         } else {
@@ -1355,8 +1339,7 @@  discard block
 block discarded – undo
1355 1339
      *
1356 1340
      * @return void
1357 1341
      */
1358
-    public function printPHPCSUsage()
1359
-    {
1342
+    public function printPHPCSUsage() {
1360 1343
         echo 'Usage: phpcs [-nwlsaepqvi] [-d key[=value]] [--colors] [--no-colors]'.PHP_EOL;
1361 1344
         echo '  [--cache[=<cacheFile>]] [--no-cache] [--tab-width=<tabWidth>]'.PHP_EOL;
1362 1345
         echo '  [--report=<report>] [--report-file=<reportFile>] [--report-<report>=<reportFile>]'.PHP_EOL;
@@ -1430,8 +1413,7 @@  discard block
 block discarded – undo
1430 1413
      *
1431 1414
      * @return void
1432 1415
      */
1433
-    public function printPHPCBFUsage()
1434
-    {
1416
+    public function printPHPCBFUsage() {
1435 1417
         echo 'Usage: phpcbf [-nwli] [-d key[=value]] [--ignore-annotations] [--bootstrap=<bootstrap>]'.PHP_EOL;
1436 1418
         echo '  [--standard=<standard>] [--sniffs=<sniffs>] [--exclude=<sniffs>] [--suffix=<suffix>]'.PHP_EOL;
1437 1419
         echo '  [--severity=<severity>] [--error-severity=<severity>] [--warning-severity=<severity>]'.PHP_EOL;
@@ -1487,8 +1469,7 @@  discard block
 block discarded – undo
1487 1469
      * @see    setConfigData()
1488 1470
      * @see    getAllConfigData()
1489 1471
      */
1490
-    public static function getConfigData($key)
1491
-    {
1472
+    public static function getConfigData($key) {
1492 1473
         $phpCodeSnifferConfig = self::getAllConfigData();
1493 1474
 
1494 1475
         if ($phpCodeSnifferConfig === null) {
@@ -1512,8 +1493,7 @@  discard block
 block discarded – undo
1512 1493
      * @return string|null
1513 1494
      * @see    getConfigData()
1514 1495
      */
1515
-    public static function getExecutablePath($name)
1516
-    {
1496
+    public static function getExecutablePath($name) {
1517 1497
         $data = self::getConfigData($name.'_path');
1518 1498
         if ($data !== null) {
1519 1499
             return $data;
@@ -1560,8 +1540,7 @@  discard block
 block discarded – undo
1560 1540
      * @see    getConfigData()
1561 1541
      * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the config file can not be written.
1562 1542
      */
1563
-    public static function setConfigData($key, $value, $temp=false)
1564
-    {
1543
+    public static function setConfigData($key, $value, $temp=false) {
1565 1544
         if (isset(self::$overriddenDefaults['runtime-set']) === true
1566 1545
             && isset(self::$overriddenDefaults['runtime-set'][$key]) === true
1567 1546
         ) {
@@ -1640,8 +1619,7 @@  discard block
 block discarded – undo
1640 1619
      * @return array<string, string>
1641 1620
      * @see    getConfigData()
1642 1621
      */
1643
-    public static function getAllConfigData()
1644
-    {
1622
+    public static function getAllConfigData() {
1645 1623
         if (self::$configData !== null) {
1646 1624
             return self::$configData;
1647 1625
         }
@@ -1687,8 +1665,7 @@  discard block
 block discarded – undo
1687 1665
      *
1688 1666
      * @return void
1689 1667
      */
1690
-    public function printConfigData($data)
1691
-    {
1668
+    public function printConfigData($data) {
1692 1669
         $max  = 0;
1693 1670
         $keys = array_keys($data);
1694 1671
         foreach ($keys as $key) {
Please login to merge, or discard this patch.