From af6b4dad51f9547b3be7ce9a200c73b780085aee Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 13:30:04 +0100 Subject: [PATCH 1/4] TASK: Rename method * To follow CGL Relates: #33 --- .../Sniffs/LegacyClassnames/ClassnameCheckerTrait.php | 2 +- .../Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index d6a2fe2..307b657 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -62,7 +62,7 @@ trait ClassnameCheckerTrait * * @return bool */ - protected function findPrev() + protected function shouldLookBefore() { return false; } diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php index 91b2eef..d10ce73 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/StaticCallSniff.php @@ -32,7 +32,7 @@ class Typo3Update_Sniffs_LegacyClassnames_StaticCallSniff implements PHP_CodeSni * * @return bool */ - protected function findPrev() + protected function shouldLookBefore() { return true; } From aa76ad796a0d1ed04ca90d30efcda8e05e053e80 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 13:33:08 +0100 Subject: [PATCH 2/4] TASK: Keep all TypeHints the same Relates: #33 --- .../LegacyClassnames/ClassnameCheckerTrait.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index 307b657..843b4d2 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -20,7 +20,7 @@ namespace Typo3Update\Sniffs\LegacyClassnames; * 02110-1301, USA. */ -use PHP_CodeSniffer_File as PhpcsFile; +use PHP_CodeSniffer_File as PhpCsFile; /** * Provide common uses for all sniffs, regarding class name checks. @@ -74,13 +74,13 @@ trait ClassnameCheckerTrait * the class name. This way only the register method has to be registered * in default cases. * - * @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(PhpcsFile $phpcsFile, $stackPtr) + public function process(PhpCsFile $phpcsFile, $stackPtr) { $tokens = $phpcsFile->getTokens(); @@ -147,11 +147,11 @@ trait ClassnameCheckerTrait /** * Add an fixable error if given $classname is legacy. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - public function addFixableError(PhpcsFile $phpcsFile, $classnamePosition, $classname) + public function addFixableError(PhpCsFile $phpcsFile, $classnamePosition, $classname) { $classname = trim($classname, '\\\'"'); // Remove trailing slash, and quotes. $this->addMaybeWarning($phpcsFile, $classnamePosition, $classname); @@ -175,11 +175,11 @@ trait ClassnameCheckerTrait /** * Add an warning if given $classname is maybe legacy. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - private function addMaybeWarning(PhpcsFile $phpcsFile, $classnamePosition, $classname) + private function addMaybeWarning(PhpCsFile $phpcsFile, $classnamePosition, $classname) { if ($this->isLegacyClassname($classname) || $this->isMaybeLegacyClassname($classname) === false) { return; @@ -196,11 +196,11 @@ trait ClassnameCheckerTrait /** * Replaces the classname at $classnamePosition with $classname in $phpcsFile. * - * @param PhpcsFile $phpcsFile + * @param PhpCsFile $phpcsFile * @param int $classnamePosition * @param string $classname */ - private function replaceLegacyClassname(PhpcsFile $phpcsFile, $classnamePosition, $classname) + private function replaceLegacyClassname(PhpCsFile $phpcsFile, $classnamePosition, $classname) { $prefix = '\\'; if ($phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) { From 05ce3d0aef51dc0b80119737d029d67c64885e07 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 21 Mar 2017 13:43:52 +0100 Subject: [PATCH 3/4] TASK: Fix call to undefined method Relates: #33 --- .../Sniffs/LegacyClassnames/ClassnameCheckerTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index 843b4d2..edeb3ee 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -85,7 +85,7 @@ trait ClassnameCheckerTrait $tokens = $phpcsFile->getTokens(); $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); - if ($this->findPrev()) { + if ($this->shouldLookBefore()) { $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); } if ($classnamePosition === false) { From fb746bf39d8bd1377d2b34247057d3d49a6ece51 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 23 Mar 2017 08:41:06 +0100 Subject: [PATCH 4/4] TASK: According to PR, use else instead of default --- .../Sniffs/LegacyClassnames/ClassnameCheckerTrait.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php index edeb3ee..4297ae7 100644 --- a/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php +++ b/src/Standards/Typo3Update/Sniffs/LegacyClassnames/ClassnameCheckerTrait.php @@ -84,10 +84,12 @@ trait ClassnameCheckerTrait { $tokens = $phpcsFile->getTokens(); - $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); if ($this->shouldLookBefore()) { $classnamePosition = $phpcsFile->findPrevious(T_STRING, $stackPtr); + } else { + $classnamePosition = $phpcsFile->findNext(T_STRING, $stackPtr); } + if ($classnamePosition === false) { return; }