|  | 
| 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; | 
| @@ -399,7 +400,7 @@ public function beginChangeset() | 
| 399 | 400 |             if ($bt[1]['class'] === __CLASS__) { | 
| 400 | 401 |                 $sniff = 'Fixer'; | 
| 401 | 402 |             } else { | 
| 402 |  | -                $sniff = Common::getSniffCode($bt[1]['class']); | 
|  | 403 | +                $sniff = $this->getSniffCodeForDebug($bt[1]['class']); | 
| 403 | 404 |             } | 
| 404 | 405 | 
 | 
| 405 | 406 |             $line = $bt[0]['line']; | 
| @@ -478,7 +479,7 @@ public function rollbackChangeset() | 
| 478 | 479 |                     $line  = $bt[0]['line']; | 
| 479 | 480 |                 } | 
| 480 | 481 | 
 | 
| 481 |  | -                $sniff = Common::getSniffCode($sniff); | 
|  | 482 | +                $sniff = $this->getSniffCodeForDebug($sniff); | 
| 482 | 483 | 
 | 
| 483 | 484 |                 $numChanges = count($this->changeset); | 
| 484 | 485 | 
 | 
| @@ -531,7 +532,7 @@ public function replaceToken($stackPtr, $content) | 
| 531 | 532 |                 $line  = $bt[0]['line']; | 
| 532 | 533 |             } | 
| 533 | 534 | 
 | 
| 534 |  | -            $sniff = Common::getSniffCode($sniff); | 
|  | 535 | +            $sniff = $this->getSniffCodeForDebug($sniff); | 
| 535 | 536 | 
 | 
| 536 | 537 |             $tokens     = $this->currentFile->getTokens(); | 
| 537 | 538 |             $type       = $tokens[$stackPtr]['type']; | 
| @@ -636,7 +637,7 @@ public function revertToken($stackPtr) | 
| 636 | 637 |                 $line  = $bt[0]['line']; | 
| 637 | 638 |             } | 
| 638 | 639 | 
 | 
| 639 |  | -            $sniff = Common::getSniffCode($sniff); | 
|  | 640 | +            $sniff = $this->getSniffCodeForDebug($sniff); | 
| 640 | 641 | 
 | 
| 641 | 642 |             $tokens     = $this->currentFile->getTokens(); | 
| 642 | 643 |             $type       = $tokens[$stackPtr]['type']; | 
| @@ -820,4 +821,24 @@ public function changeCodeBlockIndent($start, $end, $change) | 
| 820 | 821 |     }//end changeCodeBlockIndent() | 
| 821 | 822 | 
 | 
| 822 | 823 | 
 | 
|  | 824 | +    /** | 
|  | 825 | +     * Get the sniff code for the current sniff or the class name if the passed class is not a sniff. | 
|  | 826 | +     * | 
|  | 827 | +     * @param string $className Class name. | 
|  | 828 | +     * | 
|  | 829 | +     * @return string | 
|  | 830 | +     */ | 
|  | 831 | +    private function getSniffCodeForDebug($className) | 
|  | 832 | +    { | 
|  | 833 | +        try { | 
|  | 834 | +            $sniffCode = Common::getSniffCode($className); | 
|  | 835 | +            return $sniffCode; | 
|  | 836 | +        } catch (InvalidArgumentException $e) { | 
|  | 837 | +            // Sniff code could not be determined. This may be an abstract sniff class or a helper class. | 
|  | 838 | +            return $className; | 
|  | 839 | +        } | 
|  | 840 | + | 
|  | 841 | +    }//end getSniffCodeForDebug() | 
|  | 842 | + | 
|  | 843 | + | 
| 823 | 844 | }//end class | 
0 commit comments