From af50ddfd993c1012a963b45ea860ffd3404dcd62 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:20:45 +0200 Subject: [PATCH] TASK: Update StaticCallSniff tests to reflect added removed extension * Also update getBefore method of AbstractClassnameChecker to make lookups before, like in StaticCallSniff work. Relates: #44 --- .../Classname/AbstractClassnameChecker.php | 28 +++++++++++-------- .../Classname/StaticCallSniff/Expected.diff | 5 +++- .../Classname/StaticCallSniff/Expected.json | 22 +++++++++++++-- .../StaticCallSniff/InputFileForIssues.php | 7 +++++ 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php index 858e173..3ca906b 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php @@ -85,19 +85,28 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ protected function getBefore(PhpCsFile $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); + $possibleStart = $phpcsFile->findPrevious([ + T_STRING, T_NS_SEPARATOR, + ], $stackPtr - 1, null, true, null, true); + if ($possibleStart === false) { + throw new \UnexpectedValueException('Could not find start of classname.', 1494319966); + } - $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); + $classnamePosition = $phpcsFile->findNext(T_STRING, $possibleStart); if ($classnamePosition === false) { throw new \UnexpectedValueException('Could not find start of classname.', 1494319966); } - $classname = $tokens[$classnamePosition]['content']; + $end = $phpcsFile->findNext([ + T_STRING, T_NS_SEPARATOR + ], $classnamePosition + 1, $stackPtr + 1, true, null, true); + if ($end === false) { + throw new \UnexpectedValueException('Could not find end of classname.', 1494319651); + } - return [ - $classnamePosition, - $classname - ]; + $classname = $phpcsFile->getTokensAsString($classnamePosition, $end - $classnamePosition); + + return [$classnamePosition, $classname]; } /** @@ -122,9 +131,6 @@ abstract class AbstractClassnameChecker implements PhpCsSniff $classname = $phpcsFile->getTokensAsString($classnamePosition, $end - $classnamePosition); - return [ - $classnamePosition, - $classname - ]; + return [$classnamePosition, $classname]; } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.diff index 24c7315..0260e0b 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -19,13 +19,13 @@ +@@ -19,16 +19,16 @@ * 02110-1301, USA. */ @@ -19,3 +19,6 @@ -is_a($a, t3lib_Singleton::class); + ->get(\TYPO3\CMS\Extbase\Command\HelpCommandController::class); +is_a($a, \TYPO3\CMS\Core\SingletonInterface::class); + + \TYPO3\CMS\Perm\Controller\PermissionAjaxController::configurePlugin( + $_EXTKEY, diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json index 124198b..5c66396 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json @@ -56,14 +56,32 @@ "severity": 5, "source": "Typo3Update.Classname.StaticCall.legacyClassname", "type": "ERROR" + }, + { + "column": 2, + "fixable": false, + "line": 33, + "message": "Calls to removed code are not allowed; found perm. Removed in 7.0. The logic is moved into EXT:beuser. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62339-MoveExtPermIntoExtBeuser.html", + "severity": 5, + "source": "Typo3Update.Classname.StaticCall.RemovedClass.perm", + "type": "WARNING" + }, + { + "column": 28, + "fixable": false, + "line": 38, + "message": "Calls to removed code are not allowed; found perm. Removed in 7.0. The logic is moved into EXT:beuser. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62339-MoveExtPermIntoExtBeuser.html", + "severity": 5, + "source": "Typo3Update.Classname.StaticCall.RemovedClass.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 2 } }, "totals": { "errors": 6, "fixable": 6, - "warnings": 0 + "warnings": 2 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/InputFileForIssues.php index df4f280..c3e89b6 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/InputFileForIssues.php @@ -29,3 +29,10 @@ $this->objectManager->get(\Tx_Extbase_Command_HelpCommandController::class); \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager) ->get(\Tx_Extbase_Command_HelpCommandController::class); is_a($a, t3lib_Singleton::class); + +\TYPO3\CMS\Perm\Controller\PermissionAjaxController::configurePlugin( + $_EXTKEY, + 'name', + ['Controller' => 'action'] +); +$this->objectManager->get(\TYPO3\CMS\Perm\Controller\PermissionAjaxController::class);