diff --git a/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml b/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml index 44e6556..9b51023 100644 --- a/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml +++ b/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml @@ -9,6 +9,7 @@ Typo3Update\Feature\LegacyClassnameFeature: - Typo3Update_Sniffs_Classname_MissingVendorForPluginsAndModulesSniff - Typo3Update_Sniffs_Classname_PhpDocCommentSniff - Typo3Update_Sniffs_Classname_StaticCallSniff + - Typo3Update_Sniffs_Classname_StringSniff - Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff - Typo3Update_Sniffs_Classname_TypeHintSniff - Typo3Update_Sniffs_Classname_UseSniff diff --git a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php index 4612e6d..0a25222 100644 --- a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php +++ b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php @@ -96,6 +96,10 @@ class LegacyClassnameFeature implements FeatureInterface */ protected function isLegacyClassname($classname) { + if (get_class($this->sniff) === \Typo3Update_Sniffs_Classname_StringSniff::class) { + return false; + } + return $this->legacyMapping->isLegacyClassname($classname); } @@ -117,7 +121,9 @@ class LegacyClassnameFeature implements FeatureInterface return $nameParts[1]; }, $classname); - if (!in_array($extensionName, $this->legacyExtensions)) { + if (!in_array($extensionName, $this->legacyExtensions) + && get_class($this->sniff) !== \Typo3Update_Sniffs_Classname_StringSniff::class + ) { return false; } diff --git a/src/Standards/Typo3Update/Sniffs/Classname/StringSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/StringSniff.php new file mode 100644 index 0000000..f25b528 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Classname/StringSniff.php @@ -0,0 +1,53 @@ + + * + * 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 PHP_CodeSniffer_Sniff as PhpCsSniff; +use PHP_CodeSniffer_Tokens as PhpCsTokens; +use Typo3Update\Feature\FeaturesSupport; + +class Typo3Update_Sniffs_Classname_StringSniff implements PhpCsSniff +{ + use FeaturesSupport; + + /** + * @return array + */ + public function register() + { + return PhpCsTokens::$stringTokens; + } + + /** + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + */ + public function process(PhpCsFile $phpcsFile, $stackPtr) + { + $token = $phpcsFile->getTokens()[$stackPtr]['content']; + // Special chars like ":" and "&" are used in configuration directives. + $classnames = array_filter(preg_split('/\s+|:|>|-|&/', substr($token, 1, -1))); + + foreach ($classnames as $classname) { + $this->processFeatures($phpcsFile, $stackPtr, $classname); + } + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/Expected.diff new file mode 100644 index 0000000..e69de29 diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/Expected.json new file mode 100644 index 0000000..fa5eb99 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/Expected.json @@ -0,0 +1,42 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 0, + "messages": [ + { + "column": 80, + "fixable": false, + "line": 22, + "message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore", + "severity": 5, + "source": "Typo3Update.Classname.String.mightBeLegacyClassname", + "type": "WARNING" + }, + { + "column": 80, + "fixable": false, + "line": 23, + "message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore", + "severity": 5, + "source": "Typo3Update.Classname.String.mightBeLegacyClassname", + "type": "WARNING" + }, + { + "column": 93, + "fixable": false, + "line": 25, + "message": "Legacy classes are not allowed; found Tx_ExtKey_Hooks_Cache that might be a legacy class that does not exist anymore", + "severity": 5, + "source": "Typo3Update.Classname.String.mightBeLegacyClassname", + "type": "WARNING" + } + ], + "warnings": 3 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 3 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/InputFileForIssues.php new file mode 100644 index 0000000..2a902c2 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/InputFileForIssues.php @@ -0,0 +1,25 @@ + + * + * 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. + */ + +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Tx_Extbase_Command_HelpCommandController'; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_Extbase_Command_HelpCommandController"; + +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&Tx_ExtKey_Hooks_Cache->getHash';