Updated Rector to commit 27b891b219cc9bfed6540a6abfbfa762e1cc2aaf

27b891b219 Make ServiceGetterToConstructorInjectionRector report only if node has changed, retarget to Class_ node with higher priority (#2772)
This commit is contained in:
Tomas Votruba 2022-08-17 09:48:06 +00:00
parent d790bd4192
commit 050ff0c044
12 changed files with 82 additions and 61 deletions

View File

@ -123,34 +123,47 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [MethodCall::class];
return [Class_::class];
}
/**
* @param MethodCall $node
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
$classLike = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$classLike instanceof Class_) {
if ($this->classAnalyzer->isAnonymousClass($node)) {
return null;
}
if ($this->classAnalyzer->isAnonymousClass($classLike)) {
// skip empty class
$classStmts = $node->stmts;
if ($classStmts === []) {
return null;
}
foreach ($this->methodCallToServices as $methodCallToService) {
if (!$this->isObjectType($node->var, $methodCallToService->getOldObjectType())) {
continue;
$hasChanged = \false;
$class = $node;
$this->traverseNodesWithCallable($classStmts, function (Node $node) use($class, &$hasChanged) : ?PropertyFetch {
if (!$node instanceof MethodCall) {
return null;
}
if (!$this->isName($node->name, $methodCallToService->getOldMethod())) {
continue;
foreach ($this->methodCallToServices as $methodCallToService) {
if (!$this->isObjectType($node->var, $methodCallToService->getOldObjectType())) {
continue;
}
if (!$this->isName($node->name, $methodCallToService->getOldMethod())) {
continue;
}
$serviceObjectType = new ObjectType($methodCallToService->getServiceType());
$propertyName = $this->propertyNaming->fqnToVariableName($serviceObjectType);
$propertyMetadata = new PropertyMetadata($propertyName, $serviceObjectType, Class_::MODIFIER_PRIVATE);
$this->propertyToAddCollector->addPropertyToClass($class, $propertyMetadata);
$hasChanged = \true;
return new PropertyFetch(new Variable('this'), new Identifier($propertyName));
}
$serviceObjectType = new ObjectType($methodCallToService->getServiceType());
$propertyName = $this->propertyNaming->fqnToVariableName($serviceObjectType);
$propertyMetadata = new PropertyMetadata($propertyName, $serviceObjectType, Class_::MODIFIER_PRIVATE);
$this->propertyToAddCollector->addPropertyToClass($classLike, $propertyMetadata);
return new PropertyFetch(new Variable('this'), new Identifier($propertyName));
return null;
});
if ($hasChanged) {
return $node;
}
return $node;
return null;
}
/**
* @param mixed[] $configuration

View File

@ -17,12 +17,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'd86e5992e8d07d92e1278dcc03373432c79814e5';
public const PACKAGE_VERSION = '27b891b219cc9bfed6540a6abfbfa762e1cc2aaf';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2022-08-17 09:07:42';
public const RELEASE_DATE = '2022-08-17 09:41:59';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf
class ComposerAutoloaderInitb0226f9b6c3d5c00015fe6143e127539
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitb0226f9b6c3d5c00015fe6143e127539', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitb0226f9b6c3d5c00015fe6143e127539', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireb8c4ed21a58308518f172b897a8b4aaf($fileIdentifier, $file);
composerRequireb0226f9b6c3d5c00015fe6143e127539($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf
* @param string $file
* @return void
*/
function composerRequireb8c4ed21a58308518f172b897a8b4aaf($fileIdentifier, $file)
function composerRequireb0226f9b6c3d5c00015fe6143e127539($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 ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf
class ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3250,9 +3250,9 @@ class ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1852,12 +1852,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-doctrine.git",
"reference": "9781e776f068243ffb025f3d1346723cee7a2143"
"reference": "49ba991f5df9d8aa178a20e191ed4599c9786dc5"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/9781e776f068243ffb025f3d1346723cee7a2143",
"reference": "9781e776f068243ffb025f3d1346723cee7a2143",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-doctrine\/zipball\/49ba991f5df9d8aa178a20e191ed4599c9786dc5",
"reference": "49ba991f5df9d8aa178a20e191ed4599c9786dc5",
"shasum": ""
},
"require": {
@ -1882,7 +1882,7 @@
"symplify\/rule-doc-generator": "^11.0",
"symplify\/vendor-patches": "^11.0"
},
"time": "2022-08-09T20:37:56+00:00",
"time": "2022-08-17T09:23:35+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
@ -1909,7 +1909,7 @@
"description": "Rector upgrades rules for Doctrine",
"support": {
"issues": "https:\/\/github.com\/rectorphp\/rector-doctrine\/issues",
"source": "https:\/\/github.com\/rectorphp\/rector-doctrine\/tree\/0.13.0"
"source": "https:\/\/github.com\/rectorphp\/rector-doctrine\/tree\/main"
},
"install-path": "..\/rector\/rector-doctrine"
},

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-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c2ec06c'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 9781e77'), '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' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main efc7ddf'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38440b9'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 20edb95'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3638a66'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 528d313'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 87b368b'));
public const EXTENSIONS = array('rector/rector-cakephp' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-cakephp', 'relative_install_path' => '../../rector-cakephp', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main c2ec06c'), 'rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 49ba991'), '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' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main efc7ddf'), 'rector/rector-generator' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-generator', 'relative_install_path' => '../../rector-generator', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 38440b9'), 'rector/rector-laravel' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-laravel', 'relative_install_path' => '../../rector-laravel', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 20edb95'), 'rector/rector-phpoffice' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpoffice', 'relative_install_path' => '../../rector-phpoffice', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 3638a66'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 528d313'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 87b368b'));
private function __construct()
{
}

View File

@ -9,6 +9,7 @@ use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\NodeNameResolver\NodeNameResolver;
/**
* @api
@ -37,7 +38,7 @@ final class AttributeCleaner
{
$attribute = $this->attributeFinder->findAttributeByClass($node, $attributeClass);
if (!$attribute instanceof Attribute) {
return;
throw new ShouldNotHappenException();
}
foreach ($attribute->args as $key => $arg) {
if (!$arg->name instanceof Node) {

View File

@ -13,13 +13,14 @@ final class DoctrineItemDefaultValueManipulator
/**
* @param string|bool|int $defaultValue
*/
public function remove(PhpDocInfo $phpDocInfo, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, string $item, $defaultValue) : void
public function clearDoctrineAnnotationTagValueNode(PhpDocInfo $phpDocInfo, DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode, string $item, $defaultValue) : bool
{
if (!$this->hasItemWithDefaultValue($doctrineAnnotationTagValueNode, $item, $defaultValue)) {
return;
return \false;
}
$doctrineAnnotationTagValueNode->removeValue($item);
$phpDocInfo->markAsChanged();
return \true;
}
/**
* @param string|bool|int $defaultValue

View File

@ -60,20 +60,15 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
$this->refactorClassAnnotations($node);
return $node;
}
private function refactorClassAnnotations(Class_ $class) : void
{
$this->refactorEntityAnnotation($class);
}
private function refactorEntityAnnotation(Class_ $class) : void
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($class);
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass('Doctrine\\ORM\\Mapping\\Entity');
if (!$doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return;
return null;
}
$this->doctrineItemDefaultValueManipulator->remove($phpDocInfo, $doctrineAnnotationTagValueNode, 'readOnly', \false);
$hasChanged = $this->doctrineItemDefaultValueManipulator->clearDoctrineAnnotationTagValueNode($phpDocInfo, $doctrineAnnotationTagValueNode, 'readOnly', \false);
if ($hasChanged) {
return $node;
}
return null;
}
}

View File

@ -95,7 +95,8 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
$this->refactorPropertyAnnotations($node);
$hasPhpDocInfoChanged = $this->clearPropertyAnnotations($node);
$hasAttributeChanged = \false;
foreach ($this->defaultAnnotationArgValues as $defaultAnnotationArgValue) {
$argExpr = $this->attributeFinder->findAttributeByClassArgByName($node, $defaultAnnotationArgValue->getAnnotationClass(), $defaultAnnotationArgValue->getArgName());
if (!$argExpr instanceof Expr) {
@ -105,24 +106,34 @@ CODE_SAMPLE
continue;
}
$this->attributeCleaner->clearAttributeAndArgName($node, $defaultAnnotationArgValue->getAnnotationClass(), $defaultAnnotationArgValue->getArgName());
$hasAttributeChanged = \true;
}
return $node;
if ($hasPhpDocInfoChanged || $hasAttributeChanged) {
return $node;
}
return null;
}
private function refactorPropertyAnnotations(Property $property) : void
private function clearPropertyAnnotations(Property $property) : bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($property);
if ($phpDocInfo instanceof PhpDocInfo) {
foreach ($this->defaultAnnotationArgValues as $defaultAnnotationArgValue) {
$this->refactorAnnotation($phpDocInfo, $defaultAnnotationArgValue);
if (!$phpDocInfo instanceof PhpDocInfo) {
return \false;
}
$hasPropertyChanged = \false;
foreach ($this->defaultAnnotationArgValues as $defaultAnnotationArgValue) {
$hasAnnotationChanged = $this->clearAnnotation($phpDocInfo, $defaultAnnotationArgValue);
if ($hasAnnotationChanged) {
$hasPropertyChanged = \true;
}
}
return $hasPropertyChanged;
}
private function refactorAnnotation(PhpDocInfo $phpDocInfo, DefaultAnnotationArgValue $defaultAnnotationArgValue) : void
private function clearAnnotation(PhpDocInfo $phpDocInfo, DefaultAnnotationArgValue $defaultAnnotationArgValue) : bool
{
$doctrineAnnotationTagValueNode = $phpDocInfo->getByAnnotationClass($defaultAnnotationArgValue->getAnnotationClass());
if (!$doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) {
return;
return \false;
}
$this->doctrineItemDefaultValueManipulator->remove($phpDocInfo, $doctrineAnnotationTagValueNode, $defaultAnnotationArgValue->getArgName(), $defaultAnnotationArgValue->getDefaultValue());
return $this->doctrineItemDefaultValueManipulator->clearDoctrineAnnotationTagValueNode($phpDocInfo, $doctrineAnnotationTagValueNode, $defaultAnnotationArgValue->getArgName(), $defaultAnnotationArgValue->getDefaultValue());
}
}