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' + ); +});