TASK: Migrate RemovedClassFeature
* Also migrate RemovedClassFeature to new structure with AbstractYamlRemovedUsage Relates: #71
This commit is contained in:
parent
bcbd1f96bc
commit
b9bdd5dd3b
5 changed files with 140 additions and 26 deletions
103
src/Standards/Typo3Update/Feature/AbstractYamlRemovedUsage.php
Normal file
103
src/Standards/Typo3Update/Feature/AbstractYamlRemovedUsage.php
Normal file
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
namespace Typo3Update\Feature;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2017 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
use PHP_CodeSniffer as PhpCs;
|
||||
use PHP_CodeSniffer_File as PhpCsFile;
|
||||
use PHP_CodeSniffer_Sniff as PhpCsSniff;
|
||||
use Typo3Update\RemovedByYamlConfiguration;
|
||||
|
||||
/**
|
||||
* Contains common functionality for removed code like constants or functions.
|
||||
*
|
||||
* Removed parts are configured using YAML-Files, for examples see
|
||||
* src/Standards/Typo3Update/Configuration/Removed/Constants/7.0.yaml Also
|
||||
* check out the configuration options in Readme.rst.
|
||||
*/
|
||||
abstract class AbstractYamlRemovedUsage implements FeatureInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $configured;
|
||||
|
||||
/**
|
||||
* @var PhpCsSniff
|
||||
*/
|
||||
protected $sniff;
|
||||
|
||||
public function __construct(PhpCsSniff $sniff)
|
||||
{
|
||||
$this->sniff = $sniff;
|
||||
$this->configured = new RemovedByYamlConfiguration(
|
||||
$this->getRemovedConfigFiles(),
|
||||
\Closure::fromCallable([$this, 'prepareStructure'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares structure from config for later usage.
|
||||
*
|
||||
* @param array $typo3Versions
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function prepareStructure(array $typo3Versions);
|
||||
|
||||
/**
|
||||
* Return file names containing removed configurations.
|
||||
*
|
||||
* @return array<string>
|
||||
*/
|
||||
abstract protected function getRemovedConfigFiles();
|
||||
|
||||
protected function addWarning(PhpCsFile $phpcsFile, $stackPtr, array $removed)
|
||||
{
|
||||
$phpcsFile->addWarning(
|
||||
'Calls to removed code are not allowed; found %s. Removed in %s. %s. See: %s',
|
||||
$stackPtr,
|
||||
$removed['identifier'],
|
||||
[
|
||||
$removed['oldUsage'],
|
||||
$removed['versionRemoved'],
|
||||
$this->getReplacement($removed),
|
||||
$removed['docsUrl'],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The new call, or information how to migrate.
|
||||
*
|
||||
* To provide feedback for user to ease migration.
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getReplacement(array $config)
|
||||
{
|
||||
$newCall = $config['replacement'];
|
||||
if ($newCall !== null) {
|
||||
return $newCall;
|
||||
}
|
||||
return 'There is no replacement, just remove call';
|
||||
}
|
||||
}
|
|
@ -21,12 +21,18 @@ namespace Typo3Update\Feature;
|
|||
*/
|
||||
|
||||
use PHP_CodeSniffer_File as PhpCsFile;
|
||||
use PHP_CodeSniffer_Sniff as PhpCsSniff;
|
||||
|
||||
/**
|
||||
* See "Features" in documentation.
|
||||
*/
|
||||
interface FeatureInterface
|
||||
{
|
||||
/**
|
||||
* @var PhpCsSniff $sniff
|
||||
*/
|
||||
public function __construct(PhpCsSniff $sniff);
|
||||
|
||||
/**
|
||||
* Process like a PHPCS Sniff.
|
||||
*
|
||||
|
|
|
@ -20,37 +20,42 @@ namespace Typo3Update\Feature;
|
|||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
use PHP_CodeSniffer as PhpCs;
|
||||
use PHP_CodeSniffer_File as PhpCsFile;
|
||||
use PHP_CodeSniffer_Sniff as PhpCsSniff;
|
||||
use Typo3Update\Options;
|
||||
|
||||
/**
|
||||
* This feature will add fixable errors for old legacy classnames.
|
||||
*
|
||||
* Can be attached to sniffs returning classnames.
|
||||
*/
|
||||
class RemovedClassFeature implements FeatureInterface
|
||||
class RemovedClassFeature extends AbstractYamlRemovedUsage
|
||||
{
|
||||
/**
|
||||
* Process like a PHPCS Sniff.
|
||||
*
|
||||
* @param PhpCsFile $phpcsFile
|
||||
* @param int $classnamePosition
|
||||
* @param string $classname
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(PhpCsFile $phpcsFile, $classnamePosition, $classname)
|
||||
{
|
||||
if ($this->isClassnameRemoved($classname) === false) {
|
||||
if (! $this->configured->isRemoved($classname)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$phpcsFile->addError(
|
||||
'Removed classes are not allowed; found "%s", use "%s" instead',
|
||||
$this->addWarning(
|
||||
$phpcsFile,
|
||||
$classnamePosition,
|
||||
'removedClassname',
|
||||
[$classname]
|
||||
$this->configured->getRemoved($classname)
|
||||
);
|
||||
}
|
||||
|
||||
protected function prepareStructure(array $typo3Versions)
|
||||
{
|
||||
$newStructure = [];
|
||||
foreach ($typo3Versions as $typo3Version => $removals) {
|
||||
foreach ($removals as $removed => $config) {
|
||||
$config['name'] = $removed;
|
||||
$config['identifier'] = 'RemovedClass.' . str_replace('\\', '_', ltrim($removed, '\\'));
|
||||
$config['versionRemoved'] = $typo3Version;
|
||||
$config['oldUsage'] = $removed;
|
||||
|
||||
$newStructure[$removed] = $config;
|
||||
}
|
||||
}
|
||||
|
||||
return $newStructure;
|
||||
}
|
||||
|
||||
protected function getRemovedConfigFiles()
|
||||
{
|
||||
return Options::getRemovedClassConfigFiles();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ class Options
|
|||
{
|
||||
return static::getOptionFileNames(
|
||||
'removedClassConfigFiles',
|
||||
__DIR__ . '/../Configuration/Removed/Classes/*.yaml'
|
||||
__DIR__ . '/Configuration/Removed/Classes/*.yaml'
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,9 +25,9 @@
|
|||
"column": 15,
|
||||
"fixable": false,
|
||||
"line": 32,
|
||||
"message": "Legacy calls are not allowed; found \\TYPO3\\CMS\\Backend\\Template\\MediumDocumentTemplate. Removed in 7.0. Use \\TYPO3\\CMS\\Backend\\Template\\DocumentTemplate instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-61782-DeprecatedDocumentTemplateClassesRemoved.html",
|
||||
"message": "Calls to removed code are not allowed; found \\TYPO3\\CMS\\Backend\\Template\\MediumDocumentTemplate. Removed in 7.0. Use \\TYPO3\\CMS\\Backend\\Template\\DocumentTemplate instead. See: https://docs.typo3.org/typo3cms/extensions/core/7.6/Changelog/7.0/Breaking-61782-DeprecatedDocumentTemplateClassesRemoved.html",
|
||||
"severity": 5,
|
||||
"source": "Typo3Update.LegacyClassnames.DocComment.TYPO3_CMS_Backend_Template_MediumDocumentTemplate",
|
||||
"source": "Typo3Update.Classname.PhpDocComment.RemovedClass.TYPO3_CMS_Backend_Template_MediumDocumentTemplate",
|
||||
"type": "WARNING"
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue