FEATURE: Allow auto migration of classes in strings
* We now check class names case sensitive in strings. * This will prevent issues with stuff like TCA, as class names mathing table names are written in lower case. * Also add further tests and fix issues. * Extend test to check that lower version is not replaced but mentioned as warning. * Expected class names in Tx_ format are reported as fixable error. Resolves: #15
This commit is contained in:
parent
b69c262288
commit
7a16dac529
6 changed files with 77 additions and 25 deletions
|
@ -23,6 +23,7 @@ namespace Typo3Update\Feature;
|
|||
use PHP_CodeSniffer as PhpCs;
|
||||
use PHP_CodeSniffer_File as PhpCsFile;
|
||||
use PHP_CodeSniffer_Sniff as PhpCsSniff;
|
||||
use Typo3Update_Sniffs_Classname_StringSniff as StringSniff;
|
||||
|
||||
/**
|
||||
* This feature will add fixable errors for old legacy classnames.
|
||||
|
@ -96,8 +97,8 @@ class LegacyClassnameFeature implements FeatureInterface
|
|||
*/
|
||||
protected function isLegacyClassname($classname)
|
||||
{
|
||||
if (get_class($this->sniff) === \Typo3Update_Sniffs_Classname_StringSniff::class) {
|
||||
return false;
|
||||
if (get_class($this->sniff) === StringSniff::class) {
|
||||
return $this->legacyMapping->isLegacyClassname($classname);
|
||||
}
|
||||
|
||||
return $this->legacyMapping->isCaseInsensitiveLegacyClassname($classname);
|
||||
|
@ -112,6 +113,12 @@ class LegacyClassnameFeature implements FeatureInterface
|
|||
*/
|
||||
protected function isMaybeLegacyClassname($classname)
|
||||
{
|
||||
if (get_class($this->sniff) === StringSniff::class
|
||||
&& $this->legacyMapping->isCaseInsensitiveLegacyClassname($classname)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (strpos($classname, 'Tx_') === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -121,9 +128,7 @@ class LegacyClassnameFeature implements FeatureInterface
|
|||
return $nameParts[1];
|
||||
}, $classname);
|
||||
|
||||
if (!in_array($extensionName, $this->legacyExtensions)
|
||||
&& get_class($this->sniff) !== \Typo3Update_Sniffs_Classname_StringSniff::class
|
||||
) {
|
||||
if (!in_array($extensionName, $this->legacyExtensions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ final class LegacyClassnameMapping
|
|||
$lowerVersion = strtolower($classname);
|
||||
|
||||
return $this->isLegacyTypo3Classname($classname) || $this->isLegacyMappingClassname($classname)
|
||||
|| $this->isLegacyTypo3Classname($lowerVersion) || $this->isLegacyMappingClassname($lowerVersion);
|
||||
|| isset($this->typo3MappingsKeys[$lowerVersion]) || isset($this->mappingsKeys[$lowerVersion]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,7 @@ final class LegacyClassnameMapping
|
|||
*/
|
||||
public function getNewClassname($classname)
|
||||
{
|
||||
if ($this->isLegacyTypo3Classname($classname) || $this->isLegacyTypo3Classname(strtolower($classname))) {
|
||||
if ($this->isLegacyTypo3Classname($classname) || isset($this->typo3MappingsKeys[strtolower($classname)])) {
|
||||
return $this->typo3Mappings[$this->getTypo3MappingKey($classname)];
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ final class LegacyClassnameMapping
|
|||
*/
|
||||
protected function isLegacyTypo3Classname($classname)
|
||||
{
|
||||
return isset($this->typo3Mappings[$classname]) || isset($this->typo3MappingsKeys[$classname]);
|
||||
return isset($this->typo3Mappings[$classname]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -177,7 +177,7 @@ final class LegacyClassnameMapping
|
|||
*/
|
||||
protected function isLegacyMappingClassname($classname)
|
||||
{
|
||||
return isset($this->mappings[$classname]) || isset($this->mappingsKeys[$classname]);
|
||||
return isset($this->mappings[$classname]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -66,6 +66,10 @@ class LegacyClassnameMappingTest extends TestCase
|
|||
*/
|
||||
public function inCaseSensitivityLookupWorks()
|
||||
{
|
||||
$this->assertFalse(
|
||||
$this->subject->isLegacyClassname('tx_extbase_domain_model_backenduser'),
|
||||
'Classname was returned to be legacy but should not due to lowercase version and case sensitivity.'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$this->subject->isLegacyClassname('Tx_Extbase_Domain_Model_Backenduser'),
|
||||
'Classname was returned to be legacy but should not due to lowercase version and case sensitivity.'
|
||||
|
@ -81,6 +85,11 @@ class LegacyClassnameMappingTest extends TestCase
|
|||
*/
|
||||
public function weCanRetrieveNewClassname()
|
||||
{
|
||||
$this->assertSame(
|
||||
'TYPO3\CMS\Extbase\Command\HelpCommandController',
|
||||
$this->subject->getNewClassname('tx_extbase_command_helpcommandcontroller'),
|
||||
'New class name could not be fetched for lower cased version.'
|
||||
);
|
||||
$this->assertSame(
|
||||
'TYPO3\CMS\Extbase\Command\HelpCommandController',
|
||||
$this->subject->getNewClassname('Tx_Extbase_Command_HelpCommandController'),
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
--- tests/Fixtures/Standards/Typo3Update/Sniffs/Classname/StringSniff/InputFileForIssues.php
|
||||
+++ PHP_CodeSniffer
|
||||
@@ -19,10 +19,10 @@
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Tx_Extbase_Command_HelpCommandController';
|
||||
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_Extbase_Command_HelpCommandController";
|
||||
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = '\TYPO3\CMS\Extbase\Command\HelpCommandController';
|
||||
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "\\TYPO3\\CMS\\Extbase\\Command\\HelpCommandController";
|
||||
|
||||
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&Tx_Extbase_Command_HelpCommandController->getHash';
|
||||
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&\TYPO3\CMS\Extbase\Command\HelpCommandController->getHash';
|
||||
|
||||
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_About_Domain_Model_Extension";
|
||||
+$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "\\TYPO3\\CMS\\About\\Domain\\Model\\Extension";
|
||||
$GLOBALS['TCA']['tx_about_domain_model_extension'] = [];
|
|
@ -1,42 +1,60 @@
|
|||
{
|
||||
"files": {
|
||||
"InputFileForIssues.php": {
|
||||
"errors": 0,
|
||||
"errors": 4,
|
||||
"messages": [
|
||||
{
|
||||
"column": 80,
|
||||
"fixable": false,
|
||||
"fixable": true,
|
||||
"line": 22,
|
||||
"message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore",
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Command_HelpCommandController\", use \"TYPO3\\CMS\\Extbase\\Command\\HelpCommandController\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
"source": "Typo3Update.Classname.String.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 80,
|
||||
"fixable": false,
|
||||
"fixable": true,
|
||||
"line": 23,
|
||||
"message": "Legacy classes are not allowed; found Tx_Extbase_Command_HelpCommandController that might be a legacy class that does not exist anymore",
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Command_HelpCommandController\", use \"TYPO3\\CMS\\Extbase\\Command\\HelpCommandController\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
"source": "Typo3Update.Classname.String.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 93,
|
||||
"fixable": false,
|
||||
"fixable": true,
|
||||
"line": 25,
|
||||
"message": "Legacy classes are not allowed; found Tx_ExtKey_Hooks_Cache that might be a legacy class that does not exist anymore",
|
||||
"message": "Legacy classes are not allowed; found \"Tx_Extbase_Command_HelpCommandController\", use \"TYPO3\\CMS\\Extbase\\Command\\HelpCommandController\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 80,
|
||||
"fixable": true,
|
||||
"line": 27,
|
||||
"message": "Legacy classes are not allowed; found \"Tx_About_Domain_Model_Extension\", use \"TYPO3\\CMS\\About\\Domain\\Model\\Extension\" instead",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.legacyClassname",
|
||||
"type": "ERROR"
|
||||
},
|
||||
{
|
||||
"column": 17,
|
||||
"fixable": false,
|
||||
"line": 28,
|
||||
"message": "Legacy classes are not allowed; found tx_about_domain_model_extension that might be a legacy class that does not exist anymore",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.Classname.String.mightBeLegacyClassname",
|
||||
"type": "WARNING"
|
||||
}
|
||||
],
|
||||
"warnings": 3
|
||||
"warnings": 1
|
||||
}
|
||||
},
|
||||
"totals": {
|
||||
"errors": 0,
|
||||
"fixable": 0,
|
||||
"warnings": 3
|
||||
"errors": 4,
|
||||
"fixable": 4,
|
||||
"warnings": 1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,4 +22,7 @@
|
|||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = 'Tx_Extbase_Command_HelpCommandController';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_Extbase_Command_HelpCommandController";
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&Tx_ExtKey_Hooks_Cache->getHash';
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['createHashBase'][] = 'EXT:ext_key/Classes/Hooks/Cache.php:&Tx_Extbase_Command_HelpCommandController->getHash';
|
||||
|
||||
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = "Tx_About_Domain_Model_Extension";
|
||||
$GLOBALS['TCA']['tx_about_domain_model_extension'] = [];
|
||||
|
|
Loading…
Reference in a new issue