diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index 517eaed..c0210ce 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -21,7 +21,6 @@ namespace Typo3Update\Sniffs\LegacyClassnames; */ use PHP_CodeSniffer_File as PhpcsFile; -use PHP_CodeSniffer_Tokens as Tokens; /** * Provide common uses for all sniffs, regarding class name checks. @@ -57,6 +56,32 @@ trait ClassnameCheckerTrait $this->legacyClassnames = $legacyClassnames['aliasToClassNameMapping']; } + /** + * Processes the tokens that this sniff is interested in. + * + * This is the default implementation, as most of the time next T_STRING is + * the class name. This way only the register method has to be registered + * in default cases. + * + * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. + * + * @return void + */ + public function process(PhpcsFile $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($classnamePosition === false) { + return; + } + + $classname = $tokens[$classnamePosition]['content']; + $this->addFixableError($phpcsFile, $classnamePosition, $classname); + } + /** * Checks whether a mapping exists for the given $classname, * indicating it's legacy. diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php index 48a4136..72c5280 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php @@ -38,25 +38,4 @@ class Typo3Update_Sniffs_LegacyClassnames_InheritanceSniff implements PHP_CodeSn T_IMPLEMENTS, ]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - $classname = $tokens[$classnamePosition]['content']; - - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php index 4140602..1274923 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php @@ -37,25 +37,4 @@ class Typo3Update_Sniffs_LegacyClassnames_InstanceofSniff implements PHP_CodeSni T_INSTANCEOF, ]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - $classname = $tokens[$classnamePosition]['content']; - - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php index e96d117..318cbcd 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php @@ -35,25 +35,4 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithNewSniff implements P { return [T_NEW]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - $classname = $tokens[$classnamePosition]['content']; - - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php index c119f53..406c07b 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php @@ -35,25 +35,4 @@ class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSni { return [T_DOUBLE_COLON]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - $classname = $tokens[$classnamePosition]['content']; - - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php index bda35c6..6bd9b10 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php @@ -37,26 +37,4 @@ class Typo3Update_Sniffs_LegacyClassnames_TypehintCatchExceptionSniff implements { return [T_CATCH]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - - $classname = $tokens[$classnamePosition]['content']; - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php index 5446370..0b7bf6d 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php @@ -37,25 +37,4 @@ class Typo3Update_Sniffs_LegacyClassnames_UseSniff implements PHP_CodeSniffer_Sn { return [T_USE]; } - - /** - * Processes the tokens that this sniff is interested in. - * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($classnamePosition === false) { - return; - } - $classname = $tokens[$classnamePosition]['content']; - - $this->addFixableError($phpcsFile, $classnamePosition, $classname); - } }