From eaa99973b14f0d5bf68f76084ecf4ae74186da56 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 10:23:45 +0100 Subject: [PATCH] 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. *