WIP: Fix use sniff

* Make use sniff tests pass again.

Relates: #72
This commit is contained in:
Daniel Siepmann 2017-04-25 13:16:58 +02:00
parent 2b1a1a0f19
commit 94df1f2ad1
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 24 additions and 13 deletions

View file

@ -44,6 +44,11 @@ class LegacyClassnameFeature implements FeatureInterface
*/
protected $legacyMapping;
/**
* @var PhpCsSniff
*/
protected $sniff;
/**
* Used by some sniffs to keep original token for replacement.
*
@ -53,8 +58,9 @@ class LegacyClassnameFeature implements FeatureInterface
*/
protected $originalTokenContent = '';
public function __construct()
public function __construct(PhpCsSniff $sniff)
{
$this->sniff = $sniff;
$this->legacyMapping = LegacyClassnameMapping::getInstance();
}
@ -175,18 +181,14 @@ class LegacyClassnameFeature implements FeatureInterface
* @param PhpCsFile $phpcsFile
* @param int $classnamePosition
* @param string $classname
* @param bool $forceEmptyPrefix Defines whether '\\' prefix should be checked or always be left out.
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
protected function replaceLegacyClassname(
PhpCsFile $phpcsFile,
$classnamePosition,
$classname,
$forceEmptyPrefix = false
$classname
) {
$prefix = '\\';
if ($forceEmptyPrefix || $phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) {
if ($this->forceEmptyPrefix() || $phpcsFile->getTokens()[$classnamePosition -1]['code'] === T_NS_SEPARATOR) {
$prefix = '';
}
@ -233,4 +235,18 @@ class LegacyClassnameFeature implements FeatureInterface
return implode($stringSign, $token);
}
/**
* Check whether new class name for replacment should not contain the "\" as prefix.
*
* @return bool
*/
protected function forceEmptyPrefix()
{
if (get_class($this->sniff) === \Typo3Update_Sniffs_Classname_UseSniff::class) {
return true;
}
return false;
}
}

View file

@ -22,11 +22,6 @@
use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
/**
* Detect and migrate use statements with legacy classnames..
*
* According to PSR-2, only one class per use statement is expected.
*/
class Typo3Update_Sniffs_Classname_UseSniff extends AbstractClassnameChecker
{
/**

View file

@ -1,4 +1,4 @@
--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassnames/UseSniff/InputFileForIssues.php
--- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/UseSniff/InputFileForIssues.php
+++ PHP_CodeSniffer
@@ -19,8 +19,8 @@
* 02110-1301, USA.