diff --git a/src/Standards/Typo3Update/Configuration/Features/RemovedExtension.yaml b/src/Standards/Typo3Update/Configuration/Features/RemovedExtension.yaml new file mode 100644 index 0000000..20d6ee5 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Features/RemovedExtension.yaml @@ -0,0 +1,14 @@ +Typo3Update\Feature\RemovedExtensionFeature: + - Typo3Update_Sniffs_Classname_InheritanceSniff + - Typo3Update_Sniffs_Classname_InlineCommentSniff + - Typo3Update_Sniffs_Classname_InstanceofSniff + - Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff + - Typo3Update_Sniffs_Classname_InstantiationWithNewSniff + - Typo3Update_Sniffs_Classname_InstantiationWithObjectManagerSniff + - Typo3Update_Sniffs_Classname_IsACallSniff + - Typo3Update_Sniffs_Classname_MissingVendorForPluginsAndModulesSniff + - Typo3Update_Sniffs_Classname_PhpDocCommentSniff + - Typo3Update_Sniffs_Classname_StaticCallSniff + - Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff + - Typo3Update_Sniffs_Classname_TypeHintSniff + - Typo3Update_Sniffs_Classname_UseSniff diff --git a/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php new file mode 100644 index 0000000..aeab11f --- /dev/null +++ b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php @@ -0,0 +1,73 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Options; + +class RemovedExtensionFeature extends AbstractYamlRemovedUsage +{ + public function process(PhpCsFile $phpcsFile, $classnamePosition, $classname) + { + $classnameParts = array_filter(preg_split('/\\\\|_/', $classname)); + $extname = ''; + + foreach ($classnameParts as $classnamePart) { + $classnamePart = strtolower($classnamePart); + if ($this->configured->isRemoved($classnamePart) === true) { + $extname = $classnamePart; + break; + } + } + + if ($extname === '') { + return; + } + + $this->addWarning( + $phpcsFile, + $classnamePosition, + $this->configured->getRemoved($extname) + ); + } + + protected function prepareStructure(array $typo3Versions) + { + $newStructure = []; + foreach ($typo3Versions as $typo3Version => $removals) { + foreach ($removals as $removed => $config) { + $config['name'] = $removed; + $config['identifier'] = 'RemovedClass.' . str_replace('\\', '_', ltrim($removed, '\\')); + $config['versionRemoved'] = $typo3Version; + $config['oldUsage'] = $removed; + + $newStructure[$removed] = $config; + } + } + + return $newStructure; + } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedExtensionConfigFiles(); + } +} diff --git a/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php index 67c00e6..c51aae1 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php @@ -20,10 +20,13 @@ */ use PHP_CodeSniffer_File as PhpCsFile; -use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; +use PHP_CodeSniffer_Sniff as PhpCsSniff; +use Typo3Update\Feature\FeaturesSupport; -class Typo3Update_Sniffs_Classname_UseSniff extends AbstractClassnameChecker +class Typo3Update_Sniffs_Classname_UseSniff implements PhpCsSniff { + use FeaturesSupport; + /** * Returns the token types that this sniff is interested in. * @@ -33,4 +36,20 @@ class Typo3Update_Sniffs_Classname_UseSniff extends AbstractClassnameChecker { return [T_USE]; } + + public function process(PhpCsFile $phpcsFile, $stackPtr) + { + $start = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($start === false) { + return; + } + + $end = $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR], $start, null, true, null, true); + if ($end === false) { + return; + } + + $classname = $phpcsFile->getTokensAsString($start, $end - $start); + $this->processFeatures($phpcsFile, $start, $classname); + } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.diff index ff0098d..0783031 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.diff @@ -10,4 +10,4 @@ +use TYPO3\CMS\Extbase\Domain\Model\BackendUser; use TYPO3\CMS\Extbase\Mvc\Cli\Command; use \TYPO3\CMS\Extbase\Mvc\Cli\Command; - + use TYPO3\CMS\Perm\Controller\PermissionAjaxController; diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json index 63816bd..dd191bf 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json @@ -20,14 +20,41 @@ "severity": 5, "source": "Typo3Update.Classname.Use.legacyClassname", "type": "ERROR" + }, + { + "column": 5, + "fixable": false, + "line": 26, + "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.Use.RemovedClass.perm", + "type": "WARNING" + }, + { + "column": 6, + "fixable": false, + "line": 27, + "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.Use.RemovedClass.perm", + "type": "WARNING" + }, + { + "column": 5, + "fixable": false, + "line": 28, + "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.Use.RemovedClass.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 3 } }, "totals": { "errors": 2, "fixable": 2, - "warnings": 0 + "warnings": 3 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/InputFileForIssues.php index 7dbcfd4..972b2db 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/InputFileForIssues.php @@ -23,4 +23,6 @@ use \Tx_Extbase_Domain_Model_Backenduser; use Tx_Extbase_Domain_Model_Backenduser; use TYPO3\CMS\Extbase\Mvc\Cli\Command; use \TYPO3\CMS\Extbase\Mvc\Cli\Command; - +use TYPO3\CMS\Perm\Controller\PermissionAjaxController; +use \Tx_Perm_Controller_PermissionAjaxController; +use Tx_Perm_Controller_PermissionAjaxController;