parent
2b1a1a0f19
commit
94df1f2ad1
3 changed files with 24 additions and 13 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue