Skip to content

Commit 10e95c5

Browse files
committed
Updated Rector to commit 3b46948b9f2101fb62a3227ef112611429bd4ae5
rectorphp/rector-src@3b46948 Replace custom attributes with existing ones (#7732)
1 parent 19c5340 commit 10e95c5

File tree

6 files changed

+10
-44
lines changed

6 files changed

+10
-44
lines changed

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PhpParser\Node\Arg;
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\ArrowFunction;
10-
use PhpParser\Node\Expr\Assign;
1110
use PhpParser\Node\Expr\CallLike;
1211
use PhpParser\Node\Expr\Closure;
1312
use PhpParser\Node\Expr\FuncCall;
@@ -25,6 +24,7 @@
2524
use PHPStan\Reflection\Native\NativeFunctionReflection;
2625
use PHPStan\Reflection\ParametersAcceptorSelector;
2726
use PHPStan\Type\CallableType;
27+
use Rector\NodeTypeResolver\Node\AttributeKey;
2828
use Rector\PhpParser\AstResolver;
2929
use Rector\PHPStan\ScopeFetcher;
3030
use Rector\Rector\AbstractRector;
@@ -50,10 +50,6 @@ final class FunctionLikeToFirstClassCallableRector extends AbstractRector implem
5050
* @var string
5151
*/
5252
private const HAS_CALLBACK_SIGNATURE_MULTI_PARAMS = 'has_callback_signature_multi_params';
53-
/**
54-
* @var string
55-
*/
56-
private const IS_IN_ASSIGN = 'is_in_assign';
5753
public function __construct(AstResolver $astResolver, ReflectionResolver $reflectionResolver)
5854
{
5955
$this->astResolver = $astResolver;
@@ -73,19 +69,13 @@ function ($parameter) {
7369
}
7470
public function getNodeTypes(): array
7571
{
76-
return [Assign::class, CallLike::class, ArrowFunction::class, Closure::class];
72+
return [CallLike::class, ArrowFunction::class, Closure::class];
7773
}
7874
/**
7975
* @param CallLike|ArrowFunction|Closure $node
8076
*/
8177
public function refactor(Node $node): ?\PhpParser\Node\Expr\CallLike
8278
{
83-
if ($node instanceof Assign) {
84-
if ($node->expr instanceof Closure || $node->expr instanceof ArrowFunction) {
85-
$node->expr->setAttribute(self::IS_IN_ASSIGN, \true);
86-
}
87-
return null;
88-
}
8979
if ($node instanceof CallLike) {
9080
if ($node->isFirstClassCallable()) {
9181
return null;
@@ -157,7 +147,7 @@ private function shouldSkip($node, $callLike, Scope $scope): bool
157147
if ($node->getAttribute(self::HAS_CALLBACK_SIGNATURE_MULTI_PARAMS) === \true) {
158148
return \true;
159149
}
160-
if ($node->getAttribute(self::IS_IN_ASSIGN) === \true) {
150+
if ($node->getAttribute(AttributeKey::IS_ASSIGNED_TO) === \true || $node->getAttribute(AttributeKey::IS_BEING_ASSIGNED)) {
161151
return \true;
162152
}
163153
$reflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($callLike);

rules/Php70/Rector/Break_/BreakNotInLoopOrSwitchToReturnRector.php

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
namespace Rector\Php70\Rector\Break_;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr\ArrowFunction;
8-
use PhpParser\Node\FunctionLike;
97
use PhpParser\Node\Stmt\Break_;
10-
use PhpParser\Node\Stmt\Class_;
118
use PhpParser\Node\Stmt\Return_;
12-
use PhpParser\Node\Stmt\Switch_;
139
use PhpParser\NodeVisitor;
1410
use Rector\NodeNestingScope\ContextAnalyzer;
1511
use Rector\Rector\AbstractRector;
@@ -26,10 +22,6 @@ final class BreakNotInLoopOrSwitchToReturnRector extends AbstractRector implemen
2622
* @readonly
2723
*/
2824
private ContextAnalyzer $contextAnalyzer;
29-
/**
30-
* @var string
31-
*/
32-
private const IS_BREAK_IN_SWITCH = 'is_break_in_switch';
3325
public function __construct(ContextAnalyzer $contextAnalyzer)
3426
{
3527
$this->contextAnalyzer = $contextAnalyzer;
@@ -73,33 +65,17 @@ public function run()
7365
*/
7466
public function getNodeTypes(): array
7567
{
76-
return [Switch_::class, Break_::class];
68+
return [Break_::class];
7769
}
7870
/**
79-
* @param Switch_|Break_ $node
71+
* @param Break_ $node
8072
* @return Return_|null|NodeVisitor::REMOVE_NODE
8173
*/
8274
public function refactor(Node $node)
8375
{
84-
if ($node instanceof Switch_) {
85-
$this->traverseNodesWithCallable($node->cases, static function (Node $subNode): ?int {
86-
if ($subNode instanceof Class_ || $subNode instanceof FunctionLike && !$subNode instanceof ArrowFunction) {
87-
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
88-
}
89-
if (!$subNode instanceof Break_) {
90-
return null;
91-
}
92-
$subNode->setAttribute(self::IS_BREAK_IN_SWITCH, \true);
93-
return null;
94-
});
95-
return null;
96-
}
9776
if ($this->contextAnalyzer->isInLoop($node)) {
9877
return null;
9978
}
100-
if ($node->getAttribute(self::IS_BREAK_IN_SWITCH) === \true) {
101-
return null;
102-
}
10379
if ($this->contextAnalyzer->isInIf($node)) {
10480
return new Return_();
10581
}

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 = '6efa09477442d9bfed0989fdd1d773bb0d3fa5a2';
22+
public const PACKAGE_VERSION = '3b46948b9f2101fb62a3227ef112611429bd4ae5';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-12-08 00:49:28';
27+
public const RELEASE_DATE = '2025-12-07 23:51:44';
2828
/**
2929
* @var int
3030
*/

src/NodeNestingScope/ContextAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class ContextAnalyzer
1515
*/
1616
public function isInLoop(Node $node): bool
1717
{
18-
return $node->getAttribute(AttributeKey::IS_IN_LOOP) === \true;
18+
return $node->getAttribute(AttributeKey::IS_IN_LOOP_OR_SWITCH) === \true;
1919
}
2020
/**
2121
* @api

src/NodeTypeResolver/Node/AttributeKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ final class AttributeKey
143143
/**
144144
* @var string
145145
*/
146-
public const IS_IN_LOOP = 'is_in_loop';
146+
public const IS_IN_LOOP_OR_SWITCH = 'is_in_loop';
147147
/**
148148
* @var string
149149
*/

src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ContextNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private function processContextInLoop($node): void
150150
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
151151
}
152152
if ($subNode instanceof If_ || $subNode instanceof Break_) {
153-
$subNode->setAttribute(AttributeKey::IS_IN_LOOP, \true);
153+
$subNode->setAttribute(AttributeKey::IS_IN_LOOP_OR_SWITCH, \true);
154154
}
155155
return null;
156156
});

0 commit comments

Comments
 (0)