From bcbd1f96bc5740bdf19150ed813d31ff03390316 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 27 Apr 2017 13:33:28 +0200 Subject: [PATCH] TASK: Migrate GenericConstantUsageSniff * Migrate GenericConstantUsageSniff to new architecture. * Move non common functionality from AbstractGenericPhpUsage to concrete classes. Relates: #71 --- .../Removed/AbstractGenericPhpUsage.php | 21 +++------- .../Removed/GenericConstantUsageSniff.php | 40 ++++--------------- .../Removed/GenericFunctionCallSniff.php | 38 ++++++++++-------- 3 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericPhpUsage.php b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericPhpUsage.php index d93645f..c426721 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericPhpUsage.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/AbstractGenericPhpUsage.php @@ -21,11 +21,13 @@ namespace Typo3Update\Sniffs\Removed; */ use PHP_CodeSniffer_File as PhpCsFile; -use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; abstract class AbstractGenericPhpUsage extends AbstractGenericUsage { - use ExtendedPhpCsSupportTrait; + public function register() + { + return [T_STRING]; + } protected function prepareStructure(array $typo3Versions) { @@ -51,10 +53,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) { - if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { - return []; - } - $tokens = $phpcsFile->getTokens(); $staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true); @@ -120,15 +118,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage } } - protected function getOldUsage(array $config) - { - $concat = '->'; - if ($config['static']) { - $concat = '::'; - } - return $config['fqcn'] . $concat . $config['name']; - } - protected function getIdentifier(array $config) { $name = $config['name']; @@ -138,4 +127,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage return $name; } + + abstract protected function getOldUsage(array $config); } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php index 1ee46b1..e42a07d 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericConstantUsageSniff.php @@ -19,42 +19,11 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_File as PhpCsFile; -use Typo3Update\Sniffs\Removed\AbstractGenericUsage; +use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; use Typo3Update\Options; -/** - * Sniff that handles all calls to removed constants. - */ -class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericUsage +class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericPhpUsage { - /** - * Return file names containing removed configurations. - * - * @return array - */ - protected function getRemovedConfigFiles() - { - return Options::getRemovedConstantConfigFiles(); - } - - /** - * Returns the token types that this sniff is interested in. - * - * @return array - */ - public function register() - { - return [T_STRING]; - } - - /** - * The original constant call, to allow user to check matches. - * - * @param array $config - * - * @return string - */ protected function getOldUsage(array $config) { $old = $config['name']; @@ -64,4 +33,9 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGener return 'constant ' . $old; } + + protected function getRemovedConfigFiles() + { + return Options::getRemovedConstantConfigFiles(); + } } diff --git a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php index 7fa8a12..4d1784b 100644 --- a/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Removed/GenericFunctionCallSniff.php @@ -19,32 +19,38 @@ * 02110-1301, USA. */ -use PHP_CodeSniffer_Tokens as Tokens; -use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; +use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Options; +use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; +use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage; /** * Sniff that handles all calls to removed functions. */ class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGenericPhpUsage { - /** - * Returns the token types that this sniff is interested in. - * - * @return array - */ - public function register() - { - return [T_STRING]; - } + use ExtendedPhpCsSupportTrait; - /** - * Return file names containing removed configurations. - * - * @return array - */ protected function getRemovedConfigFiles() { return Options::getRemovedFunctionConfigFiles(); } + + protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr) + { + if (!$this->isFunctionCall($phpcsFile, $stackPtr)) { + return []; + } + + return parent::findRemoved($phpcsFile, $stackPtr); + } + + protected function getOldUsage(array $config) + { + $concat = '->'; + if ($config['static']) { + $concat = '::'; + } + return $config['fqcn'] . $concat . $config['name']; + } }