Updated Rector to commit 0678674828c37813873d3bd4612c86d0a405948c

0678674828 [AutoImport] Fix conflict current namespace auto import (#5024)
This commit is contained in:
Tomas Votruba 2023-09-15 19:07:43 +00:00
parent e66812ed4d
commit af93ed53e4
12 changed files with 255 additions and 18 deletions

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit1748bd5e300405eaf0158ac3d4debd08::getLoader();
return ComposerAutoloaderInite631a2204478291d1675f8dd2aa29d81::getLoader();

View File

@ -1355,6 +1355,7 @@ return array(
'Rector\\DeadCode\\ValueObject\\BinaryToVersionCompareCondition' => $baseDir . '/rules/DeadCode/ValueObject/BinaryToVersionCompareCondition.php',
'Rector\\DeadCode\\ValueObject\\VariableAndPropertyFetchAssign' => $baseDir . '/rules/DeadCode/ValueObject/VariableAndPropertyFetchAssign.php',
'Rector\\DeadCode\\ValueObject\\VersionCompareCondition' => $baseDir . '/rules/DeadCode/ValueObject/VersionCompareCondition.php',
'Rector\\Doctrine\\Bundle210\\Rector\\Class_\\EventSubscriberInterfaceToAttributeRector' => $vendorDir . '/rector/rector-doctrine/rules/Bundle210/Rector/Class_/EventSubscriberInterfaceToAttributeRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\ClassMethod\\MakeEntitySetterNullabilityInSyncWithPropertyRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\InitializeDefaultEntityCollectionRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/InitializeDefaultEntityCollectionRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => $vendorDir . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit1748bd5e300405eaf0158ac3d4debd08
class ComposerAutoloaderInite631a2204478291d1675f8dd2aa29d81
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit1748bd5e300405eaf0158ac3d4debd08
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit1748bd5e300405eaf0158ac3d4debd08', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInite631a2204478291d1675f8dd2aa29d81', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit1748bd5e300405eaf0158ac3d4debd08', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInite631a2204478291d1675f8dd2aa29d81', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInite631a2204478291d1675f8dd2aa29d81::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInite631a2204478291d1675f8dd2aa29d81::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08
class ComposerStaticInite631a2204478291d1675f8dd2aa29d81
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1575,6 +1575,7 @@ class ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08
'Rector\\DeadCode\\ValueObject\\BinaryToVersionCompareCondition' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/BinaryToVersionCompareCondition.php',
'Rector\\DeadCode\\ValueObject\\VariableAndPropertyFetchAssign' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/VariableAndPropertyFetchAssign.php',
'Rector\\DeadCode\\ValueObject\\VersionCompareCondition' => __DIR__ . '/../..' . '/rules/DeadCode/ValueObject/VersionCompareCondition.php',
'Rector\\Doctrine\\Bundle210\\Rector\\Class_\\EventSubscriberInterfaceToAttributeRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/Bundle210/Rector/Class_/EventSubscriberInterfaceToAttributeRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\ClassMethod\\MakeEntitySetterNullabilityInSyncWithPropertyRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\InitializeDefaultEntityCollectionRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/InitializeDefaultEntityCollectionRector.php',
'Rector\\Doctrine\\CodeQuality\\Rector\\Class_\\MoveCurrentDateTimeDefaultInEntityToConstructorRector' => __DIR__ . '/..' . '/rector/rector-doctrine/rules/CodeQuality/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php',
@ -2592,9 +2593,9 @@ class ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit1748bd5e300405eaf0158ac3d4debd08::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInite631a2204478291d1675f8dd2aa29d81::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite631a2204478291d1675f8dd2aa29d81::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite631a2204478291d1675f8dd2aa29d81::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1744,18 +1744,19 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "2c67f2cd122c2befd837e06eb020b2d918107263"
"reference": "4b2518028cc5bf9266a9069b1f3e287d62a0012d"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/2c67f2cd122c2befd837e06eb020b2d918107263",
"reference": "2c67f2cd122c2befd837e06eb020b2d918107263",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/4b2518028cc5bf9266a9069b1f3e287d62a0012d",
"reference": "4b2518028cc5bf9266a9069b1f3e287d62a0012d",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"require-dev": {
"doctrine\/doctrine-bundle": "^2.10",
"doctrine\/orm": "^2.16",
"phpstan\/extension-installer": "^1.3",
"phpstan\/phpstan": "^1.10",
@ -1774,7 +1775,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.3"
},
"time": "2023-09-15T11:47:10+00:00",
"time": "2023-09-15T19:02:03+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/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 2c67f2c'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 3782784'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 2a9734a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 09ddd39'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 4b25180'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 3782784'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 2a9734a'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 09ddd39'));
private function __construct()
{
}

View File

@ -23,7 +23,8 @@
"symplify\/easy-ci": "^11.2",
"tomasvotruba\/unused-public": "^0.3",
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/class-leak": "^0.1"
"tomasvotruba\/class-leak": "^0.1",
"doctrine\/doctrine-bundle": "^2.10"
},
"autoload": {
"psr-4": {

View File

@ -0,0 +1,10 @@
<?php
declare (strict_types=1);
namespace RectorPrefix202309;
use Rector\Config\RectorConfig;
use Rector\Doctrine\Bundle210\Rector\Class_\EventSubscriberInterfaceToAttributeRector;
return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(EventSubscriberInterfaceToAttributeRector::class);
};

View File

@ -1,4 +1,4 @@
# 14 Rules Overview
# 15 Rules Overview
## ChangeCompositeExpressionAddMultipleWithWithRector
@ -47,6 +47,46 @@ Change default value types to match Doctrine annotation type
<br>
## EventSubscriberInterfaceToAttributeRector
Replace EventSubscriberInterface with AsDoctrineListener attribute(s)
- class: [`Rector\Doctrine\Bundle210\Rector\Class_\EventSubscriberInterfaceToAttributeRector`](../rules/Bundle210/Rector/Class_/EventSubscriberInterfaceToAttributeRector.php)
```diff
+use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs;
-use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
-class MyEventSubscriber implements EventSubscriber
+#[AsDoctrineListener(event: Events::postUpdate)]
+#[AsDoctrineListener(event: Events::prePersist)]
+class MyEventSubscriber
{
- public function getSubscribedEvents()
- {
- return array(
- Events::postUpdate,
- Events::prePersist,
- );
- }
-
public function postUpdate(PostUpdateEventArgs $args)
{
// ...
}
public function prePersist(PrePersistEventArgs $args)
{
// ...
}
}
```
<br>
## ImproveDoctrineCollectionDocTypeInEntityRector
Improve @var, `@param` and `@return` types for Doctrine collections to make them useful both for PHPStan and PHPStorm

View File

@ -0,0 +1,179 @@
<?php
declare (strict_types=1);
namespace Rector\Doctrine\Bundle210\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Attribute;
use PhpParser\Node\AttributeGroup;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Return_;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see https://github.com/doctrine/DoctrineBundle/pull/1664
*
* @see \Rector\Doctrine\Tests\Bundle210\Rector\Class_\EventSubscriberInterfaceToAttributeRector\EventSubscriberInterfaceToAttributeRectorTest
*/
final class EventSubscriberInterfaceToAttributeRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @var \PhpParser\Node\Stmt\Class_
*/
private $subscriberClass;
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::ATTRIBUTES;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Replace EventSubscriberInterface with AsDoctrineListener attribute(s)', [new CodeSample(<<<'CODE_SAMPLE'
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Events;
class MyEventSubscriber implements EventSubscriber
{
public function getSubscribedEvents()
{
return array(
Events::postUpdate,
Events::prePersist,
);
}
public function postUpdate(PostUpdateEventArgs $args)
{
// ...
}
public function prePersist(PrePersistEventArgs $args)
{
// ...
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Event\PostUpdateEventArgs;
use Doctrine\ORM\Events;
#[AsDoctrineListener(event: Events::postUpdate)]
#[AsDoctrineListener(event: Events::prePersist)]
class MyEventSubscriber
{
public function postUpdate(PostUpdateEventArgs $args)
{
// ...
}
public function prePersist(PrePersistEventArgs $args)
{
// ...
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if (!$this->hasImplements($node, 'Doctrine\\Common\\EventSubscriber')) {
return null;
}
$this->subscriberClass = $node;
$getSubscribedEventsClassMethod = $node->getMethod('getSubscribedEvents');
if (!$getSubscribedEventsClassMethod instanceof ClassMethod) {
return null;
}
$stmts = (array) $getSubscribedEventsClassMethod->stmts;
if ($stmts === []) {
return null;
}
if ($stmts[0] instanceof Return_ && $stmts[0]->expr instanceof Array_) {
$this->handleArray($stmts);
}
$this->removeImplements($node, ['Doctrine\\Common\\EventSubscriber']);
unset($node->stmts[$getSubscribedEventsClassMethod->getAttribute(AttributeKey::STMT_KEY)]);
return $node;
}
/**
* @param array<int, Node\Stmt> $expressions
*/
private function handleArray(array $expressions) : void
{
foreach ($expressions as $expression) {
if (!$expression instanceof Return_ || !$expression->expr instanceof Array_) {
continue;
}
$arguments = [];
$arguments = $this->parseArguments($expression->expr);
$this->addAttribute($arguments);
}
}
/**
* @return array<Expr>
*/
private function parseArguments(Array_ $array) : array
{
foreach ($array->items as $item) {
if (!$item instanceof ArrayItem) {
continue;
}
$arguments[] = $item->value;
}
return $arguments ?? [];
}
/**
* @param array<Expr> $arguments
*/
private function addAttribute(array $arguments) : void
{
foreach ($arguments as $argument) {
$this->subscriberClass->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified('Doctrine\\Bundle\\DoctrineBundle\\Attribute\\AsDoctrineListener'), [new Arg($argument, \false, \false, [], new Identifier('event'))])]);
}
}
private function hasImplements(Class_ $class, string $interfaceFQN) : bool
{
foreach ($class->implements as $implement) {
if ($this->nodeNameResolver->isName($implement, $interfaceFQN)) {
return \true;
}
}
return \false;
}
/**
* @param array<string> $interfaceFQNS
*/
private function removeImplements(Class_ $class, array $interfaceFQNS) : void
{
foreach ($class->implements as $key => $implement) {
if (!$this->nodeNameResolver->isNames($implement, $interfaceFQNS)) {
continue;
}
unset($class->implements[$key]);
}
}
}

View File

@ -60,6 +60,10 @@ final class DoctrineSetList implements SetListInterface
* @var string
*/
public const DOCTRINE_ORM_214 = __DIR__ . '/../../config/sets/doctrine-orm-214.php';
/**
* @var string
*/
public const DOCTRINE_BUNDLE_210 = __DIR__ . '/../../config/sets/doctrine-bundle-210.php';
/**
* @var string
*/