@@ -174,35 +174,35 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | switch ($name) { |
177 | - case 'reportWidth' : |
|
178 | - // Support auto terminal width. |
|
179 | - if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
180 | - $value = (int) $matches[1]; |
|
181 | - } else { |
|
182 | - $value = (int) $value; |
|
183 | - } |
|
184 | - break; |
|
185 | - case 'standards' : |
|
186 | - $cleaned = array(); |
|
187 | - |
|
188 | - // Check if the standard name is valid, or if the case is invalid. |
|
189 | - $installedStandards = Util\Standards::getInstalledStandards(); |
|
190 | - foreach ($value as $standard) { |
|
191 | - foreach ($installedStandards as $validStandard) { |
|
192 | - if (strtolower($standard) === strtolower($validStandard)) { |
|
193 | - $standard = $validStandard; |
|
194 | - break; |
|
195 | - } |
|
177 | + case 'reportWidth' : |
|
178 | + // Support auto terminal width. |
|
179 | + if ($value === 'auto' && preg_match('|\d+ (\d+)|', shell_exec('stty size 2>&1'), $matches) === 1) { |
|
180 | + $value = (int) $matches[1]; |
|
181 | + } else { |
|
182 | + $value = (int) $value; |
|
196 | 183 | } |
184 | + break; |
|
185 | + case 'standards' : |
|
186 | + $cleaned = array(); |
|
187 | + |
|
188 | + // Check if the standard name is valid, or if the case is invalid. |
|
189 | + $installedStandards = Util\Standards::getInstalledStandards(); |
|
190 | + foreach ($value as $standard) { |
|
191 | + foreach ($installedStandards as $validStandard) { |
|
192 | + if (strtolower($standard) === strtolower($validStandard)) { |
|
193 | + $standard = $validStandard; |
|
194 | + break; |
|
195 | + } |
|
196 | + } |
|
197 | 197 | |
198 | - $cleaned[] = $standard; |
|
199 | - } |
|
198 | + $cleaned[] = $standard; |
|
199 | + } |
|
200 | 200 | |
201 | - $value = $cleaned; |
|
202 | - break; |
|
203 | - default : |
|
204 | - // No validation required. |
|
205 | - break; |
|
201 | + $value = $cleaned; |
|
202 | + break; |
|
203 | + default : |
|
204 | + // No validation required. |
|
205 | + break; |
|
206 | 206 | }//end switch |
207 | 207 | |
208 | 208 | $this->settings[$name] = $value; |
@@ -441,60 +441,60 @@ discard block |
||
441 | 441 | public function processShortArgument($arg, $pos) |
442 | 442 | { |
443 | 443 | switch ($arg) { |
444 | - case 'h': |
|
445 | - case '?': |
|
446 | - $this->printUsage(); |
|
447 | - exit(0); |
|
448 | - case 'i' : |
|
449 | - Util\Standards::printInstalledStandards(); |
|
450 | - exit(0); |
|
451 | - case 'v' : |
|
452 | - $this->verbosity++; |
|
453 | - $this->overriddenDefaults['verbosity'] = true; |
|
454 | - break; |
|
455 | - case 'l' : |
|
456 | - $this->local = true; |
|
457 | - $this->overriddenDefaults['local'] = true; |
|
458 | - break; |
|
459 | - case 's' : |
|
460 | - $this->showSources = true; |
|
461 | - $this->overriddenDefaults['showSources'] = true; |
|
462 | - break; |
|
463 | - case 'e': |
|
464 | - $this->explain = true; |
|
465 | - $this->overriddenDefaults['explain'] = true; |
|
466 | - break; |
|
467 | - case 'p' : |
|
468 | - $this->showProgress = true; |
|
469 | - $this->overriddenDefaults['showProgress'] = true; |
|
470 | - break; |
|
471 | - case 'm' : |
|
472 | - $this->recordErrors = false; |
|
473 | - $this->overriddenDefaults['recordErrors'] = true; |
|
474 | - break; |
|
475 | - case 'd' : |
|
476 | - $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
477 | - $this->cliArgs[($pos + 1)] = ''; |
|
478 | - if (isset($ini[1]) === true) { |
|
479 | - ini_set($ini[0], $ini[1]); |
|
480 | - } else { |
|
481 | - ini_set($ini[0], true); |
|
482 | - } |
|
483 | - break; |
|
484 | - case 'n' : |
|
485 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
486 | - $this->warningSeverity = 0; |
|
487 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
488 | - } |
|
489 | - break; |
|
490 | - case 'w' : |
|
491 | - if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
492 | - $this->warningSeverity = $this->errorSeverity; |
|
493 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
494 | - } |
|
495 | - break; |
|
496 | - default: |
|
497 | - $this->processUnknownArgument('-'.$arg, $pos); |
|
444 | + case 'h': |
|
445 | + case '?': |
|
446 | + $this->printUsage(); |
|
447 | + exit(0); |
|
448 | + case 'i' : |
|
449 | + Util\Standards::printInstalledStandards(); |
|
450 | + exit(0); |
|
451 | + case 'v' : |
|
452 | + $this->verbosity++; |
|
453 | + $this->overriddenDefaults['verbosity'] = true; |
|
454 | + break; |
|
455 | + case 'l' : |
|
456 | + $this->local = true; |
|
457 | + $this->overriddenDefaults['local'] = true; |
|
458 | + break; |
|
459 | + case 's' : |
|
460 | + $this->showSources = true; |
|
461 | + $this->overriddenDefaults['showSources'] = true; |
|
462 | + break; |
|
463 | + case 'e': |
|
464 | + $this->explain = true; |
|
465 | + $this->overriddenDefaults['explain'] = true; |
|
466 | + break; |
|
467 | + case 'p' : |
|
468 | + $this->showProgress = true; |
|
469 | + $this->overriddenDefaults['showProgress'] = true; |
|
470 | + break; |
|
471 | + case 'm' : |
|
472 | + $this->recordErrors = false; |
|
473 | + $this->overriddenDefaults['recordErrors'] = true; |
|
474 | + break; |
|
475 | + case 'd' : |
|
476 | + $ini = explode('=', $this->cliArgs[($pos + 1)]); |
|
477 | + $this->cliArgs[($pos + 1)] = ''; |
|
478 | + if (isset($ini[1]) === true) { |
|
479 | + ini_set($ini[0], $ini[1]); |
|
480 | + } else { |
|
481 | + ini_set($ini[0], true); |
|
482 | + } |
|
483 | + break; |
|
484 | + case 'n' : |
|
485 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
486 | + $this->warningSeverity = 0; |
|
487 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
488 | + } |
|
489 | + break; |
|
490 | + case 'w' : |
|
491 | + if (isset($this->overriddenDefaults['warningSeverity']) === false) { |
|
492 | + $this->warningSeverity = $this->errorSeverity; |
|
493 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
494 | + } |
|
495 | + break; |
|
496 | + default: |
|
497 | + $this->processUnknownArgument('-'.$arg, $pos); |
|
498 | 498 | }//end switch |
499 | 499 | |
500 | 500 | }//end processShortArgument() |
@@ -511,138 +511,138 @@ discard block |
||
511 | 511 | public function processLongArgument($arg, $pos) |
512 | 512 | { |
513 | 513 | switch ($arg) { |
514 | - case 'help': |
|
515 | - $this->printUsage(); |
|
516 | - exit(0); |
|
517 | - case 'version': |
|
518 | - echo 'Symplify\PHP7_CodeSniffer version '.self::VERSION; |
|
519 | - exit(0); |
|
520 | - case 'cache': |
|
521 | - $this->cache = true; |
|
522 | - $this->overriddenDefaults['cache'] = true; |
|
523 | - break; |
|
524 | - case 'no-cache': |
|
525 | - $this->cache = false; |
|
526 | - $this->overriddenDefaults['cache'] = true; |
|
527 | - break; |
|
528 | - default: |
|
529 | - if (substr($arg, 0, 7) === 'sniffs=') { |
|
530 | - $sniffs = explode(',', substr($arg, 7)); |
|
531 | - foreach ($sniffs as $sniff) { |
|
532 | - if (substr_count($sniff, '.') !== 2) { |
|
533 | - echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
534 | - $this->printUsage(); |
|
535 | - exit(2); |
|
514 | + case 'help': |
|
515 | + $this->printUsage(); |
|
516 | + exit(0); |
|
517 | + case 'version': |
|
518 | + echo 'Symplify\PHP7_CodeSniffer version '.self::VERSION; |
|
519 | + exit(0); |
|
520 | + case 'cache': |
|
521 | + $this->cache = true; |
|
522 | + $this->overriddenDefaults['cache'] = true; |
|
523 | + break; |
|
524 | + case 'no-cache': |
|
525 | + $this->cache = false; |
|
526 | + $this->overriddenDefaults['cache'] = true; |
|
527 | + break; |
|
528 | + default: |
|
529 | + if (substr($arg, 0, 7) === 'sniffs=') { |
|
530 | + $sniffs = explode(',', substr($arg, 7)); |
|
531 | + foreach ($sniffs as $sniff) { |
|
532 | + if (substr_count($sniff, '.') !== 2) { |
|
533 | + echo 'ERROR: The specified sniff code "'.$sniff.'" is invalid'.PHP_EOL.PHP_EOL; |
|
534 | + $this->printUsage(); |
|
535 | + exit(2); |
|
536 | + } |
|
536 | 537 | } |
537 | - } |
|
538 | 538 | |
539 | - $this->sniffs = $sniffs; |
|
540 | - $this->overriddenDefaults['sniffs'] = true; |
|
541 | - } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
542 | - $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
539 | + $this->sniffs = $sniffs; |
|
540 | + $this->overriddenDefaults['sniffs'] = true; |
|
541 | + } else if (substr($arg, 0, 11) === 'stdin-path=') { |
|
542 | + $this->stdinPath = Util\Common::realpath(substr($arg, 11)); |
|
543 | 543 | |
544 | - // It may not exist and return false instead, so use whatever they gave us. |
|
545 | - if ($this->stdinPath === false) { |
|
546 | - $this->stdinPath = trim(substr($arg, 11)); |
|
547 | - } |
|
548 | - |
|
549 | - $this->overriddenDefaults['stdinPath'] = true; |
|
550 | - } else if (substr($arg, 0, 9) === 'basepath=') { |
|
551 | - if (isset($this->overriddenDefaults['basepath']) === true) { |
|
552 | - break; |
|
553 | - } |
|
554 | - |
|
555 | - $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
544 | + // It may not exist and return false instead, so use whatever they gave us. |
|
545 | + if ($this->stdinPath === false) { |
|
546 | + $this->stdinPath = trim(substr($arg, 11)); |
|
547 | + } |
|
556 | 548 | |
557 | - // It may not exist and return false instead. |
|
558 | - if ($this->basepath === false) { |
|
559 | - $this->basepath = substr($arg, 9); |
|
560 | - } |
|
549 | + $this->overriddenDefaults['stdinPath'] = true; |
|
550 | + } else if (substr($arg, 0, 9) === 'basepath=') { |
|
551 | + if (isset($this->overriddenDefaults['basepath']) === true) { |
|
552 | + break; |
|
553 | + } |
|
561 | 554 | |
562 | - $this->overriddenDefaults['basepath'] = true; |
|
555 | + $this->basepath = Util\Common::realpath(substr($arg, 9)); |
|
563 | 556 | |
564 | - if (is_dir($this->basepath) === false) { |
|
565 | - echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
566 | - $this->printUsage(); |
|
567 | - exit(2); |
|
568 | - } |
|
569 | - } else if (substr($arg, 0, 7) === 'filter=') { |
|
570 | - if (isset($this->overriddenDefaults['filter']) === true) { |
|
571 | - break; |
|
572 | - } |
|
557 | + // It may not exist and return false instead. |
|
558 | + if ($this->basepath === false) { |
|
559 | + $this->basepath = substr($arg, 9); |
|
560 | + } |
|
573 | 561 | |
574 | - $this->filter = substr($arg, 7); |
|
575 | - $this->overriddenDefaults['filter'] = true; |
|
576 | - } else if (substr($arg, 0, 9) === 'standard=') { |
|
577 | - $standards = trim(substr($arg, 9)); |
|
578 | - if ($standards !== '') { |
|
579 | - $this->standards = explode(',', $standards); |
|
580 | - } |
|
562 | + $this->overriddenDefaults['basepath'] = true; |
|
581 | 563 | |
582 | - $this->overriddenDefaults['standards'] = true; |
|
583 | - } else if (substr($arg, 0, 11) === 'extensions=') { |
|
584 | - $extensions = explode(',', substr($arg, 11)); |
|
585 | - $newExtensions = array(); |
|
586 | - foreach ($extensions as $ext) { |
|
587 | - $slash = strpos($ext, '/'); |
|
588 | - if ($slash !== false) { |
|
589 | - // They specified the tokenizer too. |
|
590 | - list($ext, $tokenizer) = explode('/', $ext); |
|
591 | - $newExtensions[$ext] = strtoupper($tokenizer); |
|
592 | - continue; |
|
564 | + if (is_dir($this->basepath) === false) { |
|
565 | + echo 'ERROR: The specified basepath "'.$this->basepath.'" points to a non-existent directory'.PHP_EOL.PHP_EOL; |
|
566 | + $this->printUsage(); |
|
567 | + exit(2); |
|
568 | + } |
|
569 | + } else if (substr($arg, 0, 7) === 'filter=') { |
|
570 | + if (isset($this->overriddenDefaults['filter']) === true) { |
|
571 | + break; |
|
593 | 572 | } |
594 | 573 | |
595 | - if (isset($this->extensions[$ext]) === true) { |
|
596 | - $newExtensions[$ext] = $this->extensions[$ext]; |
|
597 | - } else { |
|
598 | - $newExtensions[$ext] = 'PHP'; |
|
574 | + $this->filter = substr($arg, 7); |
|
575 | + $this->overriddenDefaults['filter'] = true; |
|
576 | + } else if (substr($arg, 0, 9) === 'standard=') { |
|
577 | + $standards = trim(substr($arg, 9)); |
|
578 | + if ($standards !== '') { |
|
579 | + $this->standards = explode(',', $standards); |
|
599 | 580 | } |
600 | - } |
|
601 | 581 | |
602 | - $this->extensions = $newExtensions; |
|
603 | - $this->overriddenDefaults['extensions'] = true; |
|
604 | - } else if (substr($arg, 0, 7) === 'suffix=') { |
|
605 | - $this->suffix = explode(',', substr($arg, 7)); |
|
606 | - $this->overriddenDefaults['suffix'] = true; |
|
607 | - } else if (substr($arg, 0, 9) === 'severity=') { |
|
608 | - $this->errorSeverity = (int) substr($arg, 9); |
|
609 | - $this->warningSeverity = $this->errorSeverity; |
|
610 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
611 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
612 | - } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
613 | - $this->errorSeverity = (int) substr($arg, 15); |
|
614 | - $this->overriddenDefaults['errorSeverity'] = true; |
|
615 | - } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
616 | - $this->warningSeverity = (int) substr($arg, 17); |
|
617 | - $this->overriddenDefaults['warningSeverity'] = true; |
|
618 | - } else if (substr($arg, 0, 7) === 'ignore=') { |
|
619 | - // Split the ignore string on commas, unless the comma is escaped |
|
620 | - // using 1 or 3 slashes (\, or \\\,). |
|
621 | - $patterns = preg_split( |
|
622 | - '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
623 | - substr($arg, 7) |
|
624 | - ); |
|
625 | - |
|
626 | - $ignored = array(); |
|
627 | - foreach ($patterns as $pattern) { |
|
628 | - $pattern = trim($pattern); |
|
629 | - if ($pattern === '') { |
|
630 | - continue; |
|
582 | + $this->overriddenDefaults['standards'] = true; |
|
583 | + } else if (substr($arg, 0, 11) === 'extensions=') { |
|
584 | + $extensions = explode(',', substr($arg, 11)); |
|
585 | + $newExtensions = array(); |
|
586 | + foreach ($extensions as $ext) { |
|
587 | + $slash = strpos($ext, '/'); |
|
588 | + if ($slash !== false) { |
|
589 | + // They specified the tokenizer too. |
|
590 | + list($ext, $tokenizer) = explode('/', $ext); |
|
591 | + $newExtensions[$ext] = strtoupper($tokenizer); |
|
592 | + continue; |
|
593 | + } |
|
594 | + |
|
595 | + if (isset($this->extensions[$ext]) === true) { |
|
596 | + $newExtensions[$ext] = $this->extensions[$ext]; |
|
597 | + } else { |
|
598 | + $newExtensions[$ext] = 'PHP'; |
|
599 | + } |
|
631 | 600 | } |
632 | 601 | |
633 | - $ignored[$pattern] = 'absolute'; |
|
634 | - } |
|
602 | + $this->extensions = $newExtensions; |
|
603 | + $this->overriddenDefaults['extensions'] = true; |
|
604 | + } else if (substr($arg, 0, 7) === 'suffix=') { |
|
605 | + $this->suffix = explode(',', substr($arg, 7)); |
|
606 | + $this->overriddenDefaults['suffix'] = true; |
|
607 | + } else if (substr($arg, 0, 9) === 'severity=') { |
|
608 | + $this->errorSeverity = (int) substr($arg, 9); |
|
609 | + $this->warningSeverity = $this->errorSeverity; |
|
610 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
611 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
612 | + } else if (substr($arg, 0, 15) === 'error-severity=') { |
|
613 | + $this->errorSeverity = (int) substr($arg, 15); |
|
614 | + $this->overriddenDefaults['errorSeverity'] = true; |
|
615 | + } else if (substr($arg, 0, 17) === 'warning-severity=') { |
|
616 | + $this->warningSeverity = (int) substr($arg, 17); |
|
617 | + $this->overriddenDefaults['warningSeverity'] = true; |
|
618 | + } else if (substr($arg, 0, 7) === 'ignore=') { |
|
619 | + // Split the ignore string on commas, unless the comma is escaped |
|
620 | + // using 1 or 3 slashes (\, or \\\,). |
|
621 | + $patterns = preg_split( |
|
622 | + '/(?<=(?<!\\\\)\\\\\\\\),|(?<!\\\\),/', |
|
623 | + substr($arg, 7) |
|
624 | + ); |
|
625 | + |
|
626 | + $ignored = array(); |
|
627 | + foreach ($patterns as $pattern) { |
|
628 | + $pattern = trim($pattern); |
|
629 | + if ($pattern === '') { |
|
630 | + continue; |
|
631 | + } |
|
635 | 632 | |
636 | - $this->ignored = $ignored; |
|
637 | - $this->overriddenDefaults['ignored'] = true; |
|
638 | - } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
639 | - $this->tabWidth = (int) substr($arg, 10); |
|
640 | - $this->overriddenDefaults['tabWidth'] = true; |
|
641 | - } else { |
|
642 | - $this->processUnknownArgument('--'.$arg, $pos); |
|
643 | - }//end if |
|
633 | + $ignored[$pattern] = 'absolute'; |
|
634 | + } |
|
635 | + |
|
636 | + $this->ignored = $ignored; |
|
637 | + $this->overriddenDefaults['ignored'] = true; |
|
638 | + } else if (substr($arg, 0, 10) === 'tab-width=') { |
|
639 | + $this->tabWidth = (int) substr($arg, 10); |
|
640 | + $this->overriddenDefaults['tabWidth'] = true; |
|
641 | + } else { |
|
642 | + $this->processUnknownArgument('--'.$arg, $pos); |
|
643 | + }//end if |
|
644 | 644 | |
645 | - break; |
|
645 | + break; |
|
646 | 646 | }//end switch |
647 | 647 | |
648 | 648 | }//end processLongArgument() |
@@ -245,7 +245,7 @@ |
||
245 | 245 | * |
246 | 246 | * @return void |
247 | 247 | */ |
248 | - public function __construct(array $cliArgs=array()) |
|
248 | + public function __construct(array $cliArgs = array()) |
|
249 | 249 | { |
250 | 250 | $checkStdin = false; |
251 | 251 | if (empty($cliArgs) === true) { |