Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/Fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace PHP_CodeSniffer;

use InvalidArgumentException;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Util\Common;
Expand Down Expand Up @@ -402,7 +403,7 @@ public function beginChangeset()
if ($bt[1]['class'] === __CLASS__) {
$sniff = 'Fixer';
} else {
$sniff = Common::getSniffCode($bt[1]['class']);
$sniff = $this->getSniffCodeForDebug($bt[1]['class']);
}

$line = $bt[0]['line'];
Expand Down Expand Up @@ -487,7 +488,7 @@ public function rollbackChangeset()
$line = $bt[0]['line'];
}

$sniff = Common::getSniffCode($sniff);
$sniff = $this->getSniffCodeForDebug($sniff);

$numChanges = count($this->changeset);

Expand Down Expand Up @@ -544,7 +545,7 @@ public function replaceToken($stackPtr, $content)
$line = $bt[0]['line'];
}

$sniff = Common::getSniffCode($sniff);
$sniff = $this->getSniffCodeForDebug($sniff);

$tokens = $this->currentFile->getTokens();
$type = $tokens[$stackPtr]['type'];
Expand Down Expand Up @@ -659,7 +660,7 @@ public function revertToken($stackPtr)
$line = $bt[0]['line'];
}

$sniff = Common::getSniffCode($sniff);
$sniff = $this->getSniffCodeForDebug($sniff);

$tokens = $this->currentFile->getTokens();
$type = $tokens[$stackPtr]['type'];
Expand Down Expand Up @@ -843,4 +844,24 @@ public function changeCodeBlockIndent($start, $end, $change)
}//end changeCodeBlockIndent()


/**
* Get the sniff code for the current sniff or the class name if the passed class is not a sniff.
*
* @param string $className Class name.
*
* @return string
*/
private function getSniffCodeForDebug($className)
{
try {
$sniffCode = Common::getSniffCode($className);
return $sniffCode;
} catch (InvalidArgumentException $e) {
// Sniff code could not be determined. This may be an abstract sniff class or a helper class.
return $className;
}

}//end getSniffCodeForDebug()


}//end class