Completed
Pull Request — master (#11)
by Tomáš
03:35
created
src/Config.php 1 patch
Switch Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -186,35 +186,35 @@  discard block
 block discarded – undo
186 186
         }
187 187
 
188 188
         switch ($name) {
189
-        case 'reportWidth' :
190
-            // Support auto terminal width.
191
-            if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
192
-                $value = (int) $matches[1];
193
-            } else {
194
-                $value = (int) $value;
195
-            }
196
-            break;
197
-        case 'standards' :
198
-            $cleaned = array();
199
-
200
-            // Check if the standard name is valid, or if the case is invalid.
201
-            $installedStandards = Util\Standards::getInstalledStandards();
202
-            foreach ($value as $standard) {
203
-                foreach ($installedStandards as $validStandard) {
204
-                    if (strtolower($standard) === strtolower($validStandard)) {
205
-                        $standard = $validStandard;
206
-                        break;
207
-                    }
189
+            case 'reportWidth' :
190
+                // Support auto terminal width.
191
+                if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) {
192
+                    $value = (int) $matches[1];
193
+                } else {
194
+                    $value = (int) $value;
208 195
                 }
196
+                break;
197
+            case 'standards' :
198
+                $cleaned = array();
199
+
200
+                // Check if the standard name is valid, or if the case is invalid.
201
+                $installedStandards = Util\Standards::getInstalledStandards();
202
+                foreach ($value as $standard) {
203
+                    foreach ($installedStandards as $validStandard) {
204
+                        if (strtolower($standard) === strtolower($validStandard)) {
205
+                            $standard = $validStandard;
206
+                            break;
207
+                        }
208
+                    }
209 209
 
210
-                $cleaned[] = $standard;
211
-            }
210
+                    $cleaned[] = $standard;
211
+                }
212 212
 
213
-            $value = $cleaned;
214
-            break;
215
-        default :
216
-            // No validation required.
217
-            break;
213
+                $value = $cleaned;
214
+                break;
215
+            default :
216
+                // No validation required.
217
+                break;
218 218
         }//end switch
219 219
 
220 220
         $this->settings[$name] = $value;
@@ -479,68 +479,68 @@  discard block
 block discarded – undo
479 479
     public function processShortArgument($arg, $pos)
480 480
     {
481 481
         switch ($arg) {
482
-        case 'h':
483
-        case '?':
484
-            $this->printUsage();
485
-            exit(0);
486
-        case 'i' :
487
-            Util\Standards::printInstalledStandards();
488
-            exit(0);
489
-        case 'v' :
490
-            $this->verbosity++;
491
-            $this->overriddenDefaults['verbosity'] = true;
492
-            break;
493
-        case 'l' :
494
-            $this->local = true;
495
-            $this->overriddenDefaults['local'] = true;
496
-            break;
497
-        case 's' :
498
-            $this->showSources = true;
499
-            $this->overriddenDefaults['showSources'] = true;
500
-            break;
501
-        case 'a' :
502
-            $this->interactive = true;
503
-            $this->overriddenDefaults['interactive'] = true;
504
-            break;
505
-        case 'e':
506
-            $this->explain = true;
507
-            $this->overriddenDefaults['explain'] = true;
508
-            break;
509
-        case 'p' :
510
-            $this->showProgress = true;
511
-            $this->overriddenDefaults['showProgress'] = true;
512
-            break;
513
-        case 'm' :
514
-            $this->recordErrors = false;
515
-            $this->overriddenDefaults['recordErrors'] = true;
516
-            break;
517
-        case 'd' :
518
-            $ini = explode('=', $this->cliArgs[($pos + 1)]);
519
-            $this->cliArgs[($pos + 1)] = '';
520
-            if (isset($ini[1]) === true) {
521
-                ini_set($ini[0], $ini[1]);
522
-            } else {
523
-                ini_set($ini[0], true);
524
-            }
525
-            break;
526
-        case 'n' :
527
-            if (isset($this->overriddenDefaults['warningSeverity']) === false) {
528
-                $this->warningSeverity = 0;
529
-                $this->overriddenDefaults['warningSeverity'] = true;
530
-            }
531
-            break;
532
-        case 'w' :
533
-            if (isset($this->overriddenDefaults['warningSeverity']) === false) {
534
-                $this->warningSeverity = $this->errorSeverity;
535
-                $this->overriddenDefaults['warningSeverity'] = true;
536
-            }
537
-            break;
538
-        default:
539
-            if ($this->dieOnUnknownArg === false) {
540
-                $this->values[$arg] = $arg;
541
-            } else {
542
-                $this->processUnknownArgument('-'.$arg, $pos);
543
-            }
482
+            case 'h':
483
+            case '?':
484
+                $this->printUsage();
485
+                exit(0);
486
+            case 'i' :
487
+                Util\Standards::printInstalledStandards();
488
+                exit(0);
489
+            case 'v' :
490
+                $this->verbosity++;
491
+                $this->overriddenDefaults['verbosity'] = true;
492
+                break;
493
+            case 'l' :
494
+                $this->local = true;
495
+                $this->overriddenDefaults['local'] = true;
496
+                break;
497
+            case 's' :
498
+                $this->showSources = true;
499
+                $this->overriddenDefaults['showSources'] = true;
500
+                break;
501
+            case 'a' :
502
+                $this->interactive = true;
503
+                $this->overriddenDefaults['interactive'] = true;
504
+                break;
505
+            case 'e':
506
+                $this->explain = true;
507
+                $this->overriddenDefaults['explain'] = true;
508
+                break;
509
+            case 'p' :
510
+                $this->showProgress = true;
511
+                $this->overriddenDefaults['showProgress'] = true;
512
+                break;
513
+            case 'm' :
514
+                $this->recordErrors = false;
515
+                $this->overriddenDefaults['recordErrors'] = true;
516
+                break;
517
+            case 'd' :
518
+                $ini = explode('=', $this->cliArgs[($pos + 1)]);
519
+                $this->cliArgs[($pos + 1)] = '';
520
+                if (isset($ini[1]) === true) {
521
+                    ini_set($ini[0], $ini[1]);
522
+                } else {
523
+                    ini_set($ini[0], true);
524
+                }
525
+                break;
526
+            case 'n' :
527
+                if (isset($this->overriddenDefaults['warningSeverity']) === false) {
528
+                    $this->warningSeverity = 0;
529
+                    $this->overriddenDefaults['warningSeverity'] = true;
530
+                }
531
+                break;
532
+            case 'w' :
533
+                if (isset($this->overriddenDefaults['warningSeverity']) === false) {
534
+                    $this->warningSeverity = $this->errorSeverity;
535
+                    $this->overriddenDefaults['warningSeverity'] = true;
536
+                }
537
+                break;
538
+            default:
539
+                if ($this->dieOnUnknownArg === false) {
540
+                    $this->values[$arg] = $arg;
541
+                } else {
542
+                    $this->processUnknownArgument('-'.$arg, $pos);
543
+                }
544 544
         }//end switch
545 545
 
546 546
     }//end processShortArgument()
@@ -557,170 +557,170 @@  discard block
 block discarded – undo
557 557
     public function processLongArgument($arg, $pos)
558 558
     {
559 559
         switch ($arg) {
560
-        case 'help':
561
-            $this->printUsage();
562
-            exit(0);
563
-        case 'version':
564
-            echo 'Symplify\PHP7_CodeSniffer version '.self::VERSION;
565
-            exit(0);
566
-        case 'cache':
567
-            if (defined('Symplify\PHP7_CodeSniffer_IN_TESTS') === false) {
568
-                $this->cache = true;
560
+            case 'help':
561
+                $this->printUsage();
562
+                exit(0);
563
+            case 'version':
564
+                echo 'Symplify\PHP7_CodeSniffer version '.self::VERSION;
565
+                exit(0);
566
+            case 'cache':
567
+                if (defined('Symplify\PHP7_CodeSniffer_IN_TESTS') === false) {
568
+                    $this->cache = true;
569
+                    $this->overriddenDefaults['cache'] = true;
570
+                }
571
+                break;
572
+            case 'no-cache':
573
+                $this->cache = false;
569 574
                 $this->overriddenDefaults['cache'] = true;
570
-            }
571
-            break;
572
-        case 'no-cache':
573
-            $this->cache = false;
574
-            $this->overriddenDefaults['cache'] = true;
575
-            break;
576
-        default:
577
-            if (substr($arg, 0, 7) === 'sniffs=') {
578
-                $sniffs = explode(',', substr($arg, 7));
579
-                foreach ($sniffs as $sniff) {
580
-                    if (substr_count($sniff, '.') !== 2) {
581
-                        echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
582
-                        $this->printUsage();
583
-                        exit(2);
575
+                break;
576
+            default:
577
+                if (substr($arg, 0, 7) === 'sniffs=') {
578
+                    $sniffs = explode(',', substr($arg, 7));
579
+                    foreach ($sniffs as $sniff) {
580
+                        if (substr_count($sniff, '.') !== 2) {
581
+                            echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL;
582
+                            $this->printUsage();
583
+                            exit(2);
584
+                        }
584 585
                     }
585
-                }
586 586
 
587
-                $this->sniffs = $sniffs;
588
-                $this->overriddenDefaults['sniffs'] = true;
589
-            } else if (substr($arg, 0, 10) === 'bootstrap=') {
590
-                $files     = explode(',', substr($arg, 10));
591
-                $bootstrap = array();
592
-                foreach ($files as $file) {
593
-                    $path = Util\Common::realpath($file);
594
-                    if ($path === false) {
595
-                        echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
596
-                        $this->printUsage();
597
-                        exit(2);
587
+                    $this->sniffs = $sniffs;
588
+                    $this->overriddenDefaults['sniffs'] = true;
589
+                } else if (substr($arg, 0, 10) === 'bootstrap=') {
590
+                    $files     = explode(',', substr($arg, 10));
591
+                    $bootstrap = array();
592
+                    foreach ($files as $file) {
593
+                        $path = Util\Common::realpath($file);
594
+                        if ($path === false) {
595
+                            echo 'ERROR: The specified bootstrap file "'.$file.'" does not exist'.PHP_EOL.PHP_EOL;
596
+                            $this->printUsage();
597
+                            exit(2);
598
+                        }
599
+
600
+                        $bootstrap[] = $path;
598 601
                     }
599 602
 
600
-                    $bootstrap[] = $path;
601
-                }
603
+                    $this->bootstrap = array_merge($this->bootstrap, $bootstrap);
604
+                    $this->overriddenDefaults['bootstrap'] = true;
605
+                } else if (substr($arg, 0, 11) === 'stdin-path=') {
606
+                    $this->stdinPath = Util\Common::realpath(substr($arg, 11));
602 607
 
603
-                $this->bootstrap = array_merge($this->bootstrap, $bootstrap);
604
-                $this->overriddenDefaults['bootstrap'] = true;
605
-            } else if (substr($arg, 0, 11) === 'stdin-path=') {
606
-                $this->stdinPath = Util\Common::realpath(substr($arg, 11));
608
+                    // It may not exist and return false instead, so use whatever they gave us.
609
+                    if ($this->stdinPath === false) {
610
+                        $this->stdinPath = trim(substr($arg, 11));
611
+                    }
607 612
 
608
-                // It may not exist and return false instead, so use whatever they gave us.
609
-                if ($this->stdinPath === false) {
610
-                    $this->stdinPath = trim(substr($arg, 11));
611
-                }
613
+                    $this->overriddenDefaults['stdinPath'] = true;
614
+                } else if (substr($arg, 0, 9) === 'basepath=') {
615
+                    if (isset($this->overriddenDefaults['basepath']) === true) {
616
+                        break;
617
+                    }
612 618
 
613
-                $this->overriddenDefaults['stdinPath'] = true;
614
-            } else if (substr($arg, 0, 9) === 'basepath=') {
615
-                if (isset($this->overriddenDefaults['basepath']) === true) {
616
-                    break;
617
-                }
619
+                    $this->basepath = Util\Common::realpath(substr($arg, 9));
618 620
 
619
-                $this->basepath = Util\Common::realpath(substr($arg, 9));
621
+                    // It may not exist and return false instead.
622
+                    if ($this->basepath === false) {
623
+                        $this->basepath = substr($arg, 9);
624
+                    }
620 625
 
621
-                // It may not exist and return false instead.
622
-                if ($this->basepath === false) {
623
-                    $this->basepath = substr($arg, 9);
624
-                }
626
+                    $this->overriddenDefaults['basepath'] = true;
625 627
 
626
-                $this->overriddenDefaults['basepath'] = true;
628
+                    if (is_dir($this->basepath) === false) {
629
+                        echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
630
+                        $this->printUsage();
631
+                        exit(2);
632
+                    }
633
+                } else if (substr($arg, 0, 7) === 'filter=') {
634
+                    if (isset($this->overriddenDefaults['filter']) === true) {
635
+                        break;
636
+                    }
627 637
 
628
-                if (is_dir($this->basepath) === false) {
629
-                    echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL;
630
-                    $this->printUsage();
631
-                    exit(2);
632
-                }
633
-            } else if (substr($arg, 0, 7) === 'filter=') {
634
-                if (isset($this->overriddenDefaults['filter']) === true) {
635
-                    break;
636
-                }
638
+                    $this->filter = substr($arg, 7);
639
+                    $this->overriddenDefaults['filter'] = true;
640
+                } else if (substr($arg, 0, 9) === 'standard=') {
641
+                    $standards = trim(substr($arg, 9));
642
+                    if ($standards !== '') {
643
+                        $this->standards = explode(',', $standards);
644
+                    }
637 645
 
638
-                $this->filter = substr($arg, 7);
639
-                $this->overriddenDefaults['filter'] = true;
640
-            } else if (substr($arg, 0, 9) === 'standard=') {
641
-                $standards = trim(substr($arg, 9));
642
-                if ($standards !== '') {
643
-                    $this->standards = explode(',', $standards);
644
-                }
646
+                    $this->overriddenDefaults['standards'] = true;
647
+                } else if (substr($arg, 0, 11) === 'extensions=') {
648
+                    $extensions    = explode(',', substr($arg, 11));
649
+                    $newExtensions = array();
650
+                    foreach ($extensions as $ext) {
651
+                        $slash = strpos($ext, '/');
652
+                        if ($slash !== false) {
653
+                            // They specified the tokenizer too.
654
+                            list($ext, $tokenizer) = explode('/', $ext);
655
+                            $newExtensions[$ext]   = strtoupper($tokenizer);
656
+                            continue;
657
+                        }
645 658
 
646
-                $this->overriddenDefaults['standards'] = true;
647
-            } else if (substr($arg, 0, 11) === 'extensions=') {
648
-                $extensions    = explode(',', substr($arg, 11));
649
-                $newExtensions = array();
650
-                foreach ($extensions as $ext) {
651
-                    $slash = strpos($ext, '/');
652
-                    if ($slash !== false) {
653
-                        // They specified the tokenizer too.
654
-                        list($ext, $tokenizer) = explode('/', $ext);
655
-                        $newExtensions[$ext]   = strtoupper($tokenizer);
656
-                        continue;
659
+                        if (isset($this->extensions[$ext]) === true) {
660
+                            $newExtensions[$ext] = $this->extensions[$ext];
661
+                        } else {
662
+                            $newExtensions[$ext] = 'PHP';
663
+                        }
657 664
                     }
658 665
 
659
-                    if (isset($this->extensions[$ext]) === true) {
660
-                        $newExtensions[$ext] = $this->extensions[$ext];
661
-                    } else {
662
-                        $newExtensions[$ext] = 'PHP';
663
-                    }
664
-                }
666
+                    $this->extensions = $newExtensions;
667
+                    $this->overriddenDefaults['extensions'] = true;
668
+                } else if (substr($arg, 0, 7) === 'suffix=') {
669
+                    $this->suffix = explode(',', substr($arg, 7));
670
+                    $this->overriddenDefaults['suffix'] = true;
671
+                } else if (substr($arg, 0, 9) === 'parallel=') {
672
+                    $this->parallel = max((int) substr($arg, 9), 1);
673
+                    $this->overriddenDefaults['parallel'] = true;
674
+                } else if (substr($arg, 0, 9) === 'severity=') {
675
+                    $this->errorSeverity   = (int) substr($arg, 9);
676
+                    $this->warningSeverity = $this->errorSeverity;
677
+                    $this->overriddenDefaults['errorSeverity']   = true;
678
+                    $this->overriddenDefaults['warningSeverity'] = true;
679
+                } else if (substr($arg, 0, 15) === 'error-severity=') {
680
+                    $this->errorSeverity = (int) substr($arg, 15);
681
+                    $this->overriddenDefaults['errorSeverity'] = true;
682
+                } else if (substr($arg, 0, 17) === 'warning-severity=') {
683
+                    $this->warningSeverity = (int) substr($arg, 17);
684
+                    $this->overriddenDefaults['warningSeverity'] = true;
685
+                } else if (substr($arg, 0, 7) === 'ignore=') {
686
+                    // Split the ignore string on commas, unless the comma is escaped
687
+                    // using 1 or 3 slashes (\, or \\\,).
688
+                    $patterns = preg_split(
689
+                        '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
690
+                        substr($arg, 7)
691
+                    );
692
+
693
+                    $ignored = array();
694
+                    foreach ($patterns as $pattern) {
695
+                        $pattern = trim($pattern);
696
+                        if ($pattern === '') {
697
+                            continue;
698
+                        }
665 699
 
666
-                $this->extensions = $newExtensions;
667
-                $this->overriddenDefaults['extensions'] = true;
668
-            } else if (substr($arg, 0, 7) === 'suffix=') {
669
-                $this->suffix = explode(',', substr($arg, 7));
670
-                $this->overriddenDefaults['suffix'] = true;
671
-            } else if (substr($arg, 0, 9) === 'parallel=') {
672
-                $this->parallel = max((int) substr($arg, 9), 1);
673
-                $this->overriddenDefaults['parallel'] = true;
674
-            } else if (substr($arg, 0, 9) === 'severity=') {
675
-                $this->errorSeverity   = (int) substr($arg, 9);
676
-                $this->warningSeverity = $this->errorSeverity;
677
-                $this->overriddenDefaults['errorSeverity']   = true;
678
-                $this->overriddenDefaults['warningSeverity'] = true;
679
-            } else if (substr($arg, 0, 15) === 'error-severity=') {
680
-                $this->errorSeverity = (int) substr($arg, 15);
681
-                $this->overriddenDefaults['errorSeverity'] = true;
682
-            } else if (substr($arg, 0, 17) === 'warning-severity=') {
683
-                $this->warningSeverity = (int) substr($arg, 17);
684
-                $this->overriddenDefaults['warningSeverity'] = true;
685
-            } else if (substr($arg, 0, 7) === 'ignore=') {
686
-                // Split the ignore string on commas, unless the comma is escaped
687
-                // using 1 or 3 slashes (\, or \\\,).
688
-                $patterns = preg_split(
689
-                    '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/',
690
-                    substr($arg, 7)
691
-                );
692
-
693
-                $ignored = array();
694
-                foreach ($patterns as $pattern) {
695
-                    $pattern = trim($pattern);
696
-                    if ($pattern === '') {
697
-                        continue;
700
+                        $ignored[$pattern] = 'absolute';
698 701
                     }
699 702
 
700
-                    $ignored[$pattern] = 'absolute';
701
-                }
702
-
703
-                $this->ignored = $ignored;
704
-                $this->overriddenDefaults['ignored'] = true;
705
-            } else if (substr($arg, 0, 10) === 'tab-width=') {
706
-                $this->tabWidth = (int) substr($arg, 10);
707
-                $this->overriddenDefaults['tabWidth'] = true;
708
-            } else {
709
-                if ($this->dieOnUnknownArg === false) {
710
-                    $eqPos = strpos($arg, '=');
711
-                    if ($eqPos === false) {
712
-                        $this->values[$arg] = $arg;
703
+                    $this->ignored = $ignored;
704
+                    $this->overriddenDefaults['ignored'] = true;
705
+                } else if (substr($arg, 0, 10) === 'tab-width=') {
706
+                    $this->tabWidth = (int) substr($arg, 10);
707
+                    $this->overriddenDefaults['tabWidth'] = true;
708
+                } else {
709
+                    if ($this->dieOnUnknownArg === false) {
710
+                        $eqPos = strpos($arg, '=');
711
+                        if ($eqPos === false) {
712
+                            $this->values[$arg] = $arg;
713
+                        } else {
714
+                            $value = substr($arg, ($eqPos + 1));
715
+                            $arg   = substr($arg, 0, $eqPos);
716
+                            $this->values[$arg] = $value;
717
+                        }
713 718
                     } else {
714
-                        $value = substr($arg, ($eqPos + 1));
715
-                        $arg   = substr($arg, 0, $eqPos);
716
-                        $this->values[$arg] = $value;
719
+                        $this->processUnknownArgument('--'.$arg, $pos);
717 720
                     }
718
-                } else {
719
-                    $this->processUnknownArgument('--'.$arg, $pos);
720
-                }
721
-            }//end if
721
+                }//end if
722 722
 
723
-            break;
723
+                break;
724 724
         }//end switch
725 725
 
726 726
     }//end processLongArgument()
Please login to merge, or discard this patch.