|
13 | 13 | namespace PHP_CodeSniffer;
|
14 | 14 |
|
15 | 15 | use Exception;
|
| 16 | +use InvalidArgumentException; |
16 | 17 | use PHP_CodeSniffer\Exceptions\DeepExitException;
|
17 | 18 | use PHP_CodeSniffer\Exceptions\RuntimeException;
|
18 | 19 | use PHP_CodeSniffer\Files\DummyFile;
|
@@ -688,16 +689,23 @@ public function processFile($file)
|
688 | 689 | }
|
689 | 690 |
|
690 | 691 | if (empty($sniffStack) === false) {
|
691 |
| - if (empty($nextStack) === false |
692 |
| - && isset($nextStack['class']) === true |
693 |
| - && substr($nextStack['class'], -5) === 'Sniff' |
694 |
| - ) { |
695 |
| - $sniffCode = Common::getSniffCode($nextStack['class']); |
696 |
| - } else { |
| 692 | + $sniffCode = ''; |
| 693 | + try { |
| 694 | + if (empty($nextStack) === false |
| 695 | + && isset($nextStack['class']) === true |
| 696 | + && substr($nextStack['class'], -5) === 'Sniff' |
| 697 | + ) { |
| 698 | + $sniffCode = 'the '.Common::getSniffCode($nextStack['class']).' sniff'; |
| 699 | + } |
| 700 | + } catch (InvalidArgumentException $e) { |
| 701 | + // Sniff code could not be determined. This may be an abstract sniff class. |
| 702 | + } |
| 703 | + |
| 704 | + if ($sniffCode === '') { |
697 | 705 | $sniffCode = substr(strrchr(str_replace('\\', '/', $sniffStack['file']), '/'), 1);
|
698 | 706 | }
|
699 | 707 |
|
700 |
| - $error .= sprintf(PHP_EOL.'The error originated in the %s sniff on line %s.', $sniffCode, $sniffStack['line']); |
| 708 | + $error .= sprintf(PHP_EOL.'The error originated in %s on line %s.', $sniffCode, $sniffStack['line']); |
701 | 709 | }
|
702 | 710 |
|
703 | 711 | $file->addErrorOnLine($error, 1, 'Internal.Exception');
|
|
0 commit comments