FEATURE: Improve handling of missing Vendor
* Check for string concatenation instead of earlier more stupid. Relates: #36
This commit is contained in:
parent
f9f82b0629
commit
1561c13b46
2 changed files with 51 additions and 6 deletions
15
Readme.rst
15
Readme.rst
|
@ -71,6 +71,21 @@ new ones like ``\TYPO3\Extbase\...``. This is done for:
|
|||
|
||||
- Convert old legacy class definitions in extensions to namespace ones.
|
||||
|
||||
- Add missing vendor to plugin and module registrations and configurations.
|
||||
You might want to set this to non fixable and warning if you already provide the vendor inside a
|
||||
single Variable, together with your extension key, as this is not recognized. So the following
|
||||
will be recognized:
|
||||
|
||||
- $_EXTKEY,
|
||||
|
||||
- $VENDOR . $_EXTKEY,
|
||||
|
||||
- 'VENDOR.' . $_EXTKEY,
|
||||
|
||||
While the following will not:
|
||||
|
||||
- $key = 'Vendor.' . $_EXTKEY;
|
||||
|
||||
Also we check for the following deprecated calls:
|
||||
|
||||
- Check for ``create`` on ``ObjectManager``, which is "stupid" just all ``create`` calls are marked
|
||||
|
|
|
@ -68,22 +68,52 @@ class Typo3Update_Sniffs_LegacyClassnames_MissingVendorForPluginsAndModulesSniff
|
|||
return;
|
||||
}
|
||||
|
||||
$firstParameter = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true);
|
||||
if ($firstParameter === false || $tokens[$firstParameter]['code'] === T_CONSTANT_ENCAPSED_STRING) {
|
||||
$firstArgument = $phpcsFile->findNext([T_WHITESPACE, T_OPEN_PARENTHESIS], $stackPtr + 1, null, true);
|
||||
if (! $this->isVendorMissing($phpcsFile, $firstArgument)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fix = $phpcsFile->addFixableError(
|
||||
'No vendor is given, that will break TYPO3 handling for namespaced classes. Add vendor before Extensionkey like: "Vendor." . $_EXTKEY',
|
||||
$firstParameter,
|
||||
'No vendor is given, that will break TYPO3 handling for namespaced classes.'
|
||||
. ' Add vendor before Extensionkey like: "Vendor." . $_EXTKEY',
|
||||
$firstArgument,
|
||||
'missingVendor'
|
||||
);
|
||||
|
||||
if ($fix === true) {
|
||||
$phpcsFile->fixer->replaceToken(
|
||||
$firstParameter,
|
||||
"'{$this->getVendor()}.' . " . $tokens[$firstParameter]['content']
|
||||
$firstArgument,
|
||||
"'{$this->getVendor()}.' . " . $tokens[$firstArgument]['content']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether vendor is missing in given argument.
|
||||
*
|
||||
* @param PhpCsFile $phpcsFile
|
||||
* @param int|bool $argumentStart
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isVendorMissing(PhpCsFile $phpcsFile, $argumentStart)
|
||||
{
|
||||
if ($argumentStart === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$argumentEnd = $phpcsFile->findNext(T_COMMA, $argumentStart);
|
||||
if ($argumentEnd === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stringConcats = array_filter(
|
||||
array_slice($phpcsFile->getTokens(), $argumentStart, $argumentEnd - $argumentStart),
|
||||
function (array $token) {
|
||||
return $token['code'] === 'PHPCS_T_STRING_CONCAT';
|
||||
}
|
||||
);
|
||||
|
||||
return count($stringConcats) === 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue