Skip to content

Commit 668f851

Browse files
committed
use existing attribute
1 parent 6efa094 commit 668f851

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

rules/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector.php

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpParser\Node\Arg;
99
use PhpParser\Node\Expr;
1010
use PhpParser\Node\Expr\ArrowFunction;
11-
use PhpParser\Node\Expr\Assign;
1211
use PhpParser\Node\Expr\CallLike;
1312
use PhpParser\Node\Expr\Closure;
1413
use PhpParser\Node\Expr\FuncCall;
@@ -26,6 +25,7 @@
2625
use PHPStan\Reflection\Native\NativeFunctionReflection;
2726
use PHPStan\Reflection\ParametersAcceptorSelector;
2827
use PHPStan\Type\CallableType;
28+
use Rector\NodeTypeResolver\Node\AttributeKey;
2929
use Rector\PhpParser\AstResolver;
3030
use Rector\PHPStan\ScopeFetcher;
3131
use Rector\Rector\AbstractRector;
@@ -45,11 +45,6 @@ final class FunctionLikeToFirstClassCallableRector extends AbstractRector implem
4545
*/
4646
private const HAS_CALLBACK_SIGNATURE_MULTI_PARAMS = 'has_callback_signature_multi_params';
4747

48-
/**
49-
* @var string
50-
*/
51-
private const IS_IN_ASSIGN = 'is_in_assign';
52-
5348
public function __construct(
5449
private readonly AstResolver $astResolver,
5550
private readonly ReflectionResolver $reflectionResolver
@@ -77,22 +72,14 @@ function ($parameter) {
7772

7873
public function getNodeTypes(): array
7974
{
80-
return [Assign::class, CallLike::class, ArrowFunction::class, Closure::class];
75+
return [CallLike::class, ArrowFunction::class, Closure::class];
8176
}
8277

8378
/**
8479
* @param CallLike|ArrowFunction|Closure $node
8580
*/
8681
public function refactor(Node $node): null|CallLike
8782
{
88-
if ($node instanceof Assign) {
89-
if ($node->expr instanceof Closure || $node->expr instanceof ArrowFunction) {
90-
$node->expr->setAttribute(self::IS_IN_ASSIGN, true);
91-
}
92-
93-
return null;
94-
}
95-
9683
if ($node instanceof CallLike) {
9784
if ($node->isFirstClassCallable()) {
9885
return null;
@@ -186,7 +173,9 @@ private function shouldSkip(
186173
return true;
187174
}
188175

189-
if ($node->getAttribute(self::IS_IN_ASSIGN) === true) {
176+
if ($node->getAttribute(AttributeKey::IS_ASSIGNED_TO) === true || $node->getAttribute(
177+
AttributeKey::IS_BEING_ASSIGNED
178+
)) {
190179
return true;
191180
}
192181

0 commit comments

Comments
 (0)