mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
[DeprecationExtractor] RectorGuesser WIP
This commit is contained in:
parent
c458f12177
commit
bd0cc3fdf4
@ -119,13 +119,13 @@ final class ExtractDeprecationsCommand extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function shouldSkipGuessedRector(?RectorGuess $guessedRector): bool
|
||||
private function shouldSkipGuessedRector(?RectorGuess $guessedRector): bool
|
||||
{
|
||||
if ($guessedRector === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($guessedRector->getGuessedRectorClass() === RectorGuess::YAML_CONFIGURATION) {
|
||||
if (in_array($guessedRector->getGuessedRectorClass(), [RectorGuess::YAML_CONFIGURATION, RectorGuess::SERVICE], true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DeprecationExtractor\Rector;
|
||||
use Rector\DeprecationExtractor\RectorGuess\RectorGuess;
|
||||
|
||||
/**
|
||||
* This class tries to guess, which Rector could be used to create refactoring
|
||||
@ -18,6 +19,10 @@ final class RectorGuesser
|
||||
*/
|
||||
private $triggerErrorRectorGuesser;
|
||||
|
||||
/**
|
||||
* These 2 should be merged to and work primarily with $message
|
||||
* to prevent any duplications.
|
||||
*/
|
||||
public function __construct(
|
||||
AnnotationRectorGuesser $annotationRectorGuesser,
|
||||
TriggerErrorRectorGuesser $triggerErrorRectorGuesser
|
||||
|
@ -24,6 +24,32 @@ final class TriggerErrorRectorGuesser
|
||||
*/
|
||||
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',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
ClassAndMethodMatcher $classAndMethodMatcher,
|
||||
NodeValueResolver $nodeValueResolver,
|
||||
@ -67,17 +93,33 @@ final class TriggerErrorRectorGuesser
|
||||
*/
|
||||
private function createFromMessage(Node $node, string $message)
|
||||
{
|
||||
if (Strings::contains($message, 'Autowiring-types are deprecated since')) {
|
||||
return $this->rectorGuessFactory->createYamlConfiguration($message, $node);
|
||||
foreach ($this->yamlDeprecationMessages as $yamlDeprecationMessage) {
|
||||
if (Strings::contains($message, $yamlDeprecationMessage)) {
|
||||
return $this->rectorGuessFactory->createYamlConfiguration($message, $node);
|
||||
}
|
||||
}
|
||||
|
||||
if (Strings::contains($message, 'configuration key') && Strings::contains($message, 'Yaml')) {
|
||||
return $this->rectorGuessFactory->createYamlConfiguration($message, $node);
|
||||
foreach ($this->serviceDeprecationMessages as $serviceDeprecationMessage) {
|
||||
if (Strings::contains($message, $serviceDeprecationMessage)) {
|
||||
return $this->rectorGuessFactory->createService($message, $node);
|
||||
}
|
||||
}
|
||||
|
||||
if (Strings::contains($message, 'It will be made mandatory in') || Strings::contains($message, 'Not defining it is deprecated since')) {
|
||||
return $this->rectorGuessFactory->createNewArgument($message, $node);
|
||||
}
|
||||
|
||||
$result = Strings::split($message, '#use |Use#');
|
||||
|
||||
if (count($result) === 2) {
|
||||
if (Strings::contains($message, 'class is deprecated')) {
|
||||
return $this->rectorGuessFactory->createClassReplacer(
|
||||
'...',
|
||||
$message,
|
||||
$node
|
||||
);
|
||||
}
|
||||
|
||||
return $this->rectorGuessFactory->createMethodNameReplacerGuess(
|
||||
$message,
|
||||
$node
|
||||
|
@ -17,6 +17,11 @@ final class RectorGuess
|
||||
*/
|
||||
public const YAML_CONFIGURATION = 'YAML_CONFIGURATION';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const SERVICE = 'SERVICE';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -47,4 +47,24 @@ final class RectorGuessFactory
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
public function createService(string $message, Node $node): RectorGuess
|
||||
{
|
||||
return new RectorGuess(
|
||||
RectorGuess::SERVICE,
|
||||
0.95,
|
||||
$node,
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
public function createNewArgument(string $message, Node $node): RectorGuess
|
||||
{
|
||||
return new RectorGuess(
|
||||
'_new_argument_rectory_todo',
|
||||
0.95,
|
||||
$node,
|
||||
$message
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,10 @@ namespace Rector\FileSystem;
|
||||
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* Consider using NodeTraverser, same as for namespace to add to node.
|
||||
* Would allow united API.
|
||||
*/
|
||||
final class CurrentFileProvider
|
||||
{
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user