|
12 | 12 |
|
13 | 13 | namespace PHP_CodeSniffer; |
14 | 14 |
|
| 15 | +use InvalidArgumentException; |
15 | 16 | use PHP_CodeSniffer\Exceptions\RuntimeException; |
16 | 17 | use PHP_CodeSniffer\Files\File; |
17 | 18 | use PHP_CodeSniffer\Util\Common; |
@@ -402,7 +403,7 @@ public function beginChangeset() |
402 | 403 | if ($bt[1]['class'] === __CLASS__) { |
403 | 404 | $sniff = 'Fixer'; |
404 | 405 | } else { |
405 | | - $sniff = Common::getSniffCode($bt[1]['class']); |
| 406 | + $sniff = $this->getSniffCodeForDebug($bt[1]['class']); |
406 | 407 | } |
407 | 408 |
|
408 | 409 | $line = $bt[0]['line']; |
@@ -487,7 +488,7 @@ public function rollbackChangeset() |
487 | 488 | $line = $bt[0]['line']; |
488 | 489 | } |
489 | 490 |
|
490 | | - $sniff = Common::getSniffCode($sniff); |
| 491 | + $sniff = $this->getSniffCodeForDebug($sniff); |
491 | 492 |
|
492 | 493 | $numChanges = count($this->changeset); |
493 | 494 |
|
@@ -544,7 +545,7 @@ public function replaceToken($stackPtr, $content) |
544 | 545 | $line = $bt[0]['line']; |
545 | 546 | } |
546 | 547 |
|
547 | | - $sniff = Common::getSniffCode($sniff); |
| 548 | + $sniff = $this->getSniffCodeForDebug($sniff); |
548 | 549 |
|
549 | 550 | $tokens = $this->currentFile->getTokens(); |
550 | 551 | $type = $tokens[$stackPtr]['type']; |
@@ -659,7 +660,7 @@ public function revertToken($stackPtr) |
659 | 660 | $line = $bt[0]['line']; |
660 | 661 | } |
661 | 662 |
|
662 | | - $sniff = Common::getSniffCode($sniff); |
| 663 | + $sniff = $this->getSniffCodeForDebug($sniff); |
663 | 664 |
|
664 | 665 | $tokens = $this->currentFile->getTokens(); |
665 | 666 | $type = $tokens[$stackPtr]['type']; |
@@ -843,4 +844,24 @@ public function changeCodeBlockIndent($start, $end, $change) |
843 | 844 | }//end changeCodeBlockIndent() |
844 | 845 |
|
845 | 846 |
|
| 847 | + /** |
| 848 | + * Get the sniff code for the current sniff or the class name if the passed class is not a sniff. |
| 849 | + * |
| 850 | + * @param string $className Class name. |
| 851 | + * |
| 852 | + * @return string |
| 853 | + */ |
| 854 | + private function getSniffCodeForDebug($className) |
| 855 | + { |
| 856 | + try { |
| 857 | + $sniffCode = Common::getSniffCode($className); |
| 858 | + return $sniffCode; |
| 859 | + } catch (InvalidArgumentException $e) { |
| 860 | + // Sniff code could not be determined. This may be an abstract sniff class or a helper class. |
| 861 | + return $className; |
| 862 | + } |
| 863 | + |
| 864 | + }//end getSniffCodeForDebug() |
| 865 | + |
| 866 | + |
846 | 867 | }//end class |
0 commit comments