diff --git a/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml b/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml
index c510db2..44e6556 100644
--- a/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml
+++ b/src/Standards/Typo3Update/Configuration/Features/LegacyClassnames.yaml
@@ -6,10 +6,10 @@ Typo3Update\Feature\LegacyClassnameFeature:
- Typo3Update_Sniffs_Classname_InstantiationWithNewSniff
- Typo3Update_Sniffs_Classname_InstantiationWithObjectManagerSniff
- Typo3Update_Sniffs_Classname_IsACallSniff
- - Typo3Update_Sniffs_Classname_MissingNamespaceSniff
- Typo3Update_Sniffs_Classname_MissingVendorForPluginsAndModulesSniff
- Typo3Update_Sniffs_Classname_PhpDocCommentSniff
- Typo3Update_Sniffs_Classname_StaticCallSniff
- Typo3Update_Sniffs_Classname_TypeHintCatchExceptionSniff
- Typo3Update_Sniffs_Classname_TypeHintSniff
- Typo3Update_Sniffs_Classname_UseSniff
+ - Typo3Update_Sniffs_LegacyClassname_MissingNamespaceSniff
diff --git a/src/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff.php b/src/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff.php
similarity index 81%
rename from src/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff.php
rename to src/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff.php
index 1c18232..9296d88 100644
--- a/src/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff.php
+++ b/src/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff.php
@@ -20,13 +20,14 @@
*/
use PHP_CodeSniffer_File as PhpCsFile;
-use Typo3Update\Sniffs\Classname\AbstractClassnameChecker;
+use PHP_CodeSniffer_Sniff as PhpCsSniff;
+use Typo3Update\Feature\LegacyClassnameMapping;
use Typo3Update\Options;
/**
* Detect missing namespaces for class definitions.
*/
-class Typo3Update_Sniffs_Classname_MissingNamespaceSniff extends AbstractClassnameChecker
+class Typo3Update_Sniffs_LegacyClassname_MissingNamespaceSniff implements PhpCsSniff
{
/**
* Returns the token types that this sniff is interested in.
@@ -66,28 +67,16 @@ class Typo3Update_Sniffs_Classname_MissingNamespaceSniff extends AbstractClassna
}
$classname = $tokens[$classnamePosition]['content'];
- // TODO: Migrate class, use custom feature as some parts are different!
- // $this->addFixableError($phpcsFile, $classnamePosition, $classname);
- }
-
- /**
- * Overwrite as we don't look up the classname, but check whether the style is legacy.
- *
- * @param string $classname
- * @return bool
- */
- protected function isLegacyClassname($classname)
- {
- return strpos($classname, 'Tx_') === 0;
- }
-
- /**
- * @param string $classname
- * @return string
- */
- protected function getNewClassname($classname)
- {
- return substr($classname, strrpos($classname, '_') + 1);
+ $fix = $phpcsFile->addFixableError(
+ 'Legacy class definitions are not allowed; found "%s".'
+ . ' Wrap your class inside a namespace.',
+ $classnamePosition,
+ 'legacyClassname',
+ [$classname]
+ );
+ if ($fix === true) {
+ $this->replaceLegacyClassname($phpcsFile, $classnamePosition, $classname);
+ }
}
/**
@@ -95,18 +84,12 @@ class Typo3Update_Sniffs_Classname_MissingNamespaceSniff extends AbstractClassna
* @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 = true
+ $classname
) {
- parent::replaceLegacyClassname($phpcsFile, $classnamePosition, $classname, $forceEmptyPrefix);
-
$tokens = $phpcsFile->getTokens();
$lineEndings = PhpCsFile::detectLineEndings($phpcsFile->getFilename());
$suffix = $lineEndings;
@@ -115,16 +98,29 @@ class Typo3Update_Sniffs_Classname_MissingNamespaceSniff extends AbstractClassna
$suffix .= $lineEndings;
}
+ $phpcsFile->fixer->replaceToken(
+ $classnamePosition,
+ substr($classname, strrpos($classname, '_') + 1)
+ );
$phpcsFile->fixer->replaceToken(
$this->getNamespacePosition($phpcsFile),
'getNamespaceDefinition($classname) . $suffix
);
- $this->addLegacyClassname(
+ LegacyClassnameMapping::getInstance()->addLegacyClassname(
$classname,
$this->getNamespace($classname) . '\\' . $this->getNewClassname($classname)
);
}
+ /**
+ * @param string $classname
+ * @return string
+ */
+ protected function getNewClassname($classname)
+ {
+ return substr($classname, strrpos($classname, '_') + 1);
+ }
+
/**
* @param PhpCsFile $phpcsFile
* @return int|false
diff --git a/src/Standards/Typo3Update/ruleset.xml b/src/Standards/Typo3Update/ruleset.xml
index 2cc04d2..f9e1580 100644
--- a/src/Standards/Typo3Update/ruleset.xml
+++ b/src/Standards/Typo3Update/ruleset.xml
@@ -12,8 +12,4 @@
-
-
- Legacy class definitions are not allowed; found "%s". Wrap your class inside a namespace.
-
diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/Arguments.php b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/Arguments.php
similarity index 100%
rename from tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/Arguments.php
rename to tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/Arguments.php
diff --git a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/customVendor/Expected.diff b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/customVendor/Expected.diff
similarity index 77%
rename from tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/customVendor/Expected.diff
rename to tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/customVendor/Expected.diff
index fa266ab..9f60b88 100644
--- a/tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/customVendor/Expected.diff
+++ b/tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/customVendor/Expected.diff
@@ -1,4 +1,4 @@
---- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/MissingNamespaceSniff/customVendor/InputFileForIssues.php
+--- tests/Fixtures/Standards/Typo3Update/Sniffs/LegacyClassname/MissingNamespaceSniff/customVendor/InputFileForIssues.php
+++ PHP_CodeSniffer
@@ -1,4 +1,5 @@