From a4f4fd1ad7bd3801047e47a88f66c6c19e9c465a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 13:13:19 +0200 Subject: [PATCH 1/8] WIP|TASK: Copy and paste function code * Refactor afterwards Relates: #42 --- .../Typo3Update/Sniffs/OptionsAccessTrait.php | 17 + .../Removed/GenericConstantUsageSniff.php | 301 ++++++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php index 9db7ee7..feada99 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -71,4 +71,21 @@ trait OptionsAccessTrait yield (string) $file; } } + + /** + * Returns an array of absolute file names containing removed constant configurations. + * + * @return \Generator + */ + public function getRemovedConstantConfigFiles() + { + $configFiles = PhpCs::getConfigData('removedConstantConfigFiles'); + if (!$configFiles) { + $configFiles = __DIR__ . '/../Configuration/Removed/Constants/*.yaml'; + } + + foreach ((new \GlobIterator($configFiles)) as $file) { + yield (string) $file; + } + } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php new file mode 100644 index 0000000..c9ed1c1 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -0,0 +1,301 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use PHP_CodeSniffer_Sniff as PhpCsSniff; +use PHP_CodeSniffer_Tokens as Tokens; +use Symfony\Component\Yaml\Yaml; + +/** + * + */ +class Typo3Update_Sniffs_Removed_GenericConstantUsageCallSniff implements PhpCsSniff +{ + use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + use \Typo3Update\Sniffs\OptionsAccessTrait; + + /** + * Configuration to define removed constants. + * + * @var array + */ + protected static $removedConstants = []; + + /** + * Constant for the current sniff instance. + * @var array + */ + private $removedConstant = []; + + /** + * TODO: Multiple files allowed, using glob ... + * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... + */ + public function __construct() + { + if (static::$removedConstants === []) { + foreach ($this->getRemovedConstantConfigFiles() as $file) { + static::$removedConstants = array_merge( + static::$removedConstants, + $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) + ); + } + } + } + + /** + * Prepares structure from config for later usage. + * + * @param array $oldStructure + * @return array + */ + protected function prepareStructure(array $oldStructure) + { + $typo3Versions = array_keys($oldStructure); + $newStructure = []; + + foreach ($typo3Versions as $typo3Version) { + foreach ($oldStructure[$typo3Version] as $constant => $config) { + // Split static methods and methods. + $split = preg_split('/::|->/', $constant); + + $newStructure[$constant] = $config; + + $newStructure[$constant]['static'] = strpos($constant, '::') !== false; + $newStructure[$constant]['fqcn'] = null; + $newStructure[$constant]['class'] = null; + $newStructure[$constant]['constant'] = $split[0]; + $newStructure[$constant]['version_removed'] = $typo3Version; + + // If split contains two parts, it's a class with method + if (isset($split[1])) { + $newStructure[$constant]['fqcn'] = $split[0]; + $newStructure[$constant]['class'] = array_slice( + explode('\\', $newStructure[$constant]['fqcn']), + -1 + )[0]; + $newStructure[$constant]['constant'] = $split[1]; + } + }; + } + + return $newStructure; + } + + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + return Tokens::$constantNameTokens; + } + + /** + * Processes the tokens that this sniff is interested in. + * + * This is the default implementation, as most of the time next T_STRING is + * the class name. This way only the register method has to be registered + * in default cases. + * + * @param PhpCsFile $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. + * + * @return void + */ + public function process(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isConstantCallRemoved($phpcsFile, $stackPtr)) { + return; + } + + $this->addWarning($phpcsFile, $stackPtr); + } + + /** + * Check whether constant at given point is removed. + * + * @return bool + */ + protected function isConstantCallRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isConstantCall($phpcsFile, $stackPtr)) { + return false; + } + + $tokens = $phpcsFile->getTokens(); + $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); + + $constantName = $tokens[$stackPtr]['content']; + $isStatic = false; + $class = false; + + if ($staticPosition !== false) { + $isStatic = $tokens[$staticPosition]['code'] === T_DOUBLE_COLON; + } + + if ($isStatic) { + $class = $phpcsFile->findPrevious(T_STRING, $staticPosition, null, false, null, true); + if ($class !== false) { + $class = $tokens[$class]['content']; + } + } + + return $this->getRemovedConstant($constantName, $class, $isStatic) !== []; + } + + /** + * Returns all matching removed constants for given arguments. + * + * Also prepares constants for later usages in $this->removedConstant. + * + * @param string $constantName + * @param string $className The last part of the class name, splitted by namespaces. + * @param bool $isStatic + * + * @return array + */ + protected function getRemovedConstant($constantName, $className, $isStatic) + { + // We will not match any static method, without the class name, at least for now. + // Otherwise we could handle them the same way as instance methods. + if ($isStatic === true && $className === false) { + return []; + } + + $this->removedConstant = array_filter( + static::$removedConstants, + function ($config) use ($constantName, $isStatic, $className) { + return $constantName === $config['constant'] + && $isStatic === $config['static'] + && ( + $className === $config['class'] + || $className === false + ) + ; + } + ); + + return $this->removedConstant; + } + + /** + * Returns configuration for currently checked constant. + * + * @return array + */ + protected function getCurrentRemovedConstant() + { + $config = current($this->removedConstant); + + // TODO: Add exception if something went wrong? + + return $config; + } + + /** + * Add warning for the given token position. + * + * @param PhpCsFile $phpcsFile + * @param int $tokenPosition + * + * @return void + */ + protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) + { + $phpcsFile->addWarning( + 'Legacy constant calls are not allowed; found %s. Removed in %s. %s. See: %s', + $tokenPosition, + $this->getConstantIdentifier(), + [ + $this->getOldConstantCall(), + $this->getRemovedVersion(), + $this->getNewConstantCall(), + $this->getDocsUrl(), + ] + ); + } + + /** + * Identifier for configuring this specific error / warning through PHPCS. + * + * @return string + */ + protected function getConstantIdentifier() + { + $config = $this->getCurrentRemovedConstant(); + return $config['class'] . '.' . $config['constant']; + } + + /** + * The original constant call, to allow user to check matches. + * + * As we match the constant name, that can be provided by multiple classes, + * you should provide an example, so users can check that this is the + * legacy one. + * + * @return string + */ + protected function getOldConstantCall() + { + return $this->getCurrentRemovedConstant(); + } + + /** + * Returns TYPO3 version when the current constant was removed. + * + * To let user decide whether this is important for him. + * + * @return string + */ + protected function getRemovedVersion() + { + return $this->getCurrentRemovedConstant()['version_removed']; + } + + /** + * The new function call, or information how to migrate. + * + * To provide feedback for user to ease migration. + * + * @return string + */ + protected function getNewConstantCall() + { + $newCall = $this->getCurrentRemovedConstant()['newConstantCall']; + if ($newCall !== null) { + return $newCall; + } + return 'There is no replacement, just remove call'; + } + + /** + * Allow user to lookup the official docs related to this deprecation / breaking change. + * + * @return string + */ + protected function getDocsUrl() + { + return $this->getCurrentRemovedConstant()['docsUrl']; + } +} From 1a081900b23410f92dd27fe56418d6151e0b2419 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 09:59:28 +0200 Subject: [PATCH 2/8] WIP|FEATURE: Add removed constants * Add configuration. * Refactor common base for functions and constants. * Add constants handling. Relates: #42 --- .../Configuration/Removed/Constants/7.0.yaml | 11 + .../Configuration/Removed/Constants/7.4.yaml | 8 + .../Configuration/Removed/Constants/7.5.yaml | 5 + .../Configuration/Removed/Constants/7.6.yaml | 14 + .../Sniffs/Removed/AbstractGenericUsage.php | 295 ++++++++++++++++++ .../Removed/GenericConstantUsageSniff.php | 268 ++-------------- .../Removed/GenericFunctionCallSniff.php | 234 +------------- 7 files changed, 377 insertions(+), 458 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Constants/7.4.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Constants/7.5.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Constants/7.6.yaml create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php diff --git a/src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml new file mode 100644 index 0000000..49c13d4 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml @@ -0,0 +1,11 @@ +# Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Index.html#breaking-changes +'7.0': + PATH_tslib: + replacement: 'The folder and constant no longer exist' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61459-RemovalTslib.html + \TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_SOFTWARE: + replacement: 'Use \TYPO3\CMS\Core\Resource\AbstractFile::FILETYPE_APPLICATION instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61859-FileTypeSoftwareRemoved.html + REQUIRED_EXTENSIONS: + replacement: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html#packagemanager diff --git a/src/Standards/Typo3Update/Configuration/Removed/Constants/7.4.yaml b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.4.yaml new file mode 100644 index 0000000..71130bb --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.4.yaml @@ -0,0 +1,8 @@ +# Breaking changes in 7.4: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Index.html#breaking-changes +'7.4': + TYPO3_MOD_PATH: + replacement: 'It is required to route modules through typo3/mod.php from now on in case the module relies on the definition of those constants' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67987-RemovedEntryScriptHandling.html + PATH_typo3_mod: + replacement: 'It is required to route modules through typo3/mod.php from now on in case the module relies on the definition of those constants' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67987-RemovedEntryScriptHandling.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Constants/7.5.yaml b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.5.yaml new file mode 100644 index 0000000..7c02d6d --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.5.yaml @@ -0,0 +1,5 @@ +# Breaking changes in 7.5: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.5/Index.html#breaking-changes +'7.5': + TYPO3_URL_ORG: + replacement: 'Use TYPO3_URL_GENERAL instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.5/Breaking-68814-RemoveOfBaseConstantTYPO3_URL_ORG.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Constants/7.6.yaml b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.6.yaml new file mode 100644 index 0000000..0691b70 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Constants/7.6.yaml @@ -0,0 +1,14 @@ +# Breaking changes in 7.6: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Index.html#breaking-changes +'7.6': + \TYPO3\CMS\IndexedSearch\Controller\SearchFormController::WILDCARD_LEFT: + replacement: 'Use \TYPO3\CMS\IndexedSearch\Utility\LikeWildcard::LEFT instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Breaking-69227-StringsForLikeAreNotProperlyEscaped.html + \TYPO3\CMS\IndexedSearch\Controller\SearchFormController::WILDCARD_RIGHT: + replacement: 'Use \TYPO3\CMS\IndexedSearch\Utility\LikeWildcard::RIGHT instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Breaking-69227-StringsForLikeAreNotProperlyEscaped.html + \TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository::WILDCARD_LEFT: + replacement: 'Use \TYPO3\CMS\IndexedSearch\Utility\LikeWildcard::LEFT instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Breaking-69227-StringsForLikeAreNotProperlyEscaped.html + \TYPO3\CMS\IndexedSearch\Domain\Repository\IndexSearchRepository::WILDCARD_RIGHT: + replacement: 'Use \TYPO3\CMS\IndexedSearch\Utility\LikeWildcard::RIGHT instead' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Breaking-69227-StringsForLikeAreNotProperlyEscaped.html diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php new file mode 100644 index 0000000..3875dcd --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -0,0 +1,295 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use PHP_CodeSniffer_Sniff as PhpCsSniff; +use PHP_CodeSniffer_Tokens as Tokens; +use Symfony\Component\Yaml\Yaml; + +/** + * Contains common functionality for removed code like constants or functions. + * + * Removed parts are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml + * Also check out the configuration options in Readme.rst. + */ +abstract class AbstractGenericUsage implements PhpCsSniff +{ + use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + use \Typo3Update\Sniffs\OptionsAccessTrait; + + /** + * Configuration to define removed code. + * + * @var array + */ + protected $configured = []; + + /** + * Constant for the current sniff instance. + * @var array + */ + protected $removed = []; + + /** + * TODO: Multiple files allowed, using glob ... + * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... + */ + public function __construct() + { + if ($this->configured === []) { + foreach ($this->getRemovedConfigFiles() as $file) { + $this->configured = array_merge( + $this->configured, + $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) + ); + } + } + } + + /** + * Return file names containing removed configurations. + * + * @return array + */ + abstract protected function getRemovedConfigFiles(); + + /** + * Prepares structure from config for later usage. + * + * @param array $typo3Versions + * @return array + */ + protected function prepareStructure(array $typo3Versions) + { + $newStructure = []; + + foreach ($typo3Versions as $typo3Version => $removals) { + foreach ($removals as $removed => $config) { + // Split static methods and methods. + $split = preg_split('/::|->/', $removed); + + $newStructure[$removed] = $config; + + $newStructure[$removed]['static'] = strpos($removed, '::') !== false; + $newStructure[$removed]['fqcn'] = null; + $newStructure[$removed]['class'] = null; + $newStructure[$removed]['name'] = $split[0]; + $newStructure[$removed]['version_removed'] = $typo3Version; + + // If split contains two parts, it's a class with method + if (isset($split[1])) { + $newStructure[$removed]['fqcn'] = $split[0]; + $newStructure[$removed]['class'] = array_slice( + explode('\\', $newStructure[$removed]['fqcn']), + -1 + )[0]; + $newStructure[$removed]['name'] = $split[1]; + } + }; + } + + return $newStructure; + } + + /** + * Processes the tokens that this sniff is interested in. + * + * This is the default implementation, as most of the time next T_STRING is + * the class name. This way only the register method has to be registered + * in default cases. + * + * @param PhpCsFile $phpcsFile The file where the token was found. + * @param int $stackPtr The position in the stack where + * the token was found. + * + * @return void + */ + public function process(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isRemoved($phpcsFile, $stackPtr)) { + return; + } + + $this->addWarning($phpcsFile, $stackPtr); + } + + /** + * Check whether the current token is removed. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * @return bool + */ + protected function isRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); + + $name = $tokens[$stackPtr]['content']; + $isStatic = false; + $class = false; + + if ($staticPosition !== false) { + $isStatic = $tokens[$staticPosition]['code'] === T_DOUBLE_COLON; + } + + if ($isStatic) { + $class = $phpcsFile->findPrevious(T_STRING, $staticPosition, null, false, null, true); + if ($class !== false) { + $class = $tokens[$class]['content']; + } + } + + $this->removed = $this->getMatchingRemoved($name, $class, $isStatic); + return $this->removed !== []; + } + + /** + * Returns all matching removed functions for given arguments. + * + * @param string $name + * @param string $className The last part of the class name, splitted by namespaces. + * @param bool $isStatic + * + * @return array + */ + protected function getMatchingRemoved($name, $className, $isStatic) + { + // We will not match any static method, without the class name, at least for now. + // Otherwise we could handle them the same way as instance methods. + if ($isStatic === true && $className === false) { + return []; + } + + return array_filter( + $this->configured, + function ($config) use ($name, $isStatic, $className) { + return $name === $config['name'] + && $isStatic === $config['static'] + && ( + $className === $config['class'] + || $className === false + ) + ; + } + ); + } + + /** + * Add warning for the given token position. + * + * @param PhpCsFile $phpcsFile + * @param int $tokenPosition + * + * @return void + */ + protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) + { + foreach ($this->removed as $constant) { + $phpcsFile->addWarning( + 'Legacy calls are not allowed; found %s. Removed in %s. %s. See: %s', + $tokenPosition, + $this->getIdentifier($constant), + [ + $this->getOldUsage($constant), + $this->getRemovedVersion($constant), + $this->getReplacement($constant), + $this->getDocsUrl($constant), + ] + ); + } + } + + /** + * Identifier for configuring this specific error / warning through PHPCS. + * + * @param array $config The converted structure for a single function. + * + * @return string + */ + protected function getIdentifier(array $config) + { + $name = $config['name']; + if ($config['class']) { + $name = $config['class'] . '.' . $name; + } + + return $name; + } + + /** + * The original constant call, to allow user to check matches. + * + * As we match the constant 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 The converted structure for a single constant. + * + * @return string + */ + abstract protected function getOldUsage(array $config); + + /** + * Returns TYPO3 version when the current constant was removed. + * + * To let user decide whether this is important for him. + * + * @param array $config The converted structure for a single constant. + * + * @return string + */ + protected function getRemovedVersion(array $config) + { + return $config['version_removed']; + } + + /** + * The new constant call, or information how to migrate. + * + * To provide feedback for user to ease migration. + * + * @param array $config The converted structure for a single constant. + * + * @return string + */ + protected function getReplacement(array $config) + { + $newCall = $config['replacement']; + if ($newCall !== null) { + return $newCall; + } + return 'There is no replacement, just remove call'; + } + + /** + * Allow user to lookup the official docs related to this deprecation / breaking change. + * + * @param array $config The converted structure for a single constant. + * + * @return string + */ + protected function getDocsUrl(array $config) + { + return $config['docsUrl']; + } +} diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php index c9ed1c1..adb479d 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -20,85 +20,53 @@ */ use PHP_CodeSniffer_File as PhpCsFile; -use PHP_CodeSniffer_Sniff as PhpCsSniff; -use PHP_CodeSniffer_Tokens as Tokens; -use Symfony\Component\Yaml\Yaml; +use Typo3Update\Sniffs\Removed\AbstractGenericUsage; /** + * Sniff that handles all calls to removed constants. * + * Removed constants are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml + * Also check out the configuration options in Readme.rst. */ -class Typo3Update_Sniffs_Removed_GenericConstantUsageCallSniff implements PhpCsSniff +class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericUsage { - use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - use \Typo3Update\Sniffs\OptionsAccessTrait; - /** - * Configuration to define removed constants. + * Return file names containing removed configurations. * - * @var array + * @return array */ - protected static $removedConstants = []; - - /** - * Constant for the current sniff instance. - * @var array - */ - private $removedConstant = []; - - /** - * TODO: Multiple files allowed, using glob ... - * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... - */ - public function __construct() + protected function getRemovedConfigFiles() { - if (static::$removedConstants === []) { - foreach ($this->getRemovedConstantConfigFiles() as $file) { - static::$removedConstants = array_merge( - static::$removedConstants, - $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) - ); - } - } + return $this->getRemovedConstantConfigFiles(); } /** * Prepares structure from config for later usage. * - * @param array $oldStructure + * @param array $typo3Versions * @return array */ - protected function prepareStructure(array $oldStructure) - { - $typo3Versions = array_keys($oldStructure); - $newStructure = []; + // protected function prepareStructure(array $typo3Versions) + // { + // $newStructure = []; - foreach ($typo3Versions as $typo3Version) { - foreach ($oldStructure[$typo3Version] as $constant => $config) { - // Split static methods and methods. - $split = preg_split('/::|->/', $constant); + // foreach ($typo3Versions as $typo3Version => $constants) { + // foreach ($constants as $constant => $config) { + // $split = explode('::', $constant); - $newStructure[$constant] = $config; + // $newStructure[$constant] = $config; - $newStructure[$constant]['static'] = strpos($constant, '::') !== false; - $newStructure[$constant]['fqcn'] = null; - $newStructure[$constant]['class'] = null; - $newStructure[$constant]['constant'] = $split[0]; - $newStructure[$constant]['version_removed'] = $typo3Version; + // $newStructure[$constant]['static'] = strpos($constant, '::') !== false; + // $newStructure[$constant]['fqcn'] = null; + // $newStructure[$constant]['class'] = null; + // $newStructure[$constant]['constant'] = $constant; + // $newStructure[$constant]['version_removed'] = $typo3Version; + // // TODO: Handle constants of classes + // }; + // } - // If split contains two parts, it's a class with method - if (isset($split[1])) { - $newStructure[$constant]['fqcn'] = $split[0]; - $newStructure[$constant]['class'] = array_slice( - explode('\\', $newStructure[$constant]['fqcn']), - -1 - )[0]; - $newStructure[$constant]['constant'] = $split[1]; - } - }; - } - - return $newStructure; - } + // return $newStructure; + // } /** * Returns the token types that this sniff is interested in. @@ -107,144 +75,7 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageCallSniff implements PhpCsS */ public function register() { - return Tokens::$constantNameTokens; - } - - /** - * Processes the tokens that this sniff is interested in. - * - * This is the default implementation, as most of the time next T_STRING is - * the class name. This way only the register method has to be registered - * in default cases. - * - * @param PhpCsFile $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PhpCsFile $phpcsFile, $stackPtr) - { - if (!$this->isConstantCallRemoved($phpcsFile, $stackPtr)) { - return; - } - - $this->addWarning($phpcsFile, $stackPtr); - } - - /** - * Check whether constant at given point is removed. - * - * @return bool - */ - protected function isConstantCallRemoved(PhpCsFile $phpcsFile, $stackPtr) - { - if (!$this->isConstantCall($phpcsFile, $stackPtr)) { - return false; - } - - $tokens = $phpcsFile->getTokens(); - $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); - - $constantName = $tokens[$stackPtr]['content']; - $isStatic = false; - $class = false; - - if ($staticPosition !== false) { - $isStatic = $tokens[$staticPosition]['code'] === T_DOUBLE_COLON; - } - - if ($isStatic) { - $class = $phpcsFile->findPrevious(T_STRING, $staticPosition, null, false, null, true); - if ($class !== false) { - $class = $tokens[$class]['content']; - } - } - - return $this->getRemovedConstant($constantName, $class, $isStatic) !== []; - } - - /** - * Returns all matching removed constants for given arguments. - * - * Also prepares constants for later usages in $this->removedConstant. - * - * @param string $constantName - * @param string $className The last part of the class name, splitted by namespaces. - * @param bool $isStatic - * - * @return array - */ - protected function getRemovedConstant($constantName, $className, $isStatic) - { - // We will not match any static method, without the class name, at least for now. - // Otherwise we could handle them the same way as instance methods. - if ($isStatic === true && $className === false) { - return []; - } - - $this->removedConstant = array_filter( - static::$removedConstants, - function ($config) use ($constantName, $isStatic, $className) { - return $constantName === $config['constant'] - && $isStatic === $config['static'] - && ( - $className === $config['class'] - || $className === false - ) - ; - } - ); - - return $this->removedConstant; - } - - /** - * Returns configuration for currently checked constant. - * - * @return array - */ - protected function getCurrentRemovedConstant() - { - $config = current($this->removedConstant); - - // TODO: Add exception if something went wrong? - - return $config; - } - - /** - * Add warning for the given token position. - * - * @param PhpCsFile $phpcsFile - * @param int $tokenPosition - * - * @return void - */ - protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) - { - $phpcsFile->addWarning( - 'Legacy constant calls are not allowed; found %s. Removed in %s. %s. See: %s', - $tokenPosition, - $this->getConstantIdentifier(), - [ - $this->getOldConstantCall(), - $this->getRemovedVersion(), - $this->getNewConstantCall(), - $this->getDocsUrl(), - ] - ); - } - - /** - * Identifier for configuring this specific error / warning through PHPCS. - * - * @return string - */ - protected function getConstantIdentifier() - { - $config = $this->getCurrentRemovedConstant(); - return $config['class'] . '.' . $config['constant']; + return [T_STRING]; } /** @@ -254,48 +85,17 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageCallSniff implements PhpCsS * you should provide an example, so users can check that this is the * legacy one. * - * @return string - */ - protected function getOldConstantCall() - { - return $this->getCurrentRemovedConstant(); - } - - /** - * Returns TYPO3 version when the current constant was removed. - * - * To let user decide whether this is important for him. + * @param array $config The converted structure for a single constant. * * @return string */ - protected function getRemovedVersion() + protected function getOldUsage(array $config) { - return $this->getCurrentRemovedConstant()['version_removed']; - } - - /** - * The new function call, or information how to migrate. - * - * To provide feedback for user to ease migration. - * - * @return string - */ - protected function getNewConstantCall() - { - $newCall = $this->getCurrentRemovedConstant()['newConstantCall']; - if ($newCall !== null) { - return $newCall; + $old = $config['name']; + if ($config['static']) { + $old = $config['fqcn'] . '::' . $config['name']; } - return 'There is no replacement, just remove call'; - } - /** - * Allow user to lookup the official docs related to this deprecation / breaking change. - * - * @return string - */ - protected function getDocsUrl() - { - return $this->getCurrentRemovedConstant()['docsUrl']; + return 'constant ' . $old; } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index b81ff7d..9d9b30a 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -20,9 +20,8 @@ */ use PHP_CodeSniffer_File as PhpCsFile; -use PHP_CodeSniffer_Sniff as PhpCsSniff; use PHP_CodeSniffer_Tokens as Tokens; -use Symfony\Component\Yaml\Yaml; +use Typo3Update\Sniffs\Removed\AbstractGenericUsage; /** * Sniff that handles all calls to removed functions. @@ -30,76 +29,16 @@ use Symfony\Component\Yaml\Yaml; * Removed functions are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml * Also check out the configuration options in Readme.rst. */ -class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff +class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGenericUsage { - use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - use \Typo3Update\Sniffs\OptionsAccessTrait; - /** - * Configuration to define removed functions. + * Return file names containing removed configurations. * - * @var array + * @return array */ - protected static $configuredFunctions = []; - - /** - * Function for the current sniff instance. - * @var array - */ - private $removedFunctions = []; - - /** - * TODO: Multiple files allowed, using glob ... - * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... - */ - public function __construct() + protected function getRemovedConfigFiles() { - if (static::$configuredFunctions === []) { - foreach ($this->getRemovedFunctionConfigFiles() as $file) { - static::$configuredFunctions = array_merge( - static::$configuredFunctions, - $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) - ); - } - } - } - - /** - * Prepares structure from config for later usage. - * - * @param array $typo3Versions - * @return array - */ - protected function prepareStructure(array $typo3Versions) - { - $newStructure = []; - - foreach ($typo3Versions as $typo3Version => $functions) { - foreach ($functions as $function => $config) { - // Split static methods and methods. - $split = preg_split('/::|->/', $function); - - $newStructure[$function] = $config; - - $newStructure[$function]['static'] = strpos($function, '::') !== false; - $newStructure[$function]['fqcn'] = null; - $newStructure[$function]['class'] = null; - $newStructure[$function]['function'] = $split[0]; - $newStructure[$function]['version_removed'] = $typo3Version; - - // If split contains two parts, it's a class with method - if (isset($split[1])) { - $newStructure[$function]['fqcn'] = $split[0]; - $newStructure[$function]['class'] = array_slice( - explode('\\', $newStructure[$function]['fqcn']), - -1 - )[0]; - $newStructure[$function]['function'] = $split[1]; - } - }; - } - - return $newStructure; + return $this->getRemovedFunctionConfigFiles(); } /** @@ -112,127 +51,18 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff return Tokens::$functionNameTokens; } - /** - * Processes the tokens that this sniff is interested in. - * - * This is the default implementation, as most of the time next T_STRING is - * the class name. This way only the register method has to be registered - * in default cases. - * - * @param PhpCsFile $phpcsFile The file where the token was found. - * @param int $stackPtr The position in the stack where - * the token was found. - * - * @return void - */ - public function process(PhpCsFile $phpcsFile, $stackPtr) - { - if (!$this->isFunctionCallRemoved($phpcsFile, $stackPtr)) { - return; - } - - $this->addWarning($phpcsFile, $stackPtr); - } - /** * Check whether function at given point is removed. * * @return bool */ - protected function isFunctionCallRemoved(PhpCsFile $phpcsFile, $stackPtr) + protected function isRemoved(PhpCsFile $phpcsFile, $stackPtr) { if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return false; } - $tokens = $phpcsFile->getTokens(); - $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); - - $functionName = $tokens[$stackPtr]['content']; - $isStatic = false; - $class = false; - - if ($staticPosition !== false) { - $isStatic = $tokens[$staticPosition]['code'] === T_DOUBLE_COLON; - } - - if ($isStatic) { - $class = $phpcsFile->findPrevious(T_STRING, $staticPosition, null, false, null, true); - if ($class !== false) { - $class = $tokens[$class]['content']; - } - } - - $this->removedFunctions = $this->getMatchingRemovedFunctions($functionName, $class, $isStatic); - return $this->removedFunctions !== []; - } - - /** - * Returns all matching removed functions for given arguments. - * - * @param string $functionName - * @param string $className The last part of the class name, splitted by namespaces. - * @param bool $isStatic - * - * @return void - */ - protected function getMatchingRemovedFunctions($functionName, $className, $isStatic) - { - // We will not match any static method, without the class name, at least for now. - // Otherwise we could handle them the same way as instance methods. - if ($isStatic === true && $className === false) { - return; - } - - return array_filter( - static::$configuredFunctions, - function ($config) use ($functionName, $isStatic, $className) { - return $functionName === $config['function'] - && $isStatic === $config['static'] - && ( - $className === $config['class'] - || $className === false - ) - ; - } - ); - } - - /** - * Add warning for the given token position. - * - * @param PhpCsFile $phpcsFile - * @param int $tokenPosition - * - * @return void - */ - protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) - { - foreach ($this->removedFunctions as $function) { - $phpcsFile->addWarning( - 'Legacy function calls are not allowed; found %s. Removed in %s. %s. See: %s', - $tokenPosition, - $this->getFunctionIdentifier($function), - [ - $this->getOldfunctionCall($function), - $this->getRemovedVersion($function), - $this->getNewFunctionCall($function), - $this->getDocsUrl($function), - ] - ); - } - } - - /** - * Identifier for configuring this specific error / warning through PHPCS. - * - * @param array $config The converted structure for a single function. - * - * @return string - */ - protected function getFunctionIdentifier(array $config) - { - return $config['class'] . '.' . $config['function']; + parent::isRemoved($phpcsFile, $stackPtr); } /** @@ -246,56 +76,12 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * * @return string */ - protected function getOldFunctionCall(array $config) + protected function getOldUsage(array $config) { $concat = '->'; if ($config['static']) { $concat = '::'; } - return $config['fqcn'] . $concat . $config['function']; - } - - /** - * Returns TYPO3 version when the current function was removed. - * - * To let user decide whether this is important for him. - * - * @param array $config The converted structure for a single function. - * - * @return string - */ - protected function getRemovedVersion(array $config) - { - return $config['version_removed']; - } - - /** - * The new function call, or information how to migrate. - * - * To provide feedback for user to ease migration. - * - * @param array $config The converted structure for a single function. - * - * @return string - */ - protected function getNewFunctionCall(array $config) - { - $newCall = $config['newFunctionCall']; - if ($newCall !== null) { - return $newCall; - } - return 'There is no replacement, just remove call'; - } - - /** - * Allow user to lookup the official docs related to this deprecation / breaking change. - * - * @param array $config The converted structure for a single function. - * - * @return string - */ - protected function getDocsUrl(array $config) - { - return $config['docsUrl']; + return $config['fqcn'] . $concat . $config['name']; } } From 99840b080f8d46aa812efcb517d8fd3e80ef9788 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 10:21:16 +0200 Subject: [PATCH 3/8] FEATURE: Finish refactoring * Removed functions and constants are working now. Relates: #42 --- .../Configuration/Removed/Functions/7.0.yaml | 140 +++++++++--------- .../Configuration/Removed/Functions/7.2.yaml | 22 +-- .../Configuration/Removed/Functions/7.3.yaml | 6 +- .../Configuration/Removed/Functions/7.4.yaml | 52 +++---- .../Sniffs/Removed/AbstractGenericUsage.php | 9 +- .../Removed/GenericConstantUsageSniff.php | 31 ---- .../Removed/GenericFunctionCallSniff.php | 5 +- 7 files changed, 117 insertions(+), 148 deletions(-) diff --git a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml index 3913b8c..999b99f 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml @@ -1,218 +1,218 @@ # Breaking changes in 7.0: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Index.html#breaking-changes '7.0': \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-LoadTcaFunctionRemoved.html' \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->getCompressedTCarray: - newFunctionCall: 'Full TCA is always loaded during bootstrap in FE, the method is obsolete. If an eid script calls this method to load TCA, use \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA() instead' + replacement: 'Full TCA is always loaded during bootstrap in FE, the method is obsolete. If an eid script calls this method to load TCA, use \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->includeTCA: - newFunctionCall: 'Full TCA is always loaded during bootstrap in FE, the method is obsolete. If an eid script calls this method to load TCA, use \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA() instead' + replacement: 'Full TCA is always loaded during bootstrap in FE, the method is obsolete. If an eid script calls this method to load TCA, use \TYPO3\CMS\Frontend\Utility\EidUtility::initTCA() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' \TYPO3\CMS\Core\Utility\MailUtility::mail: - newFunctionCall: 'Use the \TYPO3\CMS\Core\Mail\Mailer API for sending email' + replacement: 'Use the \TYPO3\CMS\Core\Mail\Mailer API for sending email' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61783-RemoveDeprecatedMailFunctionality.html' \TYPO3\CMS\Core\Utility\GeneralUtility::plainMailEncoded: - newFunctionCall: 'Use the \TYPO3\CMS\Core\Mail\Mailer API for sending email' + replacement: 'Use the \TYPO3\CMS\Core\Mail\Mailer API for sending email' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61783-RemoveDeprecatedMailFunctionality.html' \TYPO3\CMS\Frontend\Utility\EidUtility::connectDB: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61863-ConnectDbFunctionRemoved.html' \TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver: - newFunctionCall: 'Replace the usage of the removed function with \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger()' + replacement: 'Replace the usage of the removed function with \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionNumberToInteger()' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61860-RemoveIntFromVerFunction.html' \TYPO3\CMS\Core\DataHandlin\DataHandler->getUniqueFields: - newFunctionCall: 'Replace all calls to \TYPO3\CMS\Core\DataHandling\DataHandler::getUniqueFields() with calls to \TYPO3\CMS\Version\Hook\DataHandlerHook::getUniqueFields()' + replacement: 'Replace all calls to \TYPO3\CMS\Core\DataHandling\DataHandler::getUniqueFields() with calls to \TYPO3\CMS\Version\Hook\DataHandlerHook::getUniqueFields()' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61822-GetUniqueFieldsFunctionRemoved.html' \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61802-IsLocalconfWritableFunctionRemoved.html' \TYPO3\CMS\Extbase\Object\ObjectManager->create: - newFunctionCall: 'Use ObjectManager::get() instead' + replacement: 'Use ObjectManager::get() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Extbase\Persistence\Generic\Backend->replaceObject: - newFunctionCall: 'Removed without replacement' + replacement: 'Removed without replacement' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface->setReturnRawQueryResult: - newFunctionCall: 'Removed without replacement' + replacement: 'Removed without replacement' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface->getReturnRawQueryResult: - newFunctionCall: 'Use the parameter on $query->execute() directly' + replacement: 'Use the parameter on $query->execute() directly' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings->setSysLanguageUid: - newFunctionCall: 'Use setLanguageUid() instead' + replacement: 'Use setLanguageUid() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings->getSysLanguageUid: - newFunctionCall: 'Use getLanguageUid() instead' + replacement: 'Use getLanguageUid() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' \TYPO3\CMS\Lang\LanguageService->JScharCode: - newFunctionCall: 'Use GeneralUtility::quoteJSvalue instead' + replacement: 'Use GeneralUtility::quoteJSvalue instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Frontend\ContentObjec\ContentObjectRenderer->joinTSarrays: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->tidyHTML: - newFunctionCall: 'You may use the tidy extension from TER' + replacement: 'You may use the tidy extension from TER' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Recordlist\Browser\ElementBrowser->isWebFolder: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Recordlist\Browser\ElementBrowser->checkFolder: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList->getTreeObject: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Filelist\FileList->dirData: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Frontend\ContentObject\FilesContentObject->stdWrapValue: - newFunctionCall: 'Use ContentObjectRenderer::stdWrapValue instead' + replacement: 'Use ContentObjectRenderer::stdWrapValue instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Impexp\Controller\ImportExportController->userTempFolder: - newFunctionCall: 'Use getDefaultImportExportFolder instead' + replacement: 'Use getDefaultImportExportFolder instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Impexp\Controller\ImportExportController->userSaveFolder: - newFunctionCall: 'Use getDefaultImportExportFolder instead' + replacement: 'Use getDefaultImportExportFolder instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->func_filesearch: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->findFile: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->buildStyleSheet: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->loremIpsumInsert: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Workspaces\Service\StagesService->checkCustomStagingForWS: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' \TYPO3\CMS\Core\DataHandling\DataHandler->clear_cache: - newFunctionCall: 'Use ->clear_cacheCmd() instead. Alternatively you can call ->registerPageCacheClearing() from a hook to not immediately clear the cache but register clearing after DataHandler operation finishes' + replacement: 'Use ->clear_cacheCmd() instead. Alternatively you can call ->registerPageCacheClearing() from a hook to not immediately clear the cache but register clearing after DataHandler operation finishes' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\DataHandling\DataHandler->internal_clearPageCache: - newFunctionCall: 'Use the cache manager directly' + replacement: 'Use the cache manager directly' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule: - newFunctionCall: 'Use ArrayUtility::mergeRecursiveWithOverrule() instead. WARNING: The new method changed its signature and does not return the first parameter anymore' + replacement: 'Use ArrayUtility::mergeRecursiveWithOverrule() instead. WARNING: The new method changed its signature and does not return the first parameter anymore' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\GeneralUtility::htmlspecialchars_decode: - newFunctionCall: 'Use native PHP htmlspecialchars_decode() function' + replacement: 'Use native PHP htmlspecialchars_decode() function' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' # NOTE: This is useless, adding a warning to all "get" methods is crazy. # Also this is already handeled by: Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff # \TYPO3\CMS\Core\Category\CategoryRegistry->get: - # newFunctionCall: 'Use isRegistered() instead' + # replacement: 'Use isRegistered() instead' # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Category\CategoryRegistry->applyTca: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' # NOTE: This is useless, adding a warning to all "findByUid" methods is crazy. # Many calls to repositories will be marked as warning # \TYPO3\CMS\Core\Resource\FileRepository->findByUid: - # newFunctionCall: null + # replacement: null # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\FileRepository->addToIndex: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\FileRepository->getFileIndexRecordsForFolder: - newFunctionCall: 'Use FileIndexRepository::findByFolder() instead' + replacement: 'Use FileIndexRepository::findByFolder() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\FileRepository->getFileIndexRecord: - newFunctionCall: 'Use FileIndexRepository::findOneByFileObject() instead' + replacement: 'Use FileIndexRepository::findOneByFileObject() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\FileRepository->findBySha1Hash: - newFunctionCall: 'Use FileIndexRepository::findByContentHash() instead' + replacement: 'Use FileIndexRepository::findByContentHash() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' # NOTE: This is useless, adding a warning to all "update" methods is crazy. # All repository updates will be marked as warning # \TYPO3\CMS\Core\Resource\FileRepository->update: - # newFunctionCall: 'Use FileIndexRepository::update() instead' + # replacement: 'Use FileIndexRepository::update() instead' # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\ResourceStorage->getFolderByIdentifier: - newFunctionCall: 'Use getFolder() instead' + replacement: 'Use getFolder() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\ResourceStorage->getFileByIdentifier: - newFunctionCall: 'Use getFileInfoByIdentifier() instead' + replacement: 'Use getFileInfoByIdentifier() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\ResourceStorage->getFileList: - newFunctionCall: 'Use getFilesInFolder() instead' + replacement: 'Use getFilesInFolder() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\ResourceStorage->getFolderList: - newFunctionCall: 'Use getFoldersInFolder() instead' + replacement: 'Use getFoldersInFolder() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Resource\ResourceStorage->fetchFolderListFromDriver: - newFunctionCall: 'Use getFoldersInFolder() instead' + replacement: 'Use getFoldersInFolder() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->getTotalFileInfo: - newFunctionCall: "Use ResourceStorage instead via $GLOBALS['BE_USER']->getFileStorages()" + replacement: "Use ResourceStorage instead via $GLOBALS['BE_USER']->getFileStorages()" docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->checkFileNameLen: - newFunctionCall: "Use ResourceStorage instead via $GLOBALS['BE_USER']->getFileStorages()" + replacement: "Use ResourceStorage instead via $GLOBALS['BE_USER']->getFileStorages()" docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->isPathValid: - newFunctionCall: 'Use GeneralUtility::validPathStr() instead' + replacement: 'Use GeneralUtility::validPathStr() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->blindPath: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->findTempFolder: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->rmDoubleSlash: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\BasicFileUtility->cleanDirectoryName: - newFunctionCall: 'Use PathUtility::getCanonicalPath() instead' + replacement: 'Use PathUtility::getCanonicalPath() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility->init_actionPerms: - newFunctionCall: 'Use setActionPermissions() instead' + replacement: 'Use setActionPermissions() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility->printLogErrorMessages: - newFunctionCall: 'Use pushErrorMessagesToFlashMessageQueue() instead' + replacement: 'Use pushErrorMessagesToFlashMessageQueue() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\File\ExtendedFileUtility->findRecycler: - newFunctionCall: 'Use \TYPO3\CMS\Core\Resource\ResourceStorage instead' + replacement: 'Use \TYPO3\CMS\Core\Resource\ResourceStorage instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Html\RteHtmlParser->findRecycler: - newFunctionCall: "Use $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']); instead" + replacement: "Use $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']); instead" docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Rtehtmlarea\SelectImage->getRTEImageStorageDir: - newFunctionCall: "Use $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']); instead" + replacement: "Use $fileFactory->getFolderObjectFromCombinedIdentifier($GLOBALS['TYPO3_CONF_VARS']['BE']['RTE_imageStorageDir']); instead" docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Localization\Locales->getTerLocales: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Localization\Locales->getTerLocaleDependencies: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Localization\Locales->convertToTerLocales: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getInsertionNeedles: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getRequiredExtensionListArray: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::writeNewExtensionList: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSqlSafeModeEnabled: - newFunctionCall: null + replacement: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' \TYPO3\CMS\Core\Core\ClassLoader::getAliasForClassName: - newFunctionCall: 'Use getAliasesForClassName() instead' + replacement: 'Use getAliasesForClassName() instead' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' diff --git a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml index d1cb239..d596610 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml @@ -1,36 +1,36 @@ # Breaking changes in 7.2: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Index.html '7.2': \TYPO3\CMS\Core\Page\PageRenderer->setSvgPath: - newFunctionCall: 'Use 3rd party library instead, which is already loaded by TYPO3' + replacement: 'Use 3rd party library instead, which is already loaded by TYPO3' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65962-WebSVGLibraryAndAPIRemoved.html \TYPO3\CMS\Core\Page\PageRenderer->loadSvg: - newFunctionCall: 'Use 3rd party library instead, which is already loaded by TYPO3' + replacement: 'Use 3rd party library instead, which is already loaded by TYPO3' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65962-WebSVGLibraryAndAPIRemoved.html \TYPO3\CMS\Core\Page\PageRenderer->enableSvgDebug: - newFunctionCall: 'Use 3rd party library instead, which is already loaded by TYPO3' + replacement: 'Use 3rd party library instead, which is already loaded by TYPO3' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65962-WebSVGLibraryAndAPIRemoved.html \TYPO3\CMS\Core\Page\PageRenderer->svgForceFlash: - newFunctionCall: 'Use 3rd party library instead, which is already loaded by TYPO3' + replacement: 'Use 3rd party library instead, which is already loaded by TYPO3' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65962-WebSVGLibraryAndAPIRemoved.html \TYPO3\CMS\Backend\Controller\LoginController->makeLoginForm: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html \TYPO3\CMS\Backend\Controller\LoginController->makeLogoutForm: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html \TYPO3\CMS\Backend\Controller\LoginController->wrapLoginForm: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html \TYPO3\CMS\Backend\Controller\LoginController->makeLoginBoxImage: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html \TYPO3\CMS\Backend\Controller\LoginController->makeLoginNews: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html \TYPO3\CMS\Backend\Controller\LoginController->emitRenderLoginFormSignal: - newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' + replacement: 'Use the new Fluid View to adjust the login screen instead' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html # NOTE: This is useless, adding a warning to all "getSignalSlotDispatcher" methods is crazy, many developers implement such a method. # \TYPO3\CMS\Backend\Controller\LoginController->getSignalSlotDispatcher: -# newFunctionCall: 'Use the new Fluid View to adjust the login screen instead' +# replacement: 'Use the new Fluid View to adjust the login screen instead' # docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml index 15ff9b8..4194ed6 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml @@ -2,12 +2,12 @@ '7.3': # NOTE: If this is making you crazy, just disable via ruleset.xml or phpcs.xml parent::initializeObject: - newFunctionCall: 'Remove call, if this is inside a child of \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject, there is no initializeObject in the parent anymore.' + replacement: 'Remove call, if this is inside a child of \TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject, there is no initializeObject in the parent anymore.' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Breaking-67402-ExtbaseAbstractDomainObjectInitializeObject.html \TYPO3\CMS\Extbase\Persistence\Repository::replace: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Breaking-63835-RemoveDeprecatedExtbasePersistenceParts.html \TYPO3\CMS\Extbase\Persistence\Generic\Backend::setDeletedObjects: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Breaking-63835-RemoveDeprecatedExtbasePersistenceParts.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml index ee9bbd5..aefe6e7 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml @@ -1,81 +1,81 @@ # Breaking changes in 7.4: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Index.html#breaking-changes '7.4': \TYPO3\CMS\Core\Page\PageRenderer::setExtCorePath: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html \TYPO3\CMS\Core\Page\PageRenderer::getExtCorePath: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html \TYPO3\CMS\Core\Page\PageRenderer::loadExtCore: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html \TYPO3\CMS\Core\Page\PageRenderer::enableExtCoreDebug: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html \TYPO3\CMS\Core\Page\PageRenderer::setExtCorePath: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html \TYPO3\CMS\Backend\Controller\EditDocumentController->functionMenus: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67753-DropSecondaryOptions.html \TYPO3\CMS\Backend\Utility\BackendUtility::getFileIcon: - newFunctionCall: 'Use \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile() insteadenableExtCoreDebug' + replacement: 'Use \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile() insteadenableExtCoreDebug' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67654-RemoveGLOBALSFILEICONSFunctionality.html \TYPO3\CMS\Frontend\Page\PageGenerator::getIncFiles: - newFunctionCall: 'Use hooks during the Frontend set up to execute custom PHP code' + replacement: 'Use hooks during the Frontend set up to execute custom PHP code' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67646-LibraryInclusionInFrontend.html \TYPO3\CMS\Backend\Template\DocumentTemplate\DocumentTemplate->formWidthText: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html \TYPO3\CMS\Backend\View\PageLayoutView->getBackendLayoutConfiguration: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html \TYPO3\CMS\Backend\View\PageLayoutView->wordWrapper: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->checkJumpUrlReferer: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-66602-RemoveRefererCheckWhileHandlingJumpUrl.html \TYPO3\CMS\Core\Utility\OpcodeCacheUtility::initialize: - newFunctionCall: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' + replacement: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-63838-ChangedOpcodeCacheUtilityBeingAServiceClass.html \TYPO3\CMS\Core\Utility\OpcodeCacheUtility::clearAllActive: - newFunctionCall: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' + replacement: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-63838-ChangedOpcodeCacheUtilityBeingAServiceClass.html \TYPO3\CMS\Core\Utility\OpcodeCacheUtility::getAllActive: - newFunctionCall: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' + replacement: 'Use new service class instead \TYPO3\CMS\Core\Service\OpcodeCacheService' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-63838-ChangedOpcodeCacheUtilityBeingAServiceClass.html \TYPO3\CMS\Backend\Tree\View\PagePositionMap->JSimgFunc: - newFunctionCall: 'Use proper styling for a tree list' + replacement: 'Use proper styling for a tree list' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-56951-RemoveUnusedMethodsInPagePositionMap.html \TYPO3\CMS\Backend\Tree\View\PagePositionMap->insertQuadLines: - newFunctionCall: 'Use proper styling for a tree list' + replacement: 'Use proper styling for a tree list' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-56951-RemoveUnusedMethodsInPagePositionMap.html \TYPO3\CMS\Core\Page\PageRenderer->enableExtJSQuickTips: - newFunctionCall: 'Use bootstrap tooltips, which work out of the box as alternative. Simple add data-toggle="tooltip" and data-title="your tooltip" to any element you want' + replacement: 'Use bootstrap tooltips, which work out of the box as alternative. Simple add data-toggle="tooltip" and data-title="your tooltip" to any element you want' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68276-RemoveExtJSQuicktipsIfPossible.html \TYPO3\CMS\IndexedSearch\Indexer->removeLoginpagesWithContentHash: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68193-DropRemoveLoginpagesWithContentHashFromIndexerphp.html \TYPO3\CMS\Frontend\Controller\ExtDirectEidController->actionIsAllowed: - newFunctionCall: 'Migrate your eID scripts to the new PSR-7 compliant model' + replacement: 'Migrate your eID scripts to the new PSR-7 compliant model' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68186-AdjustedAndRemovedMethodsInEIDArea.html # NOTE: It does not make sense to warn about all render methods # \TYPO3\CMS\Frontend\Controller\ExtDirectEidController->render: - # newFunctionCall: 'Migrate your eID scripts to the new PSR-7 compliant model' + # replacement: 'Migrate your eID scripts to the new PSR-7 compliant model' # docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68186-AdjustedAndRemovedMethodsInEIDArea.html \TYPO3\CMS\Frontend\Utility\EidUtility::isEidRequest: - newFunctionCall: 'Migrate your eID scripts to the new PSR-7 compliant model' + replacement: 'Migrate your eID scripts to the new PSR-7 compliant model' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68186-AdjustedAndRemovedMethodsInEIDArea.html \TYPO3\CMS\Frontend\Utility\EidUtility::getEidScriptPath: - newFunctionCall: 'Migrate your eID scripts to the new PSR-7 compliant model' + replacement: 'Migrate your eID scripts to the new PSR-7 compliant model' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68186-AdjustedAndRemovedMethodsInEIDArea.html \TYPO3\CMS\Backend\View\PageLayoutView->linkRTEbutton: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html \TYPO3\CMS\Backend\View\PageLayoutView->isRTEforField: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html \TYPO3\CMS\Backend\View\PageLayoutView->getSpecConfForField: - newFunctionCall: null + replacement: null docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index 3875dcd..018b650 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -129,7 +129,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff return; } - $this->addWarning($phpcsFile, $stackPtr); + $this->addMessage($phpcsFile, $stackPtr); } /** @@ -195,14 +195,17 @@ abstract class AbstractGenericUsage implements PhpCsSniff } /** - * Add warning for the given token position. + * Add message for the given token position. + * + * Default is a warning, non fixable. Just overwrite in concrete sniff, if + * something different suites better. * * @param PhpCsFile $phpcsFile * @param int $tokenPosition * * @return void */ - protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) + protected function addMessage(PhpCsFile $phpcsFile, $tokenPosition) { foreach ($this->removed as $constant) { $phpcsFile->addWarning( diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php index adb479d..edcba91 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -24,9 +24,6 @@ use Typo3Update\Sniffs\Removed\AbstractGenericUsage; /** * Sniff that handles all calls to removed constants. - * - * Removed constants are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml - * Also check out the configuration options in Readme.rst. */ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericUsage { @@ -40,34 +37,6 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGener return $this->getRemovedConstantConfigFiles(); } - /** - * Prepares structure from config for later usage. - * - * @param array $typo3Versions - * @return array - */ - // protected function prepareStructure(array $typo3Versions) - // { - // $newStructure = []; - - // foreach ($typo3Versions as $typo3Version => $constants) { - // foreach ($constants as $constant => $config) { - // $split = explode('::', $constant); - - // $newStructure[$constant] = $config; - - // $newStructure[$constant]['static'] = strpos($constant, '::') !== false; - // $newStructure[$constant]['fqcn'] = null; - // $newStructure[$constant]['class'] = null; - // $newStructure[$constant]['constant'] = $constant; - // $newStructure[$constant]['version_removed'] = $typo3Version; - // // TODO: Handle constants of classes - // }; - // } - - // return $newStructure; - // } - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 9d9b30a..29a957f 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -25,9 +25,6 @@ use Typo3Update\Sniffs\Removed\AbstractGenericUsage; /** * Sniff that handles all calls to removed functions. - * - * Removed functions are configured using YAML-Files, for examples see src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml - * Also check out the configuration options in Readme.rst. */ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGenericUsage { @@ -62,7 +59,7 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGeneri return false; } - parent::isRemoved($phpcsFile, $stackPtr); + return parent::isRemoved($phpcsFile, $stackPtr); } /** From 818f266b9e7abe8d23c7c37eb64917694988ebba Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 10:27:04 +0200 Subject: [PATCH 4/8] TASK: Cleanup some comments --- .../Sniffs/Removed/AbstractGenericUsage.php | 25 +++++++++---------- .../Removed/GenericConstantUsageSniff.php | 6 +---- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index 018b650..b74e5e2 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -95,7 +95,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff $newStructure[$removed]['name'] = $split[0]; $newStructure[$removed]['version_removed'] = $typo3Version; - // If split contains two parts, it's a class with method + // If split contains two parts, it's a class if (isset($split[1])) { $newStructure[$removed]['fqcn'] = $split[0]; $newStructure[$removed]['class'] = array_slice( @@ -174,8 +174,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff */ protected function getMatchingRemoved($name, $className, $isStatic) { - // We will not match any static method, without the class name, at least for now. - // Otherwise we could handle them the same way as instance methods. + // We will not match any static calls, without the class name, at least for now. if ($isStatic === true && $className === false) { return []; } @@ -225,7 +224,7 @@ abstract class AbstractGenericUsage implements PhpCsSniff /** * Identifier for configuring this specific error / warning through PHPCS. * - * @param array $config The converted structure for a single function. + * @param array $config * * @return string */ @@ -240,24 +239,24 @@ abstract class AbstractGenericUsage implements PhpCsSniff } /** - * The original constant call, to allow user to check matches. + * The original call, to allow user to check matches. * - * As we match the constant name, that can be provided by multiple classes, - * you should provide an example, so users can check that this is the - * legacy one. + * 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 The converted structure for a single constant. + * @param array $config * * @return string */ abstract protected function getOldUsage(array $config); /** - * Returns TYPO3 version when the current constant was removed. + * Returns TYPO3 version when the breaking change happened. * * To let user decide whether this is important for him. * - * @param array $config The converted structure for a single constant. + * @param array $config * * @return string */ @@ -267,11 +266,11 @@ abstract class AbstractGenericUsage implements PhpCsSniff } /** - * The new constant call, or information how to migrate. + * The new call, or information how to migrate. * * To provide feedback for user to ease migration. * - * @param array $config The converted structure for a single constant. + * @param array $config * * @return string */ diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php index edcba91..c395398 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -50,11 +50,7 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGener /** * The original constant call, to allow user to check matches. * - * As we match the constant 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 The converted structure for a single constant. + * @param array $config * * @return string */ From 4a7ffaa92dda0a08df811c90a1f671887072ca2c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 10:59:46 +0200 Subject: [PATCH 5/8] TASK: Update documentation * Add new feature to docs. Resolves: #42 --- Readme.rst | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Readme.rst b/Readme.rst index e87a3a8..e1b5cb4 100644 --- a/Readme.rst +++ b/Readme.rst @@ -108,6 +108,10 @@ available to generate a report of possible issues and during coding through ``ph inside the standard itself, and we try to deliver all information. For configuration options see ``removedFunctionConfigFiles``. +- Check for usage of removed constants. + The constants are configured in same way as removed functions. + For configuration options see ``removedConstantsConfigFiles``. + What does it look like? ======================= @@ -220,3 +224,21 @@ Example: .. code:: bash --runtime-set removedFunctionConfigFiles "/Some/Absolute/Path/*.yaml" + +``removedConstantConfigFiles`` + Configure your vendor through ``ruleset.xml`` or using ``--runtime-set``. Default is + ``Configuration/Removed/Constants/*.yaml`` inside the standard itself. + Globing is used, so placeholders like ``*`` are possible, see + https://secure.php.net/manual/en/function.glob.php + + Example: + +.. code:: xml + + + +Example: + +.. code:: bash + + --runtime-set removedConstantConfigFiles "/Some/Absolute/Path/*.yaml" From b99438fff99bfea9e8d8a72bf542f12632c1f0a1 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 6 Apr 2017 08:26:13 +0200 Subject: [PATCH 6/8] TASK: Refactor remove duplicate logic * Make option trait cleaner, remove duplicate logic and use methods for same logic. * Also fix issue in readme pointing to non existing config name. Relates: #42 --- Readme.rst | 2 +- .../Typo3Update/Sniffs/OptionsAccessTrait.php | 69 +++++++++++++------ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/Readme.rst b/Readme.rst index e1b5cb4..dcc9770 100644 --- a/Readme.rst +++ b/Readme.rst @@ -110,7 +110,7 @@ available to generate a report of possible issues and during coding through ``ph - Check for usage of removed constants. The constants are configured in same way as removed functions. - For configuration options see ``removedConstantsConfigFiles``. + For configuration options see ``removedConstantConfigFiles``. What does it look like? ======================= diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php index 5d457ea..fe2f3f6 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -34,10 +34,11 @@ trait OptionsAccessTrait */ public function getVendor() { - $vendor = PhpCs::getConfigData('vendor'); - if (!$vendor) { - $vendor = 'YourCompany'; - } + $vendor = $this->getOptionWithDefault( + 'vendor', + 'YourCompany' + ); + return trim($vendor, '\\/'); } @@ -48,11 +49,10 @@ trait OptionsAccessTrait */ public function getMappingFile() { - $mappingFile = PhpCs::getConfigData('mappingFile'); - if (!$mappingFile) { - $mappingFile = __DIR__ . '/../../../../LegacyClassnames.php'; - } - return $mappingFile; + return (string) $this->getOptionWithDefault( + 'mappingFile', + __DIR__ . '/../../../../LegacyClassnames.php' + ); } /** @@ -62,14 +62,10 @@ trait OptionsAccessTrait */ public function getRemovedFunctionConfigFiles() { - $configFiles = PhpCs::getConfigData('removedFunctionConfigFiles'); - if (!$configFiles) { - $configFiles = __DIR__ . '/../Configuration/Removed/Functions/*.yaml'; - } - - foreach ((new \GlobIterator($configFiles)) as $file) { - yield (string) $file; - } + $this->getOptionFileNames( + 'removedFunctionConfigFiles', + __DIR__ . '/../Configuration/Removed/Functions/*.yaml' + ); } /** @@ -79,12 +75,43 @@ trait OptionsAccessTrait */ public function getRemovedConstantConfigFiles() { - $configFiles = PhpCs::getConfigData('removedConstantConfigFiles'); - if (!$configFiles) { - $configFiles = __DIR__ . '/../Configuration/Removed/Constants/*.yaml'; + $this->getOptionFileNames( + 'removedConstantConfigFiles', + __DIR__ . '/../Configuration/Removed/Constants/*.yaml' + ); + } + + /** + * Get the option by optionName, if not defined, use default. + * + * @param string $optionName + * @param mixed $default + * + * @return mixed + */ + private function getOptionWithDefault($optionName, $default) + { + $option = PhpCs::getConfigData($optionName); + if (!$option) { + $option = $default; } - foreach ((new \GlobIterator($configFiles)) as $file) { + return $option; + } + + /** + * Get file names defined by option using optionName, if not defined, use default. + * + * @param string $optionName + * @param mixed $default + * + * @return \Generator + */ + private function getOptionFileNames($optionName, $default) + { + $files = $this->getOptionWithDefault($optionName, $default); + + foreach ((new \GlobIterator($files)) as $file) { yield (string) $file; } } From 20952b77101cfbb5aa4f01bf3c3a72e138b6b362 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 6 Apr 2017 08:56:46 +0200 Subject: [PATCH 7/8] TASK: Refactor options access * No longer use trait but static methods due to lack of Dependency Injection. * Adjust all calls. * Also don't use yield any longer but return array of file names. Relates: #42 --- .../AbstractClassnameChecker.php | 3 -- .../Sniffs/LegacyClassnames/Mapping.php | 8 ++-- .../MissingNamespaceSniff.php | 3 +- ...MissingVendorForPluginsAndModulesSniff.php | 6 +-- .../{OptionsAccessTrait.php => Options.php} | 38 +++++++++++-------- .../Sniffs/Removed/AbstractGenericUsage.php | 6 +-- .../Removed/GenericConstantUsageSniff.php | 3 +- .../Removed/GenericFunctionCallSniff.php | 3 +- 8 files changed, 35 insertions(+), 35 deletions(-) rename src/Standards/Typo3Update/Sniffs/{OptionsAccessTrait.php => Options.php} (72%) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index a13fe15..bd472cc 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -24,15 +24,12 @@ use PHP_CodeSniffer as PhpCs; use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; use Typo3Update\Sniffs\LegacyClassnames\Mapping; -use Typo3Update\Sniffs\OptionsAccessTrait; /** * Provide common uses for all sniffs, regarding class name checks. */ abstract class AbstractClassnameChecker implements PhpCsSniff { - use OptionsAccessTrait; - /** * A list of extension names that might contain legacy class names. * Used to check clas names for warnings. diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php index 16a8acf..201263a 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php @@ -20,7 +20,7 @@ namespace Typo3Update\Sniffs\LegacyClassnames; * 02110-1301, USA. */ -use Typo3Update\Sniffs\OptionsAccessTrait; +use Typo3Update\Sniffs\Options; /** * Singleton wrapper for mappings. @@ -30,8 +30,6 @@ use Typo3Update\Sniffs\OptionsAccessTrait; */ final class Mapping { - use OptionsAccessTrait; - // Singleton implementation - Start static protected $instance = null; /** @@ -55,7 +53,7 @@ final class Mapping } private function __construct() { - $this->mappings = require $this->getMappingFile(); + $this->mappings = require Options::getMappingFile(); } // Singleton implementation - End @@ -116,7 +114,7 @@ final class Mapping } file_put_contents( - $this->getMappingFile(), + Options::getMappingFile(), 'mappings, true) . ';' ); } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index 3f8a197..e8d0feb 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -21,6 +21,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; +use Typo3Update\Sniffs\Options; /** * Detect missing namespaces for class definitions. @@ -153,7 +154,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract */ protected function getNamespace($classname) { - $vendor = trim($this->getVendor(), '\\/'); + $vendor = trim(Options::getVendor(), '\\/'); $classnameParts = explode('_', $classname); unset($classnameParts[0]); // Remove Tx_ diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php index 3f2825f..1886995 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -22,6 +22,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; use PHP_CodeSniffer_Tokens as Tokens; +use Typo3Update\Sniffs\Options; /** * Detect whether vendor is missing for plugins and modules registrations and configurations. @@ -29,7 +30,6 @@ use PHP_CodeSniffer_Tokens as Tokens; class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff implements PhpCsSniff { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - use \Typo3Update\Sniffs\OptionsAccessTrait; /** * Returns the token types that this sniff is interested in. @@ -72,13 +72,13 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff . ' Add vendor before Extensionkey like: "%s." . $_EXTKEY', $firstArgument, 'missingVendor', - [$this->getVendor()] + [Options::getVendor()] ); if ($fix === true) { $phpcsFile->fixer->replaceToken( $firstArgument, - "'{$this->getVendor()}.' . {$tokens[$firstArgument]['content']}" + "'{Options::getVendor()}.' . {$tokens[$firstArgument]['content']}" ); } } diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/Options.php similarity index 72% rename from src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php rename to src/Standards/Typo3Update/Sniffs/Options.php index fe2f3f6..c6b5ba7 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/Options.php @@ -25,16 +25,16 @@ use PHP_CodeSniffer as PhpCs; /** * Wrapper to retrieve options from PhpCs with defaults. */ -trait OptionsAccessTrait +class Options { /** * Returns the configured vendor, e.g. to generate new namespaces. * * @return string */ - public function getVendor() + public static function getVendor() { - $vendor = $this->getOptionWithDefault( + $vendor = static::getOptionWithDefault( 'vendor', 'YourCompany' ); @@ -47,9 +47,9 @@ trait OptionsAccessTrait * * @return string */ - public function getMappingFile() + public static function getMappingFile() { - return (string) $this->getOptionWithDefault( + return (string) static::getOptionWithDefault( 'mappingFile', __DIR__ . '/../../../../LegacyClassnames.php' ); @@ -58,11 +58,11 @@ trait OptionsAccessTrait /** * Returns an array of absolute file names containing removed function configurations. * - * @return \Generator + * @return array */ - public function getRemovedFunctionConfigFiles() + public static function getRemovedFunctionConfigFiles() { - $this->getOptionFileNames( + return static::getOptionFileNames( 'removedFunctionConfigFiles', __DIR__ . '/../Configuration/Removed/Functions/*.yaml' ); @@ -71,11 +71,11 @@ trait OptionsAccessTrait /** * Returns an array of absolute file names containing removed constant configurations. * - * @return \Generator + * @return array */ - public function getRemovedConstantConfigFiles() + public static function getRemovedConstantConfigFiles() { - $this->getOptionFileNames( + return static::getOptionFileNames( 'removedConstantConfigFiles', __DIR__ . '/../Configuration/Removed/Constants/*.yaml' ); @@ -89,7 +89,7 @@ trait OptionsAccessTrait * * @return mixed */ - private function getOptionWithDefault($optionName, $default) + private static function getOptionWithDefault($optionName, $default) { $option = PhpCs::getConfigData($optionName); if (!$option) { @@ -102,17 +102,23 @@ trait OptionsAccessTrait /** * Get file names defined by option using optionName, if not defined, use default. * + * TODO: Multiple files allowed, using glob ... + * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... + * * @param string $optionName * @param mixed $default * - * @return \Generator + * @return array */ - private function getOptionFileNames($optionName, $default) + protected static function getOptionFileNames($optionName, $default) { - $files = $this->getOptionWithDefault($optionName, $default); + $files = static::getOptionWithDefault($optionName, $default); + $fileNames = []; foreach ((new \GlobIterator($files)) as $file) { - yield (string) $file; + $fileNames[] = (string) $file; } + + return $fileNames; } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php index b74e5e2..766db34 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericUsage.php @@ -24,6 +24,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; use PHP_CodeSniffer_Tokens as Tokens; use Symfony\Component\Yaml\Yaml; +use Typo3Update\Sniffs\Options; /** * Contains common functionality for removed code like constants or functions. @@ -34,7 +35,6 @@ use Symfony\Component\Yaml\Yaml; abstract class AbstractGenericUsage implements PhpCsSniff { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - use \Typo3Update\Sniffs\OptionsAccessTrait; /** * Configuration to define removed code. @@ -49,10 +49,6 @@ abstract class AbstractGenericUsage implements PhpCsSniff */ protected $removed = []; - /** - * TODO: Multiple files allowed, using glob ... - * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... - */ public function __construct() { if ($this->configured === []) { diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php index c395398..e99a226 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -21,6 +21,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\Removed\AbstractGenericUsage; +use Typo3Update\Sniffs\Options; /** * Sniff that handles all calls to removed constants. @@ -34,7 +35,7 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGener */ protected function getRemovedConfigFiles() { - return $this->getRemovedConstantConfigFiles(); + return Options::getRemovedConstantConfigFiles(); } /** diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 29a957f..7f8b730 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -22,6 +22,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Tokens as Tokens; use Typo3Update\Sniffs\Removed\AbstractGenericUsage; +use Typo3Update\Sniffs\Options; /** * Sniff that handles all calls to removed functions. @@ -35,7 +36,7 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGeneri */ protected function getRemovedConfigFiles() { - return $this->getRemovedFunctionConfigFiles(); + return Options::getRemovedFunctionConfigFiles(); } /** From 6528c391b2a0d209457a9860ef9796d08acebe08 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Sun, 9 Apr 2017 13:40:10 +0200 Subject: [PATCH 8/8] FEATURE: Make each sniff run as a new test * Allows running all further sniffs, even if a single sniff fails. * Shows all issues at once in output. * Use native SplFileInfo instead of Symfony, as we have no need for the dependency. Relates: #46 --- tests/SniffsTest.php | 62 +++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/tests/SniffsTest.php b/tests/SniffsTest.php index ad2dd10..16d58b0 100644 --- a/tests/SniffsTest.php +++ b/tests/SniffsTest.php @@ -23,7 +23,6 @@ namespace Typo3Update\Tests; use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; /** * Will test all sniffs where fixtures are available. @@ -37,10 +36,31 @@ class SniffsTest extends TestCase * * Execute each sniff based on found fixtures and compare result. * + * @dataProvider getSniffs * @test + * + * @param \SplFileInfo $folder + * @param array $arguments */ - public function sniffs() + public function sniffs(\SplFileInfo $folder, array $arguments = []) { + if ($arguments !== []) { + $this->executeSniffSubfolders($folder, $arguments); + return; + } + + $this->executeSniff($folder); + } + + /** + * Returns all sniffs to test. + * Use e.g. as data provider. + * + * @return array + */ + public function getSniffs() + { + $sniffs = []; $finder = new Finder(); $finder->in( __DIR__ @@ -51,42 +71,48 @@ class SniffsTest extends TestCase ); foreach ($finder->directories()->name('*Sniff') as $folder) { + $sniff = [ + $folder, + [], + ]; + if (is_file($this->getArgumentsFile($folder))) { $arguments = require $this->getArgumentsFile($folder); - $this->executeSniffSubfolders($folder, $arguments); - continue; + $sniff[1] = $arguments; } - $this->executeSniff($folder); + $sniffs[] = $sniff; } + + return $sniffs; } /** * Execute sniff using subfolders. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @param array $arguments * @return void */ - protected function executeSniffSubfolders(SplFileInfo $folder, array $arguments = []) + protected function executeSniffSubfolders(\SplFileInfo $folder, array $arguments = []) { $finder = new Finder(); $finder->in($folder->getRealPath()); foreach ($arguments as $subFolder => $values) { $folderName = $folder->getRealPath() . DIRECTORY_SEPARATOR . $subFolder; - $this->executeSniff(new SplFileInfo($folderName, $folderName, $folderName), $values); + $this->executeSniff(new \SplFileInfo($folderName), $values); } } /** * Execute phpunit assertion for sniff based on $folder. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @param array $arguments * @return void */ - protected function executeSniff(SplFileInfo $folder, array $arguments = []) + protected function executeSniff(\SplFileInfo $folder, array $arguments = []) { $internalArguments = array_merge_recursive([ 'runtime-set' => [ @@ -133,10 +159,10 @@ class SniffsTest extends TestCase /** * Get expected json output for comparison. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return array */ - protected function getExpectedJsonOutput(SplFileInfo $folder) + protected function getExpectedJsonOutput(\SplFileInfo $folder) { $file = $folder->getPathname() . DIRECTORY_SEPARATOR . 'Expected.json'; if (!is_file($file)) { @@ -149,12 +175,12 @@ class SniffsTest extends TestCase /** * Returns absolute file path to diff file containing expected output. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string * * @throws FileNotFoundException */ - protected function getExpectedDiffOutput(SplFileInfo $folder) + protected function getExpectedDiffOutput(\SplFileInfo $folder) { $file = $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Expected.diff'; if (!is_file($file)) { @@ -167,10 +193,10 @@ class SniffsTest extends TestCase /** * Returns PHPCS Sniff name for given folder. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string */ - protected function getSniffByFolder(SplFileInfo $folder) + protected function getSniffByFolder(\SplFileInfo $folder) { $folderParts = array_filter(explode(DIRECTORY_SEPARATOR, $folder->getPathName())); $sniffNamePosition; @@ -194,10 +220,10 @@ class SniffsTest extends TestCase /** * Get absolute file path to file containing further arguments. * - * @param SplFileInfo $folder + * @param \SplFileInfo $folder * @return string */ - protected function getArgumentsFile(SplFileInfo $folder) + protected function getArgumentsFile(\SplFileInfo $folder) { return $folder->getRealPath() . DIRECTORY_SEPARATOR . 'Arguments.php'; }