From 4461e116db56c7b7c483296af259635567d0a4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= Date: Tue, 11 Apr 2017 12:39:22 +0200 Subject: [PATCH 01/23] FEATURE: Test for removed extension key sniff added --- .../Sniffs/Removed/ExtensionKeySniff.php | 58 +++++++++++++++++++ .../Removed/ExtensionKeySniff/Expected.json | 24 ++++++++ .../ExtensionKeySniff/InputFileForIssues.php | 22 +++++++ 3 files changed, 104 insertions(+) create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php diff --git a/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php b/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php new file mode 100644 index 0000000..ef93ceb --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php @@ -0,0 +1,58 @@ + + */ + protected function getRemovedConfigFiles() + { + return []; + } + + /** + * The original call, to allow user to check matches. + * + * As we match the name, that can be provided by multiple classes, you + * should provide an example, so users can check that this is the legacy + * one. + * + * @param array $config + * + * @return string + */ + protected function getOldUsage(array $config) + { + return ''; + } + + /** + * Registers the tokens that this sniff wants to listen for. + * + * An example return value for a sniff that wants to listen for whitespace + * and any comments would be: + * + * + * return array( + * T_WHITESPACE, + * T_DOC_COMMENT, + * T_COMMENT, + * ); + * + * + * @return int[] + * @see Tokens.php + */ + public function register() + { + return []; + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json new file mode 100644 index 0000000..22c013b --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json @@ -0,0 +1,24 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 0, + "messages": [ + { + "column": 63, + "fixable": false, + "line": 22, + "message": "Legacy extension are not allowed; found \"perm\"", + "severity": 5, + "source": "Typo3Update.Removed.ExtensionKey.legacyKey", + "type": "WARNING" + } + ], + "warnings": 1 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 1 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php new file mode 100644 index 0000000..2cf7985 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php @@ -0,0 +1,22 @@ + + * + * 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. + */ + +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('perm'); From 5adbac1a251efdd275c83b22039e73290203ec2c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 4 May 2017 16:43:09 +0200 Subject: [PATCH 02/23] TASK: Implement basic structure * Adjust to latest develop state of project. * Provide basic implementation. Relates: #44 --- .../Configuration/Removed/Extension/7.0.yaml | 6 ++ src/Standards/Typo3Update/Options.php | 11 ++++ .../Sniffs/ExtendedPhpCsSupportTrait.php | 31 ++++++++++ .../Sniffs/Removed/AbstractGenericUsage.php | 17 +++++ .../Sniffs/Removed/ExtensionKeySniff.php | 58 ----------------- .../Sniffs/Removed/ExtensionSniff.php | 62 +++++++++++++++++++ .../Removed/TypoScriptConstantSniff.php | 17 ----- .../Expected.json | 0 .../InputFileForIssues.php | 3 + tests/Sniffs/Removed/ExtensionSniffTest.php | 28 +++++++++ 10 files changed, 158 insertions(+), 75 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Extension/7.0.yaml delete mode 100644 src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff.php rename tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/{ExtensionKeySniff => ExtensionSniff}/Expected.json (100%) rename tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/{ExtensionKeySniff => ExtensionSniff}/InputFileForIssues.php (86%) create mode 100644 tests/Sniffs/Removed/ExtensionSniffTest.php diff --git a/src/Standards/Typo3Update/Configuration/Removed/Extension/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/Extension/7.0.yaml new file mode 100644 index 0000000..1f1e3fe --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Extension/7.0.yaml @@ -0,0 +1,6 @@ +# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes +'7.0': + perm: + replacement: 'The logic is moved into EXT:beuser' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62339-MoveExtPermIntoExtBeuser.html' + diff --git a/src/Standards/Typo3Update/Options.php b/src/Standards/Typo3Update/Options.php index f5a4777..cc8cd08 100644 --- a/src/Standards/Typo3Update/Options.php +++ b/src/Standards/Typo3Update/Options.php @@ -56,6 +56,17 @@ class Options ); } + /** + * @return array + */ + public static function getRemovedExtensionConfigFiles() + { + return static::getOptionFileNames( + 'removedExtensionConfigFiles', + __DIR__ . '/Configuration/Removed/Extension/*.yaml' + ); + } + /** * Returns an array of absolute file names containing removed function configurations. * diff --git a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php index 2368d4d..475e014 100644 --- a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php +++ b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php @@ -66,4 +66,35 @@ trait ExtendedPhpCsSupportTrait return true; } + + /** + * Returns all parameters for function call as values. + * Quotes are removed from strings. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * + * @return array + */ + protected function getFunctionCallParameters(PhpCsFile $phpcsFile, $stackPtr) + { + $start = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr) + 1; + $parameters = explode(',', $phpcsFile->getTokensAsString( + $start, + $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) - $start + )); + + return array_map([$this, 'getStringContent'], $parameters); + } + + /** + * Remove special chars like quotes from string. + * + * @param string + * @return string + */ + public function getStringContent($string) + { + return trim($string, " \t\n\r\0\x0B'\""); + } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index 557dcb5..a4a600f 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -33,6 +33,23 @@ abstract class AbstractGenericUsage extends BaseAbstractYamlRemovedUsage impleme */ abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr); + protected function prepareStructure(array $typo3Versions) + { + $newStructure = []; + + foreach ($typo3Versions as $typo3Version => $removals) { + foreach ($removals as $removed => $config) { + $config['name'] = $removed; + $config['identifier'] = $removed; + $config['oldUsage'] = $removed; + $config['versionRemoved'] = $typo3Version; + $newStructure[$removed] = $config; + } + } + + return $newStructure; + } + /** * @param PhpCsFile $phpcsFile * @param int $stackPtr diff --git a/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php b/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php deleted file mode 100644 index ef93ceb..0000000 --- a/src/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff.php +++ /dev/null @@ -1,58 +0,0 @@ - - */ - protected function getRemovedConfigFiles() - { - return []; - } - - /** - * The original call, to allow user to check matches. - * - * As we match the name, that can be provided by multiple classes, you - * should provide an example, so users can check that this is the legacy - * one. - * - * @param array $config - * - * @return string - */ - protected function getOldUsage(array $config) - { - return ''; - } - - /** - * Registers the tokens that this sniff wants to listen for. - * - * An example return value for a sniff that wants to listen for whitespace - * and any comments would be: - * - * - * return array( - * T_WHITESPACE, - * T_DOC_COMMENT, - * T_COMMENT, - * ); - * - * - * @return int[] - * @see Tokens.php - */ - public function register() - { - return []; - } -} diff --git a/src/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff.php new file mode 100644 index 0000000..16d829e --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff.php @@ -0,0 +1,62 @@ + + * + * 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; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; +use Typo3Update\Sniffs\Removed\AbstractGenericUsage; + +class Typo3Update_Sniffs_Removed_ExtensionSniff extends AbstractGenericUsage +{ + use ExtendedPhpCsSupportTrait; + + /** + * @var array + */ + public $methodsToCheck = ['isLoaded', 'extPath', 'extRelPath', 'getCN', 'getExtensionVersion']; + + public function register() + { + return [T_STRING]; + } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedExtensionConfigFiles(); + } + + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + $token = $phpcsFile->getTokens()[$stackPtr]; + if (!$this->isFunctionCall($phpcsFile, $stackPtr) + || !in_array($token['content'], $this->methodsToCheck) + ) { + return []; + } + + $arguments = $this->getFunctionCallParameters($phpcsFile, $stackPtr); + if ($this->configured->isRemoved($arguments[0])) { + return [$this->configured->getRemoved($arguments[0])]; + } + + return []; + } +} diff --git a/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php index c396d32..3a71618 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/TypoScriptConstantSniff.php @@ -42,23 +42,6 @@ class Typo3Update_Sniffs_Removed_TypoScriptConstantSniff extends AbstractGeneric ]; } - protected function prepareStructure(array $typo3Versions) - { - $newStructure = []; - - foreach ($typo3Versions as $typo3Version => $removals) { - foreach ($removals as $removed => $config) { - $config['name'] = $removed; - $config['identifier'] = $removed; - $config['oldUsage'] = $removed; - $config['versionRemoved'] = $typo3Version; - $newStructure[$removed] = $config; - } - } - - return $newStructure; - } - protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) { $removed = []; diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json similarity index 100% rename from tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/Expected.json rename to tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php similarity index 86% rename from tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php rename to tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php index 2cf7985..55f6cb2 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionKeySniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php @@ -19,4 +19,7 @@ * 02110-1301, USA. */ +use TYPO3\CMS\Perm\Controller\PermissionModuleController; + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('perm'); +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('perm'); diff --git a/tests/Sniffs/Removed/ExtensionSniffTest.php b/tests/Sniffs/Removed/ExtensionSniffTest.php new file mode 100644 index 0000000..d563ca0 --- /dev/null +++ b/tests/Sniffs/Removed/ExtensionSniffTest.php @@ -0,0 +1,28 @@ + + * + * 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 Typo3Update\Tests\SniffsTest; + +class ExtensionSniffTest extends SniffsTest +{ +} From c7ddbc4aef535deebe95c96566651bf655d64781 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 08:35:58 +0200 Subject: [PATCH 03/23] TASK: Finish removed extension test * Adjust expected result to match result. * Remove example usage of "use" as this is part of a feature and not this sniff. Relates: #44 --- .../Removed/ExtensionSniff/Expected.json | 19 ++++++++++++++----- .../ExtensionSniff/InputFileForIssues.php | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json index 22c013b..a2cc1d7 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/Expected.json @@ -4,21 +4,30 @@ "errors": 0, "messages": [ { - "column": 63, + "column": 53, "fixable": false, "line": 22, - "message": "Legacy extension are not allowed; found \"perm\"", + "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.Removed.ExtensionKey.legacyKey", + "source": "Typo3Update.Removed.Extension.perm", + "type": "WARNING" + }, + { + "column": 53, + "fixable": false, + "line": 23, + "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.Removed.Extension.perm", "type": "WARNING" } ], - "warnings": 1 + "warnings": 2 } }, "totals": { "errors": 0, "fixable": 0, - "warnings": 1 + "warnings": 2 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php index 55f6cb2..c9039ad 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/ExtensionSniff/InputFileForIssues.php @@ -19,7 +19,5 @@ * 02110-1301, USA. */ -use TYPO3\CMS\Perm\Controller\PermissionModuleController; - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('perm'); \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('perm'); From 633a7140437caf25ccb7f3779a179e2935149427 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 08:37:41 +0200 Subject: [PATCH 04/23] FEATURE: Implement removed extension into use sniff. * Detect removed extensions in use statements. Relates: #44 --- .../Features/RemovedExtension.yaml | 14 ++++ .../Feature/RemovedExtensionFeature.php | 73 +++++++++++++++++++ .../Typo3Update/Sniffs/Classname/UseSniff.php | 23 +++++- .../Sniffs/Classname/UseSniff/Expected.diff | 2 +- .../Sniffs/Classname/UseSniff/Expected.json | 31 +++++++- .../Classname/UseSniff/InputFileForIssues.php | 4 +- 6 files changed, 141 insertions(+), 6 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Features/RemovedExtension.yaml create mode 100644 src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php 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; From 3034f3fec4ec82b4d66be62d31a472cb9715d855 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 10:34:58 +0200 Subject: [PATCH 05/23] 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) + { + } } From fda1921d50726adeedc3713f61a8f04ba7df51f2 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 10:54:17 +0200 Subject: [PATCH 06/23] TASK: Refactor sniffs * Move generic logic to abstract class. * As not only UseSniff but also all others have the same logic, if method is not overwritten. * Therefore all other sniffs should work with new feature of removed extension. Relates: #44 --- .../Classname/AbstractClassnameChecker.php | 70 ++++++++++++++++--- .../Typo3Update/Sniffs/Classname/UseSniff.php | 24 +------ 2 files changed, 62 insertions(+), 32 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php index e405fdc..858e173 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php @@ -62,19 +62,69 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ public function process(PhpCsFile $phpcsFile, $stackPtr) { - $tokens = $phpcsFile->getTokens(); - - if ($this->shouldLookBefore()) { - $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); - } else { - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - } - - if ($classnamePosition === false) { + try { + if ($this->shouldLookBefore()) { + list($classnamePosition, $classname) = $this->getBefore($phpcsFile, $stackPtr); + } else { + list($classnamePosition, $classname) = $this->getAfter($phpcsFile, $stackPtr); + } + } catch (\UnexpectedValueException $e) { return; } - $classname = $tokens[$classnamePosition]['content']; $this->processFeatures($phpcsFile, $classnamePosition, $classname); } + + /** + * Get position and classname before current stack pointer. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr The position in the stack where + * + * @return array + */ + protected function getBefore(PhpCsFile $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + + $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); + if ($classnamePosition === false) { + throw new \UnexpectedValueException('Could not find start of classname.', 1494319966); + } + + $classname = $tokens[$classnamePosition]['content']; + + return [ + $classnamePosition, + $classname + ]; + } + + /** + * Get position and classname after current stack pointer. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr The position in the stack where + * + * @return array + */ + protected function getAfter(PhpCsFile $phpcsFile, $stackPtr) + { + $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($classnamePosition === false) { + throw new \UnexpectedValueException('Could not find start of classname.', 1494319665); + } + + $end = $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR], $classnamePosition, null, true, null, true); + if ($end === false) { + throw new \UnexpectedValueException('Could not find end of classname.', 1494319651); + } + + $classname = $phpcsFile->getTokensAsString($classnamePosition, $end - $classnamePosition); + + return [ + $classnamePosition, + $classname + ]; + } } diff --git a/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php index c51aae1..a58a54d 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/UseSniff.php @@ -19,14 +19,10 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_File as PhpCsFile; -use PHP_CodeSniffer_Sniff as PhpCsSniff; -use Typo3Update\Feature\FeaturesSupport; +use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -class Typo3Update_Sniffs_Classname_UseSniff implements PhpCsSniff +class Typo3Update_Sniffs_Classname_UseSniff extends AbstractClassnameChecker { - use FeaturesSupport; - /** * Returns the token types that this sniff is interested in. * @@ -36,20 +32,4 @@ class Typo3Update_Sniffs_Classname_UseSniff implements PhpCsSniff { 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); - } } From b32fc01110999e112e3d990e9f9b870aa5d44bf3 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 10:55:17 +0200 Subject: [PATCH 07/23] TASK: Add test for TypeHintCatchExceptionSniff * Check that the sniff works with new feature of removed extension. Relates: #44 --- .../TypeHintCatchExceptionSniff/Expected.json | 13 +++++++++++-- .../InputFileForIssues.php | 6 ++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json index 59701dd..0094c2d 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json @@ -20,14 +20,23 @@ "severity": 5, "source": "Typo3Update.Classname.TypeHintCatchException.legacyClassname", "type": "ERROR" + }, + { + "column": 11, + "fixable": false, + "line": 48, + "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.TypeHintCatchException.RemovedClass.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 1 } }, "totals": { "errors": 2, "fixable": 2, - "warnings": 0 + "warnings": 1 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/InputFileForIssues.php index 0ea392d..28e47f6 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/InputFileForIssues.php @@ -42,3 +42,9 @@ try { } catch (TYPO3\CMS\Extbase\Exception $e) { // else } + +try { + // something +} catch (\TYPO3\CMS\Perm\Controller\PermissionAjaxController $e) { + // else +} From af50ddfd993c1012a963b45ea860ffd3404dcd62 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:20:45 +0200 Subject: [PATCH 08/23] 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); From 3503a5b63ad5aa65469c77adf1713765d980708d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:25:54 +0200 Subject: [PATCH 09/23] TASK: Update PhpDocCommentSniff tests to reflect added removed extension Relates: #44 --- .../Classname/PhpDocCommentSniff/Expected.diff | 3 ++- .../Classname/PhpDocCommentSniff/Expected.json | 17 +++++++++++++---- .../PhpDocCommentSniff/InputFileForIssues.php | 1 + 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff index 36a8cf7..3c7394d 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -22,20 +22,20 @@ +@@ -22,21 +22,21 @@ class InputFileForIssues { /** @@ -14,6 +14,7 @@ - * @param t3lib_div + * @param \TYPO3\CMS\Core\Utility\GeneralUtility * @param \TYPO3\CMS\Backend\Template\MediumDocumentTemplate + * @param \TYPO3\CMS\Perm\Controller\PermissionAjaxController * - * @return Tx_Extbase_Configuration_Configurationmanager + * @return \TYPO3\CMS\Extbase\Configuration\ConfigurationManager diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json index 89158c7..8d55953 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json @@ -30,10 +30,19 @@ "source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate", "type": "WARNING" }, + { + "column": 15, + "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.PhpDocComment.RemovedClass.perm", + "type": "WARNING" + }, { "column": 16, "fixable": true, - "line": 34, + "line": 35, "message": "Legacy classes are not allowed; found \"Tx_Extbase_Configuration_Configurationmanager\", use \"TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", @@ -42,19 +51,19 @@ { "column": 18, "fixable": true, - "line": 38, + "line": 39, "message": "Legacy classes are not allowed; found \"t3lib_div\", use \"TYPO3\\CMS\\Core\\Utility\\GeneralUtility\" instead", "severity": 5, "source": "Typo3Update.Classname.PhpDocComment.legacyClassname", "type": "ERROR" } ], - "warnings": 1 + "warnings": 2 } }, "totals": { "errors": 4, "fixable": 4, - "warnings": 1 + "warnings": 2 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php index 7a2de67..181b1fd 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/InputFileForIssues.php @@ -30,6 +30,7 @@ class InputFileForIssues /** * @param t3lib_div * @param \TYPO3\CMS\Backend\Template\MediumDocumentTemplate + * @param \TYPO3\CMS\Perm\Controller\PermissionAjaxController * * @return Tx_Extbase_Configuration_Configurationmanager */ From 9b028d24e675c94fa617cee0fd97c68ec2c2db3d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:31:15 +0200 Subject: [PATCH 10/23] TASK: Update IsACallSniff tests to reflect added removed extension Relates: #44 --- .../Sniffs/Classname/IsACallSniff/Expected.diff | 3 ++- .../Sniffs/Classname/IsACallSniff/Expected.json | 13 +++++++++++-- .../Classname/IsACallSniff/InputFileForIssues.php | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.diff index d099979..30d8556 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -23,15 +23,15 @@ +@@ -23,16 +23,16 @@ if (is_a($a, t3lib_Singleton::class)) { // do something } @@ -20,3 +20,4 @@ +if (is_a($a, "\\TYPO3\\CMS\\Core\\SingletonInterface")) { // do something } + if (is_a($a, "\\TYPO3\CMS\Perm\Controller\PermissionAjaxController")) { diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json index 6795e14..ee399d9 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json @@ -38,14 +38,23 @@ "severity": 5, "source": "Typo3Update.Classname.IsACall.legacyClassname", "type": "ERROR" + }, + { + "column": 14, + "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.IsACall.RemovedClass.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 1 } }, "totals": { "errors": 4, "fixable": 4, - "warnings": 0 + "warnings": 1 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/InputFileForIssues.php index 53a8a7b..cdcf3ba 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/InputFileForIssues.php @@ -35,3 +35,6 @@ if (is_a($a, "t3lib_Singleton")) { if (is_a($a, "\\t3lib_Singleton")) { // do something } +if (is_a($a, "\\TYPO3\CMS\Perm\Controller\PermissionAjaxController")) { + // do something +} From d38ce3dc4148438494a2b59d8d567e26760d8aa1 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:33:55 +0200 Subject: [PATCH 11/23] BUGFIX: Fix identifier for removed extension * Due to copy and paste the identifier was not indicating a removed extension. * Identifier and tests were adjusted accordingly. Relates: #44 --- .../Typo3Update/Feature/RemovedExtensionFeature.php | 2 +- .../Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json | 2 +- .../Sniffs/Classname/PhpDocCommentSniff/Expected.json | 2 +- .../Sniffs/Classname/StaticCallSniff/Expected.json | 4 ++-- .../Classname/TypeHintCatchExceptionSniff/Expected.json | 2 +- .../Sniffs/Classname/TypeHintSniff/Expected.json | 6 +++--- .../Typo3Update/Sniffs/Classname/UseSniff/Expected.json | 6 +++--- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php index aeab11f..dce19fc 100644 --- a/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php +++ b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php @@ -55,7 +55,7 @@ class RemovedExtensionFeature extends AbstractYamlRemovedUsage foreach ($typo3Versions as $typo3Version => $removals) { foreach ($removals as $removed => $config) { $config['name'] = $removed; - $config['identifier'] = 'RemovedClass.' . str_replace('\\', '_', ltrim($removed, '\\')); + $config['identifier'] = 'RemovedExtension.' . str_replace('\\', '_', ltrim($removed, '\\')); $config['versionRemoved'] = $typo3Version; $config['oldUsage'] = $removed; diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json index ee399d9..4120a2d 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/IsACallSniff/Expected.json @@ -45,7 +45,7 @@ "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.IsACall.RemovedClass.perm", + "source": "Typo3Update.Classname.IsACall.RemovedExtension.perm", "type": "WARNING" } ], diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json index 8d55953..1d56ad0 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/PhpDocCommentSniff/Expected.json @@ -36,7 +36,7 @@ "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.PhpDocComment.RemovedClass.perm", + "source": "Typo3Update.Classname.PhpDocComment.RemovedExtension.perm", "type": "WARNING" }, { diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json index 5c66396..e9ade00 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff/Expected.json @@ -63,7 +63,7 @@ "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", + "source": "Typo3Update.Classname.StaticCall.RemovedExtension.perm", "type": "WARNING" }, { @@ -72,7 +72,7 @@ "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", + "source": "Typo3Update.Classname.StaticCall.RemovedExtension.perm", "type": "WARNING" } ], diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json index 0094c2d..5748bcc 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff/Expected.json @@ -27,7 +27,7 @@ "line": 48, "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.TypeHintCatchException.RemovedClass.perm", + "source": "Typo3Update.Classname.TypeHintCatchException.RemovedExtension.perm", "type": "WARNING" } ], diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json index 2e56a13..f0d2559 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff/Expected.json @@ -63,7 +63,7 @@ "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", + "source": "Typo3Update.Classname.TypeHint.RemovedExtension.perm", "type": "WARNING" }, { @@ -72,7 +72,7 @@ "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", + "source": "Typo3Update.Classname.TypeHint.RemovedExtension.perm", "type": "WARNING" }, { @@ -81,7 +81,7 @@ "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", + "source": "Typo3Update.Classname.TypeHint.RemovedExtension.perm", "type": "WARNING" } ], diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json index dd191bf..7df8978 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/Expected.json @@ -27,7 +27,7 @@ "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", + "source": "Typo3Update.Classname.Use.RemovedExtension.perm", "type": "WARNING" }, { @@ -36,7 +36,7 @@ "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", + "source": "Typo3Update.Classname.Use.RemovedExtension.perm", "type": "WARNING" }, { @@ -45,7 +45,7 @@ "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", + "source": "Typo3Update.Classname.Use.RemovedExtension.perm", "type": "WARNING" } ], From e2c972ed581991f9eb095a992a96c5bc607c48ed Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:39:59 +0200 Subject: [PATCH 12/23] TASK: Update InstantiationWithObjectManagerSniff tests Relates: #44 --- .../Expected.diff | 5 ++++- .../Expected.json | 22 +++++++++++++++++-- .../InputFileForIssues.php | 4 ++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.diff index 873ee97..56def1d 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -21,13 +21,13 @@ +@@ -21,16 +21,16 @@ // Not handled by this sniff, but StaticCallSniff, as this uses double colon. $this->objectManager->get(\Tx_Extbase_Command_HelpCommandController::class); @@ -18,3 +18,6 @@ \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager) - ->get('Tx_Extbase_Command_HelpCommandController'); + ->get('\TYPO3\CMS\Extbase\Command\HelpCommandController'); + + \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager) + ->get('\TYPO3\CMS\Perm\Controller\PermissionAjaxController'); diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.json index 273b495..58fa8c8 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/Expected.json @@ -38,14 +38,32 @@ "severity": 5, "source": "Typo3Update.Classname.InstantiationWithObjectManager.legacyClassname", "type": "ERROR" + }, + { + "column": 11, + "fixable": false, + "line": 36, + "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.InstantiationWithObjectManager.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 27, + "fixable": false, + "line": 37, + "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.InstantiationWithObjectManager.RemovedExtension.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 2 } }, "totals": { "errors": 4, "fixable": 4, - "warnings": 0 + "warnings": 2 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/InputFileForIssues.php index 75d9d58..12a81fc 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff/InputFileForIssues.php @@ -31,3 +31,7 @@ $this->objectManager->get('Tx_Extbase_Command_HelpCommandController'); ->get('\Tx_Extbase_Command_HelpCommandController'); \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager) ->get('Tx_Extbase_Command_HelpCommandController'); + +\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager) + ->get('\TYPO3\CMS\Perm\Controller\PermissionAjaxController'); +$this->objectManager->get('TYPO3\CMS\Perm\Controller\PermissionAjaxController'); From 2894784978a8e020b7241fc79dd0051a710fd766 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 11:42:32 +0200 Subject: [PATCH 13/23] TASK: Update InstantiationWithNewSniff tests Relates: #44 --- .../InstantiationWithNewSniff/Expected.diff | 3 ++- .../InstantiationWithNewSniff/Expected.json | 22 +++++++++++++++++-- .../InputFileForIssues.php | 5 +++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.diff index 3e4f8b5..4c9871f 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -19,13 +19,13 @@ +@@ -19,14 +19,14 @@ * 02110-1301, USA. */ @@ -20,3 +20,4 @@ +(new \TYPO3\CMS\Extbase\Command\HelpCommandController) ->doSomething() ; + diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.json index d06ec76..8be441e 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/Expected.json @@ -56,14 +56,32 @@ "severity": 5, "source": "Typo3Update.Classname.InstantiationWithNew.legacyClassname", "type": "ERROR" + }, + { + "column": 5, + "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.InstantiationWithNew.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 7, + "fixable": false, + "line": 34, + "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.InstantiationWithNew.RemovedExtension.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/InstantiationWithNewSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/InputFileForIssues.php index 1f58640..9304a3e 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff/InputFileForIssues.php @@ -29,3 +29,8 @@ new Tx_Extbase_Command_HelpCommandController; (new Tx_Extbase_Command_HelpCommandController) ->doSomething() ; + +new TYPO3\CMS\Perm\Controller\PermissionAjaxController; +(new \TYPO3\CMS\Perm\Controller\PermissionAjaxController) + ->doSomething() + ; From e3dd6013ba3c3b00be3ca19e443e305de4b0f876 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 12:05:54 +0200 Subject: [PATCH 14/23] BUGFIX: Look for argument only in current statement * Just check T_STRING as this are all function calls. * Remove unused line of code. * Limit position to current statement to not return later classname multiple times. Relates: #44 --- .../Sniffs/Classname/InstantiationWithMakeInstanceSniff.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php index 070162a..04c9a89 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php @@ -34,7 +34,7 @@ class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends Ab */ public function register() { - return Tokens::$functionNameTokens; + return [T_STRING]; } /** @@ -57,13 +57,12 @@ class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends Ab return; } - $classnamePosition = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr); + $classnamePosition = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr, null, false, null, true); if ($classnamePosition === false) { return; } $classname = $tokens[$classnamePosition]['content']; - $this->originalTokenContent = $tokens[$classnamePosition]['content']; $this->processFeatures($phpcsFile, $classnamePosition, $classname); } } From 8dd569a6a618b977518b8a777ae2d2f79e01c428 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 12:07:12 +0200 Subject: [PATCH 15/23] TASK: Update InstantiationWithMakeInstanceSniff tests Relates: #44 --- .../Expected.json | 13 +++++++++++-- .../InputFileForIssues.php | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/Expected.json index b0f764e..505d5ee 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/Expected.json @@ -11,14 +11,23 @@ "severity": 5, "source": "Typo3Update.Classname.InstantiationWithMakeInstance.legacyClassname", "type": "ERROR" + }, + { + "column": 25, + "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.InstantiationWithMakeInstance.RemovedExtension.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 1 } }, "totals": { "errors": 1, "fixable": 1, - "warnings": 0 + "warnings": 1 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/InputFileForIssues.php index ccc9a0c..85f095c 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff/InputFileForIssues.php @@ -23,3 +23,5 @@ t3lib_div::makeInstance('Tx_Extbase_Command_HelpCommandController'); t3lib_div::makeInstance(\TYPO3\CMS\Core\Resource\Service\IndexerService::class); // Not handled by this sniff, but StaticCallSniff, as this uses double colon. t3lib_div::makeInstance(Tx_Extbase_Command_HelpCommandController::class); + +t3lib_div::makeInstance('TYPO3\CMS\Perm\Controller\PermissionAjaxController'); From 27864c70a1dc9f333c1af3d326f4499379df850e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 12:09:51 +0200 Subject: [PATCH 16/23] TASK: Update InstanceofSniff tests to reflect added removed extension Relates: #44 --- .../Classname/InstanceofSniff/Expected.diff | 3 ++- .../Classname/InstanceofSniff/Expected.json | 22 +++++++++++++++++-- .../InstanceofSniff/InputFileForIssues.php | 6 +++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.diff index 49e34a3..43118c8 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.diff @@ -1,6 +1,6 @@ --- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/InputFileForIssues.php +++ PHP_CodeSniffer -@@ -19,6 +19,6 @@ +@@ -19,7 +19,7 @@ * 02110-1301, USA. */ @@ -8,3 +8,4 @@ +if ($a instanceof \TYPO3\CMS\Core\SingletonInterface) { // do something } + if ($a instanceof \TYPO3\CMS\Perm\Controller\PermissionAjaxController) { diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.json index 2cb2586..53b774e 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/Expected.json @@ -11,14 +11,32 @@ "severity": 5, "source": "Typo3Update.Classname.Instanceof.legacyClassname", "type": "ERROR" + }, + { + "column": 20, + "fixable": false, + "line": 25, + "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.Instanceof.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 19, + "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.Instanceof.RemovedExtension.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 2 } }, "totals": { "errors": 1, "fixable": 1, - "warnings": 0 + "warnings": 2 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/InputFileForIssues.php index 8fe907f..96f6a76 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff/InputFileForIssues.php @@ -22,3 +22,9 @@ if ($a instanceof t3lib_Singleton) { // do something } +if ($a instanceof \TYPO3\CMS\Perm\Controller\PermissionAjaxController) { + // do something +} +if ($a instanceof TYPO3\CMS\Perm\Controller\PermissionAjaxController) { + // do something +} From 84e4c426efc00b9b2a67687af8b3225277911d30 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 12:12:46 +0200 Subject: [PATCH 17/23] TASK: Update InlineCommentSniff tests to reflect added removed extension Relates: #44 --- .../InlineCommentSniff/Expected.diff | 4 +- .../InlineCommentSniff/Expected.json | 40 ++++++++++++++++++- .../InlineCommentSniff/InputFileForIssues.php | 12 ++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.diff index 5f59195..57d888b 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.diff +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.diff @@ -19,5 +19,5 @@ - // @var Tx_Extbase_Command_HelpCommandController $variable + // @var \TYPO3\CMS\Extbase\Command\HelpCommandController $variable $variable; - } - } + + /* @var $variable TYPO3\CMS\Perm\Controller\PermissionAjaxController */ diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.json index 2a6f3ab..580e6d2 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/Expected.json @@ -38,14 +38,50 @@ "severity": 5, "source": "Typo3Update.Classname.InlineComment.legacyClassname", "type": "ERROR" + }, + { + "column": 9, + "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.InlineComment.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 9, + "fixable": false, + "line": 41, + "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.InlineComment.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 9, + "fixable": false, + "line": 44, + "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.InlineComment.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 9, + "fixable": false, + "line": 47, + "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.InlineComment.RemovedExtension.perm", + "type": "WARNING" } ], - "warnings": 0 + "warnings": 4 } }, "totals": { "errors": 4, "fixable": 4, - "warnings": 0 + "warnings": 4 } } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/InputFileForIssues.php index eedd2f8..47ffde1 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff/InputFileForIssues.php @@ -34,5 +34,17 @@ class InputFileForIssues // @var Tx_Extbase_Command_HelpCommandController $variable $variable; + + /* @var $variable TYPO3\CMS\Perm\Controller\PermissionAjaxController */ + $variable; + + // @var $variable \TYPO3\CMS\Perm\Controller\PermissionAjaxController + $variable; + + /* @var \TYPO3\CMS\Perm\Controller\PermissionAjaxController $variable */ + $variable; + + // @var TYPO3\CMS\Perm\Controller\PermissionAjaxController $variable + $variable; } } From 640f85af7dd67bd13efe675457497ce0e4e930b3 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 13:20:20 +0200 Subject: [PATCH 18/23] TASK: Update InheritanceSniff tests to reflect added removed extension Relates: #44 --- .../Sniffs/Classname/InheritanceSniff.php | 16 +++++++--- .../Classname/InheritanceSniff/Expected.json | 31 +++++++++++++++++-- .../InheritanceSniff/InputFileForIssues.php | 7 +++++ 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php index 2ce6d36..ffcf0ad 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php @@ -72,11 +72,19 @@ class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChe return; } + $lastPosition = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr); + foreach ($interfaces as $interface) { - $position = $phpcsFile->findNext(T_STRING, $stackPtr, null, false, $interface); - if ($position === false) { - continue; - } + $interface = trim($interface, '\\'); + $position = $stackPtr; + + do { + try { + list($position, $classname) = $this->getAfter($phpcsFile, $position + 1); + } catch (\UnexpectedValueException $e) { + continue 2; + } + } while ($classname !== $interface && $position <= $lastPosition); $this->processFeatures($phpcsFile, $position, $interface); } diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/Expected.json index e441162..a4d63d5 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/Expected.json @@ -56,14 +56,41 @@ "severity": 5, "source": "Typo3Update.Classname.Inheritance.legacyClassname", "type": "ERROR" + }, + { + "column": 35, + "fixable": false, + "line": 34, + "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.Inheritance.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 6, + "fixable": false, + "line": 35, + "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.Inheritance.RemovedExtension.perm", + "type": "WARNING" + }, + { + "column": 5, + "fixable": false, + "line": 36, + "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.Inheritance.RemovedExtension.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/InheritanceSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/InputFileForIssues.php index ee8fd0f..4eeafb3 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/InputFileForIssues.php +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff/InputFileForIssues.php @@ -30,3 +30,10 @@ class InputFileForIssues extends Tx_Extbase_Configuration_Configurationmanager i { } + +class InputFileForIssues extends \TYPO3\CMS\Perm\Controller\PermissionAjaxController implements + \TYPO3\CMS\Perm\Controller\PermissionAjaxController, + TYPO3\CMS\Perm\Controller\PermissionModuleController +{ + +} From c1712d0bc5f03f404e0bb506fda2c93c959f9cd5 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 13:31:51 +0200 Subject: [PATCH 19/23] TASK: Update docs Relates: #44 --- Documentation/source/configuration.rst | 22 ++++++++++++++++++++++ Documentation/source/features.rst | 3 +++ 2 files changed, 25 insertions(+) diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 5cc0c0e..5b66200 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -187,6 +187,28 @@ Using ``runtime-set``: --runtime-set removedClassConfigFiles "/Some/Absolute/Path/*.yaml" +.. _configuration-removedExtensionConfigFiles: + +removedExtensionConfigFiles +^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Configure where to look for configuration files defining the removed extensions. Default is +``Configuration/Removed/Extension/*.yaml`` inside the standard itself. We already try to deliver as +much as possible. Globing is used, so placeholders like ``*`` are possible, see +https://secure.php.net/manual/en/function.glob.php + +Using :file:`ruleset.xml`: + +.. code:: xml + + + +Using ``runtime-set``: + +.. code:: bash + + --runtime-set removedExtensionConfigFiles "/Some/Absolute/Path/*.yaml" + .. _configuration-removedTypoScriptConfigFiles: removedTypoScriptConfigFiles diff --git a/Documentation/source/features.rst b/Documentation/source/features.rst index 7576335..16644ab 100644 --- a/Documentation/source/features.rst +++ b/Documentation/source/features.rst @@ -106,6 +106,9 @@ functions. For configuration options see :ref:`configuration-removedConstantConf Check for usage of *removed PHP classes*. The classes are configured in same way as removed functions. For configuration options see :ref:`configuration-removedClassConfigFiles`. +Check for usage of *removed TYPO3 extension*. For configuration options see +:ref:`configuration-removedExtensionConfigFiles`. + Check for usage of *removed TypoScript*. The TypoScript objects are configured in same way as removed functions. For configuration options see :ref:`configuration-removedTypoScriptConfigFiles`. This will check whether you are using already removed TypoScript parts, supported are: From 4ac34503d1c09a0f2a3b85f9343092473f773d38 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 14:48:44 +0200 Subject: [PATCH 20/23] FEATURE: Check removed globals * Add feature, tests and configuration. * Refactor to follow DRY, move prepareStructure to abstract. Resolves: #77 --- .../Configuration/Removed/Globals/7.0.yaml | 8 +++ src/Standards/Typo3Update/Options.php | 13 ++++ .../Sniffs/ExtendedPhpCsSupportTrait.php | 22 +++++++ .../Sniffs/Removed/AbstractGenericUsage.php | 21 ++++++ .../Sniffs/Removed/GenericGlobalSniff.php | 66 +++++++++++++++++++ .../Removed/GenericGlobalSniff/Expected.json | 33 ++++++++++ .../GenericGlobalSniff/InputFileForIssues.php | 27 ++++++++ .../Sniffs/Removed/GenericGlobalSniffTest.php | 28 ++++++++ 8 files changed, 218 insertions(+) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Globals/7.0.yaml create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/InputFileForIssues.php create mode 100644 tests/Sniffs/Removed/GenericGlobalSniffTest.php diff --git a/src/Standards/Typo3Update/Configuration/Removed/Globals/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/Globals/7.0.yaml new file mode 100644 index 0000000..90a5d12 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Globals/7.0.yaml @@ -0,0 +1,8 @@ +# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Index.html#breaking-changes +'7.0': + typo3CacheManager: + replacement: 'Use GeneralUtility::makeInstance() instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes' + typo3CacheFactory: + replacement: 'Use GeneralUtility::makeInstance() instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes' diff --git a/src/Standards/Typo3Update/Options.php b/src/Standards/Typo3Update/Options.php index f5a4777..ea7954d 100644 --- a/src/Standards/Typo3Update/Options.php +++ b/src/Standards/Typo3Update/Options.php @@ -121,6 +121,19 @@ class Options ); } + /** + * Returns an array of absolute file names containing removed globals configurations. + * + * @return array + */ + public static function getRemovedGlobalConfigFiles() + { + return static::getOptionFileNames( + 'removedGlobalConfigFiles', + __DIR__ . '/Configuration/Removed/Globals/*.yaml' + ); + } + /** * Get the option by optionName, if not defined, use default. * diff --git a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php index 2368d4d..ad4385e 100644 --- a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php +++ b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php @@ -66,4 +66,26 @@ trait ExtendedPhpCsSupportTrait return true; } + + /** + * Check whether variable at $stackPtr is global. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * + * @return bool + */ + protected function isGlobalVariable(PhpCsFile $phpcsFile, $stackPtr) + { + $position = $phpcsFile->findPrevious(T_GLOBAL, $stackPtr, null, false, null, true); + if ($position !== false) { + return true; + } + + if ($phpcsFile->getTokens()[$stackPtr]['content'] === '$GLOBALS') { + return true; + } + + return false; + } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index 557dcb5..e20d8e0 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -33,6 +33,27 @@ abstract class AbstractGenericUsage extends BaseAbstractYamlRemovedUsage impleme */ abstract protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr); + /** + * @param array $typo3Versions + * @return array + */ + protected function prepareStructure(array $typo3Versions) + { + $newStructure = []; + + foreach ($typo3Versions as $typo3Version => $removals) { + foreach ($removals as $removed => $config) { + $config['name'] = $removed; + $config['identifier'] = $removed; + $config['oldUsage'] = $removed; + $config['versionRemoved'] = $typo3Version; + $newStructure[$removed] = $config; + } + } + + return $newStructure; + } + /** * @param PhpCsFile $phpcsFile * @param int $stackPtr diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff.php new file mode 100644 index 0000000..1aabb4c --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff.php @@ -0,0 +1,66 @@ + + * + * 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; +use Typo3Update\Sniffs\Removed\AbstractGenericUsage; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + +class Typo3Update_Sniffs_Removed_GenericGlobalSniff extends AbstractGenericUsage +{ + use ExtendedPhpCsSupportTrait; + + public function register() + { + return [T_VARIABLE]; + } + + /** + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * @return array + */ + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + if ($this->isGlobalVariable($phpcsFile, $stackPtr) === false) { + return []; + } + + $variableName = substr($phpcsFile->getTokens()[$stackPtr]['content'], 1); + if ($variableName === 'GLOBALS') { + $variableName = trim( + $phpcsFile->getTokens()[$phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr)]['content'], + '\'"' + ); + } + + if ($this->configured->isRemoved($variableName)) { + return [$this->configured->getRemoved($variableName)]; + } + + return []; + } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedGlobalConfigFiles(); + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json new file mode 100644 index 0000000..4e2c2b9 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json @@ -0,0 +1,33 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 0, + "messages": [ + { + "column": 12, + "fixable": false, + "line": 24, + "message": "Calls to removed code are not allowed; found typo3CacheFactory. Removed in 7.0. Use GeneralUtility::makeInstance() instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes", + "severity": 5, + "source": "Typo3Update.Removed.GenericGlobal.typo3CacheFactory", + "type": "WARNING" + }, + { + "column": 13, + "fixable": false, + "line": 25, + "message": "Calls to removed code are not allowed; found typo3CacheManager. Removed in 7.0. Use GeneralUtility::makeInstance() instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes", + "severity": 5, + "source": "Typo3Update.Removed.GenericGlobal.typo3CacheManager", + "type": "WARNING" + } + ], + "warnings": 2 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 2 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/InputFileForIssues.php new file mode 100644 index 0000000..d63cfd4 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/InputFileForIssues.php @@ -0,0 +1,27 @@ + + * + * 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. + */ + +function name() +{ + global $typo3CacheFactory; + $typo3CacheManager = $GLOBALS['typo3CacheManager']; + $typo3CacheManager->something(); +} diff --git a/tests/Sniffs/Removed/GenericGlobalSniffTest.php b/tests/Sniffs/Removed/GenericGlobalSniffTest.php new file mode 100644 index 0000000..b19e40d --- /dev/null +++ b/tests/Sniffs/Removed/GenericGlobalSniffTest.php @@ -0,0 +1,28 @@ + + * + * 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 Typo3Update\Tests\SniffsTest; + +class GenericGlobalSniffTest extends SniffsTest +{ +} From 219103561e4abe76d0a99bc9b8737a1fff9bb9d9 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 15:03:35 +0200 Subject: [PATCH 21/23] TASK: Update docs * To reflect new feature. Relates: #77 --- Documentation/source/configuration.rst | 22 ++++++++++++++++++++++ Documentation/source/features.rst | 3 +++ 2 files changed, 25 insertions(+) diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 5cc0c0e..a4efe38 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -187,6 +187,28 @@ Using ``runtime-set``: --runtime-set removedClassConfigFiles "/Some/Absolute/Path/*.yaml" +.. _configuration-removedGlobalConfigFiles: + +removedGlobalConfigFiles +^^^^^^^^^^^^^^^^^^^^^^^^ + +Configure where to look for configuration files defining the removed globals. Default is +``Configuration/Removed/Globals/*.yaml`` inside the standard itself. We already try to deliver as +much as possible. Globing is used, so placeholders like ``*`` are possible, see +https://secure.php.net/manual/en/function.glob.php + +Using :file:`ruleset.xml`: + +.. code:: xml + + + +Using ``runtime-set``: + +.. code:: bash + + --runtime-set removedGlobalConfigFiles "/Some/Absolute/Path/*.yaml" + .. _configuration-removedTypoScriptConfigFiles: removedTypoScriptConfigFiles diff --git a/Documentation/source/features.rst b/Documentation/source/features.rst index 7576335..69cd6ca 100644 --- a/Documentation/source/features.rst +++ b/Documentation/source/features.rst @@ -106,6 +106,9 @@ functions. For configuration options see :ref:`configuration-removedConstantConf Check for usage of *removed PHP classes*. The classes are configured in same way as removed functions. For configuration options see :ref:`configuration-removedClassConfigFiles`. +Check for usage of *removed PHP globals*. The globals are configured in same way as removed +functions. For configuration options see :ref:`configuration-removedGlobalConfigFiles`. + Check for usage of *removed TypoScript*. The TypoScript objects are configured in same way as removed functions. For configuration options see :ref:`configuration-removedTypoScriptConfigFiles`. This will check whether you are using already removed TypoScript parts, supported are: From 7aafc28dbfc884d8fe10ab6df5b5bf78a96e7891 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 9 May 2017 15:55:43 +0200 Subject: [PATCH 22/23] TASK: Fix broken test Relates: #77 --- .../Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json index 4e2c2b9..c94aa82 100644 --- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericGlobalSniff/Expected.json @@ -13,7 +13,7 @@ "type": "WARNING" }, { - "column": 13, + "column": 26, "fixable": false, "line": 25, "message": "Calls to removed code are not allowed; found typo3CacheManager. Removed in 7.0. Use GeneralUtility::makeInstance() instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#removed-php-classes", From 87cf3a319527972203dfa8b51b38a72b941cf0b7 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 18 May 2017 08:33:10 +0200 Subject: [PATCH 23/23] TASK: Do not check all classname parts for extension name * As discussed in PR, fetch possible extension names and lookup only them, not all parts of class name. Relates: #44, !70 --- .../Typo3Update/Feature/FeaturesSupport.php | 5 +++ .../Feature/RemovedExtensionFeature.php | 33 ++++++++++++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/Standards/Typo3Update/Feature/FeaturesSupport.php b/src/Standards/Typo3Update/Feature/FeaturesSupport.php index 26975c5..5eb06ec 100644 --- a/src/Standards/Typo3Update/Feature/FeaturesSupport.php +++ b/src/Standards/Typo3Update/Feature/FeaturesSupport.php @@ -21,12 +21,15 @@ namespace Typo3Update\Feature; */ use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; /** * Provides "feature" support for sniffs. */ trait FeaturesSupport { + use ExtendedPhpCsSupportTrait; + /** * @return Features */ @@ -44,6 +47,8 @@ trait FeaturesSupport */ public function processFeatures(PhpCsFile $phpcsFile, $stackPtr, $content) { + $content = $this->getStringContent($content); + foreach ($this->getFeatures() as $featureClassName) { $feature = $this->createFeature($featureClassName); $feature->process($phpcsFile, $stackPtr, $content); diff --git a/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php index dce19fc..38d2e91 100644 --- a/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php +++ b/src/Standards/Typo3Update/Feature/RemovedExtensionFeature.php @@ -27,18 +27,8 @@ 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 === '') { + $extname = $this->getExtnameFromClassname($classname); + if ($extname === '' || $this->configured->isRemoved($extname) === false) { return; } @@ -49,6 +39,25 @@ class RemovedExtensionFeature extends AbstractYamlRemovedUsage ); } + protected function getExtnameFromClassname($classname) + { + $classname = ltrim($classname, '\\'); + $classnameParts = array_filter(preg_split('/\\\\|_/', $classname)); + $classnameParts = array_values($classnameParts); // To reset key numbers of array. + $extname = ''; + + if (count($classnameParts) <= 2) { + return ''; + } + + $extname = $classnameParts[1]; + if (stripos($classname, 'TYPO3\CMS') === 0) { + $extname = $classnameParts[2]; + } + + return strtolower($extname); + } + protected function prepareStructure(array $typo3Versions) { $newStructure = [];