Skip to content

Commit

Permalink
Updated Rector to commit 27b891b
Browse files Browse the repository at this point in the history
rectorphp/rector-src@27b891b Make ServiceGetterToConstructorInjectionRector report only if node has changed, retarget to Class_ node with higher priority (#2772)
  • Loading branch information
TomasVotruba committed Aug 17, 2022
1 parent d790bd4 commit 050ff0c
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,34 +123,47 @@ public function run()
*/
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
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf::getLoader();
return ComposerAutoloaderInitb0226f9b6c3d5c00015fe6143e127539::getLoader();
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInitb8c4ed21a58308518f172b897a8b4aaf
class ComposerAutoloaderInitb0226f9b6c3d5c00015fe6143e127539
{
private static $loader;

Expand All @@ -22,19 +22,19 @@ public static function getLoader()
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;
Expand All @@ -46,7 +46,7 @@ public static function getLoader()
* @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;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInitb8c4ed21a58308518f172b897a8b4aaf
class ComposerStaticInitb0226f9b6c3d5c00015fe6143e127539
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -37,7 +38,7 @@ public function clearAttributeAndArgName($node, string $attributeClass, string $
{
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,15 @@ public function getNodeTypes() : array
*/
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;
}
$hasChanged = $this->doctrineItemDefaultValueManipulator->clearDoctrineAnnotationTagValueNode($phpDocInfo, $doctrineAnnotationTagValueNode, 'readOnly', \false);
if ($hasChanged) {
return $node;
}
$this->doctrineItemDefaultValueManipulator->remove($phpDocInfo, $doctrineAnnotationTagValueNode, 'readOnly', \false);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public function getNodeTypes() : array
*/
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) {
Expand All @@ -105,24 +106,34 @@ public function refactor(Node $node) : ?Node
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());
}
}

0 comments on commit 050ff0c

Please sign in to comment.