Updated Rector to commit efef8aca6e7aaf688759cd09b48c64990adbfb53

efef8aca6e [Php81] Skip property hook on ReadOnlyPropertyRector (#6758)
This commit is contained in:
Tomas Votruba 2025-02-28 14:03:15 +00:00
parent 8457889ed4
commit 6d653bc5d2
8 changed files with 112 additions and 8 deletions

View File

@ -1431,6 +1431,7 @@ return array(
'Rector\\Doctrine\\NodeManipulator\\ToOneRelationPropertyTypeResolver' => $vendorDir . '/rector/rector-doctrine/src/NodeManipulator/ToOneRelationPropertyTypeResolver.php',
'Rector\\Doctrine\\Orm214\\Rector\\Param\\ReplaceLifecycleEventArgsByDedicatedEventArgsRector' => $vendorDir . '/rector/rector-doctrine/rules/Orm214/Rector/Param/ReplaceLifecycleEventArgsByDedicatedEventArgsRector.php',
'Rector\\Doctrine\\Orm28\\Rector\\MethodCall\\IterateToToIterableRector' => $vendorDir . '/rector/rector-doctrine/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php',
'Rector\\Doctrine\\Orm30\\Rector\\MethodCall\\SetParametersArrayToCollectionRector' => $vendorDir . '/rector/rector-doctrine/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php',
'Rector\\Doctrine\\PhpDocParser\\DoctrineDocBlockResolver' => $vendorDir . '/rector/rector-doctrine/src/PhpDocParser/DoctrineDocBlockResolver.php',
'Rector\\Doctrine\\PhpDoc\\ShortClassExpander' => $vendorDir . '/rector/rector-doctrine/src/PhpDoc/ShortClassExpander.php',
'Rector\\Doctrine\\Set\\DoctrineSetList' => $vendorDir . '/rector/rector-doctrine/src/Set/DoctrineSetList.php',

View File

@ -1650,6 +1650,7 @@ class ComposerStaticInit57511360b381a600aff109823304b5c7
'Rector\\Doctrine\\NodeManipulator\\ToOneRelationPropertyTypeResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/NodeManipulator/ToOneRelationPropertyTypeResolver.php',
'Rector\\Doctrine\\Orm214\\Rector\\Param\\ReplaceLifecycleEventArgsByDedicatedEventArgsRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/Orm214/Rector/Param/ReplaceLifecycleEventArgsByDedicatedEventArgsRector.php',
'Rector\\Doctrine\\Orm28\\Rector\\MethodCall\\IterateToToIterableRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/Orm28/Rector/MethodCall/IterateToToIterableRector.php',
'Rector\\Doctrine\\Orm30\\Rector\\MethodCall\\SetParametersArrayToCollectionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/Orm30/Rector/MethodCall/SetParametersArrayToCollectionRector.php',
'Rector\\Doctrine\\PhpDocParser\\DoctrineDocBlockResolver' => __DIR__ . '/..' . '/rector/rector-doctrine/src/PhpDocParser/DoctrineDocBlockResolver.php',
'Rector\\Doctrine\\PhpDoc\\ShortClassExpander' => __DIR__ . '/..' . '/rector/rector-doctrine/src/PhpDoc/ShortClassExpander.php',
'Rector\\Doctrine\\Set\\DoctrineSetList' => __DIR__ . '/..' . '/rector/rector-doctrine/src/Set/DoctrineSetList.php',

View File

@ -1687,12 +1687,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "f058b83421528abba7e0d18ca6da5f70a699ac99"
"reference": "75a098f63ae4f4e10ae7c4ca0d4ba5ea692b0483"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/f058b83421528abba7e0d18ca6da5f70a699ac99",
"reference": "f058b83421528abba7e0d18ca6da5f70a699ac99",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/75a098f63ae4f4e10ae7c4ca0d4ba5ea692b0483",
"reference": "75a098f63ae4f4e10ae7c4ca0d4ba5ea692b0483",
"shasum": ""
},
"require": {
@ -1715,7 +1715,7 @@
"tomasvotruba\/class-leak": "^2.0",
"tracy\/tracy": "^2.10"
},
"time": "2025-02-26T22:52:41+00:00",
"time": "2025-02-28T13:56:24+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
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 f058b83'), '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 6dba109'), '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 15a2aab'), '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 c02c255'));
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 75a098f'), '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 6dba109'), '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 15a2aab'), '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 c02c255'));
private function __construct()
{
}

View File

@ -8,4 +8,6 @@ use Rector\Doctrine\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPrope
use Rector\Doctrine\CodeQuality\Rector\Class_\ExplicitRelationCollectionRector;
use Rector\Doctrine\CodeQuality\Rector\Property\ImproveDoctrineCollectionDocTypeInEntityRector;
use Rector\Doctrine\CodeQuality\Rector\Property\TypedPropertyFromToManyRelationTypeRector;
return RectorConfig::configure()->withRules([ExplicitRelationCollectionRector::class, AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector::class, TypedPropertyFromToManyRelationTypeRector::class, ImproveDoctrineCollectionDocTypeInEntityRector::class]);
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rules([ExplicitRelationCollectionRector::class, AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector::class, TypedPropertyFromToManyRelationTypeRector::class, ImproveDoctrineCollectionDocTypeInEntityRector::class]);
};

View File

@ -3,13 +3,13 @@
declare (strict_types=1);
namespace Rector\Doctrine\CodeQuality\Rector\Class_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeVisitor;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;

View File

@ -0,0 +1,100 @@
<?php
declare (strict_types=1);
namespace Rector\Doctrine\Orm30\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Scalar\LNumber;
use PHPStan\Type\ObjectType;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/doctrine/orm/pull/9490
* @see https://github.com/doctrine/orm/blob/3.0.x/UPGRADE.md#query-querybuilder-and-nativequery-parameters-bc-break
*/
final class SetParametersArrayToCollectionRector extends AbstractRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change the argument type for setParameters from array to ArrayCollection and Parameter calls', [new CodeSample(<<<'CODE_SAMPLE'
$entityManager->createQueryBuilder()->setParameters([
'foo' => 'bar'
]);
CODE_SAMPLE
, <<<'CODE_SAMPLE'
$entityManager->createQueryBuilder()->setParameters(new \Doctrine\Common\Collections\ArrayCollection([
new \Doctrine\ORM\Query\Parameter('foo', 'bar')
]));
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
}
/**
* @param MethodCall $node
*/
public function refactor(Node $node) : ?\PhpParser\Node
{
$varType = $this->nodeTypeResolver->getType($node->var);
if (!$varType instanceof ObjectType) {
return null;
}
if (!$varType->isInstanceOf('Doctrine\\ORM\\QueryBuilder')->yes()) {
return null;
}
if ($node->isFirstClassCallable()) {
return null;
}
if (!$this->isNames($node->name, ['setParameters'])) {
return null;
}
$args = $node->getArgs();
if (\count($args) !== 1) {
return null;
}
$currentArg = $args[0]->value;
$isAlreadyAnArrayCollection = \false;
$currentArgType = $this->nodeTypeResolver->getType($currentArg);
if ($currentArgType instanceof ObjectType && $currentArgType->isInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection')->yes() && $currentArg instanceof New_ && \count($currentArg->args) === 1 && $currentArg->args[0] instanceof Arg) {
$currentArg = $currentArg->args[0]->value;
$isAlreadyAnArrayCollection = \true;
}
if (!$currentArg instanceof Array_) {
return null;
}
$changedParameterType = \false;
$parameters = [];
foreach ($currentArg->items as $index => $value) {
if (!$value instanceof ArrayItem) {
return null;
}
$arrayValueType = $this->nodeTypeResolver->getType($value->value);
if (!$arrayValueType instanceof ObjectType || !$arrayValueType->isInstanceOf('Doctrine\\ORM\\Query\\Parameter')->yes()) {
$newParameter = new New_(new FullyQualified('Doctrine\\ORM\\Query\\Parameter'));
$newParameter->args = [new Arg($value->key ?? new LNumber($index)), new Arg($value->value)];
$value->value = $newParameter;
$changedParameterType = \true;
}
$parameters[] = new ArrayItem($value->value);
}
if ($changedParameterType === \false && $isAlreadyAnArrayCollection) {
return null;
}
$newCollection = new New_(new FullyQualified('Doctrine\\Common\\Collections\\ArrayCollection'));
$newCollection->args = [new Arg(new Array_($parameters))];
$node->args = [new Arg($newCollection)];
return $node;
}
}