Merge pull request #35 from DanielSiepmann/feature/cleanup
Feature/cleanup
This commit is contained in:
commit
5a70f8458c
2 changed files with 15 additions and 13 deletions
|
@ -20,7 +20,7 @@ namespace Typo3Update\Sniffs\LegacyClassnames;
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHP_CodeSniffer_File as PhpcsFile;
|
use PHP_CodeSniffer_File as PhpCsFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide common uses for all sniffs, regarding class name checks.
|
* Provide common uses for all sniffs, regarding class name checks.
|
||||||
|
@ -62,7 +62,7 @@ trait ClassnameCheckerTrait
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function findPrev()
|
protected function shouldLookBefore()
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -74,20 +74,22 @@ trait ClassnameCheckerTrait
|
||||||
* the class name. This way only the register method has to be registered
|
* the class name. This way only the register method has to be registered
|
||||||
* in default cases.
|
* in default cases.
|
||||||
*
|
*
|
||||||
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
|
* @param PhpCsFile $phpcsFile The file where the token was found.
|
||||||
* @param int $stackPtr The position in the stack where
|
* @param int $stackPtr The position in the stack where
|
||||||
* the token was found.
|
* the token was found.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function process(PhpcsFile $phpcsFile, $stackPtr)
|
public function process(PhpCsFile $phpcsFile, $stackPtr)
|
||||||
{
|
{
|
||||||
$tokens = $phpcsFile->getTokens();
|
$tokens = $phpcsFile->getTokens();
|
||||||
|
|
||||||
$classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr);
|
if ($this->shouldLookBefore()) {
|
||||||
if ($this->findPrev()) {
|
|
||||||
$classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr);
|
$classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr);
|
||||||
|
} else {
|
||||||
|
$classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($classnamePosition === false) {
|
if ($classnamePosition === false) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -147,11 +149,11 @@ trait ClassnameCheckerTrait
|
||||||
/**
|
/**
|
||||||
* Add an fixable error if given $classname is legacy.
|
* Add an fixable error if given $classname is legacy.
|
||||||
*
|
*
|
||||||
* @param PhpcsFile $phpcsFile
|
* @param PhpCsFile $phpcsFile
|
||||||
* @param int $classnamePosition
|
* @param int $classnamePosition
|
||||||
* @param string $classname
|
* @param string $classname
|
||||||
*/
|
*/
|
||||||
public function addFixableError(PhpcsFile $phpcsFile, $classnamePosition, $classname)
|
public function addFixableError(PhpCsFile $phpcsFile, $classnamePosition, $classname)
|
||||||
{
|
{
|
||||||
$classname = trim($classname, '\\\'"'); // Remove trailing slash, and quotes.
|
$classname = trim($classname, '\\\'"'); // Remove trailing slash, and quotes.
|
||||||
$this->addMaybeWarning($phpcsFile, $classnamePosition, $classname);
|
$this->addMaybeWarning($phpcsFile, $classnamePosition, $classname);
|
||||||
|
@ -175,11 +177,11 @@ trait ClassnameCheckerTrait
|
||||||
/**
|
/**
|
||||||
* Add an warning if given $classname is maybe legacy.
|
* Add an warning if given $classname is maybe legacy.
|
||||||
*
|
*
|
||||||
* @param PhpcsFile $phpcsFile
|
* @param PhpCsFile $phpcsFile
|
||||||
* @param int $classnamePosition
|
* @param int $classnamePosition
|
||||||
* @param string $classname
|
* @param string $classname
|
||||||
*/
|
*/
|
||||||
private function addMaybeWarning(PhpcsFile $phpcsFile, $classnamePosition, $classname)
|
private function addMaybeWarning(PhpCsFile $phpcsFile, $classnamePosition, $classname)
|
||||||
{
|
{
|
||||||
if ($this->isLegacyClassname($classname) || $this->isMaybeLegacyClassname($classname) === false) {
|
if ($this->isLegacyClassname($classname) || $this->isMaybeLegacyClassname($classname) === false) {
|
||||||
return;
|
return;
|
||||||
|
@ -196,11 +198,11 @@ trait ClassnameCheckerTrait
|
||||||
/**
|
/**
|
||||||
* Replaces the classname at $classnamePosition with $classname in $phpcsFile.
|
* Replaces the classname at $classnamePosition with $classname in $phpcsFile.
|
||||||
*
|
*
|
||||||
* @param PhpcsFile $phpcsFile
|
* @param PhpCsFile $phpcsFile
|
||||||
* @param int $classnamePosition
|
* @param int $classnamePosition
|
||||||
* @param string $classname
|
* @param string $classname
|
||||||
*/
|
*/
|
||||||
private function replaceLegacyClassname(PhpcsFile $phpcsFile, $classnamePosition, $classname)
|
private function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname)
|
||||||
{
|
{
|
||||||
$prefix = '\\';
|
$prefix = '\\';
|
||||||
if ($phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) {
|
if ($phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) {
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSni
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function findPrev()
|
protected function shouldLookBefore()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue