TASK: Cleanup code

* Remove unnecessary documentation.
* Remove unused code.
* Add missing documentation.

Relates: #72
This commit is contained in:
Daniel Siepmann 2017-04-25 15:20:35 +02:00
parent 21cf62b949
commit 2cc21fdafa
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
15 changed files with 27 additions and 91 deletions

View file

@ -23,7 +23,7 @@ namespace Typo3Update\Feature;
use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_File as PhpCsFile;
/** /**
* * See "Features" in documentation.
*/ */
interface FeatureInterface interface FeatureInterface
{ {

View file

@ -24,13 +24,16 @@ use PHP_CodeSniffer_Sniff as PhpCsSniff;
use Typo3Update\Options; use Typo3Update\Options;
/** /**
* * Contains all configured features for a single sniff.
*/ */
class Features implements \Iterator class Features implements \Iterator
{ {
protected $index = 0; protected $index = 0;
protected $features = []; protected $features = [];
/**
* @param PhpCsSniff $sniff The sniff to collect features for.
*/
public function __construct(PhpCsSniff $sniff) public function __construct(PhpCsSniff $sniff)
{ {
foreach (Options::getFeaturesConfiguration() as $featureName => $sniffs) { foreach (Options::getFeaturesConfiguration() as $featureName => $sniffs) {

View file

@ -23,7 +23,7 @@ namespace Typo3Update\Feature;
use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_File as PhpCsFile;
/** /**
* Provides "feature" support for sniff. * Provides "feature" support for sniffs.
*/ */
trait FeaturesSupport trait FeaturesSupport
{ {
@ -37,6 +37,13 @@ trait FeaturesSupport
$this->features = new Features($this); $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) public function processFeatures(PhpCsFile $phpcsFile, $stackPtr, $content)
{ {
foreach ($this->features as $featureClassName) { 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) protected function createFeature($featureClassname)
{ {
return new $featureClassname($this); return new $featureClassname($this);

View file

@ -25,7 +25,9 @@ use PHP_CodeSniffer_File as PhpCsFile;
use PHP_CodeSniffer_Sniff as PhpCsSniff; 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 class LegacyClassnameFeature implements FeatureInterface
{ {
@ -131,20 +133,6 @@ class LegacyClassnameFeature implements FeatureInterface
return $this->legacyMapping->getNewClassname($classname); 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. * Add an warning if given $classname is maybe legacy.
* *

View file

@ -26,6 +26,9 @@ use Typo3Update\Feature\FeaturesSupport;
/** /**
* Provide common uses for all sniffs, regarding class name checks. * 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 abstract class AbstractClassnameChecker implements PhpCsSniff
{ {

View file

@ -22,9 +22,6 @@
use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate extend and implement of old legacy classnames.
*/
class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChecker
{ {
/** /**
@ -34,10 +31,7 @@ class Typo3Update_Sniffs_Classname_InheritanceSniff extends AbstractClassnameChe
*/ */
public function register() public function register()
{ {
return [ return [T_EXTENDS, T_IMPLEMENTS];
T_EXTENDS,
T_IMPLEMENTS,
];
} }
/** /**

View file

@ -22,9 +22,6 @@
use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Migrate PHP inline comments, e.g. for IDEs.
*/
class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameChecker
{ {
/** /**
@ -34,9 +31,7 @@ class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameC
*/ */
public function register() public function register()
{ {
return [ return [T_COMMENT];
T_COMMENT,
];
} }
/** /**
@ -77,25 +72,4 @@ class Typo3Update_Sniffs_Classname_InlineCommentSniff extends AbstractClassnameC
return 3; 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);
}
} }

View file

@ -21,9 +21,6 @@
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate instanceof checks of old legacy classnames.
*/
class Typo3Update_Sniffs_Classname_InstanceofSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InstanceofSniff extends AbstractClassnameChecker
{ {
/** /**
@ -33,8 +30,6 @@ class Typo3Update_Sniffs_Classname_InstanceofSniff extends AbstractClassnameChec
*/ */
public function register() public function register()
{ {
return [ return [T_INSTANCEOF];
T_INSTANCEOF,
];
} }
} }

View file

@ -23,9 +23,6 @@ use PHP_CodeSniffer_File as PhpCsFile;
use PHP_CodeSniffer_Tokens as Tokens; use PHP_CodeSniffer_Tokens as Tokens;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate instantiations of old legacy classnames using "makeInstance".
*/
class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends AbstractClassnameChecker
{ {
use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
@ -69,17 +66,4 @@ class Typo3Update_Sniffs_Classname_InstantiationWithMakeInstanceSniff extends Ab
$this->originalTokenContent = $tokens[$classnamePosition]['content']; $this->originalTokenContent = $tokens[$classnamePosition]['content'];
$this->processFeatures($phpcsFile, $classnamePosition, $classname); $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);
}
} }

View file

@ -21,9 +21,6 @@
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate old legacy classnames instantiations using phps "new".
*/
class Typo3Update_Sniffs_Classname_InstantiationWithNewSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InstantiationWithNewSniff extends AbstractClassnameChecker
{ {
/** /**

View file

@ -23,9 +23,6 @@ use PHP_CodeSniffer_File as PhpCsFile;
use PHP_CodeSniffer_Tokens as Tokens; use PHP_CodeSniffer_Tokens as Tokens;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate old legacy classname instantiations using objectmanager create and get.
*/
class Typo3Update_Sniffs_Classname_InstantiationWithObjectManagerSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_InstantiationWithObjectManagerSniff extends AbstractClassnameChecker
{ {
use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;

View file

@ -22,9 +22,6 @@
use PHP_CodeSniffer_File as PhpcsFile; use PHP_CodeSniffer_File as PhpcsFile;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate instantiations of old legacy classnames using "makeInstance".
*/
class Typo3Update_Sniffs_Classname_IsACallSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_IsACallSniff extends AbstractClassnameChecker
{ {
use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait; use \Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;

View file

@ -21,9 +21,6 @@
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate static calls to old legacy classnames.
*/
class Typo3Update_Sniffs_Classname_StaticCallSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_StaticCallSniff extends AbstractClassnameChecker
{ {
/** /**

View file

@ -21,9 +21,6 @@
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Migrate Typehints in catch statements.
*/
class Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff extends AbstractClassnameChecker
{ {
/** /**

View file

@ -22,9 +22,6 @@
use PHP_CodeSniffer_File as PhpCsFile; use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker; use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Migrate Typehints in function / method definitions.
*/
class Typo3Update_Sniffs_Classname_TypeHintSniff extends AbstractClassnameChecker class Typo3Update_Sniffs_Classname_TypeHintSniff extends AbstractClassnameChecker
{ {
/** /**