From 5fd8e965acd6aabdf481f62340a9331457242a8c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 10:31:14 +0100 Subject: [PATCH] BUGFIX: Fix bug introduced in e6e372f8b1046bd90eeeb54832f644925b26c3e7 * Allow static calls to find class name before $stackPtr. --- .../LegacyClassnames/ClassnameCheckerTrait.php | 14 ++++++++++++++ .../Sniffs/LegacyClassnames/StaticCallSniff.php | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index c5e6e29..d6a2fe2 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -56,6 +56,17 @@ trait ClassnameCheckerTrait $this->legacyClassnames = $legacyClassnames['aliasToClassNameMapping']; } + /** + * Define whether the T_STRING default behaviour should be checked before + * or after the $stackPtr. + * + * @return bool + */ + protected function findPrev() + { + return false; + } + /** * Processes the tokens that this sniff is interested in. * @@ -74,6 +85,9 @@ trait ClassnameCheckerTrait $tokens = $phpcsFile->getTokens(); $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($this->findPrev()) { + $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); + } if ($classnamePosition === false) { return; } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php index 406c07b..91b2eef 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php @@ -26,6 +26,17 @@ class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSni { use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; + /** + * Define whether the T_STRING default behaviour should be checked before + * or after the $stackPtr. + * + * @return bool + */ + protected function findPrev() + { + return true; + } + /** * Returns the token types that this sniff is interested in. *