From 5adbac1a251efdd275c83b22039e73290203ec2c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 4 May 2017 16:43:09 +0200 Subject: [PATCH] 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 +{ +}