From 3034f3fec4ec82b4d66be62d31a472cb9715d855 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 10:34:58 +0200 Subject: [PATCH] FEATURE: Add removed extension to type hint sniff * Integrate feature and adjust code as needed. * We need to find the class names inside of type hints more accurate. * Also tests need to cover the new feature. Relates: #44 --- .../Sniffs/Classname/TypeHintSniff.php | 10 +++++- .../Classname/TypeHintSniff/Expected.diff | 2 +- .../Classname/TypeHintSniff/Expected.json | 31 +++++++++++++++++-- .../TypeHintSniff/InputFileForIssues.php | 7 +++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php index 05f49c1..0aa738c 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php @@ -51,10 +51,18 @@ class Typo3Update_Sniffs_Classname_TypeHintSniff extends AbstractClassnameChecke continue; } - $position = $phpcsFile->findPrevious(T_STRING, $parameter['token'], $stackPtr, false, null, true); + $position = $phpcsFile->findPrevious([ + T_OPEN_PARENTHESIS, T_COMMA + ], $parameter['token'] - 2, $stackPtr, false, null, true); if ($position === false) { continue; } + + $position = $phpcsFile->findNext(T_STRING, $position); + if ($position === false) { + continue; + } + $this->processFeatures($phpcsFile, $position, $parameter['type_hint']); } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.diff index 54ec8ea..7ccb526 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.diff @@ -38,4 +38,4 @@ + public function something(\TYPO3\CMS\Extbase\Domain\Model\BackendUser $user) { } - } + diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json index 9fde95c..2e56a13 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json @@ -56,14 +56,41 @@ "severity": 5, "source": "Typo3Update.Classname.TypeHint.legacyClassname", "type": "ERROR" + }, + { + "column": 31, + "fixable": false, + "line": 63, + "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.TypeHint.RemovedClass.perm", + "type": "WARNING" + }, + { + "column": 96, + "fixable": false, + "line": 63, + "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.TypeHint.RemovedClass.perm", + "type": "WARNING" + }, + { + "column": 31, + "fixable": false, + "line": 66, + "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.TypeHint.RemovedClass.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 3 } }, "totals": { "errors": 6, "fixable": 6, - "warnings": 0 + "warnings": 3 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/InputFileForIssues.php index 8200349..7f88ddd 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/InputFileForIssues.php @@ -59,4 +59,11 @@ class SomeClass public function something(Tx_Extbase_Domain_Model_Backenduser $user) { } + + public function something(TYPO3\CMS\Perm\Controller\PermissionAjaxController $controller, \Tx_Perm_Controller_PermissionAjaxController $controller) + { + } + public function something(Tx_Perm_Controller_PermissionAjaxController $controller) + { + } }