Skip to content

Commit e8620a3

Browse files
committed
Updated Rector to commit 88d58c1141c1a75b7b73816f68e5c9c17a485998
rectorphp/rector-src@88d58c1 Remove setAttribute() from Rector rules, where not suitable + add phpstan rule to help separate to DecoratingNodeVisitors (#7738)
1 parent e9708a7 commit e8620a3

File tree

19 files changed

+75
-104
lines changed

19 files changed

+75
-104
lines changed

rules/DeadCode/Rector/Expression/RemoveDeadStmtRector.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
declare (strict_types=1);
44
namespace Rector\DeadCode\Rector\Expression;
55

6+
use PhpParser\Comment\Doc;
67
use PhpParser\Node;
78
use PhpParser\Node\Expr\PropertyFetch;
89
use PhpParser\Node\Expr\StaticPropertyFetch;
910
use PhpParser\Node\Stmt\Expression;
1011
use PhpParser\Node\Stmt\Nop;
1112
use PhpParser\NodeVisitor;
1213
use PHPStan\Reflection\Php\PhpPropertyReflection;
13-
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1414
use Rector\DeadCode\NodeManipulator\LivingCodeManipulator;
1515
use Rector\NodeAnalyzer\PropertyFetchAnalyzer;
16-
use Rector\NodeTypeResolver\Node\AttributeKey;
1716
use Rector\Rector\AbstractRector;
1817
use Rector\Reflection\ReflectionResolver;
1918
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -35,16 +34,11 @@ final class RemoveDeadStmtRector extends AbstractRector
3534
* @readonly
3635
*/
3736
private ReflectionResolver $reflectionResolver;
38-
/**
39-
* @readonly
40-
*/
41-
private PhpDocInfoFactory $phpDocInfoFactory;
42-
public function __construct(LivingCodeManipulator $livingCodeManipulator, PropertyFetchAnalyzer $propertyFetchAnalyzer, ReflectionResolver $reflectionResolver, PhpDocInfoFactory $phpDocInfoFactory)
37+
public function __construct(LivingCodeManipulator $livingCodeManipulator, PropertyFetchAnalyzer $propertyFetchAnalyzer, ReflectionResolver $reflectionResolver)
4338
{
4439
$this->livingCodeManipulator = $livingCodeManipulator;
4540
$this->propertyFetchAnalyzer = $propertyFetchAnalyzer;
4641
$this->reflectionResolver = $reflectionResolver;
47-
$this->phpDocInfoFactory = $phpDocInfoFactory;
4842
}
4943
public function getRuleDefinition(): RuleDefinition
5044
{
@@ -108,10 +102,9 @@ private function hasGetMagic(Expression $expression): bool
108102
*/
109103
private function removeNodeAndKeepComments(Expression $expression)
110104
{
111-
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($expression);
112-
if ($expression->getComments() !== []) {
105+
if ($expression->getDocComment() instanceof Doc) {
113106
$nop = new Nop();
114-
$nop->setAttribute(AttributeKey::PHP_DOC_INFO, $phpDocInfo);
107+
$nop->setDocComment($expression->getDocComment());
115108
return $nop;
116109
}
117110
return NodeVisitor::REMOVE_NODE;

rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ public function refactor(Node $node)
121121
if ($node->stmts === []) {
122122
return NodeVisitor::REMOVE_NODE;
123123
}
124-
$node->stmts[0]->setAttribute(AttributeKey::COMMENTS, array_merge($node->getComments(), $node->stmts[0]->getComments()));
125-
$node->stmts[0]->setAttribute(AttributeKey::HAS_MERGED_COMMENTS, \true);
124+
// keep original comments
125+
if ($node->getComments() !== []) {
126+
$node->stmts[0]->setAttribute(AttributeKey::COMMENTS, array_merge($node->getComments(), $node->stmts[0]->getComments()));
127+
}
126128
return $node->stmts;
127129
}
128130
private function shouldSkipFromVariable(Expr $expr): bool

rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Rector\DeadCode\ConditionEvaluator;
1212
use Rector\DeadCode\ConditionResolver;
1313
use Rector\DeadCode\Contract\ConditionInterface;
14+
use Rector\NodeTypeResolver\Node\AttributeKey;
1415
use Rector\Rector\AbstractRector;
1516
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
1617
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -89,7 +90,7 @@ private function refactorIsMatch(If_ $if): ?array
8990
if ($if->elseifs !== []) {
9091
return null;
9192
}
92-
return $if->stmts;
93+
return $this->keepIfLevelComments($if, $if->stmts);
9394
}
9495
/**
9596
* @return Stmt[]|NodeVisitor::REMOVE_NODE
@@ -100,7 +101,17 @@ private function refactorIsNotMatch(If_ $if)
100101
if (!$if->else instanceof Else_) {
101102
return NodeVisitor::REMOVE_NODE;
102103
}
103-
// else is always used
104-
return $if->else->stmts;
104+
return $this->keepIfLevelComments($if, $if->else->stmts);
105+
}
106+
/**
107+
* @param Stmt[] $stmts
108+
* @return Stmt[]
109+
*/
110+
private function keepIfLevelComments(If_ $if, array $stmts): array
111+
{
112+
if ($stmts !== []) {
113+
$stmts[0]->setAttribute(AttributeKey::COMMENTS, array_merge($if->getComments(), $stmts[0]->getComments()));
114+
}
115+
return $stmts;
105116
}
106117
}

rules/Php72/Rector/FuncCall/GetClassOnNullRector.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function refactor(Node $node): ?Node
7070
return null;
7171
}
7272
// just created func call
73-
if ($node->getAttribute(AttributeKey::DO_NOT_CHANGE) === \true) {
73+
if ($node->getAttribute(AttributeKey::ORIGINAL_NODE) === null) {
7474
return null;
7575
}
7676
if (!$this->isName($node, 'get_class')) {
@@ -101,8 +101,6 @@ public function refactor(Node $node): ?Node
101101
}
102102
private function createGetClassFuncCall(FuncCall $oldFuncCall): FuncCall
103103
{
104-
$funcCall = new FuncCall($oldFuncCall->name, $oldFuncCall->args);
105-
$funcCall->setAttribute(AttributeKey::DO_NOT_CHANGE, \true);
106-
return $funcCall;
104+
return new FuncCall($oldFuncCall->name, $oldFuncCall->args);
107105
}
108106
}

rules/Php74/Rector/Closure/ClosureToArrowFunctionRector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function refactor(Node $node): ?Node
7474
$comments = $node->stmts[0]->getAttribute(AttributeKey::COMMENTS) ?? [];
7575
if ($comments !== []) {
7676
$this->mirrorComments($arrowFunction->expr, $node->stmts[0]);
77-
$arrowFunction->setAttribute(AttributeKey::COMMENT_CLOSURE_RETURN_MIRRORED, \true);
77+
$arrowFunction->setAttribute(AttributeKey::COMMENTS, \true);
7878
}
7979
return $arrowFunction;
8080
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '19a4c038808d4f11f5b81205dedeeb33aa8d181a';
22+
public const PACKAGE_VERSION = '88d58c1141c1a75b7b73816f68e5c9c17a485998';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-08 16:41:14';
27+
public const RELEASE_DATE = '2025-12-08 21:38:21';
2828
/**
2929
* @var int
3030
*/

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ final class AttributeKey
6969
* @var string
7070
*/
7171
public const IS_REGULAR_PATTERN = 'is_regular_pattern';
72-
/**
73-
* @var string
74-
*/
75-
public const DO_NOT_CHANGE = 'do_not_change';
7672
/**
7773
* Helps with infinite loop detection
7874
* @var string
@@ -82,10 +78,6 @@ final class AttributeKey
8278
* @var string
8379
*/
8480
public const WRAPPED_IN_PARENTHESES = 'wrapped_in_parentheses';
85-
/**
86-
* @var string
87-
*/
88-
public const COMMENT_CLOSURE_RETURN_MIRRORED = 'comment_closure_return_mirrored';
8981
/**
9082
* To pass PHP 8.0 attribute FQN names
9183
* @var string
@@ -96,6 +88,7 @@ final class AttributeKey
9688
*/
9789
public const EXTRA_USE_IMPORT = 'extra_use_import';
9890
/**
91+
* Used internally by php-parser
9992
* @var string
10093
*/
10194
public const DOC_LABEL = 'docLabel';
@@ -217,10 +210,6 @@ final class AttributeKey
217210
* @var string
218211
*/
219212
public const IS_FIRST_LEVEL_STATEMENT = 'first_level_stmt';
220-
/**
221-
* @var string
222-
*/
223-
public const HAS_MERGED_COMMENTS = 'has_merged_comments';
224213
public const IS_DEFAULT_PROPERTY_VALUE = 'is_default_property_value';
225214
public const IS_CLASS_CONST_VALUE = 'is_default_class_const_value';
226215
public const IS_INSIDE_SYMFONY_PHP_CLOSURE = 'is_inside_symfony_php_closure';

src/PhpParser/Printer/BetterStandardPrinter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function p(Node $node, int $precedence = self::MAX_PRECEDENCE, int $lh
141141
}
142142
protected function pExpr_ArrowFunction(ArrowFunction $arrowFunction, int $precedence, int $lhsPrecedence): string
143143
{
144-
if (!$arrowFunction->hasAttribute(AttributeKey::COMMENT_CLOSURE_RETURN_MIRRORED)) {
144+
if (!$arrowFunction->hasAttribute(AttributeKey::COMMENTS)) {
145145
return parent::pExpr_ArrowFunction($arrowFunction, $precedence, $lhsPrecedence);
146146
}
147147
$expr = $arrowFunction->expr;

src/Rector/AbstractRector.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,6 @@ private function postRefactorProcess(Node $originalNode, Node $node, $refactored
226226
/** @var MutatingScope|null $currentScope */
227227
$currentScope = $node->getAttribute(AttributeKey::SCOPE);
228228
if (is_array($refactoredNode)) {
229-
$firstNode = current($refactoredNode);
230-
if ($firstNode->getAttribute(AttributeKey::HAS_MERGED_COMMENTS, \false) === \false) {
231-
$this->mirrorComments($firstNode, $originalNode);
232-
}
233229
$this->refreshScopeNodes($refactoredNode, $filePath, $currentScope);
234230
// search "infinite recursion" in https://github.com/nikic/PHP-Parser/blob/master/doc/component/Walking_the_AST.markdown
235231
$originalNodeId = spl_object_id($originalNode);

vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

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

22-
return ComposerAutoloaderInit12735a61b7a06210a61ac1597c9ec8fa::getLoader();
22+
return ComposerAutoloaderInit74acfc93a8a335df0429191cbf621bda::getLoader();

0 commit comments

Comments
 (0)