Skip to content

Commit 0e07993

Browse files
committed
Updated Rector to commit 4ed71aeee69c5f327243c840d2ead5cbf064e378
rectorphp/rector-src@4ed71ae Skip ClosureToArrowFunctionRector when closure has @var docblock (#7885)
1 parent 4147350 commit 0e07993

2 files changed

Lines changed: 6 additions & 26 deletions

File tree

rules/Php74/NodeAnalyzer/ClosureArrowFunctionAnalyzer.php

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
use PhpParser\Node\Expr\Variable;
1212
use PhpParser\Node\Stmt\Return_;
1313
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
14-
use PHPStan\Type\MixedType;
1514
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
1615
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
1716
use Rector\NodeAnalyzer\CompactFuncCallAnalyzer;
18-
use Rector\NodeTypeResolver\NodeTypeResolver;
1917
use Rector\PhpParser\Comparing\NodeComparator;
2018
use Rector\PhpParser\Node\BetterNodeFinder;
2119
use Rector\Util\ArrayChecker;
@@ -37,21 +35,16 @@ final class ClosureArrowFunctionAnalyzer
3735
* @readonly
3836
*/
3937
private PhpDocInfoFactory $phpDocInfoFactory;
40-
/**
41-
* @readonly
42-
*/
43-
private NodeTypeResolver $nodeTypeResolver;
4438
/**
4539
* @readonly
4640
*/
4741
private CompactFuncCallAnalyzer $compactFuncCallAnalyzer;
48-
public function __construct(BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, ArrayChecker $arrayChecker, PhpDocInfoFactory $phpDocInfoFactory, NodeTypeResolver $nodeTypeResolver, CompactFuncCallAnalyzer $compactFuncCallAnalyzer)
42+
public function __construct(BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, ArrayChecker $arrayChecker, PhpDocInfoFactory $phpDocInfoFactory, CompactFuncCallAnalyzer $compactFuncCallAnalyzer)
4943
{
5044
$this->betterNodeFinder = $betterNodeFinder;
5145
$this->nodeComparator = $nodeComparator;
5246
$this->arrayChecker = $arrayChecker;
5347
$this->phpDocInfoFactory = $phpDocInfoFactory;
54-
$this->nodeTypeResolver = $nodeTypeResolver;
5548
$this->compactFuncCallAnalyzer = $compactFuncCallAnalyzer;
5649
}
5750
public function matchArrowFunctionExpr(Closure $closure): ?Expr
@@ -98,7 +91,8 @@ private function shouldSkipForUseVariableUsedByCompact(Closure $closure): bool
9891
});
9992
}
10093
/**
101-
* Ensure @var doc usage with more specific type on purpose to be skipped
94+
* Ensure @var doc usage to be skipped, as arrow functions do not support
95+
* inline @var annotations for type narrowing (e.g. generic types like Builder<Team>)
10296
*/
10397
private function shouldSkipMoreSpecificTypeWithVarDoc(Return_ $return, Expr $expr): bool
10498
{
@@ -107,21 +101,7 @@ private function shouldSkipMoreSpecificTypeWithVarDoc(Return_ $return, Expr $exp
107101
return \false;
108102
}
109103
$varTagValueNode = $phpDocInfo->getVarTagValueNode();
110-
if (!$varTagValueNode instanceof VarTagValueNode) {
111-
return \false;
112-
}
113-
$varType = $phpDocInfo->getVarType();
114-
if ($varType instanceof MixedType) {
115-
return \false;
116-
}
117-
$variableName = ltrim($varTagValueNode->variableName, '$');
118-
$variable = $this->betterNodeFinder->findFirst($expr, static fn(Node $node): bool => $node instanceof Variable && $node->name === $variableName);
119-
if (!$variable instanceof Variable) {
120-
return \false;
121-
}
122-
$nativeVariableType = $this->nodeTypeResolver->getNativeType($variable);
123-
// not equal with native type means more specific type
124-
return !$nativeVariableType->equals($varType);
104+
return $varTagValueNode instanceof VarTagValueNode;
125105
}
126106
private function shouldSkipForUsedReferencedValue(Closure $closure): bool
127107
{

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 = '142f1c81c7a9d26fd5119526186aba14f4cf6382';
22+
public const PACKAGE_VERSION = '4ed71aeee69c5f327243c840d2ead5cbf064e378';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2026-02-06 17:31:57';
27+
public const RELEASE_DATE = '2026-02-08 11:29:50';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)