Updated Rector to commit e17f4526a7aa8344d0bfbf61d16d125970a3d31a

e17f4526a7 Fix RectorParser::parseString() parameter name (#5467)
This commit is contained in:
Tomas Votruba 2024-01-15 10:34:53 +00:00
parent bc8f465840
commit b13cc2ebb6
8 changed files with 145 additions and 8 deletions

View File

@ -2094,6 +2094,7 @@ return array(
'Rector\\Symfony\\Contract\\Tag\\TagInterface' => $vendorDir . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php', 'Rector\\Symfony\\Contract\\Tag\\TagInterface' => $vendorDir . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php',
'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php',
'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => $vendorDir . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php',
'Rector\\Symfony\\DowngradeSymfony70\\Rector\\Class_\\DowngradeSymfonyCommandAttributeRector' => $vendorDir . '/rector/rector-symfony/rules/DowngradeSymfony70/Rector/Class_/DowngradeSymfonyCommandAttributeRector.php',
'Rector\\Symfony\\Enum\\SensioAttribute' => $vendorDir . '/rector/rector-symfony/src/Enum/SensioAttribute.php', 'Rector\\Symfony\\Enum\\SensioAttribute' => $vendorDir . '/rector/rector-symfony/src/Enum/SensioAttribute.php',
'Rector\\Symfony\\Enum\\SymfonyAnnotation' => $vendorDir . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php', 'Rector\\Symfony\\Enum\\SymfonyAnnotation' => $vendorDir . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php',
'Rector\\Symfony\\Enum\\SymfonyClass' => $vendorDir . '/rector/rector-symfony/src/Enum/SymfonyClass.php', 'Rector\\Symfony\\Enum\\SymfonyClass' => $vendorDir . '/rector/rector-symfony/src/Enum/SymfonyClass.php',

View File

@ -2308,6 +2308,7 @@ class ComposerStaticInit0d7ac37abdc3277d2804c7296dfa0f13
'Rector\\Symfony\\Contract\\Tag\\TagInterface' => __DIR__ . '/..' . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php', 'Rector\\Symfony\\Contract\\Tag\\TagInterface' => __DIR__ . '/..' . '/rector/rector-symfony/src/Contract/Tag/TagInterface.php',
'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceMapProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceMapProvider.php',
'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php', 'Rector\\Symfony\\DataProvider\\ServiceNameToTypeUniqueProvider' => __DIR__ . '/..' . '/rector/rector-symfony/src/DataProvider/ServiceNameToTypeUniqueProvider.php',
'Rector\\Symfony\\DowngradeSymfony70\\Rector\\Class_\\DowngradeSymfonyCommandAttributeRector' => __DIR__ . '/..' . '/rector/rector-symfony/rules/DowngradeSymfony70/Rector/Class_/DowngradeSymfonyCommandAttributeRector.php',
'Rector\\Symfony\\Enum\\SensioAttribute' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SensioAttribute.php', 'Rector\\Symfony\\Enum\\SensioAttribute' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SensioAttribute.php',
'Rector\\Symfony\\Enum\\SymfonyAnnotation' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php', 'Rector\\Symfony\\Enum\\SymfonyAnnotation' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SymfonyAnnotation.php',
'Rector\\Symfony\\Enum\\SymfonyClass' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SymfonyClass.php', 'Rector\\Symfony\\Enum\\SymfonyClass' => __DIR__ . '/..' . '/rector/rector-symfony/src/Enum/SymfonyClass.php',

View File

@ -1867,12 +1867,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git", "url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "c9d78b386a7658e3f9ad71ad055a38eca436ee69" "reference": "364641ced830a2b1077596a811fbf6885b49fcff"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/c9d78b386a7658e3f9ad71ad055a38eca436ee69", "url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/364641ced830a2b1077596a811fbf6885b49fcff",
"reference": "c9d78b386a7658e3f9ad71ad055a38eca436ee69", "reference": "364641ced830a2b1077596a811fbf6885b49fcff",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1906,7 +1906,7 @@
"tomasvotruba\/unused-public": "^0.2", "tomasvotruba\/unused-public": "^0.2",
"tracy\/tracy": "^2.10" "tracy\/tracy": "^2.10"
}, },
"time": "2024-01-02T14:07:13+00:00", "time": "2024-01-15T10:31:19+00:00",
"default-branch": true, "default-branch": true,
"type": "rector-extension", "type": "rector-extension",
"extra": { "extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/ */
final class GeneratedConfig final class GeneratedConfig
{ {
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b419ce7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 51ff6e7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 4581a9a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main c9d78b3')); public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main b419ce7'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 51ff6e7'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 4581a9a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 364641c'));
private function __construct() private function __construct()
{ {
} }

View File

@ -0,0 +1,135 @@
<?php
declare (strict_types=1);
namespace Rector\Symfony\DowngradeSymfony70\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PHPStan\Reflection\ClassReflection;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Rector\ValueObject\Visibility;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Symfony\Tests\DowngradeSymfony70\Rector\Class_\DowngradeSymfonyCommandAttributeRector\DowngradeSymfonyCommandAttributeRectorTest
*/
final class DowngradeSymfonyCommandAttributeRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(ReflectionResolver $reflectionResolver)
{
$this->reflectionResolver = $reflectionResolver;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Downgrade Symfony Command Attribute', [new CodeSample(<<<'CODE_SAMPLE'
#[AsCommand(name: 'app:create-user', description: 'some description')]
class CreateUserCommand extends Command
{}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
#[AsCommand(name: 'app:create-user', description: 'some description')]
class CreateUserCommand extends Command
{
protected function configure(): void
{
$this->setName('app:create-user');
$this->setDescription('some description');
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
if (!$classReflection instanceof ClassReflection) {
return null;
}
if (!$classReflection->isSubClassOf('Symfony\\Component\\Console\\Command\\Command')) {
return null;
}
$resolveNameAndDescription = $this->resolveNameAndDescription($node);
$name = $resolveNameAndDescription['name'];
$description = $resolveNameAndDescription['description'];
if ($name === null && $description === null) {
return null;
}
$configureClassMethod = $node->getMethod('configure');
$stmts = [];
if ($name !== null) {
$stmts[] = new Expression(new MethodCall(new Variable('this'), 'setName', [new Arg($name)]));
}
if ($description !== null) {
$stmts[] = new Expression(new MethodCall(new Variable('this'), 'setDescription', [new Arg($description)]));
}
if ($configureClassMethod instanceof ClassMethod) {
$configureClassMethod->stmts = \array_merge((array) $configureClassMethod->stmts, $stmts);
} else {
$classMethod = new ClassMethod('configure');
$classMethod->flags = Visibility::PROTECTED;
$classMethod->stmts = $stmts;
$node->stmts[] = $classMethod;
}
foreach ($node->attrGroups as $keyAttribute => $attrGroup) {
foreach ($attrGroup->attrs as $key => $attr) {
if ($attr->name->toString() === 'Symfony\\Component\\Console\\Attribute\\AsCommand') {
unset($attrGroup->attrs[$key]);
}
}
if ($attrGroup->attrs === []) {
unset($node->attrGroups[$keyAttribute]);
}
}
return $node;
}
/**
* @return array{name: ?Expr, description: ?Expr}
*/
private function resolveNameAndDescription(Class_ $node) : array
{
$name = null;
$description = null;
foreach ($node->attrGroups as $attrGroup) {
foreach ($attrGroup->attrs as $attr) {
if ($attr->name->toString() !== 'Symfony\\Component\\Console\\Attribute\\AsCommand') {
continue;
}
foreach ($attr->args as $arg) {
if (!$arg->name instanceof Identifier) {
continue;
}
if ($arg->name->toString() === 'name') {
$name = $arg->value;
}
if ($arg->name->toString() === 'description') {
$description = $arg->value;
}
}
}
}
return ['name' => $name, 'description' => $description];
}
}

View File

@ -16,9 +16,9 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\String_; use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use Rector\Rector\AbstractRector; use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\Symfony\Enum\SensioAttribute; use Rector\Symfony\Enum\SensioAttribute;
use Rector\Symfony\Enum\SymfonyAnnotation; use Rector\Symfony\Enum\SymfonyAnnotation;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

View File

@ -11,8 +11,8 @@ use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType; use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType; use PHPStan\Type\ThisType;
use PHPStan\Type\TypeWithClassName; use PHPStan\Type\TypeWithClassName;
use Rector\Reflection\ReflectionResolver;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Reflection\ReflectionResolver;
final class ControllerAnalyzer final class ControllerAnalyzer
{ {
/** /**