TASK: Migrate GenericConstantUsageSniff
* Migrate GenericConstantUsageSniff to new architecture. * Move non common functionality from AbstractGenericPhpUsage to concrete classes. Relates: #71
This commit is contained in:
parent
84dd380a3c
commit
bcbd1f96bc
3 changed files with 35 additions and 64 deletions
|
@ -21,11 +21,13 @@ namespace Typo3Update\Sniffs\Removed;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHP_CodeSniffer_File as PhpCsFile;
|
use PHP_CodeSniffer_File as PhpCsFile;
|
||||||
use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
|
|
||||||
|
|
||||||
abstract class AbstractGenericPhpUsage extends AbstractGenericUsage
|
abstract class AbstractGenericPhpUsage extends AbstractGenericUsage
|
||||||
{
|
{
|
||||||
use ExtendedPhpCsSupportTrait;
|
public function register()
|
||||||
|
{
|
||||||
|
return [T_STRING];
|
||||||
|
}
|
||||||
|
|
||||||
protected function prepareStructure(array $typo3Versions)
|
protected function prepareStructure(array $typo3Versions)
|
||||||
{
|
{
|
||||||
|
@ -51,10 +53,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage
|
||||||
|
|
||||||
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
|
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
|
||||||
{
|
{
|
||||||
if (!$this->isFunctionCall($phpcsFile, $stackPtr)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
$tokens = $phpcsFile->getTokens();
|
$tokens = $phpcsFile->getTokens();
|
||||||
$staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true);
|
$staticPosition = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true, null, true);
|
||||||
|
|
||||||
|
@ -120,15 +118,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getOldUsage(array $config)
|
|
||||||
{
|
|
||||||
$concat = '->';
|
|
||||||
if ($config['static']) {
|
|
||||||
$concat = '::';
|
|
||||||
}
|
|
||||||
return $config['fqcn'] . $concat . $config['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getIdentifier(array $config)
|
protected function getIdentifier(array $config)
|
||||||
{
|
{
|
||||||
$name = $config['name'];
|
$name = $config['name'];
|
||||||
|
@ -138,4 +127,6 @@ abstract class AbstractGenericPhpUsage extends AbstractGenericUsage
|
||||||
|
|
||||||
return $name;
|
return $name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract protected function getOldUsage(array $config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,42 +19,11 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHP_CodeSniffer_File as PhpCsFile;
|
use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage;
|
||||||
use Typo3Update\Sniffs\Removed\AbstractGenericUsage;
|
|
||||||
use Typo3Update\Options;
|
use Typo3Update\Options;
|
||||||
|
|
||||||
/**
|
class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericPhpUsage
|
||||||
* Sniff that handles all calls to removed constants.
|
|
||||||
*/
|
|
||||||
class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGenericUsage
|
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Return file names containing removed configurations.
|
|
||||||
*
|
|
||||||
* @return array<string>
|
|
||||||
*/
|
|
||||||
protected function getRemovedConfigFiles()
|
|
||||||
{
|
|
||||||
return Options::getRemovedConstantConfigFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the token types that this sniff is interested in.
|
|
||||||
*
|
|
||||||
* @return array<int>
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
return [T_STRING];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The original constant call, to allow user to check matches.
|
|
||||||
*
|
|
||||||
* @param array $config
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getOldUsage(array $config)
|
protected function getOldUsage(array $config)
|
||||||
{
|
{
|
||||||
$old = $config['name'];
|
$old = $config['name'];
|
||||||
|
@ -64,4 +33,9 @@ class Typo3Update_Sniffs_Removed_GenericConstantUsageSniff extends AbstractGener
|
||||||
|
|
||||||
return 'constant ' . $old;
|
return 'constant ' . $old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getRemovedConfigFiles()
|
||||||
|
{
|
||||||
|
return Options::getRemovedConstantConfigFiles();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,32 +19,38 @@
|
||||||
* 02110-1301, USA.
|
* 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use PHP_CodeSniffer_Tokens as Tokens;
|
use PHP_CodeSniffer_File as PhpCsFile;
|
||||||
use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage;
|
|
||||||
use Typo3Update\Options;
|
use Typo3Update\Options;
|
||||||
|
use Typo3Update\Sniffs\ExtendedPhpCsSupportTrait;
|
||||||
|
use Typo3Update\Sniffs\Removed\AbstractGenericPhpUsage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sniff that handles all calls to removed functions.
|
* Sniff that handles all calls to removed functions.
|
||||||
*/
|
*/
|
||||||
class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGenericPhpUsage
|
class Typo3Update_Sniffs_Removed_GenericFunctionCallSniff extends AbstractGenericPhpUsage
|
||||||
{
|
{
|
||||||
/**
|
use ExtendedPhpCsSupportTrait;
|
||||||
* Returns the token types that this sniff is interested in.
|
|
||||||
*
|
|
||||||
* @return array<int>
|
|
||||||
*/
|
|
||||||
public function register()
|
|
||||||
{
|
|
||||||
return [T_STRING];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return file names containing removed configurations.
|
|
||||||
*
|
|
||||||
* @return array<string>
|
|
||||||
*/
|
|
||||||
protected function getRemovedConfigFiles()
|
protected function getRemovedConfigFiles()
|
||||||
{
|
{
|
||||||
return Options::getRemovedFunctionConfigFiles();
|
return Options::getRemovedFunctionConfigFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function findRemoved(PhpCsFile $phpcsFile, $stackPtr)
|
||||||
|
{
|
||||||
|
if (!$this->isFunctionCall($phpcsFile, $stackPtr)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::findRemoved($phpcsFile, $stackPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getOldUsage(array $config)
|
||||||
|
{
|
||||||
|
$concat = '->';
|
||||||
|
if ($config['static']) {
|
||||||
|
$concat = '::';
|
||||||
|
}
|
||||||
|
return $config['fqcn'] . $concat . $config['name'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue