From fcb778d903fa0aa95e15d5fd1d9d252799387c6a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 16:35:25 +0100 Subject: [PATCH 01/34] WIP|FEATURE: Provide sniff to convert old legacy class definitions * Insert missing namespace, based on existing class name. * Allow configuration of Vendor to use. * Will not adjust uses of the class. * All other sniffs are broken right now, they need to be adjusted to new abstract class. Relates: #36 --- Readme.rst | 18 ++ ...Trait.php => AbstractClassnameChecker.php} | 26 ++- .../MissingNamespaceSniff.php | 157 ++++++++++++++++++ src/Standards/Typo3Update/ruleset.xml | 4 + 4 files changed, 200 insertions(+), 5 deletions(-) rename src/Standards/Typo3Update/Sniffs/LegacyClassnames/{ClassnameCheckerTrait.php => AbstractClassnameChecker.php} (90%) create mode 100644 src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php diff --git a/Readme.rst b/Readme.rst index 86f6a6e..1c13268 100644 --- a/Readme.rst +++ b/Readme.rst @@ -69,6 +69,8 @@ new ones like ``\TYPO3\Extbase\...``. This is done for: - ``catch`` of legacy class names. +- Convert old legacy class definitions in extensions to namespace ones. + Also we check for the following deprecated calls: - Check for ``create`` on ``ObjectManager``, which is "stupid" just all ``create`` calls are marked @@ -136,3 +138,19 @@ Typo3Update.LegacyClassnames.DocComment: ``allowedTags`` + +``vendor`` + Configure your vendor through ``ruleset.xml`` or using ``--runtime-set``. Default is + ``YourCompany``. + + Example: + +.. code:: xml + + + +Example: + +.. code:: bash + + --runtime-set vendor YourVendor diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php similarity index 90% rename from src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php rename to src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index d6a2fe2..305213e 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -20,12 +20,14 @@ namespace Typo3Update\Sniffs\LegacyClassnames; * 02110-1301, USA. */ +use PHP_CodeSniffer as PhpCs; use PHP_CodeSniffer_File as PhpcsFile; +use PHP_CodeSniffer_Sniff as PhpCsSniff; /** * Provide common uses for all sniffs, regarding class name checks. */ -trait ClassnameCheckerTrait +abstract class AbstractClassnameChecker implements PhpCsSniff { /** * Contains mapping from old -> new class names. @@ -43,6 +45,20 @@ trait ClassnameCheckerTrait */ public $legacyExtensions = ['Extbase', 'Fluid']; + /** + * Returns the configured vendor, e.g. to generate new namespaces. + * + * @return string + */ + protected function getVendor() + { + $vendor = PhpCs::getConfigData('vendor'); + if (!$vendor) { + $vendor = 'YourCompany'; + } + return trim($vendor, '\\/'); + } + /** * @param string $mappingFile File containing php array for mapping. */ @@ -103,7 +119,7 @@ trait ClassnameCheckerTrait * @param string $classname * @return bool */ - private function isLegacyClassname($classname) + protected function isLegacyClassname($classname) { $this->initialize(); return isset($this->legacyClassnames[strtolower($classname)]); @@ -138,7 +154,7 @@ trait ClassnameCheckerTrait * @param string $classname * @return string */ - private function getNewClassname($classname) + protected function getNewClassname($classname) { $this->initialize(); return $this->legacyClassnames[strtolower($classname)]; @@ -200,10 +216,10 @@ trait ClassnameCheckerTrait * @param int $classnamePosition * @param string $classname */ - private function replaceLegacyClassname(PhpcsFile $phpcsFile, $classnamePosition, $classname) + protected function replaceLegacyClassname(PhpcsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = false) { $prefix = '\\'; - if ($phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) { + if ($forceEmptyPrefix || $phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) { $prefix = ''; } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php new file mode 100644 index 0000000..2d74d70 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -0,0 +1,157 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + +/** + * Detect missing namespaces for class definitions. + */ +class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends AbstractClassnameChecker +{ + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + return [T_CLASS]; + } + + /** + * Processes the tokens that this sniff is interested in. + * + * @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) + { + $tokens = $phpcsFile->getTokens(); + + $namespacePosition = $phpcsFile->findPrevious(T_NAMESPACE, $stackPtr); + if ($namespacePosition !== false) { + return; + } + $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($classnamePosition === false) { + return; + } + $classname = $tokens[$classnamePosition]['content']; + + $this->addFixableError($phpcsFile, $classnamePosition, $classname); + } + + /** + * Overwrite as we don't look up the classname, but check whether the style is legacy. + * + * @param string $classname + * @return bool + */ + protected function isLegacyClassname($classname) + { + return strpos($classname, 'Tx_') === 0; + } + + /** + * @param string $classname + * @return string + */ + protected function getNewClassname($classname) + { + return substr($classname, strrpos($classname, '_') + 1); + } + + /** + * + * @param PhpCsFile $phpcsFile + * @param int $classnamePosition + * @param string $classname + */ + protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = true) + { + parent::replaceLegacyClassname($phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix); + + $tokens = $phpcsFile->getTokens(); + $lineEndings = PhpCsFile::detectLineEndings($phpcsFile->getFilename()); + $suffix = $lineEndings; + + // TODO, does not work. + if ($tokens[1] === "\n") { + $suffix .= $lineEndings; + } + + $phpcsFile->fixer->replaceToken( + $this->getNamespacePosition($phpcsFile), + 'getNamespaceDefinition($classname) . $suffix + ); + } + + /** + * @param PhpCsFile $phpcsFile + * @return int + */ + protected function getNamespacePosition(PhpCsFile $phpcsFile) + { + return $phpcsFile->findNext(T_OPEN_TAG, 0); + } + + /** + * Returns whole statement to define namespace. + * + * E.g. namespace VENDOR\ExtName\FolderName; + * + * @param string $classname + * @return string + */ + protected function getNamespaceDefinition($classname) + { + $vendor = trim($this->getVendor(), '\\/'); + + return 'namespace ' + . $vendor + . '\\' + . $this->getNamespace($classname) + . ';' + ; + } + + /** + * Returns namespace, without vendor, based on legacy class name. + * + * E.g. Tx_ExtName_FolderName_FileName -> ExtName\FolderName + * + * @param string $classname + * @return string + */ + protected function getNamespace($classname) + { + $classnameParts = explode('_', $classname); + + unset($classnameParts[0]); // Remove Tx_ + unset($classnameParts[count($classnameParts)]); // Remove class name itself. + + return implode('\\', $classnameParts); + } +} diff --git a/src/Standards/Typo3Update/ruleset.xml b/src/Standards/Typo3Update/ruleset.xml index c8e6a69..260cadb 100644 --- a/src/Standards/Typo3Update/ruleset.xml +++ b/src/Standards/Typo3Update/ruleset.xml @@ -12,4 +12,8 @@ + + + Legacy class definitions are not allowed; found "%s". Wrap your class inside a namespace. + From 21c72c8b96757847e578c2ff4f68a8715eb5a199 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 17:22:18 +0100 Subject: [PATCH 02/34] WIP|FEATURE: Handle trait and interfaces beside classes * Also fix check whether another line should be added after namespace definition. Relates: #36 --- .../Sniffs/LegacyClassnames/MissingNamespaceSniff.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index 2d74d70..391c357 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -34,7 +34,11 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract */ public function register() { - return [T_CLASS]; + return [ + T_CLASS, + T_INTERFACE, + T_TRAIT, + ]; } /** @@ -97,8 +101,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract $lineEndings = PhpCsFile::detectLineEndings($phpcsFile->getFilename()); $suffix = $lineEndings; - // TODO, does not work. - if ($tokens[1] === "\n") { + if ($tokens[1]['code'] !== T_WHITESPACE) { $suffix .= $lineEndings; } From 9a13223d62a69d3931c1646160e07cf1a3995217 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 13:30:04 +0100 Subject: [PATCH 03/34] TASK: Rename method * To follow CGL Relates: #33 --- .../AbstractClassnameChecker.php | 20 +++++++++---------- .../LegacyClassnames/StaticCallSniff.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 305213e..3827b27 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -21,7 +21,7 @@ namespace Typo3Update\Sniffs\LegacyClassnames; */ use PHP_CodeSniffer as PhpCs; -use PHP_CodeSniffer_File as PhpcsFile; +use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; /** @@ -78,7 +78,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * * @return bool */ - protected function findPrev() + protected function shouldLookBefore() { return false; } @@ -90,13 +90,13 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * the class name. This way only the register method has to be registered * in default cases. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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) + public function process(PhpCsFile $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -163,11 +163,11 @@ abstract class AbstractClassnameChecker implements PhpCsSniff /** * Add an fixable error if given $classname is legacy. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - public function addFixableError(PhpcsFile $phpcsFile, $classnamePosition, $classname) + public function addFixableError(PhpCsFile $phpcsFile, $classnamePosition, $classname) { $classname = trim($classname, '\\\'"'); // Remove trailing slash, and quotes. $this->addMaybeWarning($phpcsFile, $classnamePosition, $classname); @@ -191,11 +191,11 @@ abstract class AbstractClassnameChecker implements PhpCsSniff /** * Add an warning if given $classname is maybe legacy. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - private function addMaybeWarning(PhpcsFile $phpcsFile, $classnamePosition, $classname) + private function addMaybeWarning(PhpCsFile $phpcsFile, $classnamePosition, $classname) { if ($this->isLegacyClassname($classname) || $this->isMaybeLegacyClassname($classname) === false) { return; @@ -212,11 +212,11 @@ abstract class AbstractClassnameChecker implements PhpCsSniff /** * Replaces the classname at $classnamePosition with $classname in $phpcsFile. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - protected function replaceLegacyClassname(PhpcsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = false) + protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = false) { $prefix = '\\'; if ($forceEmptyPrefix || $phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php index 91b2eef..d10ce73 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php @@ -32,7 +32,7 @@ class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSni * * @return bool */ - protected function findPrev() + protected function shouldLookBefore() { return true; } From 0d985ef42a8d2e6512f541e7cb7378c009df992e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 13:43:52 +0100 Subject: [PATCH 04/34] TASK: Fix call to undefined method Relates: #33 --- .../Sniffs/LegacyClassnames/AbstractClassnameChecker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 3827b27..347717b 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -101,7 +101,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff $tokens = $phpcsFile->getTokens(); $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($this->findPrev()) { + if ($this->shouldLookBefore()) { $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); } if ($classnamePosition === false) { From f91d3240e52e6a377adc98f2b3423a1c75e9f0c7 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 08:41:06 +0100 Subject: [PATCH 05/34] TASK: According to PR, use else instead of default --- .../Sniffs/LegacyClassnames/AbstractClassnameChecker.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 347717b..57668a3 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -100,10 +100,12 @@ abstract class AbstractClassnameChecker implements PhpCsSniff { $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); if ($this->shouldLookBefore()) { $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); + } else { + $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); } + if ($classnamePosition === false) { return; } From eaa99973b14f0d5bf68f76084ecf4ae74186da56 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 10:23:45 +0100 Subject: [PATCH 06/34] TASK: Refactor existing sniffs to work again * As we migrated trait to class, all sniffs have to extend instead to use the new class. * Also make PhpCsFile import and type hints the same across all sniffs. Relates: #36 --- .../Sniffs/LegacyClassnames/DocCommentSniff.php | 11 ++++++----- .../Sniffs/LegacyClassnames/InheritanceSniff.php | 6 +++--- .../Sniffs/LegacyClassnames/InlineCommentSniff.php | 11 ++++++----- .../Sniffs/LegacyClassnames/InstanceofSniff.php | 6 +++--- .../InstantiationWithMakeInstanceSniff.php | 9 +++++---- .../LegacyClassnames/InstantiationWithNewSniff.php | 6 +++--- .../InstantiationWithObjectManagerSniff.php | 9 +++++---- .../Sniffs/LegacyClassnames/IsACallSniff.php | 10 +++++----- .../Sniffs/LegacyClassnames/StaticCallSniff.php | 6 +++--- .../LegacyClassnames/TypeHintCatchExceptionSniff.php | 6 ++---- .../Sniffs/LegacyClassnames/TypeHintSniff.php | 11 +++++------ .../Typo3Update/Sniffs/LegacyClassnames/UseSniff.php | 6 ++---- 12 files changed, 48 insertions(+), 49 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php index 7ab8eca..7edd478 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php @@ -19,15 +19,16 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Migrate PHP Doc comments. * * E.g. annotations like @param or @return, see $allowedTags. */ -class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * The configured tags will be processed. * @var array @@ -55,13 +56,13 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff implements PHP_CodeSni /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); if (!in_array($tokens[$stackPtr]['content'], $this->allowedTags)) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php index 72c5280..884d4b5 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php @@ -19,13 +19,13 @@ * 02110-1301, USA. */ +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Detect and migrate extend and implement of old legacy classnames. */ -class Typo3Update_Sniffs_LegacyClassnames_InheritanceSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InheritanceSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php index c6e8303..2b7caaf 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php @@ -19,13 +19,14 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Migrate PHP inline comments, e.g. for IDEs. */ -class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Original token content for reuse accross methods. * @var string @@ -47,13 +48,13 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff implements PHP_Code /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); $this->originalTokenContent = $tokens[$stackPtr]['content']; diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php index 1274923..b261922 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstanceofSniff.php @@ -19,13 +19,13 @@ * 02110-1301, USA. */ +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Detect and migrate instanceof checks of old legacy classnames. */ -class Typo3Update_Sniffs_LegacyClassnames_InstanceofSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InstanceofSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php index 8b46d7e..169716e 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php @@ -19,14 +19,15 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Tokens as Tokens; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Detect and migrate instantiations of old legacy classnames using "makeInstance". */ -class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; /** @@ -48,13 +49,13 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff imp /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return; diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php index 318cbcd..9a1758e 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithNewSniff.php @@ -19,13 +19,13 @@ * 02110-1301, USA. */ +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Detect and migrate old legacy classnames instantiations using phps "new". */ -class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithNewSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithNewSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php index 632edce..a3d173f 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php @@ -19,14 +19,15 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Tokens as Tokens; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Detect and migrate old legacy classname instantiations using objectmanager create and get. */ -class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; /** @@ -42,13 +43,13 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff im /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return; diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php index 3d41927..b169ac4 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php @@ -19,14 +19,14 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer_File as PhpcsFile; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Detect and migrate instantiations of old legacy classnames using "makeInstance". */ -class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; /** @@ -48,13 +48,13 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff implements PHP_CodeSniffe /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return; diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php index d10ce73..1be8982 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php @@ -19,13 +19,13 @@ * 02110-1301, USA. */ +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; + /** * Detect and migrate static calls to old legacy classnames. */ -class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Define whether the T_STRING default behaviour should be checked before * or after the $stackPtr. diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php index 6bd9b10..876aec8 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintCatchExceptionSniff.php @@ -19,15 +19,13 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_Tokens as Tokens; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Migrate Typehints in catch statements. */ -class Typo3Update_Sniffs_LegacyClassnames_TypehintCatchExceptionSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_TypehintCatchExceptionSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintSniff.php index 7e1bb56..3901309 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/TypeHintSniff.php @@ -19,15 +19,14 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_Tokens as Tokens; +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Migrate Typehints in function / method definitions. */ -class Typo3Update_Sniffs_LegacyClassnames_TypehintSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_TypehintSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * @@ -41,13 +40,13 @@ class Typo3Update_Sniffs_LegacyClassnames_TypehintSniff implements PHP_CodeSniff /** * Processes the tokens that this sniff is interested in. * - * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. + * @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(PHP_CodeSniffer_File $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { $params = $phpcsFile->getMethodParameters($stackPtr); foreach ($params as $parameter) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php index 0b7bf6d..9d882c5 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php @@ -19,15 +19,13 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_Tokens as Tokens; +use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** * Migrate old legacy class names in use statements. */ -class Typo3Update_Sniffs_LegacyClassnames_UseSniff implements PHP_CodeSniffer_Sniff +class Typo3Update_Sniffs_LegacyClassnames_UseSniff extends AbstractClassnameChecker { - use \Typo3Update\Sniffs\LegacyClassnames\ClassnameCheckerTrait; - /** * Returns the token types that this sniff is interested in. * From f9f82b06292ac05dc86f1664a085ce1caafaf499 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 10:55:09 +0100 Subject: [PATCH 07/34] FEATURE: Migrate plugin and module registration and configuration * Prefix with configured vendor if first argument does not start with a string already. Relates: #36 --- .../AbstractClassnameChecker.php | 18 +--- ...MissingVendorForPluginsAndModulesSniff.php | 89 +++++++++++++++++++ .../Typo3Update/Sniffs/OptionsAccessTrait.php | 43 +++++++++ 3 files changed, 135 insertions(+), 15 deletions(-) create mode 100644 src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php create mode 100644 src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 57668a3..6019cdc 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -20,15 +20,17 @@ namespace Typo3Update\Sniffs\LegacyClassnames; * 02110-1301, USA. */ -use PHP_CodeSniffer as PhpCs; use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; +use Typo3Update\Sniffs\OptionsAccessTrait; /** * Provide common uses for all sniffs, regarding class name checks. */ abstract class AbstractClassnameChecker implements PhpCsSniff { + use OptionsAccessTrait; + /** * Contains mapping from old -> new class names. * @var array @@ -45,20 +47,6 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ public $legacyExtensions = ['Extbase', 'Fluid']; - /** - * Returns the configured vendor, e.g. to generate new namespaces. - * - * @return string - */ - protected function getVendor() - { - $vendor = PhpCs::getConfigData('vendor'); - if (!$vendor) { - $vendor = 'YourCompany'; - } - return trim($vendor, '\\/'); - } - /** * @param string $mappingFile File containing php array for mapping. */ diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php new file mode 100644 index 0000000..e2fc43b --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -0,0 +1,89 @@ + + * + * 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; + +/** + * Detect whether vendor is missing for plugins and modules registrations and configurations. + */ +class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff implements PhpCsSniff +{ + use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + use \Typo3Update\Sniffs\OptionsAccessTrait; + + /** + * Original token content for reuse accross methods. + * @var string + */ + protected $originalTokenContent = ''; + + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + return Tokens::$functionNameTokens; + } + + /** + * Processes the tokens that this sniff is interested in. + * + * @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) + { + $functionsToHandle = ['registerPlugin', 'configurePlugin', 'registerModule', 'configureModule']; + if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { + return; + } + $tokens = $phpcsFile->getTokens(); + + if (!in_array($tokens[$stackPtr]['content'], $functionsToHandle)) { + return; + } + + $firstParameter = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true); + if ($firstParameter === false || $tokens[$firstParameter]['code'] === T_CONSTANT_ENCAPSED_STRING) { + return; + } + + $fix = $phpcsFile->addFixableError( + 'No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: "Vendor." . $_EXTKEY', + $firstParameter, + 'missingVendor' + ); + + if ($fix === true) { + $phpcsFile->fixer->replaceToken( + $firstParameter, + "'{$this->getVendor()}.' . " . $tokens[$firstParameter]['content'] + ); + } + } +} diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php new file mode 100644 index 0000000..3037bd8 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -0,0 +1,43 @@ + + * + * 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 as PhpCs; + +/** + * Wrapper to retrieve options from PhpCs with defaults. + */ +trait OptionsAccessTrait +{ + /** + * Returns the configured vendor, e.g. to generate new namespaces. + * + * @return string + */ + public function getVendor() + { + $vendor = PhpCs::getConfigData('vendor'); + if (!$vendor) { + $vendor = 'YourCompany'; + } + return trim($vendor, '\\/'); + } +} From 1561c13b468d45afa6e44b42afde5d459a220a2f Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 11:27:40 +0100 Subject: [PATCH 08/34] FEATURE: Improve handling of missing Vendor * Check for string concatenation instead of earlier more stupid. Relates: #36 --- Readme.rst | 15 +++++++ ...MissingVendorForPluginsAndModulesSniff.php | 42 ++++++++++++++++--- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Readme.rst b/Readme.rst index 1c13268..8d8b781 100644 --- a/Readme.rst +++ b/Readme.rst @@ -71,6 +71,21 @@ new ones like ``\TYPO3\Extbase\...``. This is done for: - Convert old legacy class definitions in extensions to namespace ones. +- Add missing vendor to plugin and module registrations and configurations. + You might want to set this to non fixable and warning if you already provide the vendor inside a + single Variable, together with your extension key, as this is not recognized. So the following + will be recognized: + + - $_EXTKEY, + + - $VENDOR . $_EXTKEY, + + - 'VENDOR.' . $_EXTKEY, + + While the following will not: + + - $key = 'Vendor.' . $_EXTKEY; + Also we check for the following deprecated calls: - Check for ``create`` on ``ObjectManager``, which is "stupid" just all ``create`` calls are marked diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php index e2fc43b..e4eafe8 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -68,22 +68,52 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff return; } - $firstParameter = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true); - if ($firstParameter === false || $tokens[$firstParameter]['code'] === T_CONSTANT_ENCAPSED_STRING) { + $firstArgument = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true); + if (! $this->isVendorMissing($phpcsFile, $firstArgument)) { return; } $fix = $phpcsFile->addFixableError( - 'No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: "Vendor." . $_EXTKEY', - $firstParameter, + 'No vendor is given, that will break TYPO3 handling for namespaced classes.' + . ' Add vendor before Extensionkey like: "Vendor." . $_EXTKEY', + $firstArgument, 'missingVendor' ); if ($fix === true) { $phpcsFile->fixer->replaceToken( - $firstParameter, - "'{$this->getVendor()}.' . " . $tokens[$firstParameter]['content'] + $firstArgument, + "'{$this->getVendor()}.' . " . $tokens[$firstArgument]['content'] ); } } + + /** + * Checks whether vendor is missing in given argument. + * + * @param PhpCsFile $phpcsFile + * @param int|bool $argumentStart + * + * @return bool + */ + protected function isVendorMissing(PhpCsFile $phpcsFile, $argumentStart) + { + if ($argumentStart === false) { + return false; + } + + $argumentEnd = $phpcsFile->findNext(T_COMMA, $argumentStart); + if ($argumentEnd === false) { + return false; + } + + $stringConcats = array_filter( + array_slice($phpcsFile->getTokens(), $argumentStart, $argumentEnd - $argumentStart), + function (array $token) { + return $token['code'] === 'PHPCS_T_STRING_CONCAT'; + } + ); + + return count($stringConcats) === 0; + } } From 8fbe25a422b5e8b733634c9f9c9920ea79fc0532 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 11:40:17 +0100 Subject: [PATCH 09/34] TASK: Cleanup missing vendor * Add configured vendor in message for easer migration in IDEs (by hand). * Remove non existing function from checks. Relates: #36 --- .../MissingVendorForPluginsAndModulesSniff.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php index e4eafe8..072bf62 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -58,7 +58,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff */ public function process(PhpCsFile $phpcsFile, $stackPtr) { - $functionsToHandle = ['registerPlugin', 'configurePlugin', 'registerModule', 'configureModule']; + $functionsToHandle = ['registerPlugin', 'configurePlugin', 'registerModule']; if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return; } @@ -75,9 +75,10 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff $fix = $phpcsFile->addFixableError( 'No vendor is given, that will break TYPO3 handling for namespaced classes.' - . ' Add vendor before Extensionkey like: "Vendor." . $_EXTKEY', + . ' Add vendor before Extensionkey like: "%s." . $_EXTKEY', $firstArgument, - 'missingVendor' + 'missingVendor', + [$this->getVendor()] ); if ($fix === true) { From 6420c72945f856b0c18b781f71baa89dcddc532d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 13:09:58 +0100 Subject: [PATCH 10/34] FEATURE: Allow remapping of usages for redefiined classes * As we already adjust function, trait and interface definitions, we now also migrate the usage of the old versions. * This is done in second run, as mentioned in adjusted Readme. Relates: #36 --- Readme.rst | 7 + .../AbstractClassnameChecker.php | 39 +++--- .../Sniffs/LegacyClassnames/Mapping.php | 124 ++++++++++++++++++ .../MissingNamespaceSniff.php | 16 +-- 4 files changed, 157 insertions(+), 29 deletions(-) create mode 100644 src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php diff --git a/Readme.rst b/Readme.rst index 8d8b781..cf19a83 100644 --- a/Readme.rst +++ b/Readme.rst @@ -71,6 +71,13 @@ new ones like ``\TYPO3\Extbase\...``. This is done for: - Convert old legacy class definitions in extensions to namespace ones. +- Convert usage of previously converted class definitions. On first run the definition will be + converted, on second the usage. This is due to the fact, that PHPCS might find the definition + after the usage, so please run twice. + + *NOTE* The configured file will be updated after each run, for each converted class, trait and + interface definition. + - Add missing vendor to plugin and module registrations and configurations. You might want to set this to non fixable and warning if you already provide the vendor inside a single Variable, together with your extension key, as this is not recognized. So the following diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 6019cdc..b72e1d2 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -22,6 +22,7 @@ namespace Typo3Update\Sniffs\LegacyClassnames; use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; +use Typo3Update\Sniffs\LegacyClassnames\Mapping; use Typo3Update\Sniffs\OptionsAccessTrait; /** @@ -31,12 +32,6 @@ abstract class AbstractClassnameChecker implements PhpCsSniff { use OptionsAccessTrait; - /** - * Contains mapping from old -> new class names. - * @var array - */ - private $legacyClassnames = []; - /** * A list of extension names that might contain legacy class names. * Used to check clas names for warnings. @@ -47,17 +42,9 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ public $legacyExtensions = ['Extbase', 'Fluid']; - /** - * @param string $mappingFile File containing php array for mapping. - */ - private function initialize($mappingFile = __DIR__ . '/../../../../../LegacyClassnames.php') + public function __construct() { - if ($this->legacyClassnames !== []) { - return; - } - - $legacyClassnames = require $mappingFile; - $this->legacyClassnames = $legacyClassnames['aliasToClassNameMapping']; + $this->legacyMapping = Mapping::getInstance(); } /** @@ -111,8 +98,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ protected function isLegacyClassname($classname) { - $this->initialize(); - return isset($this->legacyClassnames[strtolower($classname)]); + return $this->legacyMapping->isLegacyClassname($classname); } /** @@ -146,8 +132,21 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ protected function getNewClassname($classname) { - $this->initialize(); - return $this->legacyClassnames[strtolower($classname)]; + return $this->legacyMapping->getNewClassname($classname); + } + + /** + * Use to add new mappings found during parsing. + * E.g. in MissingNamespaceSniff old class definitions are fixed and a new mapping exists afterwards. + * + * @param string $legacyClassname + * @param string $newClassname + * + * @return void + */ + protected function addLegacyClassname($legacyClassname, $newClassname) + { + $this->legacyMapping->addLegacyClassname($legacyClassname, $newClassname); } /** diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php new file mode 100644 index 0000000..885ecfd --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php @@ -0,0 +1,124 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Typo3Update\Sniffs\OptionsAccessTrait; + +/** + * Singleton wrapper for mappings. + * + * Will check the configured file for whether a class is legacy and provides further methods. + * Also can update to add new migrated class names. + */ +class Mapping +{ + use OptionsAccessTrait; + + // Singleton implementation - Start + static protected $instance = null; + public static function getInstance() + { + if (static::$instance === null) { + static::$instance = new Mapping(); + } + + return static::$instance; + } + private function __clone() + { + } + private function __wakeup() + { + } + private function __construct() + { + // $mappingFile = $this->getMappingFile(); + $mappingFile = __DIR__ . '/../../../../../LegacyClassnames.php'; + + $this->mappings = require $mappingFile; + } + // Singleton implementation - End + + /** + * Contains mappings as defined by composer for alias mapping. + * @var array + */ + protected $mappings = []; + + /** + * Checks whether a mapping exists for the given $classname, + * indicating it's legacy. + * + * @param string $classname + * @return bool + */ + public function isLegacyClassname($classname) + { + return isset($this->mappings['aliasToClassNameMapping'][strtolower($classname)]); + } + + /** + * @param string $classname + * @return string + */ + public function getNewClassname($classname) + { + return $this->mappings['aliasToClassNameMapping'][strtolower($classname)]; + } + + /** + * Use to add new mappings found during parsing. + * E.g. in MissingNamespaceSniff old class definitions are fixed and a new mapping exists afterwards. + * + * @param string $legacyClassname + * @param string $newClassname + * + * @return void + */ + public function addLegacyClassname($legacyClassname, $newClassname) + { + $key = strtolower($legacyClassname); + + $this->mappings['aliasToClassNameMapping'][$key] = $newClassname; + $this->mappings['classNameToAliasMapping'][$newClassname] = [$key => $key]; + } + + /** + * Used to persist new mappings. + */ + public function __destruct() + { + // For some reasons desctruct is called multiple times, while construct + // is called once. Until we know the issue and fix it, this is our + // workaround to not break the file and do stuff in an unkown instance. + if ($this !== static::$instance) { + return; + } + + // $mappingFile = $this->getMappingFile(); + $mappingFile = __DIR__ . '/../../../../../LegacyClassnames.php'; + + file_put_contents( + $mappingFile, + 'mappings, true) . ';' + ); + } +} diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index 391c357..5374dd3 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -109,6 +109,10 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract $this->getNamespacePosition($phpcsFile), 'getNamespaceDefinition($classname) . $suffix ); + $this->addLegacyClassname( + $classname, + $this->getNamespace($classname) . '\\' . $this->getNewClassname($classname) + ); } /** @@ -130,14 +134,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract */ protected function getNamespaceDefinition($classname) { - $vendor = trim($this->getVendor(), '\\/'); - - return 'namespace ' - . $vendor - . '\\' - . $this->getNamespace($classname) - . ';' - ; + return 'namespace ' . $this->getNamespace($classname) . ';'; } /** @@ -150,11 +147,12 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract */ protected function getNamespace($classname) { + $vendor = trim($this->getVendor(), '\\/'); $classnameParts = explode('_', $classname); unset($classnameParts[0]); // Remove Tx_ unset($classnameParts[count($classnameParts)]); // Remove class name itself. - return implode('\\', $classnameParts); + return $vendor . '\\' . implode('\\', $classnameParts); } } From 9b3d5d95152d081a05d1ba40640a5ee201fb5dd9 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 16:12:40 +0100 Subject: [PATCH 11/34] BUGFIX: Support multiple interfaces * Process extends as before. * Process all interfaces in addition, not only the first one. --- .../LegacyClassnames/InheritanceSniff.php | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php index 884d4b5..59c9dd3 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InheritanceSniff.php @@ -19,6 +19,7 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** @@ -38,4 +39,56 @@ class Typo3Update_Sniffs_LegacyClassnames_InheritanceSniff extends AbstractClass T_IMPLEMENTS, ]; } + + /** + * 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 ($phpcsFile->getTokens()[$stackPtr]['code'] === T_IMPLEMENTS) { + $this->processInterfaces($phpcsFile, $stackPtr); + return; + } + + parent::process($phpcsFile, $stackPtr); + } + + /** + * Process all interfaces for current class. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * + * @return void + */ + protected function processInterfaces(PhpCsFile $phpcsFile, $stackPtr) + { + $interfaces = $phpcsFile->findImplementedInterfaceNames($phpcsFile->findPrevious(T_CLASS, $stackPtr)); + if ($interfaces === false) { + return; + } + + foreach ($interfaces as $interface) { + if (! $this->isLegacyClassname($interface)) { + continue; + } + + $position = $phpcsFile->findNext(T_STRING, $stackPtr, null, false, $interface); + if ($position === false) { + continue; + } + + $this->addFixableError($phpcsFile, $position, $interface); + } + } } From 6a115bd8d02711aa2d82cee023bba873b74652ad Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 16:24:22 +0100 Subject: [PATCH 12/34] TASK: Cleanup before PR * Adjust some comments and formating. * Add missing, but used, properties. * Shorten variables used only once. Resolves: #36 --- .../Sniffs/LegacyClassnames/AbstractClassnameChecker.php | 6 ++++++ .../Typo3Update/Sniffs/LegacyClassnames/Mapping.php | 8 ++------ .../Sniffs/LegacyClassnames/MissingNamespaceSniff.php | 5 +++-- .../MissingVendorForPluginsAndModulesSniff.php | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 218ccee..a01da60 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -43,6 +43,11 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ public $legacyExtensions = ['Extbase', 'Fluid']; + /** + * @var Mapping + */ + protected $legacyMapping; + public function __construct() { $this->legacyMapping = Mapping::getInstance(); @@ -205,6 +210,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname + * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. */ protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = false) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php index e704584..c7c455e 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php @@ -50,9 +50,7 @@ class Mapping } private function __construct() { - $mappingFile = $this->getMappingFile(); - - $this->mappings = require $mappingFile; + $this->mappings = require $this->getMappingFile(); } // Singleton implementation - End @@ -112,10 +110,8 @@ class Mapping return; } - $mappingFile = $this->getMappingFile(); - file_put_contents( - $mappingFile, + $this->getMappingFile(), 'mappings, true) . ';' ); } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index 5374dd3..3e3acac 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -92,6 +92,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname + * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. */ protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = true) { @@ -138,9 +139,9 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract } /** - * Returns namespace, without vendor, based on legacy class name. + * Returns namespace, based on legacy class name. * - * E.g. Tx_ExtName_FolderName_FileName -> ExtName\FolderName + * E.g. Tx_ExtName_FolderName_FileName -> VENDOR\ExtName\FolderName * * @param string $classname * @return string diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php index 072bf62..4c76a90 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -84,7 +84,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff if ($fix === true) { $phpcsFile->fixer->replaceToken( $firstArgument, - "'{$this->getVendor()}.' . " . $tokens[$firstArgument]['content'] + "'{$this->getVendor()}.' . {$tokens[$firstArgument]['content']}" ); } } From 842a54d5d98c7f3bd288fa1838ea046c586b0716 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 16:40:03 +0100 Subject: [PATCH 13/34] TASK: Fix quality issues --- .../LegacyClassnames/AbstractClassnameChecker.php | 8 ++++++-- .../Sniffs/LegacyClassnames/InlineCommentSniff.php | 3 ++- .../Typo3Update/Sniffs/LegacyClassnames/Mapping.php | 7 ++++++- .../LegacyClassnames/MissingNamespaceSniff.php | 13 +++++++++---- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index a01da60..2e9896b 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -212,8 +212,12 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * @param string $classname * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. */ - protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = false) - { + protected function replaceLegacyClassname( + PhpCsFile $phpcsFile, + $classnamePosition, + $classname, + $forceEmptyPrefix = false + ) { $prefix = '\\'; if ($forceEmptyPrefix || $phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) { $prefix = ''; diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php index 2b7caaf..fcf9229 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php @@ -60,7 +60,8 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractCla $this->originalTokenContent = $tokens[$stackPtr]['content']; $commentParts = preg_split('/\s+/', $this->originalTokenContent); - if (count($commentParts) !== 5 || $commentParts[1] !== '@var' || ($commentParts[2][0] !== '$' && $commentParts[3][0] !== '$')) { + if (count($commentParts) !== 5 || $commentParts[1] !== '@var' + || ($commentParts[2][0] !== '$' && $commentParts[3][0] !== '$')) { return; } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php index c7c455e..16a8acf 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/Mapping.php @@ -28,12 +28,17 @@ use Typo3Update\Sniffs\OptionsAccessTrait; * Will check the configured file for whether a class is legacy and provides further methods. * Also can update to add new migrated class names. */ -class Mapping +final class Mapping { use OptionsAccessTrait; // Singleton implementation - Start static protected $instance = null; + /** + * Get the singleton instance. + * + * @return Mapping + */ public static function getInstance() { if (static::$instance === null) { diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php index 3e3acac..3f8a197 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingNamespaceSniff.php @@ -59,11 +59,12 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract return; } $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); + if ($classnamePosition === false) { return; } - $classname = $tokens[$classnamePosition]['content']; + $classname = $tokens[$classnamePosition]['content']; $this->addFixableError($phpcsFile, $classnamePosition, $classname); } @@ -94,8 +95,12 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract * @param string $classname * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. */ - protected function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix = true) - { + protected function replaceLegacyClassname( + PhpCsFile $phpcsFile, + $classnamePosition, + $classname, + $forceEmptyPrefix = true + ) { parent::replaceLegacyClassname($phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix); $tokens = $phpcsFile->getTokens(); @@ -118,7 +123,7 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingNamespaceSniff extends Abstract /** * @param PhpCsFile $phpcsFile - * @return int + * @return int|false */ protected function getNamespacePosition(PhpCsFile $phpcsFile) { From 426dc8b318f90ce0d7ec02571859d819a41dc57a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 16:48:28 +0100 Subject: [PATCH 14/34] BUGFIX: Define property where it's used * As we use it in parent class, define it there. --- .../Sniffs/LegacyClassnames/AbstractClassnameChecker.php | 9 +++++++++ .../Sniffs/LegacyClassnames/DocCommentSniff.php | 6 ------ .../Sniffs/LegacyClassnames/InlineCommentSniff.php | 6 ------ .../InstantiationWithMakeInstanceSniff.php | 6 ------ .../Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php | 6 ------ .../MissingVendorForPluginsAndModulesSniff.php | 6 ------ 6 files changed, 9 insertions(+), 30 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index 2e9896b..a13fe15 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -48,6 +48,15 @@ abstract class AbstractClassnameChecker implements PhpCsSniff */ protected $legacyMapping; + /** + * Used by some sniffs to keep original token for replacement. + * + * E.g. when Token itself is a whole inline comment, and we just want to replace the classname within. + * + * @var string + */ + protected $originalTokenContent = ''; + public function __construct() { $this->legacyMapping = Mapping::getInstance(); diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php index 7edd478..2a85c89 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php @@ -35,12 +35,6 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassn */ public $allowedTags = ['@param', '@return', '@var']; - /** - * Original token content for reuse accross methods. - * @var string - */ - protected $originalTokenContent = ''; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php index fcf9229..dc9c17d 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php @@ -27,12 +27,6 @@ use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; */ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractClassnameChecker { - /** - * Original token content for reuse accross methods. - * @var string - */ - protected $originalTokenContent = ''; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php index 169716e..7e06b6b 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php @@ -30,12 +30,6 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff ext { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - /** - * Original token content for reuse accross methods. - * @var string - */ - protected $originalTokenContent = ''; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php index b169ac4..b4a2f30 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php @@ -29,12 +29,6 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - /** - * Original token content for reuse accross methods. - * @var string - */ - protected $originalTokenContent = ''; - /** * Returns the token types that this sniff is interested in. * diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php index 4c76a90..3f2825f 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/MissingVendorForPluginsAndModulesSniff.php @@ -31,12 +31,6 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; use \Typo3Update\Sniffs\OptionsAccessTrait; - /** - * Original token content for reuse accross methods. - * @var string - */ - protected $originalTokenContent = ''; - /** * Returns the token types that this sniff is interested in. * From 69de131a4c9c71b8b248af883578fed24065acd6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 08:40:19 +0200 Subject: [PATCH 15/34] TASK: Improve readme --- Readme.rst | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/Readme.rst b/Readme.rst index 6a90ec5..ce6c08f 100644 --- a/Readme.rst +++ b/Readme.rst @@ -69,29 +69,29 @@ new ones like ``\TYPO3\Extbase\...``. This is done for: - ``catch`` of legacy class names. -- Convert old legacy class definitions in extensions to namespace ones. +- Convert old legacy class *definitions* in extensions to namespaces. - Convert usage of previously converted class definitions. On first run the definition will be - converted, on second the usage. This is due to the fact, that PHPCS might find the definition + converted, on second run the usage. This is due to the fact, that PHPCS might find the definition after the usage, so please run twice. *NOTE* The configured file will be updated after each run, for each converted class, trait and - interface definition. + interface definition. See options. - Add missing vendor to plugin and module registrations and configurations. You might want to set this to non fixable and warning if you already provide the vendor inside a single Variable, together with your extension key, as this is not recognized. So the following will be recognized: - - $_EXTKEY, + - ``$_EXTKEY,`` - - $VENDOR . $_EXTKEY, + - ``$VENDOR . $_EXTKEY,`` - - 'VENDOR.' . $_EXTKEY, + - ``'VENDOR.' . $_EXTKEY,`` While the following will not: - - $key = 'Vendor.' . $_EXTKEY; + - ``$key = 'Vendor.' . $_EXTKEY;`` Also we check for the following deprecated calls: @@ -161,22 +161,6 @@ Typo3Update.LegacyClassnames.DocComment: ``allowedTags`` -``vendor`` - Configure your vendor through ``ruleset.xml`` or using ``--runtime-set``. Default is - ``YourCompany``. - - Example: - -.. code:: xml - - - -Example: - -.. code:: bash - - --runtime-set vendor YourVendor - ``mappingFile`` Configure where the `LegacyClassnames.php` is located, through ``ruleset.xml`` or using ``--runtime-set``. Default is `LegacyClassnames.php` in the project root. @@ -192,3 +176,19 @@ Example: .. code:: bash --runtime-set mappingFile /projects/typo3_installation/vendor/composer/autoload_classaliasmap.php + +``vendor`` + Configure your vendor through ``ruleset.xml`` or using ``--runtime-set``. Default is + ``YourCompany``. + + Example: + +.. code:: xml + + + +Example: + +.. code:: bash + + --runtime-set vendor YourVendor From 3cc85feec794ce208b1a1ac8a241be5e1bfabcdf Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 08:48:43 +0200 Subject: [PATCH 16/34] TASK: Extend readme --- Readme.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.rst b/Readme.rst index ce6c08f..a7a1243 100644 --- a/Readme.rst +++ b/Readme.rst @@ -49,6 +49,8 @@ new ones like ``\TYPO3\Extbase\...``. This is done for: - Static calls like ``t3lib_div::`` to ``\TYPO3\Core\Utility\GeneralUtility``. +- Static call also checks for ``::class``, as technically we just look before the ``::``. + - Typehints in methods and function like injects. - ``instanceof`` checks. From 293a6570a89ff1f7912084864d3a22975ef78bd4 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 09:27:42 +0200 Subject: [PATCH 17/34] FEATURE: Add sniff to check for Breaking: #69916 Relates: #33 --- .../Deprecated/AjaxRegistrationSniff.php | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php new file mode 100644 index 0000000..73a2061 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php @@ -0,0 +1,96 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use PHP_CodeSniffer_Sniff as PhpCsSniff; +use PHP_CodeSniffer_Tokens as PhpCsTokens; + +/** + */ +class Typo3Update_Sniffs_Deprecated_AjaxRegistrationSniff implements PhpCsSniff +{ + /** + * Defines files to check. + * As soon as PHP_CS 3 is used, define them in ruleset.xml. + * + * @var array + */ + public $filenamesToCheck = [ + 'ext_tables.php', + 'ext_localconf.php', + ]; + + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + return PhpCsTokens::$stringTokens; + } + + /** + * Processes the tokens that this sniff is interested in. + * + * @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 (in_array(basename($phpcsFile->getFilename()), $this->filenamesToCheck) === false) { + return; + } + + $tokens = $phpcsFile->getTokens(); + if ($tokens[$stackPtr]['content'] !== "'AJAX'") { + return; + } + $equalSign = $phpcsFile->findNext(T_EQUAL, $stackPtr, null, false, null, true); + if ($equalSign === false) { + return; + } + $tokenToCheck = $phpcsFile->findNext(T_WHITESPACE, $equalSign + 1, null, true, null, true); + if ($tokenToCheck === false) { + return; + } + $token = $tokens[$tokenToCheck]; + if ($token['code'] !== T_CONSTANT_ENCAPSED_STRING) { + return; + } + + $phpcsFile->addWarning( + "Defining AJAX using %s is no longer supported with a single String like %s.\n" + . "Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests.\n" + . 'See: %s', + $tokenToCheck, + '', + [ + "\$GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX'][\$ajaxID]", + $token['content'], + 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html' + ] + ); + } +} From 2118d86879c15d1cadbffefe809beb2d4f671db6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 10:31:30 +0200 Subject: [PATCH 18/34] WIP|FEATURE: First working check for deprecated functions * Provide a generic sniff with configuration (property) containing all deprecated calls. * Check function calls and provide warning with information. Relates: #33 --- .../Deprecated/AbstractFunctionCall.php | 95 +++++++++++++++++++ .../Deprecated/GenericFunctionCallSniff.php | 60 ++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php create mode 100644 src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php new file mode 100644 index 0000000..30fb56a --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php @@ -0,0 +1,95 @@ + + * + * 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; + +/** + * + */ +abstract class AbstractFunctionCall implements PhpCsSniff +{ + use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + + abstract protected function getFunctionNames(); + abstract protected function getOldFunctionCall($functionName); + abstract protected function getNewFunctionCall($functionName); + abstract protected function getDocsUrl($functionName); + + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + 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->isFunctionCall($phpcsFile, $stackPtr)) { + return; + } + + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; + + if (in_array($token['content'], $this->getFunctionNames()) === false) { + return; + } + + $this->addWarning($phpcsFile, $stackPtr); + } + + protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) + { + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$tokenPosition]; + $functionCall = $token['content']; + + $phpcsFile->addWarning( + 'Legacy function calls are not allowed; found %s. %s. See: %s', + $tokenPosition, + 'legacyFunctioncall', + [ + $this->getOldFunctionCall($functionCall), + $this->getNewFunctionCall($functionCall), + $this->getDocsUrl($functionCall), + ] + ); + } +} diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php new file mode 100644 index 0000000..e801ea4 --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -0,0 +1,60 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Sniffs\Deprecated\AbstractFunctionCall; + +/** + */ +class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff extends AbstractFunctionCall +{ + protected $deprecatedFunctions = [ + 'loadTCA' => [ + 'oldFunctionCall' => '\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA()', + 'newFunctionCall' => null, + 'docsUrl' => 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-LoadTcaFunctionRemoved.html', + ], + ]; + + protected function getFunctionNames() + { + return array_keys($this->deprecatedFunctions); + } + + protected function getOldFunctionCall($functionName) + { + return $this->deprecatedFunctions[$functionName]['oldFunctionCall']; + } + + protected function getNewFunctionCall($functionName) + { + $newCall = $this->deprecatedFunctions[$functionName]['newFunctionCall']; + if ($newCall !== null) { + return $newCall; + } + return 'There is no replacement, just remove call'; + } + + protected function getDocsUrl($functionName) + { + return $this->deprecatedFunctions[$functionName]['docsUrl']; + } +} From 65773c88b5673f15f9df3b07521e0e584f233a6d Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 10:57:35 +0200 Subject: [PATCH 19/34] WIP|FEATURE: Provide first deprecation function sniff * Use a single generic sniff with configuration. Relates: #33 --- .../Deprecated/AbstractFunctionCall.php | 95 --------------- .../Deprecated/GenericFunctionCallSniff.php | 111 +++++++++++++++++- 2 files changed, 109 insertions(+), 97 deletions(-) delete mode 100644 src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php deleted file mode 100644 index 30fb56a..0000000 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/AbstractFunctionCall.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * 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; - -/** - * - */ -abstract class AbstractFunctionCall implements PhpCsSniff -{ - use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; - - abstract protected function getFunctionNames(); - abstract protected function getOldFunctionCall($functionName); - abstract protected function getNewFunctionCall($functionName); - abstract protected function getDocsUrl($functionName); - - /** - * Returns the token types that this sniff is interested in. - * - * @return array - */ - public function register() - { - 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->isFunctionCall($phpcsFile, $stackPtr)) { - return; - } - - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; - - if (in_array($token['content'], $this->getFunctionNames()) === false) { - return; - } - - $this->addWarning($phpcsFile, $stackPtr); - } - - protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) - { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$tokenPosition]; - $functionCall = $token['content']; - - $phpcsFile->addWarning( - 'Legacy function calls are not allowed; found %s. %s. See: %s', - $tokenPosition, - 'legacyFunctioncall', - [ - $this->getOldFunctionCall($functionCall), - $this->getNewFunctionCall($functionCall), - $this->getDocsUrl($functionCall), - ] - ); - } -} diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index e801ea4..d6cd39a 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -20,12 +20,25 @@ */ use PHP_CodeSniffer_File as PhpCsFile; -use Typo3Update\Sniffs\Deprecated\AbstractFunctionCall; +use PHP_CodeSniffer_Sniff as PhpCsSniff; +use PHP_CodeSniffer_Tokens as Tokens; /** + * Sniff that handles all calls to deprecated functions. + * + * A single array defines the deprecations, see $deprecatedFunctions. */ -class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff extends AbstractFunctionCall +class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSniff { + use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + + /** + * Configuration to define deprecated functions. + * + * Keys have to match the function name. + * + * @var array + */ protected $deprecatedFunctions = [ 'loadTCA' => [ 'oldFunctionCall' => '\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA()', @@ -34,16 +47,105 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff extends AbstractFun ], ]; + /** + * Returns the token types that this sniff is interested in. + * + * @return array + */ + public function register() + { + 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->isFunctionCall($phpcsFile, $stackPtr)) { + return; + } + + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$stackPtr]; + + if (in_array($token['content'], $this->getFunctionNames()) === false) { + return; + } + + $this->addWarning($phpcsFile, $stackPtr); + } + + /** + * Add warning for the given token position. + * + * @param PhpCsFile $phpcsFile + * @param int $tokenPosition + * + * @return void + */ + protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) + { + $tokens = $phpcsFile->getTokens(); + $token = $tokens[$tokenPosition]; + $functionCall = $token['content']; + + $phpcsFile->addWarning( + "Legacy function calls are not allowed; found %s.\n" + . "%s.\n" + . "See: %s", + $tokenPosition, + $functionCall, + [ + $this->getOldFunctionCall($functionCall), + $this->getNewFunctionCall($functionCall), + $this->getDocsUrl($functionCall), + ] + ); + } + + /** + * Provide all function names that are deprecated and should be handled by + * the Sniff. + * + * @return array + */ protected function getFunctionNames() { return array_keys($this->deprecatedFunctions); } + /** + * The original function call, to allow user to check matches. + * + * As we match the function 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 getOldFunctionCall($functionName) { return $this->deprecatedFunctions[$functionName]['oldFunctionCall']; } + /** + * The new function call, or information how to migrate. + * + * To provide feedback for user to ease migration. + * + * @return string + */ protected function getNewFunctionCall($functionName) { $newCall = $this->deprecatedFunctions[$functionName]['newFunctionCall']; @@ -53,6 +155,11 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff extends AbstractFun 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($functionName) { return $this->deprecatedFunctions[$functionName]['docsUrl']; From 0ee10ea61fe218d02d7df8a269f3d49fbf89d106 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 11:44:06 +0200 Subject: [PATCH 20/34] BUGFIX: Allow deprecations to work in vim too. * Remove line breaks from output, as syntastic will not parse them. * It's up to the report to format the messages, not the Sniff. Relates: #33 --- .../Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php | 6 +++--- .../Sniffs/Deprecated/GenericFunctionCallSniff.php | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php index 73a2061..603ea88 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php @@ -81,9 +81,9 @@ class Typo3Update_Sniffs_Deprecated_AjaxRegistrationSniff implements PhpCsSniff } $phpcsFile->addWarning( - "Defining AJAX using %s is no longer supported with a single String like %s.\n" - . "Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests.\n" - . 'See: %s', + 'Defining AJAX using %s is no longer supported with a single String like %s.' + . ' Since TYPO3 7.6, use PSR-7-based Routing for Backend AJAX Requests.' + . ' See: %s', $tokenToCheck, '', [ diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index d6cd39a..9dac445 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -101,9 +101,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni $functionCall = $token['content']; $phpcsFile->addWarning( - "Legacy function calls are not allowed; found %s.\n" - . "%s.\n" - . "See: %s", + 'Legacy function calls are not allowed; found %s. %s. See: %s', $tokenPosition, $functionCall, [ From cd434ac6398d3e256dc3fee0e17c931ec158adc4 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 12:52:14 +0200 Subject: [PATCH 21/34] WIP|FEATURE: Provide configuration files for deprecated functions * To provide a way to adjust deprecations without touching standard. * Provide an option defining the path to lookup the configuration files. * Parse yaml files containing deprecations. Relates: #33 --- composer.json | 3 +- .../Deprecated/Functions/7.0.yaml | 114 ++++++++++++++++++ .../Deprecated/GenericFunctionCallSniff.php | 40 ++++-- .../Typo3Update/Sniffs/OptionsAccessTrait.php | 17 +++ 4 files changed, 162 insertions(+), 12 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml diff --git a/composer.json b/composer.json index 4f488fb..2a3c23e 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ } }, "require": { - "squizlabs/php_codesniffer": "2.8.*" + "squizlabs/php_codesniffer": "2.8.*", + "symfony/yaml": "3.2.*" }, "license": "GPL-2.0+", "authors": [ diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml new file mode 100644 index 0000000..f01183a --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml @@ -0,0 +1,114 @@ +# Deprecated in 7.0: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Index.html#breaking-changes +loadTCA: + oldFunctionCall: '\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-LoadTcaFunctionRemoved.html' +getCompressedTCarray: + oldFunctionCall: '\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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' +includeTCA: + oldFunctionCall: '\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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' +mail: + oldFunctionCall: 'MailUtility::mail()' + newFunctionCall: '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' +plainMailEncoded: + oldFunctionCall: 'GeneralUtility::plainMailEncoded()' + newFunctionCall: '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' +connectDB: + oldFunctionCall: '\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61863-ConnectDbFunctionRemoved.html' +int_from_ver: + oldFunctionCall: '\TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver' + newFunctionCall: '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' +getUniqueFields: + oldFunctionCall: '\TYPO3\CMS\Core\DataHandling\DataHandler::getUniqueFields()' + newFunctionCall: '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' +isSafeModeEnabled: + oldFunctionCall: '\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +isMagicQuotesGpcEnabled: + oldFunctionCall: '\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +isLocalconfWritable: + oldFunctionCall: '\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61802-IsLocalconfWritableFunctionRemoved.html' +create: + oldFunctionCall: 'ObjectManager::create()' + newFunctionCall: 'Use ObjectManager::get() instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# TODO: Find a way to make same method name in different classes work. +# create: +# oldFunctionCall: 'ObjectManagerInterface::create()' +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +replaceObject: + oldFunctionCall: 'PersistenceGenericBackend::replaceObject()' + newFunctionCall: 'Removed without replacement' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +setReturnRawQueryResult: + oldFunctionCall: 'QuerySettingsInterface::setReturnRawQueryResult()' + newFunctionCall: 'Removed without replacement' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +getReturnRawQueryResult: + oldFunctionCall: 'QuerySettingsInterface::getReturnRawQueryResult()' + newFunctionCall: 'Use the parameter on $query->execute() directly' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +setSysLanguageUid: + oldFunctionCall: 'Typo3QuerySettings::setSysLanguageUid()' + newFunctionCall: 'Use setLanguageUid() instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +getSysLanguageUid: + oldFunctionCall: 'Typo3QuerySettings::getSysLanguageUid()' + newFunctionCall: 'Use getLanguageUid() instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +JScharCode: + oldFunctionCall: 'LanguageService::JScharCode()' + newFunctionCall: 'Use GeneralUtility::quoteJSvalue instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +joinTSarrays: + oldFunctionCall: 'ContentObjectRenderer::joinTSarrays()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +tidyHTML: + oldFunctionCall: 'TypoScriptFrontendController::tidyHTML()' + newFunctionCall: 'You may use the tidy extension from TER' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +isWebFolder: + oldFunctionCall: 'ElementBrowser::isWebFolder()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +checkFolder: + oldFunctionCall: 'ElementBrowser::checkFolder()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +getTreeObject: + oldFunctionCall: 'AbstractDatabaseRecordList::getTreeObject()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +dirData: + oldFunctionCall: 'FileList::dirData()' + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +stdWrapValue: + oldFunctionCall: 'FilesContentObject::stdWrapValue()' + newFunctionCall: 'Use ContentObjectRenderer::stdWrapValue instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +userTempFolder: + oldFunctionCall: 'ImportExportController::userTempFolder()' + newFunctionCall: 'Use getDefaultImportExportFolder instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +userSaveFolder: + oldFunctionCall: 'ImportExportController::userSaveFolder()' + newFunctionCall: 'Use getDefaultImportExportFolder instead' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index 9dac445..ff02b8d 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -22,6 +22,7 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; use PHP_CodeSniffer_Tokens as Tokens; +use Symfony\Component\Yaml\Yaml; /** * Sniff that handles all calls to deprecated functions. @@ -31,21 +32,31 @@ use PHP_CodeSniffer_Tokens as Tokens; class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSniff { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; + use \Typo3Update\Sniffs\OptionsAccessTrait; /** * Configuration to define deprecated functions. * * Keys have to match the function name. * + * TODO: Multiple files allowed, using glob ... to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... + * TODO: Build necessary structure from that files, to make it more independent ... ?! + * * @var array */ - protected $deprecatedFunctions = [ - 'loadTCA' => [ - 'oldFunctionCall' => '\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA()', - 'newFunctionCall' => null, - 'docsUrl' => 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-LoadTcaFunctionRemoved.html', - ], - ]; + protected static $deprecatedFunctions = []; + + public function __construct() + { + if (static::$deprecatedFunctions === []) { + foreach ($this->getDeprecatedFunctionConfigFiles() as $file) { + static::$deprecatedFunctions = array_merge( + static::$deprecatedFunctions, + Yaml::parse(file_get_contents((string) $file)) + ); + } + } + } /** * Returns the token types that this sniff is interested in. @@ -83,6 +94,13 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni return; } + // TODO: Check if function is static and whether last class name part matches. + // TODO: Add new property to array "last class name part" and use for check if exists. + // TODO: How to handle methods? They are not static, are behind a variable or something else ... + + // E.g.: getUniqueFields + // E.g.: mail + $this->addWarning($phpcsFile, $stackPtr); } @@ -120,7 +138,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getFunctionNames() { - return array_keys($this->deprecatedFunctions); + return array_keys(static::$deprecatedFunctions); } /** @@ -134,7 +152,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getOldFunctionCall($functionName) { - return $this->deprecatedFunctions[$functionName]['oldFunctionCall']; + return static::$deprecatedFunctions[$functionName]['oldFunctionCall']; } /** @@ -146,7 +164,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getNewFunctionCall($functionName) { - $newCall = $this->deprecatedFunctions[$functionName]['newFunctionCall']; + $newCall = static::$deprecatedFunctions[$functionName]['newFunctionCall']; if ($newCall !== null) { return $newCall; } @@ -160,6 +178,6 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getDocsUrl($functionName) { - return $this->deprecatedFunctions[$functionName]['docsUrl']; + return static::$deprecatedFunctions[$functionName]['docsUrl']; } } diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php index 7193e07..93c6745 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -54,4 +54,21 @@ trait OptionsAccessTrait } return $mappingFile; } + + /** + * Returns an array of absolute file names containing deprecation function configurations. + * + * @return \Generator + */ + public function getDeprecatedFunctionConfigFiles() + { + $configFiles = PhpCs::getConfigData('deprecatedfunctionConfigFiles'); + if (!$configFiles) { + $configFiles = __DIR__ . '/../Configuration/Deprecated/Functions/*.yaml'; + } + + foreach ((new \GlobIterator($configFiles)) as $file) { + yield (string) $file; + } + } } From b652137e96a7231c2d1e1c2e0c5d0db70f6b393c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 15:29:26 +0200 Subject: [PATCH 22/34] FEATURE: Provide code to handle deprecated method calls * Add parsing of YAML-files. * Check matching deprecated calls. * Provide necessary information for PHPCS and user. Relates: #33 --- .../Deprecated/Functions/7.0.yaml | 169 ++++++++--------- .../Deprecated/GenericFunctionCallSniff.php | 170 ++++++++++++++---- 2 files changed, 205 insertions(+), 134 deletions(-) diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml index f01183a..4a56a00 100644 --- a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml @@ -1,114 +1,85 @@ # Deprecated in 7.0: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Index.html#breaking-changes -loadTCA: - oldFunctionCall: '\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA()' +\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA: newFunctionCall: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-LoadTcaFunctionRemoved.html' -getCompressedTCarray: - oldFunctionCall: '\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::getCompressedTCarray()' +\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' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' -includeTCA: - oldFunctionCall: '\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::includeTCA()' +\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' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61785-FrontendTcaFunctionsRemoved.html' -mail: - oldFunctionCall: 'MailUtility::mail()' +\TYPO3\CMS\Core\Utility\MailUtility::mail: newFunctionCall: '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' -plainMailEncoded: - oldFunctionCall: 'GeneralUtility::plainMailEncoded()' +\TYPO3\CMS\Core\Utility\GeneralUtility::plainMailEncoded: newFunctionCall: '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' -connectDB: - oldFunctionCall: '\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB()' +\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB: newFunctionCall: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61863-ConnectDbFunctionRemoved.html' -int_from_ver: - oldFunctionCall: '\TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver' - newFunctionCall: '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' -getUniqueFields: - oldFunctionCall: '\TYPO3\CMS\Core\DataHandling\DataHandler::getUniqueFields()' - newFunctionCall: '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' -isSafeModeEnabled: - oldFunctionCall: '\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -isMagicQuotesGpcEnabled: - oldFunctionCall: '\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -isLocalconfWritable: - oldFunctionCall: '\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61802-IsLocalconfWritableFunctionRemoved.html' -create: - oldFunctionCall: 'ObjectManager::create()' - newFunctionCall: 'Use ObjectManager::get() instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# TODO: Find a way to make same method name in different classes work. -# create: -# oldFunctionCall: 'ObjectManagerInterface::create()' +# int_from_ver: +# newFunctionCall: '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' +# getUniqueFields: +# newFunctionCall: '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' +# isSafeModeEnabled: # newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +# isMagicQuotesGpcEnabled: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +# isLocalconfWritable: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61802-IsLocalconfWritableFunctionRemoved.html' +# create: +# newFunctionCall: 'Use ObjectManager::get() instead' # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -replaceObject: - oldFunctionCall: 'PersistenceGenericBackend::replaceObject()' - newFunctionCall: 'Removed without replacement' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -setReturnRawQueryResult: - oldFunctionCall: 'QuerySettingsInterface::setReturnRawQueryResult()' - newFunctionCall: 'Removed without replacement' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -getReturnRawQueryResult: - oldFunctionCall: 'QuerySettingsInterface::getReturnRawQueryResult()' - newFunctionCall: 'Use the parameter on $query->execute() directly' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -setSysLanguageUid: - oldFunctionCall: 'Typo3QuerySettings::setSysLanguageUid()' - newFunctionCall: 'Use setLanguageUid() instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -getSysLanguageUid: - oldFunctionCall: 'Typo3QuerySettings::getSysLanguageUid()' - newFunctionCall: 'Use getLanguageUid() instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -JScharCode: - oldFunctionCall: 'LanguageService::JScharCode()' - newFunctionCall: 'Use GeneralUtility::quoteJSvalue instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -joinTSarrays: - oldFunctionCall: 'ContentObjectRenderer::joinTSarrays()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -tidyHTML: - oldFunctionCall: 'TypoScriptFrontendController::tidyHTML()' - newFunctionCall: 'You may use the tidy extension from TER' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -isWebFolder: - oldFunctionCall: 'ElementBrowser::isWebFolder()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -checkFolder: - oldFunctionCall: 'ElementBrowser::checkFolder()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -getTreeObject: - oldFunctionCall: 'AbstractDatabaseRecordList::getTreeObject()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -dirData: - oldFunctionCall: 'FileList::dirData()' - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -stdWrapValue: - oldFunctionCall: 'FilesContentObject::stdWrapValue()' - newFunctionCall: 'Use ContentObjectRenderer::stdWrapValue instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -userTempFolder: - oldFunctionCall: 'ImportExportController::userTempFolder()' - newFunctionCall: 'Use getDefaultImportExportFolder instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -userSaveFolder: - oldFunctionCall: 'ImportExportController::userSaveFolder()' - newFunctionCall: 'Use getDefaultImportExportFolder instead' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# # create: +# # newFunctionCall: null +# # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# replaceObject: +# newFunctionCall: 'Removed without replacement' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# setReturnRawQueryResult: +# newFunctionCall: 'Removed without replacement' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# getReturnRawQueryResult: +# newFunctionCall: 'Use the parameter on $query->execute() directly' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# setSysLanguageUid: +# newFunctionCall: 'Use setLanguageUid() instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# getSysLanguageUid: +# newFunctionCall: 'Use getLanguageUid() instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' +# JScharCode: +# newFunctionCall: 'Use GeneralUtility::quoteJSvalue instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# joinTSarrays: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# tidyHTML: +# newFunctionCall: 'You may use the tidy extension from TER' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# isWebFolder: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# checkFolder: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# getTreeObject: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# dirData: +# newFunctionCall: null +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# stdWrapValue: +# newFunctionCall: 'Use ContentObjectRenderer::stdWrapValue instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# userTempFolder: +# newFunctionCall: 'Use getDefaultImportExportFolder instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +# userSaveFolder: +# newFunctionCall: 'Use getDefaultImportExportFolder instead' +# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index ff02b8d..895332f 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -37,27 +37,59 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni /** * Configuration to define deprecated functions. * - * Keys have to match the function name. - * - * TODO: Multiple files allowed, using glob ... to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... - * TODO: Build necessary structure from that files, to make it more independent ... ?! - * * @var array */ protected static $deprecatedFunctions = []; + /** + * Function for the current sniff instance. + * @var array + */ + private $deprecatedFunction = []; + + /** + * 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::$deprecatedFunctions === []) { foreach ($this->getDeprecatedFunctionConfigFiles() as $file) { static::$deprecatedFunctions = array_merge( static::$deprecatedFunctions, - Yaml::parse(file_get_contents((string) $file)) + $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) ); } } } + /** + * Prepares structure from config for later usage. + * + * @param array $deprecatedFunctions + * @return array + */ + protected function prepareStructure(array $deprecatedFunctions) + { + array_walk($deprecatedFunctions, function (&$config, $function) { + // Split static methods and methods. + $split = preg_split('/::|->/', $function); + + $config['static'] = strpos($function, '::') !== false; + $config['fqcn'] = null; + $config['class'] = null; + $config['function'] = $split[0]; + + // If split contains two parts, it's a class with method + if (isset($split[1])) { + $config['fqcn'] = $split[0]; + $config['class'] = array_slice(explode('\\', $config['fqcn']), -1)[0]; + $config['function'] = $split[1]; + } + }); + + return $deprecatedFunctions; + } + /** * Returns the token types that this sniff is interested in. * @@ -83,25 +115,92 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ public function process(PhpCsFile $phpcsFile, $stackPtr) { - if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { + if (!$this->isFunctionCallDeprecated($phpcsFile, $stackPtr)) { return; } + $this->addWarning($phpcsFile, $stackPtr); + } + + /** + * Check whether function at given point is deprecated. + * + * @return bool + */ + protected function isFunctionCallDeprecated(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { + return false; + } + $tokens = $phpcsFile->getTokens(); - $token = $tokens[$stackPtr]; + $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); - if (in_array($token['content'], $this->getFunctionNames()) === false) { - return; + $functionName = $tokens[$stackPtr]['content']; + $isStatic = false; + $class = false; + + if ($staticPosition !== false) { + $isStatic = $tokens[$staticPosition]['code'] === T_DOUBLE_COLON; } - // TODO: Check if function is static and whether last class name part matches. - // TODO: Add new property to array "last class name part" and use for check if exists. - // TODO: How to handle methods? They are not static, are behind a variable or something else ... + if ($isStatic) { + $class = $phpcsFile->findPrevious(T_STRING, $staticPosition, null, false, null, true); + if ($class !== false) { + $class = $tokens[$class]['content']; + } + } - // E.g.: getUniqueFields - // E.g.: mail + return $this->getDeprecatedFunction($functionName, $class, $isStatic) !== []; + } - $this->addWarning($phpcsFile, $stackPtr); + /** + * Returns all matching deprecated functions for given arguments. + * + * Also prepares functions for later usages in $this->deprecatedFunction. + * + * @param string $functionName + * @param string $className The last part of the class name, splitted by namespaces. + * @param bool $isStatic + * + * @return array + */ + protected function getDeprecatedFunction($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 []; + } + + $this->deprecatedFunction = array_filter( + static::$deprecatedFunctions, + function ($config) use ($functionName, $isStatic, $className) { + return $functionName === $config['function'] + && $isStatic === $config['static'] + && ( + $className === $config['class'] + || $className === false + ) // TODO: If no class, it's also fine, vor variable, non static methods. + ; + } + ); + + return $this->deprecatedFunction; + } + + /** + * Returns configuration for currently checked function. + * + * @return array + */ + protected function getCurrentDeprecatedFunction() + { + $config = current($this->deprecatedFunction); + + // TODO: Add exception if something went wrong? + + return $config; } /** @@ -114,31 +213,27 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) { - $tokens = $phpcsFile->getTokens(); - $token = $tokens[$tokenPosition]; - $functionCall = $token['content']; - $phpcsFile->addWarning( 'Legacy function calls are not allowed; found %s. %s. See: %s', $tokenPosition, - $functionCall, + $this->getFunctionIdentifier(), [ - $this->getOldFunctionCall($functionCall), - $this->getNewFunctionCall($functionCall), - $this->getDocsUrl($functionCall), + $this->getOldfunctionCall(), + $this->getNewFunctionCall(), + $this->getDocsUrl(), ] ); } /** - * Provide all function names that are deprecated and should be handled by - * the Sniff. + * Identifier for configuring this specific error / warning through PHPCS. * - * @return array + * @return string */ - protected function getFunctionNames() + protected function getFunctionIdentifier() { - return array_keys(static::$deprecatedFunctions); + $config = $this->getCurrentDeprecatedFunction(); + return $config['class'] . '.' . $config['function']; } /** @@ -150,9 +245,14 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * * @return string */ - protected function getOldFunctionCall($functionName) + protected function getOldFunctionCall() { - return static::$deprecatedFunctions[$functionName]['oldFunctionCall']; + $config = $this->getCurrentDeprecatedFunction(); + $concat = '->'; + if ($config['static']) { + $concat = '::'; + } + return $config['fqcn'] . $concat . $config['function']; } /** @@ -162,9 +262,9 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * * @return string */ - protected function getNewFunctionCall($functionName) + protected function getNewFunctionCall() { - $newCall = static::$deprecatedFunctions[$functionName]['newFunctionCall']; + $newCall = $this->getCurrentDeprecatedFunction()['newFunctionCall']; if ($newCall !== null) { return $newCall; } @@ -176,8 +276,8 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * * @return string */ - protected function getDocsUrl($functionName) + protected function getDocsUrl() { - return static::$deprecatedFunctions[$functionName]['docsUrl']; + return $this->getCurrentDeprecatedFunction()['docsUrl']; } } From 81fc7f7608e00547cee88d16a4221bb792205606 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 28 Mar 2017 16:41:15 +0200 Subject: [PATCH 23/34] WIP|FEATURE: Add further deprecated calls * Configure further deprecated calls for TYPO3 7.0 * Remove todo as it's already done. Relates: #33 --- .../Deprecated/Functions/7.0.yaml | 217 ++++++++++++------ .../Deprecated/GenericFunctionCallSniff.php | 2 +- 2 files changed, 152 insertions(+), 67 deletions(-) diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml index 4a56a00..0cd9429 100644 --- a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml @@ -17,69 +17,154 @@ \TYPO3\CMS\Frontend\Utility\EidUtility::connectDB: newFunctionCall: null docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61863-ConnectDbFunctionRemoved.html' -# int_from_ver: -# newFunctionCall: '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' -# getUniqueFields: -# newFunctionCall: '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' -# isSafeModeEnabled: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -# isMagicQuotesGpcEnabled: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -# isLocalconfWritable: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61802-IsLocalconfWritableFunctionRemoved.html' -# create: -# newFunctionCall: 'Use ObjectManager::get() instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# # create: -# # newFunctionCall: null -# # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# replaceObject: -# newFunctionCall: 'Removed without replacement' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# setReturnRawQueryResult: -# newFunctionCall: 'Removed without replacement' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# getReturnRawQueryResult: -# newFunctionCall: 'Use the parameter on $query->execute() directly' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# setSysLanguageUid: -# newFunctionCall: 'Use setLanguageUid() instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# getSysLanguageUid: -# newFunctionCall: 'Use getLanguageUid() instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62673-ExtbaseDeprecatedCodeRemoved.html' -# JScharCode: -# newFunctionCall: 'Use GeneralUtility::quoteJSvalue instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# joinTSarrays: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# tidyHTML: -# newFunctionCall: 'You may use the tidy extension from TER' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# isWebFolder: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# checkFolder: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# getTreeObject: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# dirData: -# newFunctionCall: null -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# stdWrapValue: -# newFunctionCall: 'Use ContentObjectRenderer::stdWrapValue instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# userTempFolder: -# newFunctionCall: 'Use getDefaultImportExportFolder instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -# userSaveFolder: -# newFunctionCall: 'Use getDefaultImportExportFolder instead' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Core\Utility\GeneralUtility::int_from_ver: + newFunctionCall: '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()' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61822-GetUniqueFieldsFunctionRemoved.html' +\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable: + newFunctionCall: 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' + 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' + 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' + 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' + 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Frontend\ContentObjec\ContentObjectRenderer->joinTSarrays: + newFunctionCall: 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Recordlist\Browser\ElementBrowser->isWebFolder: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Recordlist\Browser\ElementBrowser->checkFolder: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList->getTreeObject: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Filelist\FileList->dirData: + newFunctionCall: 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->func_filesearch: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->findFile: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->buildStyleSheet: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->loremIpsumInsert: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' +\TYPO3\CMS\Workspaces\Service\StagesService->checkCustomStagingForWS: + newFunctionCall: 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' + 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +# TODO: This is useless, adding a warning to all "get" methods is crazy. +# \TYPO3\CMS\Core\Category\CategoryRegistry->get: +# newFunctionCall: '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 + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Resource\FileRepository->findByUid: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Resource\FileRepository->addToIndex: + newFunctionCall: 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Resource\FileRepository->update: + newFunctionCall: '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' + 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' + 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' + 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' + 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' + 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()" + 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()" + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\File\BasicFileUtility->blindPath: + newFunctionCall: 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 + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\File\BasicFileUtility->rmDoubleSlash: + newFunctionCall: 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index 895332f..a4c7330 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -181,7 +181,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni && ( $className === $config['class'] || $className === false - ) // TODO: If no class, it's also fine, vor variable, non static methods. + ) ; } ); From 4c162af3d49987cf6a9a6dde66fb8d6fdcd18fff Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 08:08:41 +0200 Subject: [PATCH 24/34] TASK: Finish 7.0 breaking changes --- .../Deprecated/Functions/7.0.yaml | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml index 0cd9429..05105d1 100644 --- a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml @@ -108,6 +108,7 @@ newFunctionCall: 'Use native PHP htmlspecialchars_decode() function' docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' # TODO: 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' # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' @@ -168,3 +169,45 @@ \TYPO3\CMS\Core\Utility\File\BasicFileUtility->cleanDirectoryName: newFunctionCall: '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' + 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' + 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' + 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" + 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" + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Localization\Locales->getTerLocales: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Localization\Locales->getTerLocaleDependencies: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Localization\Locales->convertToTerLocales: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getInsertionNeedles: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getRequiredExtensionListArray: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::writeNewExtensionList: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSqlSafeModeEnabled: + newFunctionCall: 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' From 21b7c09416f35ce89e320d98aa77a85f21a570b2 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 11:03:30 +0200 Subject: [PATCH 25/34] FEATURE: Add removed functions for TYPO3 7.x. * Adjust structure of deprecated functions yaml. * Add version of removal to message for removed functions. Relates: #33 --- .../Deprecated/Functions/7.0.yaml | 431 +++++++++--------- .../Deprecated/Functions/7.1.yaml | 4 + .../Deprecated/Functions/7.2.yaml | 36 ++ .../Deprecated/Functions/7.3.yaml | 13 + .../Deprecated/Functions/7.4.yaml | 81 ++++ .../Deprecated/Functions/7.5.yaml | 2 + .../Deprecated/GenericFunctionCallSniff.php | 58 ++- 7 files changed, 395 insertions(+), 230 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml index 05105d1..3913b8c 100644 --- a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml @@ -1,213 +1,218 @@ -# Deprecated in 7.0: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Index.html#breaking-changes -\TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA: - newFunctionCall: 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' - 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' - 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' - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61783-RemoveDeprecatedMailFunctionality.html' -\TYPO3\CMS\Frontend\Utility\EidUtility::connectDB: - newFunctionCall: 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()' - 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()' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61822-GetUniqueFieldsFunctionRemoved.html' -\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable: - newFunctionCall: 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' - 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' - 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' - 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' - 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' - 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' - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Frontend\ContentObjec\ContentObjectRenderer->joinTSarrays: - newFunctionCall: 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Recordlist\Browser\ElementBrowser->isWebFolder: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Recordlist\Browser\ElementBrowser->checkFolder: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList->getTreeObject: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Filelist\FileList->dirData: - newFunctionCall: 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' - 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' - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->func_filesearch: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->findFile: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->buildStyleSheet: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->loremIpsumInsert: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' -\TYPO3\CMS\Workspaces\Service\StagesService->checkCustomStagingForWS: - newFunctionCall: 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' - 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' - 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' - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -# TODO: 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' -# docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Category\CategoryRegistry->applyTca: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Resource\FileRepository->findByUid: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Resource\FileRepository->addToIndex: - newFunctionCall: 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' - 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' - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Resource\FileRepository->update: - newFunctionCall: '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' - 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' - 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' - 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' - 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' - 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()" - 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()" - 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\File\BasicFileUtility->blindPath: - newFunctionCall: 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 - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\File\BasicFileUtility->rmDoubleSlash: - newFunctionCall: 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' - 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' - 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' - 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' - 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" - 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" - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Localization\Locales->getTerLocales: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Localization\Locales->getTerLocaleDependencies: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Localization\Locales->convertToTerLocales: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getInsertionNeedles: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getRequiredExtensionListArray: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::writeNewExtensionList: - newFunctionCall: null - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' -\TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSqlSafeModeEnabled: - newFunctionCall: 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' - docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' +# 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 + 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' + 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61783-RemoveDeprecatedMailFunctionality.html' + \TYPO3\CMS\Frontend\Utility\EidUtility::connectDB: + newFunctionCall: 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()' + 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()' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61822-GetUniqueFieldsFunctionRemoved.html' + \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSafeModeEnabled: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' + \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isMagicQuotesGpcEnabled: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-61820-PhpOptionsUtilityDeprecatedFunctionsRemoved.html' + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLocalconfWritable: + newFunctionCall: 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' + 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' + 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' + 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' + 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Frontend\ContentObjec\ContentObjectRenderer->joinTSarrays: + newFunctionCall: 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Recordlist\Browser\ElementBrowser->isWebFolder: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Recordlist\Browser\ElementBrowser->checkFolder: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Recordlist\RecordList\AbstractDatabaseRecordList->getTreeObject: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Filelist\FileList->dirData: + newFunctionCall: 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' + 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' + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->func_filesearch: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Lowlevel\View\DatabaseIntegrityView->findFile: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->buildStyleSheet: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Rtehtmlarea\RteHtmlAreaBase->loremIpsumInsert: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62670-DeprecatedCodeRemovalInMultipleSysexts.html' + \TYPO3\CMS\Workspaces\Service\StagesService->checkCustomStagingForWS: + newFunctionCall: 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' + 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' + 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' + 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' + 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' + # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Category\CategoryRegistry->applyTca: + newFunctionCall: 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 + # docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Resource\FileRepository->addToIndex: + newFunctionCall: 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' + 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' + 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' + 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' + # 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' + 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' + 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' + 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' + 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' + 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()" + 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()" + 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\File\BasicFileUtility->blindPath: + newFunctionCall: 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 + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\File\BasicFileUtility->rmDoubleSlash: + newFunctionCall: 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' + 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' + 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' + 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' + 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" + 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" + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Localization\Locales->getTerLocales: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Localization\Locales->getTerLocaleDependencies: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Localization\Locales->convertToTerLocales: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getInsertionNeedles: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::insertModuleFunction: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getRequiredExtensionListArray: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::writeNewExtensionList: + newFunctionCall: null + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' + \TYPO3\CMS\Core\Utility\PhpOptionsUtility::isSqlSafeModeEnabled: + newFunctionCall: 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' + docsUrl: 'https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.0/Breaking-62416-DeprecatedCodeRemovalInCoreSysext.html' diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml new file mode 100644 index 0000000..f1184a1 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml @@ -0,0 +1,4 @@ +# Breaking changes in 7.1: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.1/Index.html +# Nothing in here? Right, there were no breaking changes to functions in this version. +# We keep this file to let you know we didn't forget anything. +'7.1': [] diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml new file mode 100644 index 0000000..d1cb239 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml @@ -0,0 +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' + 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' + 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' + 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' + 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' + 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' + 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' + 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' + 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' + 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' + 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' +# docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml new file mode 100644 index 0000000..15ff9b8 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml @@ -0,0 +1,13 @@ +# Breaking changes in 7.3: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Index.html#breaking-changes +'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.' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Breaking-67402-ExtbaseAbstractDomainObjectInitializeObject.html + \TYPO3\CMS\Extbase\Persistence\Repository::replace: + newFunctionCall: 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 + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.3/Breaking-63835-RemoveDeprecatedExtbasePersistenceParts.html + diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml new file mode 100644 index 0000000..ee9bbd5 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml @@ -0,0 +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 + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html + \TYPO3\CMS\Core\Page\PageRenderer::getExtCorePath: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html + \TYPO3\CMS\Core\Page\PageRenderer::loadExtCore: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html + \TYPO3\CMS\Core\Page\PageRenderer::enableExtCoreDebug: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html + \TYPO3\CMS\Core\Page\PageRenderer::setExtCorePath: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68001-RemovedExtJSCoreAndExtJSAdapters.html + \TYPO3\CMS\Backend\Controller\EditDocumentController->functionMenus: + newFunctionCall: 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' + 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' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67646-LibraryInclusionInFrontend.html + \TYPO3\CMS\Backend\Template\DocumentTemplate\DocumentTemplate->formWidthText: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html + \TYPO3\CMS\Backend\View\PageLayoutView->getBackendLayoutConfiguration: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html + \TYPO3\CMS\Backend\View\PageLayoutView->wordWrapper: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-67565-DeprecatedBackendRelatedMethodsRemoved.html + \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController->checkJumpUrlReferer: + newFunctionCall: 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' + 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' + 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' + 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' + 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' + 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' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68276-RemoveExtJSQuicktipsIfPossible.html + \TYPO3\CMS\IndexedSearch\Indexer->removeLoginpagesWithContentHash: + newFunctionCall: 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' + 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' + # 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' + 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' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68186-AdjustedAndRemovedMethodsInEIDArea.html + \TYPO3\CMS\Backend\View\PageLayoutView->linkRTEbutton: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html + \TYPO3\CMS\Backend\View\PageLayoutView->isRTEforField: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html + \TYPO3\CMS\Backend\View\PageLayoutView->getSpecConfForField: + newFunctionCall: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.4/Breaking-68020-DroppedDisableBigButtons.html diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml new file mode 100644 index 0000000..a8e1483 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml @@ -0,0 +1,2 @@ +# Breaking changes in 7.5: https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.5/Index.html#breaking-changes +'7.5': [] diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php index a4c7330..f2f616b 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php @@ -68,26 +68,35 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * @param array $deprecatedFunctions * @return array */ - protected function prepareStructure(array $deprecatedFunctions) + protected function prepareStructure(array $oldStructure) { - array_walk($deprecatedFunctions, function (&$config, $function) { - // Split static methods and methods. - $split = preg_split('/::|->/', $function); + $typo3Versions = array_keys($oldStructure); + $newStructure = []; - $config['static'] = strpos($function, '::') !== false; - $config['fqcn'] = null; - $config['class'] = null; - $config['function'] = $split[0]; + foreach ($typo3Versions as $typo3Version) { + foreach ($oldStructure[$typo3Version] as $function => $config) { + // Split static methods and methods. + $split = preg_split('/::|->/', $function); - // If split contains two parts, it's a class with method - if (isset($split[1])) { - $config['fqcn'] = $split[0]; - $config['class'] = array_slice(explode('\\', $config['fqcn']), -1)[0]; - $config['function'] = $split[1]; - } - }); + $newStructure[$function] = $config; - return $deprecatedFunctions; + $newStructure[$function]['static'] = strpos($function, '::') !== false; + $newStructure[$function]['fqcn'] = null; + $newStructure[$function]['class'] = null; + $newStructure[$function]['function'] = $split[0]; + // TODO: Add a way to check for removed or deprecated. + $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; } /** @@ -214,11 +223,14 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) { $phpcsFile->addWarning( - 'Legacy function calls are not allowed; found %s. %s. See: %s', + // TODO: Add a way to check for removed or deprecated. + 'Legacy function calls are not allowed; found %s. Removed in %s. %s. See: %s', $tokenPosition, $this->getFunctionIdentifier(), [ $this->getOldfunctionCall(), + // TODO: Add a way to check for removed or deprecated. + $this->getRemovedVersion(), $this->getNewFunctionCall(), $this->getDocsUrl(), ] @@ -255,6 +267,18 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni 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. + * + * @return string + */ + protected function getRemovedVersion() + { + return $this->getCurrentDeprecatedFunction()['version_removed']; + } + /** * The new function call, or information how to migrate. * From 93c0cff635bc27ee24a7ca388b92725fa998f9cc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 11:08:42 +0200 Subject: [PATCH 26/34] TASK: Rename deprecated to removed for functions * As we check removed functions, the folder and code should reflect that. Relates: #33 --- .../Functions/7.0.yaml | 0 .../Functions/7.1.yaml | 0 .../Functions/7.2.yaml | 0 .../Functions/7.3.yaml | 0 .../Functions/7.4.yaml | 0 .../Functions/7.5.yaml | 0 .../Typo3Update/Sniffs/OptionsAccessTrait.php | 8 +-- .../GenericFunctionCallSniff.php | 59 +++++++++---------- 8 files changed, 32 insertions(+), 35 deletions(-) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.0.yaml (100%) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.1.yaml (100%) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.2.yaml (100%) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.3.yaml (100%) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.4.yaml (100%) rename src/Standards/Typo3Update/Configuration/{Deprecated => Removed}/Functions/7.5.yaml (100%) rename src/Standards/Typo3Update/Sniffs/{Deprecated => Removed}/GenericFunctionCallSniff.php (80%) diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.0.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.0.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.1.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.1.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.1.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.2.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.2.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.3.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.3.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.4.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.4.yaml diff --git a/src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml b/src/Standards/Typo3Update/Configuration/Removed/Functions/7.5.yaml similarity index 100% rename from src/Standards/Typo3Update/Configuration/Deprecated/Functions/7.5.yaml rename to src/Standards/Typo3Update/Configuration/Removed/Functions/7.5.yaml diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php index 93c6745..9db7ee7 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -56,15 +56,15 @@ trait OptionsAccessTrait } /** - * Returns an array of absolute file names containing deprecation function configurations. + * Returns an array of absolute file names containing removed function configurations. * * @return \Generator */ - public function getDeprecatedFunctionConfigFiles() + public function getRemovedFunctionConfigFiles() { - $configFiles = PhpCs::getConfigData('deprecatedfunctionConfigFiles'); + $configFiles = PhpCs::getConfigData('removedfunctionConfigFiles'); if (!$configFiles) { - $configFiles = __DIR__ . '/../Configuration/Deprecated/Functions/*.yaml'; + $configFiles = __DIR__ . '/../Configuration/Removed/Functions/*.yaml'; } foreach ((new \GlobIterator($configFiles)) as $file) { diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php similarity index 80% rename from src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php rename to src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index f2f616b..2a106de 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -25,37 +25,37 @@ use PHP_CodeSniffer_Tokens as Tokens; use Symfony\Component\Yaml\Yaml; /** - * Sniff that handles all calls to deprecated functions. + * Sniff that handles all calls to removed functions. * - * A single array defines the deprecations, see $deprecatedFunctions. + * A single array defines the deprecations, see $removedFunctions. */ -class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSniff +class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; use \Typo3Update\Sniffs\OptionsAccessTrait; /** - * Configuration to define deprecated functions. + * Configuration to define removed functions. * * @var array */ - protected static $deprecatedFunctions = []; + protected static $removedFunctions = []; /** * Function for the current sniff instance. * @var array */ - private $deprecatedFunction = []; + private $removedFunction = []; /** * 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::$deprecatedFunctions === []) { - foreach ($this->getDeprecatedFunctionConfigFiles() as $file) { - static::$deprecatedFunctions = array_merge( - static::$deprecatedFunctions, + if (static::$removedFunctions === []) { + foreach ($this->getRemovedFunctionConfigFiles() as $file) { + static::$removedFunctions = array_merge( + static::$removedFunctions, $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) ); } @@ -65,7 +65,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni /** * Prepares structure from config for later usage. * - * @param array $deprecatedFunctions + * @param array $removedFunctions * @return array */ protected function prepareStructure(array $oldStructure) @@ -84,7 +84,6 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni $newStructure[$function]['fqcn'] = null; $newStructure[$function]['class'] = null; $newStructure[$function]['function'] = $split[0]; - // TODO: Add a way to check for removed or deprecated. $newStructure[$function]['version_removed'] = $typo3Version; // If split contains two parts, it's a class with method @@ -124,7 +123,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ public function process(PhpCsFile $phpcsFile, $stackPtr) { - if (!$this->isFunctionCallDeprecated($phpcsFile, $stackPtr)) { + if (!$this->isFunctionCallRemoved($phpcsFile, $stackPtr)) { return; } @@ -132,11 +131,11 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni } /** - * Check whether function at given point is deprecated. + * Check whether function at given point is removed. * * @return bool */ - protected function isFunctionCallDeprecated(PhpCsFile $phpcsFile, $stackPtr) + protected function isFunctionCallRemoved(PhpCsFile $phpcsFile, $stackPtr) { if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { return false; @@ -160,13 +159,13 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni } } - return $this->getDeprecatedFunction($functionName, $class, $isStatic) !== []; + return $this->getRemovedFunction($functionName, $class, $isStatic) !== []; } /** - * Returns all matching deprecated functions for given arguments. + * Returns all matching removed functions for given arguments. * - * Also prepares functions for later usages in $this->deprecatedFunction. + * Also prepares functions for later usages in $this->removedFunction. * * @param string $functionName * @param string $className The last part of the class name, splitted by namespaces. @@ -174,7 +173,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * * @return array */ - protected function getDeprecatedFunction($functionName, $className, $isStatic) + protected function getRemovedFunction($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. @@ -182,8 +181,8 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni return []; } - $this->deprecatedFunction = array_filter( - static::$deprecatedFunctions, + $this->removedFunction = array_filter( + static::$removedFunctions, function ($config) use ($functionName, $isStatic, $className) { return $functionName === $config['function'] && $isStatic === $config['static'] @@ -195,7 +194,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni } ); - return $this->deprecatedFunction; + return $this->removedFunction; } /** @@ -203,9 +202,9 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni * * @return array */ - protected function getCurrentDeprecatedFunction() + protected function getCurrentRemovedFunction() { - $config = current($this->deprecatedFunction); + $config = current($this->removedFunction); // TODO: Add exception if something went wrong? @@ -223,13 +222,11 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) { $phpcsFile->addWarning( - // TODO: Add a way to check for removed or deprecated. 'Legacy function calls are not allowed; found %s. Removed in %s. %s. See: %s', $tokenPosition, $this->getFunctionIdentifier(), [ $this->getOldfunctionCall(), - // TODO: Add a way to check for removed or deprecated. $this->getRemovedVersion(), $this->getNewFunctionCall(), $this->getDocsUrl(), @@ -244,7 +241,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getFunctionIdentifier() { - $config = $this->getCurrentDeprecatedFunction(); + $config = $this->getCurrentRemovedFunction(); return $config['class'] . '.' . $config['function']; } @@ -259,7 +256,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getOldFunctionCall() { - $config = $this->getCurrentDeprecatedFunction(); + $config = $this->getCurrentRemovedFunction(); $concat = '->'; if ($config['static']) { $concat = '::'; @@ -276,7 +273,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getRemovedVersion() { - return $this->getCurrentDeprecatedFunction()['version_removed']; + return $this->getCurrentRemovedFunction()['version_removed']; } /** @@ -288,7 +285,7 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getNewFunctionCall() { - $newCall = $this->getCurrentDeprecatedFunction()['newFunctionCall']; + $newCall = $this->getCurrentRemovedFunction()['newFunctionCall']; if ($newCall !== null) { return $newCall; } @@ -302,6 +299,6 @@ class Typo3Update_Sniffs_Deprecated_GenericFunctionCallSniff implements PhpCsSni */ protected function getDocsUrl() { - return $this->getCurrentDeprecatedFunction()['docsUrl']; + return $this->getCurrentRemovedFunction()['docsUrl']; } } From 1c4fce23157263425dcb9e9c2a489f1c7ea7bd09 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 11:16:45 +0200 Subject: [PATCH 27/34] TASK: Adjust for CGL --- .../Sniffs/Deprecated/AjaxRegistrationSniff.php | 3 +++ .../Sniffs/Removed/GenericFunctionCallSniff.php | 10 +++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php index 603ea88..355e408 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php @@ -24,6 +24,9 @@ use PHP_CodeSniffer_Sniff as PhpCsSniff; use PHP_CodeSniffer_Tokens as PhpCsTokens; /** + * Analyses feature 6991. + * + * @see https://docs.typo3.org/typo3cms/extensions/core/Changelog/7.6/Feature-69916-PSR-7-basedRoutingForBackendAJAXRequests.html */ class Typo3Update_Sniffs_Deprecated_AjaxRegistrationSniff implements PhpCsSniff { diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 2a106de..7420a63 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -48,7 +48,8 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff private $removedFunction = []; /** - * TODO: Multiple files allowed, using glob ... to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... + * TODO: Multiple files allowed, using glob ... + * to allow splitting per ext (extbase, fluid, ...) and TYPO3 Version 7.1, 7.0, ... */ public function __construct() { @@ -65,7 +66,7 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff /** * Prepares structure from config for later usage. * - * @param array $removedFunctions + * @param array $oldStructure * @return array */ protected function prepareStructure(array $oldStructure) @@ -89,7 +90,10 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff // 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]['class'] = array_slice( + explode('\\', $newStructure[$function]['fqcn']), + -1 + )[0]; $newStructure[$function]['function'] = $split[1]; } }; From 56d692bac7ed2a60706c0d09837ac0dce75cc7fa Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 30 Mar 2017 13:18:18 +0200 Subject: [PATCH 28/34] TASK: Add missing docs * Add docs for new feature. Relates: #33 --- Readme.rst | 26 +++++++++++++++++++ .../Typo3Update/Sniffs/OptionsAccessTrait.php | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Readme.rst b/Readme.rst index a7a1243..e87a3a8 100644 --- a/Readme.rst +++ b/Readme.rst @@ -100,6 +100,14 @@ Also we check for the following deprecated calls: - Check for ``create`` on ``ObjectManager``, which is "stupid" just all ``create`` calls are marked with a warning. +Beside the features above which are covered by ``phpcs`` and phpcbf``, the following linting is also +available to generate a report of possible issues and during coding through ``phpcs``: + +- Check for usage of removed functions. + The functions are configured via yaml files. The location of them is configurable, default is + inside the standard itself, and we try to deliver all information. + For configuration options see ``removedFunctionConfigFiles``. + What does it look like? ======================= @@ -194,3 +202,21 @@ Example: .. code:: bash --runtime-set vendor YourVendor + +``removedFunctionConfigFiles`` + Configure your vendor through ``ruleset.xml`` or using ``--runtime-set``. Default is + ``Configuration/Removed/Functions/*.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 removedFunctionConfigFiles "/Some/Absolute/Path/*.yaml" diff --git a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php index 9db7ee7..9920467 100644 --- a/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php +++ b/src/Standards/Typo3Update/Sniffs/OptionsAccessTrait.php @@ -62,7 +62,7 @@ trait OptionsAccessTrait */ public function getRemovedFunctionConfigFiles() { - $configFiles = PhpCs::getConfigData('removedfunctionConfigFiles'); + $configFiles = PhpCs::getConfigData('removedFunctionConfigFiles'); if (!$configFiles) { $configFiles = __DIR__ . '/../Configuration/Removed/Functions/*.yaml'; } From aa8ffab3fa76030c41c464f0e66756536fd87acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Hu=CC=88rtgen?= Date: Thu, 30 Mar 2017 16:58:34 +0200 Subject: [PATCH 29/34] TASK: Rename removed function method --- .../Sniffs/Removed/GenericFunctionCallSniff.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 7420a63..8b97280 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -163,26 +163,26 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff } } - return $this->getRemovedFunction($functionName, $class, $isStatic) !== []; + $this->detectRemovedFunctions($functionName, $class, $isStatic) + + return $this->removedFunction !== []; } /** - * Returns all matching removed functions for given arguments. - * - * Also prepares functions for later usages in $this->removedFunction. + * Detect 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 array + * @return void */ - protected function getRemovedFunction($functionName, $className, $isStatic) + protected function detectRemovedFunctions($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; } $this->removedFunction = array_filter( @@ -197,8 +197,6 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff ; } ); - - return $this->removedFunction; } /** From 9c6085642e6d8233c25adad06ae27c9c7584656a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 08:12:14 +0200 Subject: [PATCH 30/34] BUGFIX: Respect double quotes for ajax deprecation Relates: #33 --- .../Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php index 355e408..14574ac 100644 --- a/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Deprecated/AjaxRegistrationSniff.php @@ -67,7 +67,7 @@ class Typo3Update_Sniffs_Deprecated_AjaxRegistrationSniff implements PhpCsSniff } $tokens = $phpcsFile->getTokens(); - if ($tokens[$stackPtr]['content'] !== "'AJAX'") { + if (preg_match('/"AJAX"|\'AJAX\'/', $tokens[$stackPtr]['content']) !== 1) { return; } $equalSign = $phpcsFile->findNext(T_EQUAL, $stackPtr, null, false, null, true); From 830584fa8788915e6330941c1f7f27f316ec8b8b Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 08:31:36 +0200 Subject: [PATCH 31/34] TASK: Improve docs --- .../Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 8b97280..706d892 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -27,7 +27,8 @@ use Symfony\Component\Yaml\Yaml; /** * Sniff that handles all calls to removed functions. * - * A single array defines the deprecations, see $removedFunctions. + * 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 { From 034ab57a34af371ee3325c7c92637d8b8833f7df Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 08:31:54 +0200 Subject: [PATCH 32/34] TASK: Skip unnecessary function call --- .../Removed/GenericFunctionCallSniff.php | 100 ++++++++---------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 706d892..b81ff7d 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -40,13 +40,13 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * * @var array */ - protected static $removedFunctions = []; + protected static $configuredFunctions = []; /** * Function for the current sniff instance. * @var array */ - private $removedFunction = []; + private $removedFunctions = []; /** * TODO: Multiple files allowed, using glob ... @@ -54,10 +54,10 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff */ public function __construct() { - if (static::$removedFunctions === []) { + if (static::$configuredFunctions === []) { foreach ($this->getRemovedFunctionConfigFiles() as $file) { - static::$removedFunctions = array_merge( - static::$removedFunctions, + static::$configuredFunctions = array_merge( + static::$configuredFunctions, $this->prepareStructure(Yaml::parse(file_get_contents((string) $file))) ); } @@ -67,16 +67,15 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff /** * Prepares structure from config for later usage. * - * @param array $oldStructure + * @param array $typo3Versions * @return array */ - protected function prepareStructure(array $oldStructure) + protected function prepareStructure(array $typo3Versions) { - $typo3Versions = array_keys($oldStructure); $newStructure = []; - foreach ($typo3Versions as $typo3Version) { - foreach ($oldStructure[$typo3Version] as $function => $config) { + foreach ($typo3Versions as $typo3Version => $functions) { + foreach ($functions as $function => $config) { // Split static methods and methods. $split = preg_split('/::|->/', $function); @@ -164,13 +163,12 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff } } - $this->detectRemovedFunctions($functionName, $class, $isStatic) - - return $this->removedFunction !== []; + $this->removedFunctions = $this->getMatchingRemovedFunctions($functionName, $class, $isStatic); + return $this->removedFunctions !== []; } /** - * Detect removed functions for given arguments. + * Returns all matching removed functions for given arguments. * * @param string $functionName * @param string $className The last part of the class name, splitted by namespaces. @@ -178,7 +176,7 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * * @return void */ - protected function detectRemovedFunctions($functionName, $className, $isStatic) + 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. @@ -186,8 +184,8 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff return; } - $this->removedFunction = array_filter( - static::$removedFunctions, + return array_filter( + static::$configuredFunctions, function ($config) use ($functionName, $isStatic, $className) { return $functionName === $config['function'] && $isStatic === $config['static'] @@ -195,25 +193,11 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff $className === $config['class'] || $className === false ) - ; + ; } ); } - /** - * Returns configuration for currently checked function. - * - * @return array - */ - protected function getCurrentRemovedFunction() - { - $config = current($this->removedFunction); - - // TODO: Add exception if something went wrong? - - return $config; - } - /** * Add warning for the given token position. * @@ -224,27 +208,30 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff */ protected function addWarning(PhpCsFile $phpcsFile, $tokenPosition) { - $phpcsFile->addWarning( - 'Legacy function calls are not allowed; found %s. Removed in %s. %s. See: %s', - $tokenPosition, - $this->getFunctionIdentifier(), - [ - $this->getOldfunctionCall(), - $this->getRemovedVersion(), - $this->getNewFunctionCall(), - $this->getDocsUrl(), - ] - ); + 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() + protected function getFunctionIdentifier(array $config) { - $config = $this->getCurrentRemovedFunction(); return $config['class'] . '.' . $config['function']; } @@ -255,11 +242,12 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * you should provide an example, so users can check that this is the * legacy one. * + * @param array $config The converted structure for a single function. + * * @return string */ - protected function getOldFunctionCall() + protected function getOldFunctionCall(array $config) { - $config = $this->getCurrentRemovedFunction(); $concat = '->'; if ($config['static']) { $concat = '::'; @@ -272,11 +260,13 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * * 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() + protected function getRemovedVersion(array $config) { - return $this->getCurrentRemovedFunction()['version_removed']; + return $config['version_removed']; } /** @@ -284,11 +274,13 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff * * To provide feedback for user to ease migration. * + * @param array $config The converted structure for a single function. + * * @return string */ - protected function getNewFunctionCall() + protected function getNewFunctionCall(array $config) { - $newCall = $this->getCurrentRemovedFunction()['newFunctionCall']; + $newCall = $config['newFunctionCall']; if ($newCall !== null) { return $newCall; } @@ -298,10 +290,12 @@ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff implements PhpCsSniff /** * 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() + protected function getDocsUrl(array $config) { - return $this->getCurrentRemovedFunction()['docsUrl']; + return $config['docsUrl']; } } From f3e708f5e08b184711f586fe18731fea44f2188e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 10:54:41 +0200 Subject: [PATCH 33/34] BUGFIX: Allow multiple type hints in php docs * Respect possible separation by "|" and handle each of them. Resolves: #48 --- .../AbstractClassnameChecker.php | 9 +++++---- .../LegacyClassnames/DocCommentSniff.php | 20 ++++++++++++++----- .../LegacyClassnames/InlineCommentSniff.php | 7 ++++--- .../InstantiationWithMakeInstanceSniff.php | 7 ++++--- .../InstantiationWithObjectManagerSniff.php | 7 ++++--- .../Sniffs/LegacyClassnames/IsACallSniff.php | 7 ++++--- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php index a13fe15..77bd49c 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/AbstractClassnameChecker.php @@ -234,7 +234,7 @@ abstract class AbstractClassnameChecker implements PhpCsSniff $phpcsFile->fixer->replaceToken( $classnamePosition, - $this->getTokenForReplacement($prefix . $this->getNewClassname($classname)) + $this->getTokenForReplacement($prefix . $this->getNewClassname($classname), $classname) ); } @@ -242,12 +242,13 @@ abstract class AbstractClassnameChecker implements PhpCsSniff * String to use for replacing / fixing the token. * Default is class name itself, can be overwritten in sniff for special behaviour. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { - return $classname; + return $newClassname; } /** diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php index 2a85c89..2a540bb 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/DocCommentSniff.php @@ -66,22 +66,32 @@ class Typo3Update_Sniffs_LegacyClassnames_DocCommentSniff extends AbstractClassn if ($classnamePosition === false) { return; } - $classname = explode(' ', $tokens[$classnamePosition]['content'])[0]; + $classnames = explode('|', explode(' ', $tokens[$classnamePosition]['content'])[0]); $this->originalTokenContent = $tokens[$classnamePosition]['content']; - $this->addFixableError($phpcsFile, $classnamePosition, $classname); + foreach ($classnames as $classname) { + $this->addFixableError($phpcsFile, $classnamePosition, $classname); + } } /** * As token contains more then just class name, we have to build new content ourself. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { $token = explode(' ', $this->originalTokenContent); - $token[0] = $classname; + + $classNames = explode('|', $token[0]); + foreach ($classNames as $position => $classname) { + if ($classname === $originalClassname) { + $classNames[$position] = $newClassname; + } + } + $token[0] = implode('|', $classNames); return implode(' ', $token); } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php index dc9c17d..4740c0e 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InlineCommentSniff.php @@ -81,13 +81,14 @@ class Typo3Update_Sniffs_LegacyClassnames_InlineCommentSniff extends AbstractCla /** * As token contains more then just class name, we have to build new content ourself. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { $token = preg_split('/\s+/', $this->originalTokenContent); - $token[$this->getClassnamePosition($token)] = $classname; + $token[$this->getClassnamePosition($token)] = $newClassname; return implode(' ', $token); } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php index 7e06b6b..b25c613 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithMakeInstanceSniff.php @@ -73,11 +73,12 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithMakeInstanceSniff ext /** * As token contains more then just class name, we have to build new content ourself. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { - return $this->getTokenReplacementForString($classname); + return $this->getTokenReplacementForString($newClassname); } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php index a3d173f..67014fe 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/InstantiationWithObjectManagerSniff.php @@ -83,11 +83,12 @@ class Typo3Update_Sniffs_LegacyClassnames_InstantiationWithObjectManagerSniff ex /** * As token contains more then just class name, we have to build new content ourself. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { - return $this->getTokenReplacementForString($classname); + return $this->getTokenReplacementForString($newClassname); } } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php index b4a2f30..89bd2fa 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/IsACallSniff.php @@ -72,11 +72,12 @@ class Typo3Update_Sniffs_LegacyClassnames_IsACallSniff extends AbstractClassname /** * As token contains more then just class name, we have to build new content ourself. * - * @param string $classname + * @param string $newClassname + * @param string $originalClassname * @return string */ - protected function getTokenForReplacement($classname) + protected function getTokenForReplacement($newClassname, $originalClassname) { - return $this->getTokenReplacementForString($classname); + return $this->getTokenReplacementForString($newClassname); } } From 2e115bb3f7b46c1b9a37ade40de7d1db134f09f6 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 4 Apr 2017 14:39:31 +0200 Subject: [PATCH 34/34] FEATURE: Migrate legacy class names in use statements Resolves: #49 --- .../Sniffs/LegacyClassnames/UseSniff.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php index 9d882c5..f1129ba 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff.php @@ -19,10 +19,13 @@ * 02110-1301, USA. */ +use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\LegacyClassnames\AbstractClassnameChecker; /** - * Migrate old legacy class names in use statements. + * Detect and migrate use statements with legacy classnames.. + * + * According to PSR-2, only one class per use statement is expected. */ class Typo3Update_Sniffs_LegacyClassnames_UseSniff extends AbstractClassnameChecker { @@ -35,4 +38,21 @@ class Typo3Update_Sniffs_LegacyClassnames_UseSniff extends AbstractClassnameChec { return [T_USE]; } + + /** + * Overwrite to remove prefix. + * + * @param PhpCsFile $phpcsFile + * @param int $classnamePosition + * @param string $classname + * @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out. + */ + protected function replaceLegacyClassname( + PhpCsFile $phpcsFile, + $classnamePosition, + $classname, + $forceEmptyPrefix = true + ) { + return parent::replaceLegacyClassname($phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix); + } }