Updated Rector to commit 868612ae6bac93afe8d9aea8fd7d2fb6c6306991

868612ae6b [DX] Remove parent node from AbstractRector (#4465)
This commit is contained in:
Tomas Votruba 2023-07-09 18:49:55 +00:00
parent 9bef88551a
commit 484c94d08a
16 changed files with 40 additions and 88 deletions

View File

@ -12,7 +12,6 @@ use PhpParser\ConstExprEvaluator;
use PhpParser\Lexer;
use PhpParser\NodeFinder;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeFactory;
use PHPStan\Dependency\DependencyResolver;
@ -142,7 +141,6 @@ return static function (RectorConfig $rectorConfig) : void {
$services->set(SimpleCallableNodeTraverser::class);
$services->set(BuilderFactory::class);
$services->set(CloningVisitor::class);
$services->set(ParentConnectingVisitor::class);
$services->set(NodeFinder::class);
$services->set(RectorConsoleOutputStyle::class)->factory([service(RectorConsoleOutputStyleFactory::class), 'create']);
$services->set(Parser::class)->factory([service(PHPStanServicesFactory::class), 'createPHPStanParser']);

View File

@ -61,6 +61,11 @@ final class AttributeKey
* @internal of php-parser, do not change
* @see https://github.com/nikic/PHP-Parser/pull/681/files
* @var string
*
* @api for BC layer
*
* The parent node can be still enabled by using custom PHPStan configuration,
* @see https://github.com/rectorphp/rector-src/pull/4458#discussion_r1257478146
*/
public const PARENT_NODE = 'parent';
/**

View File

@ -6,7 +6,6 @@ namespace Rector\NodeTypeResolver;
use PhpParser\Node\Stmt;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\ParentConnectingVisitor;
use Rector\Core\PhpParser\NodeTraverser\FileWithoutNamespaceNodeTraverser;
use Rector\Core\PHPStan\NodeVisitor\UnreachableStatementNodeVisitor;
use Rector\Core\ValueObject\Application\File;
@ -35,16 +34,14 @@ final class NodeScopeAndMetadataDecorator
* @var \PhpParser\NodeTraverser
*/
private $nodeTraverser;
public function __construct(CloningVisitor $cloningVisitor, PHPStanNodeScopeResolver $phpStanNodeScopeResolver, ParentConnectingVisitor $parentConnectingVisitor, FunctionLikeParamArgPositionNodeVisitor $functionLikeParamArgPositionNodeVisitor, ScopeFactory $scopeFactory, FileWithoutNamespaceNodeTraverser $fileWithoutNamespaceNodeTraverser)
public function __construct(CloningVisitor $cloningVisitor, PHPStanNodeScopeResolver $phpStanNodeScopeResolver, FunctionLikeParamArgPositionNodeVisitor $functionLikeParamArgPositionNodeVisitor, ScopeFactory $scopeFactory, FileWithoutNamespaceNodeTraverser $fileWithoutNamespaceNodeTraverser)
{
$this->phpStanNodeScopeResolver = $phpStanNodeScopeResolver;
$this->scopeFactory = $scopeFactory;
$this->fileWithoutNamespaceNodeTraverser = $fileWithoutNamespaceNodeTraverser;
$this->nodeTraverser = new NodeTraverser();
// needed also for format preserving printing
// needed for format preserving printing
$this->nodeTraverser->addVisitor($cloningVisitor);
// this one has to be run again to re-connect parent nodes with new attributes
$this->nodeTraverser->addVisitor($parentConnectingVisitor);
$this->nodeTraverser->addVisitor($functionLikeParamArgPositionNodeVisitor);
}
/**

View File

@ -10,7 +10,7 @@ use PhpParser\Node\Stmt\Nop;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\ParameterProvider;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
/**
@ -32,10 +32,10 @@ final class RemoveDeepChainMethodCallNodeVisitor extends NodeVisitorAbstract imp
* @var \PhpParser\Node\Stmt\Expression|null
*/
private $removingExpression;
public function __construct(BetterNodeFinder $betterNodeFinder, ParameterProvider $parameterProvider)
public function __construct(BetterNodeFinder $betterNodeFinder)
{
$this->betterNodeFinder = $betterNodeFinder;
$this->nestedChainMethodCallLimit = (int) $parameterProvider->provideParameter(Option::NESTED_CHAIN_METHOD_CALL_LIMIT);
$this->nestedChainMethodCallLimit = SimpleParameterProvider::provideIntParameter(Option::NESTED_CHAIN_METHOD_CALL_LIMIT);
}
public function enterNode(Node $node) : ?int
{

View File

@ -4,8 +4,11 @@ declare (strict_types=1);
namespace Rector\PostRector\Rector;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Analyser\Scope;
use Rector\CodingStyle\Application\UseImportsRemover;
use Rector\Core\Configuration\Option;
@ -72,6 +75,10 @@ final class ClassRenamingPostRector extends \Rector\PostRector\Rector\AbstractPo
}
public function enterNode(Node $node) : ?Node
{
// cannot be renamed
if ($node instanceof Expr || $node instanceof Arg || $node instanceof PropertyProperty) {
return null;
}
$oldToNewClasses = $this->renamedClassesDataCollector->getOldToNewClasses();
if ($oldToNewClasses === []) {
return null;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'a771c5621971eb1c527c75de17119a82ac8294e6';
public const PACKAGE_VERSION = '868612ae6bac93afe8d9aea8fd7d2fb6c6306991';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-07-09 17:26:22';
public const RELEASE_DATE = '2023-07-10 01:45:43';
/**
* @var int
*/

View File

@ -224,7 +224,7 @@ CODE_SAMPLE;
$errorMessage = \sprintf(self::EMPTY_NODE_ARRAY_MESSAGE, static::class);
throw new ShouldNotHappenException($errorMessage);
}
return $this->postRefactorProcess($originalNode, $node, $refactoredNode);
return $this->postRefactorProcess($originalNode, $refactoredNode);
}
/**
* Replacing nodes in leaveNode() method avoids infinite recursion
@ -302,13 +302,12 @@ CODE_SAMPLE;
/**
* @param \PhpParser\Node|mixed[]|int $refactoredNode
*/
private function postRefactorProcess(Node $originalNode, Node $node, $refactoredNode) : Node
private function postRefactorProcess(Node $originalNode, $refactoredNode) : Node
{
/** @var non-empty-array<Node>|Node $refactoredNode */
$this->createdByRuleDecorator->decorate($refactoredNode, $originalNode, static::class);
$rectorWithLineChange = new RectorWithLineChange(static::class, $originalNode->getLine());
$this->file->addRectorClassWithLine($rectorWithLineChange);
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
/** @var MutatingScope|null $currentScope */
$currentScope = $originalNode->getAttribute(AttributeKey::SCOPE);
$filePath = $this->file->getFilePath();
@ -317,13 +316,11 @@ CODE_SAMPLE;
if (\is_array($refactoredNode)) {
$firstNode = \current($refactoredNode);
$this->mirrorComments($firstNode, $originalNode);
$this->updateParentNodes($refactoredNode, $parentNode);
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);
$this->nodesToReturn[$originalNodeHash] = $refactoredNode;
// will be replaced in leaveNode() the original node must be passed
return $originalNode;
}
$this->updateParentNodes($refactoredNode, $parentNode);
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);
$this->nodesToReturn[$originalNodeHash] = $refactoredNode;
return $refactoredNode;
@ -358,20 +355,6 @@ CODE_SAMPLE;
}
return $this->rectifiedAnalyzer->hasRectified(static::class, $node);
}
/**
* @param mixed[]|\PhpParser\Node $node
*/
private function updateParentNodes($node, ?Node $parentNode) : void
{
if (!$parentNode instanceof Node) {
return;
}
$nodes = $node instanceof Node ? [$node] : $node;
foreach ($nodes as $node) {
// update parents relations
$node->setAttribute(AttributeKey::PARENT_NODE, $parentNode);
}
}
private function printCurrentFileAndRule() : void
{
$relativeFilePath = $this->filePathHelper->relativePath($this->file->getFilePath());

View File

@ -39,17 +39,7 @@ abstract class AbstractScopeAwareRector extends \Rector\Core\Rector\AbstractRect
$currentScope = $this->scopeAnalyzer->resolveScope($node, $this->file->getFilePath());
}
if (!$currentScope instanceof Scope) {
/**
* @var Node $parentNode
*
* $parentNode is always a Node when $mutatingScope is null, as checked in previous
*
* $this->scopeAnalyzer->resolveScope()
*
* which verify if no parent and no scope, it resolve Scope from File
*/
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
$errorMessage = \sprintf('Scope not available on "%s" node with parent node of "%s", but is required by a refactorWithScope() method of "%s" rule. Fix scope refresh on changed nodes first', \get_class($node), \get_class($parentNode), static::class);
$errorMessage = \sprintf('Scope not available on "%s" node, but is required by a refactorWithScope() method of "%s" rule. Fix scope refresh on changed nodes first', \get_class($node), static::class);
throw new ShouldNotHappenException($errorMessage);
}
return $this->refactorWithScope($node, $currentScope);

2
vendor/autoload.php vendored
View File

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

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitd87870bba647133abcf187f88c151efc
class ComposerAutoloaderInitf67370c644d7b19c8289f290b6e08054
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitd87870bba647133abcf187f88c151efc
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitd87870bba647133abcf187f88c151efc', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitf67370c644d7b19c8289f290b6e08054', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitd87870bba647133abcf187f88c151efc', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitf67370c644d7b19c8289f290b6e08054', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitd87870bba647133abcf187f88c151efc::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitf67370c644d7b19c8289f290b6e08054::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitd87870bba647133abcf187f88c151efc::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitf67370c644d7b19c8289f290b6e08054::$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 ComposerStaticInitd87870bba647133abcf187f88c151efc
class ComposerStaticInitf67370c644d7b19c8289f290b6e08054
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3067,9 +3067,9 @@ class ComposerStaticInitd87870bba647133abcf187f88c151efc
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitd87870bba647133abcf187f88c151efc::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd87870bba647133abcf187f88c151efc::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd87870bba647133abcf187f88c151efc::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitf67370c644d7b19c8289f290b6e08054::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf67370c644d7b19c8289f290b6e08054::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf67370c644d7b19c8289f290b6e08054::$classMap;
}, null, ClassLoader::class);
}

View File

@ -1982,12 +1982,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "9e5a36d271b6cec5f89ec413378dd80d9d1b9e00"
"reference": "f64a7b129850a61288dd41b9322487d546dd8548"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/9e5a36d271b6cec5f89ec413378dd80d9d1b9e00",
"reference": "9e5a36d271b6cec5f89ec413378dd80d9d1b9e00",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/f64a7b129850a61288dd41b9322487d546dd8548",
"reference": "f64a7b129850a61288dd41b9322487d546dd8548",
"shasum": ""
},
"require": {
@ -2011,7 +2011,7 @@
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
},
"time": "2023-07-09T10:06:07+00:00",
"time": "2023-07-09T18:08:08+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' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8afdccb'), '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 9e5a36d'), '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 0a640b3'), '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 e788554'));
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' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 8afdccb'), '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 f64a7b1'), '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 0a640b3'), '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 e788554'));
private function __construct()
{
}

View File

@ -44,7 +44,6 @@ return static function (RectorConfig $rectorConfig) : void {
// @see https://wiki.php.net/rfc/stringable
'Stringable',
]);
$rectorConfig->rule(DowngradeNamedArgumentRector::class);
$rectorConfig->ruleWithConfiguration(DowngradeAttributeToAnnotationRector::class, [
// Symfony
new DowngradeAttributeToAnnotation('Symfony\\Contracts\\Service\\Attribute\\Required', 'required'),
@ -53,33 +52,5 @@ return static function (RectorConfig $rectorConfig) : void {
// Jetbrains\PhpStorm\Language under nette/utils
new DowngradeAttributeToAnnotation('Jetbrains\\PhpStorm\\Language', 'language'),
]);
$rectorConfig->rule(DowngradeDereferenceableOperationRector::class);
$rectorConfig->rule(DowngradeUnionTypeTypedPropertyRector::class);
$rectorConfig->rule(DowngradeUnionTypeDeclarationRector::class);
$rectorConfig->rule(DowngradeMixedTypeDeclarationRector::class);
$rectorConfig->rule(DowngradeStaticTypeDeclarationRector::class);
$rectorConfig->rule(DowngradeAbstractPrivateMethodInTraitRector::class);
$rectorConfig->rule(DowngradePropertyPromotionRector::class);
$rectorConfig->rule(DowngradeNonCapturingCatchesRector::class);
$rectorConfig->rule(DowngradeStrContainsRector::class);
$rectorConfig->rule(DowngradeMatchToSwitchRector::class);
$rectorConfig->rule(DowngradeClassOnObjectToGetClassRector::class);
$rectorConfig->rule(DowngradeArbitraryExpressionsSupportRector::class);
$rectorConfig->rule(DowngradeNullsafeToTernaryOperatorRector::class);
$rectorConfig->rule(DowngradeTrailingCommasInParamUseRector::class);
$rectorConfig->rule(DowngradeStrStartsWithRector::class);
$rectorConfig->rule(DowngradeStrEndsWithRector::class);
$rectorConfig->rule(DowngradePhpTokenRector::class);
$rectorConfig->rule(DowngradeThrowExprRector::class);
$rectorConfig->rule(DowngradePhp80ResourceReturnToObjectRector::class);
$rectorConfig->rule(DowngradeReflectionGetAttributesRector::class);
$rectorConfig->rule(DowngradeRecursiveDirectoryIteratorHasChildrenRector::class);
$rectorConfig->rule(DowngradeReflectionPropertyGetDefaultValueRector::class);
$rectorConfig->rule(DowngradeReflectionClassGetConstantsFilterRector::class);
$rectorConfig->rule(DowngradeArrayFilterNullableCallbackRector::class);
$rectorConfig->rule(DowngradeNumberFormatNoFourthArgRector::class);
$rectorConfig->rule(DowngradeStringReturnTypeOnToStringRector::class);
$rectorConfig->rule(DowngradeMixedTypeTypedPropertyRector::class);
$rectorConfig->rule(RemoveReturnTypeDeclarationFromCloneRector::class);
$rectorConfig->rule(DowngradeEnumToConstantListClassRector::class);
$rectorConfig->rules([DowngradeNamedArgumentRector::class, DowngradeDereferenceableOperationRector::class, DowngradeUnionTypeTypedPropertyRector::class, DowngradeUnionTypeDeclarationRector::class, DowngradeMixedTypeDeclarationRector::class, DowngradeStaticTypeDeclarationRector::class, DowngradeAbstractPrivateMethodInTraitRector::class, DowngradePropertyPromotionRector::class, DowngradeNonCapturingCatchesRector::class, DowngradeStrContainsRector::class, DowngradeMatchToSwitchRector::class, DowngradeClassOnObjectToGetClassRector::class, DowngradeArbitraryExpressionsSupportRector::class, DowngradeNullsafeToTernaryOperatorRector::class, DowngradeTrailingCommasInParamUseRector::class, DowngradeStrStartsWithRector::class, DowngradeStrEndsWithRector::class, DowngradePhpTokenRector::class, DowngradeThrowExprRector::class, DowngradePhp80ResourceReturnToObjectRector::class, DowngradeReflectionGetAttributesRector::class, DowngradeRecursiveDirectoryIteratorHasChildrenRector::class, DowngradeReflectionPropertyGetDefaultValueRector::class, DowngradeReflectionClassGetConstantsFilterRector::class, DowngradeArrayFilterNullableCallbackRector::class, DowngradeNumberFormatNoFourthArgRector::class, DowngradeStringReturnTypeOnToStringRector::class, DowngradeMixedTypeTypedPropertyRector::class, RemoveReturnTypeDeclarationFromCloneRector::class, DowngradeEnumToConstantListClassRector::class]);
};

View File

@ -26,6 +26,7 @@ use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\UnionType;
use RectorPrefix202307\PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;