From 83239ddeee0b6b2a63e715a189cc086f563f57dc Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 14:24:59 +0200 Subject: [PATCH 1/8] FEATURE: Add check for removed signals * Add docs, sniff, tests. * Add first configuration. Relates: #45 --- Documentation/source/configuration.rst | 23 +++++ Documentation/source/features.rst | 2 + .../Configuration/Removed/Signals/7.2.yaml | 17 ++++ src/Standards/Typo3Update/Options.php | 13 +++ .../Sniffs/ExtendedPhpCsSupportTrait.php | 22 +++++ .../Sniffs/Removed/GenericSignalSniff.php | 86 +++++++++++++++++++ .../Removed/GenericSignalSniff/Expected.json | 60 +++++++++++++ .../GenericSignalSniff/InputFileForIssues.php | 59 +++++++++++++ 8 files changed, 282 insertions(+) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Signals/7.2.yaml create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/InputFileForIssues.php diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 7f8ffc7..9df38a2 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -143,6 +143,29 @@ Using ``runtime-set``: --runtime-set removedFunctionConfigFiles "/Some/Absolute/Path/*.yaml" +.. _configuration-removedSignalConfigFiles: + +removedSignalConfigFiles +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Configure where to look for configuration files defining the removed signals and methods. Default +is ``Configuration/Removed/Signals/*.yaml`` inside the standard itself. We already try to deliver +as much as possible. +Globing is used, so placeholders like ``*`` are possible, see +https://secure.php.net/manual/en/function.glob.php + +Using :file:`ruleset.xml`: + +.. code:: xml + + + +Using ``runtime-set``: + +.. code:: bash + + --runtime-set removedSignalConfigFiles "/Some/Absolute/Path/*.yaml" + .. _configuration-removedConstantConfigFiles: removedConstantConfigFiles diff --git a/Documentation/source/features.rst b/Documentation/source/features.rst index e055e92..89531eb 100644 --- a/Documentation/source/features.rst +++ b/Documentation/source/features.rst @@ -103,6 +103,8 @@ information. For configuration options see :ref:`configuration-removedFunctionCo Check for usage of *removed constants*. The constants are configured in same way as removed functions. For configuration options see :ref:`configuration-removedConstantConfigFiles`. +Check for usage of *removed signals*. The signals are configured in same way as removed +functions. For configuration options see :ref:`configuration-removedSignalConfigFiles`. Further checks -------------- diff --git a/src/Standards/Typo3Update/Configuration/Removed/Signals/7.2.yaml b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.2.yaml new file mode 100644 index 0000000..8276a37 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.2.yaml @@ -0,0 +1,17 @@ +# Breaking changes in 7.2: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Index.html#breaking-changes +'7.2': + \TYPO3\CMS\Backend\Controller\LoginController::makeLoginBoxImage: + replacement: 'Use the introduced Fluid view to adapt the login screen to your demands' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html + \TYPO3\CMS\Backend\Controller\LoginController::wrapLoginForm: + replacement: 'Use the introduced Fluid view to adapt the login screen to your demands' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html + \TYPO3\CMS\Backend\Controller\LoginController::makeLoginNews: + replacement: 'Use the introduced Fluid view to adapt the login screen to your demands' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html + \TYPO3\CMS\Backend\Controller\LoginController::makeLoginForm: + replacement: 'Use the introduced Fluid view to adapt the login screen to your demands' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html + \TYPO3\CMS\Backend\Controller\LoginController::makeLogoutForm: + replacement: 'Use the introduced Fluid view to adapt the login screen to your demands' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html diff --git a/src/Standards/Typo3Update/Options.php b/src/Standards/Typo3Update/Options.php index 62b8a78..9a65354 100644 --- a/src/Standards/Typo3Update/Options.php +++ b/src/Standards/Typo3Update/Options.php @@ -69,6 +69,19 @@ class Options ); } + /** + * Returns an array of absolute file names containing removed function configurations. + * + * @return array + */ + public static function getRemovedSignalConfigFiles() + { + return static::getOptionFileNames( + 'removedSignalConfigFiles', + __DIR__ . '/Configuration/Removed/Signals/*.yaml' + ); + } + /** * Returns an array of absolute file names containing removed constant configurations. * diff --git a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php index 2368d4d..2173b4f 100644 --- a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php +++ b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php @@ -66,4 +66,26 @@ trait ExtendedPhpCsSupportTrait return true; } + + /** + * Returns all parameters for function call as values. + * Quotes are removed from strings. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * + * @return array + */ + protected function getFunctionCallParameters(PhpCsFile $phpcsFile, $stackPtr) + { + $start = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr) + 1; + $parameters = explode(',', $phpcsFile->getTokensAsString( + $start, + $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) - $start + )); + + return array_map(function ($parameter) { + return trim($parameter, " \t\n\r\0\x0B'\""); + }, $parameters); + } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff.php new file mode 100644 index 0000000..d72601c --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff.php @@ -0,0 +1,86 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use PHP_CodeSniffer_File as PhpCsFile; +use Typo3Update\Options; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; +use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; + +class Typo3Update_Sniffs_Removed_GenericSignalSniff extends AbstractGenericPhpUsage +{ + use ExtendedPhpCsSupportTrait; + + protected function getRemovedConfigFiles() + { + return Options::getRemovedSignalConfigFiles(); + } + + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isFunctionCall($phpcsFile, $stackPtr) || $phpcsFile->getTokens()[$stackPtr]['content'] !== 'connect') { + return []; + } + + $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr); + if (count($parameters) < 4) { + return []; + } + + $lookup = $this->getClass($parameters[0]) . '::' . $parameters[1]; + + if ($this->configured->isRemoved($lookup) === false) { + return []; + } + + return [$this->configured->getRemoved($lookup)]; + } + + /** + * Returns same formatted class representation for incoming strings. + * + * @param string $string + * @return string + */ + protected function getClass($string) + { + $search = [ + '::class', + '\\\\', + ]; + $replace = [ + '', + '\\', + ]; + + $string = str_replace($search, $replace, $string); + + if ($string[0] !== '\\') { + $string = '\\' . $string; + } + + return $string; + } + + protected function getOldUsage(array $config) + { + return $config['fqcn'] . '::' . $config['name']; + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/Expected.json new file mode 100644 index 0000000..8a194da --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/Expected.json @@ -0,0 +1,60 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 0, + "messages": [ + { + "column": 28, + "fixable": false, + "line": 25, + "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Controller\\LoginController::makeLoginNews. Removed in 7.2. Use the introduced Fluid view to adapt the login screen to your demands. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericSignal.LoginController.makeLoginNews", + "type": "WARNING" + }, + { + "column": 28, + "fixable": false, + "line": 32, + "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Controller\\LoginController::makeLoginNews. Removed in 7.2. Use the introduced Fluid view to adapt the login screen to your demands. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericSignal.LoginController.makeLoginNews", + "type": "WARNING" + }, + { + "column": 28, + "fixable": false, + "line": 39, + "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Controller\\LoginController::makeLoginNews. Removed in 7.2. Use the introduced Fluid view to adapt the login screen to your demands. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericSignal.LoginController.makeLoginNews", + "type": "WARNING" + }, + { + "column": 28, + "fixable": false, + "line": 46, + "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Controller\\LoginController::makeLoginNews. Removed in 7.2. Use the introduced Fluid view to adapt the login screen to your demands. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericSignal.LoginController.makeLoginNews", + "type": "WARNING" + }, + { + "column": 28, + "fixable": false, + "line": 53, + "message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Controller\\LoginController::makeLoginNews. Removed in 7.2. Use the introduced Fluid view to adapt the login screen to your demands. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.2/Breaking-65939-BackendLoginRefactoring.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericSignal.LoginController.makeLoginNews", + "type": "WARNING" + } + ], + "warnings": 5 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 5 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/InputFileForIssues.php new file mode 100644 index 0000000..608d8b9 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericSignalSniff/InputFileForIssues.php @@ -0,0 +1,59 @@ + + * + * 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. + */ + +call_user_func(function () { + $signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class); + + $signalSlotDispatcher->connect( + \TYPO3\CMS\Backend\Controller\LoginController::class, + 'makeLoginNews', + 'OwnClass', + 'ownMethod' + ); + + $signalSlotDispatcher->connect( + TYPO3\CMS\Backend\Controller\LoginController::class, + 'makeLoginNews', + 'OwnClass', + 'ownMethod' + ); + + $signalSlotDispatcher->connect( + '\TYPO3\CMS\Backend\Controller\LoginController', + 'makeLoginNews', + 'OwnClass', + 'ownMethod' + ); + + $signalSlotDispatcher->connect( + 'TYPO3\CMS\Backend\Controller\LoginController', + 'makeLoginNews', + 'OwnClass', + 'ownMethod' + ); + + $signalSlotDispatcher->connect( + "TYPO3\\CMS\\Backend\\Controller\\LoginController", + 'makeLoginNews', + 'OwnClass', + 'ownMethod' + ); +}); From 91ab7e3424dcf07e322be5c54cbcd18df7123dec Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 14:34:52 +0200 Subject: [PATCH 2/8] TASK: Configure removed or changed signals Relates: #45 --- .../Typo3Update/Configuration/Removed/Signals/7.3.yaml | 5 +++++ .../Typo3Update/Configuration/Removed/Signals/7.4.yaml | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Signals/7.3.yaml create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml diff --git a/src/Standards/Typo3Update/Configuration/Removed/Signals/7.3.yaml b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.3.yaml new file mode 100644 index 0000000..e8684eb --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.3.yaml @@ -0,0 +1,5 @@ +# Breaking changes in 7.3: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Index.html#breaking-changes +'7.3': + \TYPO3\CMS\Lang\Service\UpdateTranslationService::postProcessMirrorUrl: + replacement: 'Change the slot to use the \TYPO3\CMS\Lang\Service\TranslationService::postProcessMirrorUrl signal' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-62983-PostProcessMirrorUrlSignalHasMoved.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml new file mode 100644 index 0000000..4d2ee7a --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml @@ -0,0 +1,5 @@ +# Breaking changes in 7.4: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Index.html#breaking-changes +'7.4': + \TYPO3\CMS\Core\Resource\ResourceStorage::preFileAdd + replacement: 'The signal will now receive an empty string in $sourceFilePath' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-67545-PreFileAddSignalBehaviourChanged.html From 17368e32f92536343827997cc4cb0b831bbd21ba Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 15:15:30 +0200 Subject: [PATCH 3/8] TASK: Fix copy and paste issue in docs --- Documentation/source/configuration.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index 9df38a2..5b5b458 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -148,7 +148,7 @@ Using ``runtime-set``: removedSignalConfigFiles ^^^^^^^^^^^^^^^^^^^^^^^^^^ -Configure where to look for configuration files defining the removed signals and methods. Default +Configure where to look for configuration files defining the removed signals. Default is ``Configuration/Removed/Signals/*.yaml`` inside the standard itself. We already try to deliver as much as possible. Globing is used, so placeholders like ``*`` are possible, see From 4d7aeea5ae2965a8dea84fa4a2e8453a0c16e594 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 15:43:29 +0200 Subject: [PATCH 4/8] FEATURE: Implement removed hook sniff. * Update docs, add sniff and test. * Add first configuration. Relates: #45 --- Documentation/source/configuration.rst | 23 +++++++ Documentation/source/features.rst | 3 + .../Configuration/Removed/Hooks/7.3.yaml | 8 +++ src/Standards/Typo3Update/Options.php | 13 ++++ .../Sniffs/ExtendedPhpCsSupportTrait.php | 15 +++- .../Sniffs/Removed/GenericHookSniff.php | 68 +++++++++++++++++++ .../Removed/GenericHookSniff/Expected.json | 42 ++++++++++++ .../GenericHookSniff/InputFileForIssues.php | 33 +++++++++ tests/Sniffs/Removed/GenericHookSniffTest.php | 28 ++++++++ .../Sniffs/Removed/GenericSignalSniffTest.php | 28 ++++++++ 10 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml create mode 100644 src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/Expected.json create mode 100644 tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/InputFileForIssues.php create mode 100644 tests/Sniffs/Removed/GenericHookSniffTest.php create mode 100644 tests/Sniffs/Removed/GenericSignalSniffTest.php diff --git a/Documentation/source/configuration.rst b/Documentation/source/configuration.rst index cf33c5b..8d18018 100644 --- a/Documentation/source/configuration.rst +++ b/Documentation/source/configuration.rst @@ -166,6 +166,29 @@ Using ``runtime-set``: --runtime-set removedSignalConfigFiles "/Some/Absolute/Path/*.yaml" +.. _configuration-removedHookConfigFiles: + +removedHookConfigFiles +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Configure where to look for configuration files defining the removed hooks. Default +is ``Configuration/Removed/Hooks/*.yaml`` inside the standard itself. We already try to deliver +as much as possible. +Globing is used, so placeholders like ``*`` are possible, see +https://secure.php.net/manual/en/function.glob.php + +Using :file:`ruleset.xml`: + +.. code:: xml + + + +Using ``runtime-set``: + +.. code:: bash + + --runtime-set removedHookConfigFiles "/Some/Absolute/Path/*.yaml" + .. _configuration-removedConstantConfigFiles: removedConstantConfigFiles diff --git a/Documentation/source/features.rst b/Documentation/source/features.rst index 8e8f021..b4a6323 100644 --- a/Documentation/source/features.rst +++ b/Documentation/source/features.rst @@ -106,6 +106,9 @@ functions. For configuration options see :ref:`configuration-removedConstantConf Check for usage of *removed signals*. The signals are configured in same way as removed functions. For configuration options see :ref:`configuration-removedSignalConfigFiles`. +Check for usage of *removed hooks*. The hooks are configured in same way as removed +functions. For configuration options see :ref:`configuration-removedHookConfigFiles`. + Check for usage of *removed TypoScript*. The TypoScript objects are configured in same way as removed functions. For configuration options see :ref:`configuration-removedTypoScriptConfigFiles`. This will check whether you are using already removed TypoScript parts, supported are: diff --git a/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml new file mode 100644 index 0000000..561a717 --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml @@ -0,0 +1,8 @@ +# Breaking changes in 7.3: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Index.html#breaking-changes +'7.3': + typo3/index.php->loginScriptHook: + replacement: 'Use the new backend login form API' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html + typo3/index.php->loginFormHook: + replacement: 'Use the new backend login form API' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html diff --git a/src/Standards/Typo3Update/Options.php b/src/Standards/Typo3Update/Options.php index 9a65354..3462aa8 100644 --- a/src/Standards/Typo3Update/Options.php +++ b/src/Standards/Typo3Update/Options.php @@ -82,6 +82,19 @@ class Options ); } + /** + * Returns an array of absolute file names containing removed function configurations. + * + * @return array + */ + public static function getRemovedHookConfigFiles() + { + return static::getOptionFileNames( + 'removedHookConfigFiles', + __DIR__ . '/Configuration/Removed/Hooks/*.yaml' + ); + } + /** * Returns an array of absolute file names containing removed constant configurations. * diff --git a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php index 2173b4f..475e014 100644 --- a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php +++ b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php @@ -84,8 +84,17 @@ trait ExtendedPhpCsSupportTrait $phpcsFile->findNext(T_CLOSE_PARENTHESIS, $stackPtr) - $start )); - return array_map(function ($parameter) { - return trim($parameter, " \t\n\r\0\x0B'\""); - }, $parameters); + return array_map([$this, 'getStringContent'], $parameters); + } + + /** + * Remove special chars like quotes from string. + * + * @param string + * @return string + */ + public function getStringContent($string) + { + return trim($string, " \t\n\r\0\x0B'\""); } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php new file mode 100644 index 0000000..f75247d --- /dev/null +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php @@ -0,0 +1,68 @@ + + * + * 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_Tokens as PhpCsTokens; +use Typo3Update\Options; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; +use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; + +class Typo3Update_Sniffs_Removed_GenericHookSniff extends AbstractGenericPhpUsage +{ + use ExtendedPhpCsSupportTrait; + public function register() + { + return PhpCsTokens::$stringTokens; + } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedHookConfigFiles(); + } + + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + $tokens = $phpcsFile->getTokens(); + $firstPart = $this->getStringContent($tokens[$stackPtr]['content']); + $secondPart = $this->getStringContent($tokens[$phpcsFile->findNext(PhpCsTokens::$stringTokens, $stackPtr + 1)]['content']); + + $lookup = $firstPart . '->' . $secondPart; + + if ($this->configured->isRemoved($lookup) === false) { + return []; + } + + return [$this->configured->getRemoved($lookup)]; + } + + protected function getIdentifier(array $config) + { + $search = ['/', '.']; + $replace = ['-']; + + return str_replace($search, $replace, $config['fqcn']) . $config['name']; + } + + protected function getOldUsage(array $config) + { + return '["' . $config['fqcn'] . '"]["' . $config['name'] . '"] = ...'; + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/Expected.json b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/Expected.json new file mode 100644 index 0000000..6b3c4a1 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/Expected.json @@ -0,0 +1,42 @@ +{ + "files": { + "InputFileForIssues.php": { + "errors": 0, + "messages": [ + { + "column": 43, + "fixable": false, + "line": 22, + "message": "Calls to removed code are not allowed; found [\"typo3/index.php\"][\"loginScriptHook\"] = .... Removed in 7.3. Use the new backend login form API. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericHook.typo3-indexphploginScriptHook", + "type": "WARNING" + }, + { + "column": 43, + "fixable": false, + "line": 23, + "message": "Calls to removed code are not allowed; found [\"typo3/index.php\"][\"loginFormHook\"] = .... Removed in 7.3. Use the new backend login form API. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericHook.typo3-indexphploginFormHook", + "type": "WARNING" + }, + { + "column": 9, + "fixable": false, + "line": 28, + "message": "Calls to removed code are not allowed; found [\"typo3/index.php\"][\"loginFormHook\"] = .... Removed in 7.3. Use the new backend login form API. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html", + "severity": 5, + "source": "Typo3Update.Removed.GenericHook.typo3-indexphploginFormHook", + "type": "WARNING" + } + ], + "warnings": 3 + } + }, + "totals": { + "errors": 0, + "fixable": 0, + "warnings": 3 + } +} diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/InputFileForIssues.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/InputFileForIssues.php new file mode 100644 index 0000000..1bbb546 --- /dev/null +++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff/InputFileForIssues.php @@ -0,0 +1,33 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/index.php']['loginScriptHook'] = 'Configuration'; +$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']["typo3/index.php"]["loginFormHook"] = 'Configuration'; + +array_merge( + $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'], + [ + 'typo3/index.php' => [ + 'loginFormHook' => 'Configuration', + ], + ] +); + diff --git a/tests/Sniffs/Removed/GenericHookSniffTest.php b/tests/Sniffs/Removed/GenericHookSniffTest.php new file mode 100644 index 0000000..15ed1e6 --- /dev/null +++ b/tests/Sniffs/Removed/GenericHookSniffTest.php @@ -0,0 +1,28 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Typo3Update\Tests\SniffsTest; + +class GenericHookSniffTest extends SniffsTest +{ +} diff --git a/tests/Sniffs/Removed/GenericSignalSniffTest.php b/tests/Sniffs/Removed/GenericSignalSniffTest.php new file mode 100644 index 0000000..5a0d4c0 --- /dev/null +++ b/tests/Sniffs/Removed/GenericSignalSniffTest.php @@ -0,0 +1,28 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +use Typo3Update\Tests\SniffsTest; + +class GenericSignalSniffTest extends SniffsTest +{ +} From 4d77e99026ee974d4f35cd602aa9ea4e497bbd2a Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 15:44:54 +0200 Subject: [PATCH 5/8] BUGFIX: Fix syntax issue in yaml file * Ass missing colon. --- .../Typo3Update/Configuration/Removed/Signals/7.4.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml index 4d2ee7a..8f81ad1 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Signals/7.4.yaml @@ -1,5 +1,5 @@ # Breaking changes in 7.4: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Index.html#breaking-changes '7.4': - \TYPO3\CMS\Core\Resource\ResourceStorage::preFileAdd + \TYPO3\CMS\Core\Resource\ResourceStorage::preFileAdd: replacement: 'The signal will now receive an empty string in $sourceFilePath' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.4/Breaking-67545-PreFileAddSignalBehaviourChanged.html From 8312ac3ec601f96d24fc232730289f72d1656975 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 2 May 2017 15:50:28 +0200 Subject: [PATCH 6/8] TASK: Add all hooks Resolves: #45 --- .../Typo3Update/Configuration/Removed/Hooks/7.3.yaml | 3 +++ .../Typo3Update/Configuration/Removed/Hooks/7.5.yaml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 src/Standards/Typo3Update/Configuration/Removed/Hooks/7.5.yaml diff --git a/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml index 561a717..eb05d06 100644 --- a/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml +++ b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.3.yaml @@ -6,3 +6,6 @@ typo3/index.php->loginFormHook: replacement: 'Use the new backend login form API' docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-66669-BackendLoginControllerRefactored.html + t3lib/class.t3lib_tceforms.php->getSingleFieldClass: + replacement: null + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.3/Breaking-63846-FormEngineRefactoring.html diff --git a/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.5.yaml b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.5.yaml new file mode 100644 index 0000000..889bd3c --- /dev/null +++ b/src/Standards/Typo3Update/Configuration/Removed/Hooks/7.5.yaml @@ -0,0 +1,5 @@ +# Breaking changes in 7.5: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.5/Index.html#breaking-changes +'7.5': + t3lib/class.t3lib_tceforms.php->getMainFieldsClass: + replacement: 'Use FormDataProvider to change data given to the render engine of FormEngine from now on' + docsUrl: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.5/Breaking-69568-FormEngine.html From 06a45a528a77350e1d503725040db3913790a69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=BCrtgen?= Date: Tue, 16 May 2017 14:28:26 +0200 Subject: [PATCH 7/8] TASK: Added missing variable name in phpdoc --- src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php index 475e014..01898b0 100644 --- a/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php +++ b/src/Standards/Typo3Update/Sniffs/ExtendedPhpCsSupportTrait.php @@ -90,7 +90,7 @@ trait ExtendedPhpCsSupportTrait /** * Remove special chars like quotes from string. * - * @param string + * @param string $string * @return string */ public function getStringContent($string) From c8f6917b38f30e2bd6e34d75f06705451c9f9f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=BCrtgen?= Date: Tue, 16 May 2017 14:31:47 +0200 Subject: [PATCH 8/8] TASK: CS fixes --- src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php index f75247d..75a1ecf 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericHookSniff.php @@ -28,6 +28,7 @@ use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; class Typo3Update_Sniffs_Removed_GenericHookSniff extends AbstractGenericPhpUsage { use ExtendedPhpCsSupportTrait; + public function register() { return PhpCsTokens::$stringTokens;