TASK: Do not check all classname parts for extension name

* As discussed in PR, fetch possible extension names and lookup only
  them, not all parts of class name.

Relates: #44, !70
This commit is contained in:
Daniel Siepmann 2017-05-18 08:33:10 +02:00
parent 41d5ec0dff
commit 87cf3a3195
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
2 changed files with 26 additions and 12 deletions

View file

@ -21,12 +21,15 @@ namespace Typo3Update\Feature;
*/
use PHP_CodeSniffer_File as PhpCsFile;
use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
/**
* Provides "feature" support for sniffs.
*/
trait FeaturesSupport
{
use ExtendedPhpCsSupportTrait;
/**
* @return Features
*/
@ -44,6 +47,8 @@ trait FeaturesSupport
*/
public function processFeatures(PhpCsFile $phpcsFile, $stackPtr, $content)
{
$content = $this->getStringContent($content);
foreach ($this->getFeatures() as $featureClassName) {
$feature = $this->createFeature($featureClassName);
$feature->process($phpcsFile, $stackPtr, $content);

View file

@ -27,18 +27,8 @@ class RemovedExtensionFeature extends AbstractYamlRemovedUsage
{
public function process(PhpCsFile $phpcsFile, $classnamePosition, $classname)
{
$classnameParts = array_filter(preg_split('/\\\\|_/', $classname));
$extname = '';
foreach ($classnameParts as $classnamePart) {
$classnamePart = strtolower($classnamePart);
if ($this->configured->isRemoved($classnamePart) === true) {
$extname = $classnamePart;
break;
}
}
if ($extname === '') {
$extname = $this->getExtnameFromClassname($classname);
if ($extname === '' || $this->configured->isRemoved($extname) === false) {
return;
}
@ -49,6 +39,25 @@ class RemovedExtensionFeature extends AbstractYamlRemovedUsage
);
}
protected function getExtnameFromClassname($classname)
{
$classname = ltrim($classname, '\\');
$classnameParts = array_filter(preg_split('/\\\\|_/', $classname));
$classnameParts = array_values($classnameParts); // To reset key numbers of array.
$extname = '';
if (count($classnameParts) <= 2) {
return '';
}
$extname = $classnameParts[1];
if (stripos($classname, 'TYPO3\CMS') === 0) {
$extname = $classnameParts[2];
}
return strtolower($extname);
}
protected function prepareStructure(array $typo3Versions)
{
$newStructure = [];