From 2cc21fdafaae0d6071132d7577140eafb8d89811 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 25 Apr 2017 15:20:35 +0200 Subject: [PATCH] TASK: Cleanup code * Remove unnecessary documentation. * Remove unused code. * Add missing documentation. Relates: #72 --- .../Typo3Update/Feature/FeatureInterface.php | 2 +- .../Typo3Update/Feature/Features.php | 5 +++- .../Typo3Update/Feature/FeaturesSupport.php | 15 +++++++++- .../Feature/LegacyClassnameFeature.php | 16 ++--------- .../Classname/AbstractClassnameChecker.php | 3 ++ .../Sniffs/Classname/InheritanceSniff.php | 8 +----- .../Sniffs/Classname/InlineCommentSniff.php | 28 +------------------ .../Sniffs/Classname/InstanceofSniff.php | 7 +---- .../InstantiationWithMakeInstanceSniff.php | 16 ----------- .../Classname/InstantiationWithNewSniff.php | 3 -- .../InstantiationWithObjectManagerSniff.php | 3 -- .../Sniffs/Classname/IsACallSniff.php | 3 -- .../Sniffs/Classname/StaticCallSniff.php | 3 -- .../Classname/TypeHintCatchExceptionSniff.php | 3 -- .../Sniffs/Classname/TypeHintSniff.php | 3 -- 15 files changed, 27 insertions(+), 91 deletions(-) diff --git a/src/Standards/Typo3Update/Feature/FeatureInterface.php b/src/Standards/Typo3Update/Feature/FeatureInterface.php index 36d63c7..39de10c 100644 --- a/src/Standards/Typo3Update/Feature/FeatureInterface.php +++ b/src/Standards/Typo3Update/Feature/FeatureInterface.php @@ -23,7 +23,7 @@ namespace Typo3Update\Feature; use PHP_CodeSniffer_File as PhpCsFile; /** - * + * See "Features" in documentation. */ interface FeatureInterface { diff --git a/src/Standards/Typo3Update/Feature/Features.php b/src/Standards/Typo3Update/Feature/Features.php index 996f012..ac6ee42 100644 --- a/src/Standards/Typo3Update/Feature/Features.php +++ b/src/Standards/Typo3Update/Feature/Features.php @@ -24,13 +24,16 @@ use PHP_CodeSniffer_Sniff as PhpCsSniff; use Typo3Update\Options; /** - * + * Contains all configured features for a single sniff. */ class Features implements \Iterator { protected $index = 0; protected $features = []; + /** + * @param PhpCsSniff $sniff The sniff to collect features for. + */ public function __construct(PhpCsSniff $sniff) { foreach (Options::getFeaturesConfiguration() as $featureName => $sniffs) { diff --git a/src/Standards/Typo3Update/Feature/FeaturesSupport.php b/src/Standards/Typo3Update/Feature/FeaturesSupport.php index fa71785..2f84bc7 100644 --- a/src/Standards/Typo3Update/Feature/FeaturesSupport.php +++ b/src/Standards/Typo3Update/Feature/FeaturesSupport.php @@ -23,7 +23,7 @@ namespace Typo3Update\Feature; use PHP_CodeSniffer_File as PhpCsFile; /** - * Provides "feature" support for sniff. + * Provides "feature" support for sniffs. */ trait FeaturesSupport { @@ -37,6 +37,13 @@ trait FeaturesSupport $this->features = new Features($this); } + /** + * Processes all features for the sniff. + * + * @param PhpCsFile $phpcsFile + * @param int $stackPtr + * @param string $content + */ public function processFeatures(PhpCsFile $phpcsFile, $stackPtr, $content) { foreach ($this->features as $featureClassName) { @@ -45,6 +52,12 @@ trait FeaturesSupport } } + /** + * Create a new instance of the given feature. + * + * @param string $featureClassname + * @return FeatureInterface + */ protected function createFeature($featureClassname) { return new $featureClassname($this); diff --git a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php index 269650c..4612e6d 100644 --- a/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php +++ b/src/Standards/Typo3Update/Feature/LegacyClassnameFeature.php @@ -25,7 +25,9 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Sniff as PhpCsSniff; /** + * This feature will add fixable errors for old legacy classnames. * + * Can be attached to sniffs returning classnames. */ class LegacyClassnameFeature implements FeatureInterface { @@ -131,20 +133,6 @@ class LegacyClassnameFeature implements FeatureInterface 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); - } - /** * Add an warning if given $classname is maybe legacy. * diff --git a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php index dbc60b2..e405fdc 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/AbstractClassnameChecker.php @@ -26,6 +26,9 @@ use Typo3Update\Feature\FeaturesSupport; /** * Provide common uses for all sniffs, regarding class name checks. + * + * Will do nothing but calling configured features, allowing new extending + * sniffs to find further class names. */ abstract class AbstractClassnameChecker implements PhpCsSniff { diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php index d9096f1..2ce6d36 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InheritanceSniff.php @@ -22,9 +22,6 @@ use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate extend and implement of old legacy classnames. - */ class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChecker { /** @@ -34,10 +31,7 @@ class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChe */ public function register() { - return [ - T_EXTENDS, - T_IMPLEMENTS, - ]; + return [T_EXTENDS, T_IMPLEMENTS]; } /** diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff.php index 7f1b58c..676dad9 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InlineCommentSniff.php @@ -22,9 +22,6 @@ use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Migrate PHP inline comments, e.g. for IDEs. - */ class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameChecker { /** @@ -34,9 +31,7 @@ class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameC */ public function register() { - return [ - T_COMMENT, - ]; + return [T_COMMENT]; } /** @@ -77,25 +72,4 @@ class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameC return 3; } - - /** - * As token contains more then just class name, we have to build new content ourself. - * - * @param string $newClassname - * @param string $originalClassname - * @param PhpCsFile $phpcsFile - * @return string - */ - protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile) - { - $token = preg_split('/\s+/', $this->originalTokenContent); - $token[$this->getClassnamePosition($token)] = $newClassname; - - // Keep line ending, removed by preg_split - if ($token[0] === '//') { - $token[count($token)] = $phpcsFile->eolChar; - } - - return implode(' ', $token); - } } diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff.php index 07fd90a..b6a4640 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InstanceofSniff.php @@ -21,9 +21,6 @@ use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate instanceof checks of old legacy classnames. - */ class Typo3Update_Sniffs_Classname_InstanceofSniff extends AbstractClassnameChecker { /** @@ -33,8 +30,6 @@ class Typo3Update_Sniffs_Classname_InstanceofSniff extends AbstractClassnameChec */ public function register() { - return [ - T_INSTANCEOF, - ]; + return [T_INSTANCEOF]; } } diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php index ee71469..070162a 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithMakeInstanceSniff.php @@ -23,9 +23,6 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Tokens as Tokens; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate instantiations of old legacy classnames using "makeInstance". - */ class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends AbstractClassnameChecker { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; @@ -69,17 +66,4 @@ class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends Ab $this->originalTokenContent = $tokens[$classnamePosition]['content']; $this->processFeatures($phpcsFile, $classnamePosition, $classname); } - - /** - * As token contains more then just class name, we have to build new content ourself. - * - * @param string $newClassname - * @param string $originalClassname - * @param PhpCsFile $phpcsFile - * @return string - */ - protected function getTokenForReplacement($newClassname, $originalClassname, PhpCsFile $phpcsFile) - { - return $this->getTokenReplacementForString($newClassname); - } } diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff.php index be836f5..37313c7 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithNewSniff.php @@ -21,9 +21,6 @@ use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate old legacy classnames instantiations using phps "new". - */ class Typo3Update_Sniffs_Classname_InstantiationWithNewSniff extends AbstractClassnameChecker { /** diff --git a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff.php index 14afa1e..7843243 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/InstantiationWithObjectManagerSniff.php @@ -23,9 +23,6 @@ use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_Tokens as Tokens; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate old legacy classname instantiations using objectmanager create and get. - */ class Typo3Update_Sniffs_Classname_InstantiationWithObjectManagerSniff extends AbstractClassnameChecker { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; diff --git a/src/Standards/Typo3Update/Sniffs/Classname/IsACallSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/IsACallSniff.php index 06ac05c..7888d01 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/IsACallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/IsACallSniff.php @@ -22,9 +22,6 @@ use PHP_CodeSniffer_File as PhpcsFile; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate instantiations of old legacy classnames using "makeInstance". - */ class Typo3Update_Sniffs_Classname_IsACallSniff extends AbstractClassnameChecker { use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; diff --git a/src/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff.php index 7e99447..ded2b6d 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/StaticCallSniff.php @@ -21,9 +21,6 @@ use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Detect and migrate static calls to old legacy classnames. - */ class Typo3Update_Sniffs_Classname_StaticCallSniff extends AbstractClassnameChecker { /** diff --git a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff.php index 2242e6b..231b676 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintCatchExceptionSniff.php @@ -21,9 +21,6 @@ use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Migrate Typehints in catch statements. - */ class Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff extends AbstractClassnameChecker { /** diff --git a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php index 7d08f16..05f49c1 100644 --- a/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php +++ b/src/Standards/Typo3Update/Sniffs/Classname/TypeHintSniff.php @@ -22,9 +22,6 @@ use PHP_CodeSniffer_File as PhpCsFile; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; -/** - * Migrate Typehints in function / method definitions. - */ class Typo3Update_Sniffs_Classname_TypeHintSniff extends AbstractClassnameChecker { /**