From 9b3d5d95152d081a05d1ba40640a5ee201fb5dd9 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 16:12:40 +0100 Subject: [PATCH] BUGFIX: Support multiple interfaces * Process extends as before. * Process all interfaces in addition, not only the first one. --- .../LegacyClassnames/InheritanceSniff.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php index 884d4b5..59c9dd3 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php @@ -19,6 +19,7 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** @@ -38,4 +39,56 @@ class Typo3Update_Sniffs_LegacyClassnames_InheritanceSniff extends AbstractClass T_IMPLEMENTS, ]; } + + /** + * 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 PhpCsFile $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) + { + if ($phpcsFile->getTokens()[$stackPtr]['code'] === T_IMPLEMENTS) { + $this->processInterfaces($phpcsFile, $stackPtr); + return; + } + + parent::process($phpcsFile, $stackPtr); + } + + /** + * Process all interfaces for current class. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * + * @return void + */ + protected function processInterfaces(PhpCsFile $phpcsFile, $stackPtr) + { + $interfaces = $phpcsFile->findImplementedInterfaceNames($phpcsFile->findPrevious(T_CLASS, $stackPtr)); + if ($interfaces === false) { + return; + } + + foreach ($interfaces as $interface) { + if (! $this->isLegacyClassname($interface)) { + continue; + } + + $position = $phpcsFile->findNext(T_STRING, $stackPtr, null, false, $interface); + if ($position === false) { + continue; + } + + $this->addFixableError($phpcsFile, $position, $interface); + } + } }