[DeprecationExtractor] add TYPE_UNSUPPORTED to RectorGuess

This commit is contained in:
TomasVotruba 2017-10-11 19:24:52 +02:00
parent fd45756be2
commit 1d5a01fcb0
4 changed files with 15 additions and 87 deletions

View File

@ -107,14 +107,9 @@ final class ExtractDeprecationsCommand extends Command
return 0;
}
private function shouldSkipGuessedRector(?RectorGuess $guessedRector): bool
private function shouldSkipGuessedRector(RectorGuess $guessedRector): bool
{
if ($guessedRector === null) {
return true;
}
$typesToHide = [RectorGuess::TYPE_YAML_CONFIGURATION, RectorGuess::TYPE_SERVICE];
if (in_array($guessedRector->getGuessedRectorClass(), $typesToHide, true)) {
if ($guessedRector->getGuessedRectorClass() === RectorGuess::TYPE_UNSUPPORTED) {
return true;
}

View File

@ -19,54 +19,23 @@ use Rector\NodeValueResolver\NodeValueResolver;
*/
final class RectorGuesser
{
/**
* @var NodeValueResolver
*/
private $nodeValueResolver;
/**
* @var RectorGuessFactory
*/
private $rectorGuessFactory;
/**
* @var string[]
*/
private $yamlDeprecationMessages = [
'Autowiring-types are deprecated since',
'The "=" suffix that used to disable strict references',
'The XmlFileLoader will raise an exception in Symfony 4.0, instead of silently ignoring unsupported',
'The "strict" attribute used when referencing the "" service is deprecated since version 3.3 and will be removed in 4.0.',
'Service names that start with an underscore are deprecated since Symfony 3.3 and will be reserved in 4.0',
'configuration key',
];
/**
* @var string[]
*/
private $serviceDeprecationMessages = [
'It should either be deprecated or its implementation upgraded.',
'It should either be deprecated or its factory upgraded.',
'Service identifiers will be made case sensitive',
'Generating a dumped container without populating the method map is deprecated',
'Dumping an uncompiled ContainerBuilder is deprecated',
'service is private, ',
'service is already initialized, ',
'Relying on its factory\'s return-type to define the class of service',
];
/**
* @var UnsupportedDeprecationFilter
*/
private $unsupportedDeprecationFilter;
public function __construct(
NodeValueResolver $nodeValueResolver,
// NodeValueResolver $nodeValueResolver,
ClassPrepender $classPrepender,
RectorGuessFactory $rectorGuessFactory,
UnsupportedDeprecationFilter $unsupportedDeprecationFilter
) {
$this->nodeValueResolver = $nodeValueResolver;
// $this->nodeValueResolver = $nodeValueResolver;
$this->classPrepender = $classPrepender;
$this->rectorGuessFactory = $rectorGuessFactory;
$this->unsupportedDeprecationFilter = $unsupportedDeprecationFilter;
@ -75,12 +44,7 @@ final class RectorGuesser
public function guessForDeprecation(Deprecation $deprecation): ?RectorGuess
{
if ($this->unsupportedDeprecationFilter->matches($deprecation)) {
return $this->rectorGuessFactory->
}
$rectorGuess = $this->processWithEarlyFilter($deprecation);
if ($rectorGuess !== null) {
return $rectorGuess;
return $this->rectorGuessFactory->createUnsupported($deprecation->getMessage(), $deprecation->getNode());
}
$message = $this->classPrepender->completeClassToLocalMethods(
@ -135,23 +99,6 @@ final class RectorGuesser
return $guessedRectors;
}
private function processWithEarlyFilter(Deprecation $deprecation): ?RectorGuess
{
foreach ($this->yamlDeprecationMessages as $yamlDeprecationMessage) {
if (Strings::contains($deprecation->getMessage(), $yamlDeprecationMessage)) {
return $this->rectorGuessFactory->createYamlConfiguration($deprecation->getMessage(), $deprecation->getNode());
}
}
foreach ($this->serviceDeprecationMessages as $serviceDeprecationMessage) {
if (Strings::contains($deprecation->getMessage(), $serviceDeprecationMessage)) {
return $this->rectorGuessFactory->createService($deprecation->getMessage(), $deprecation->getNode());
}
}
return null;
}
// private function guess(string $message, Node $node): ?RectorGuess
// {
// // @todo: per node resolver...

View File

@ -15,12 +15,7 @@ final class RectorGuess
/**
* @var string
*/
public const TYPE_YAML_CONFIGURATION = 'YAML_CONFIGURATION';
/**
* @var string
*/
public const TYPE_SERVICE = 'SERVICE';
public const TYPE_UNSUPPORTED = 'UNSUPPORTED';
/**
* @var string

View File

@ -36,24 +36,6 @@ final class RectorGuessFactory
);
}
public function createYamlConfiguration(string $message, Node $node): RectorGuess
{
return new RectorGuess(
RectorGuess::TYPE_YAML_CONFIGURATION,
$node,
$message
);
}
public function createService(string $message, Node $node): RectorGuess
{
return new RectorGuess(
RectorGuess::TYPE_SERVICE,
$node,
$message
);
}
public function createNewArgument(string $message, Node $node): RectorGuess
{
return new RectorGuess(
@ -62,4 +44,13 @@ final class RectorGuessFactory
$message
);
}
public function createUnsupported(string $message, Node $node): RectorGuess
{
return new RectorGuess(
RectorGuess::TYPE_UNSUPPORTED,
$node,
$message
);
}
}