mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-21 16:02:23 +02:00
Updated Rector to commit d57daa7529d035667ca2bf03b19d4b68c07d401d
d57daa7529
[TypeDeclaration] Direclty use ArrayDimFetch instance on ArrowFunction->expr on AddArrowFunctionParamArrayWhereDimFetchRector (#6819)
This commit is contained in:
parent
e96d8dabd6
commit
059eb00d78
@ -7,12 +7,7 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ArrayDimFetch;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeVisitor;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\ValueObject\PhpVersionFeature;
|
||||
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
|
||||
@ -65,11 +60,14 @@ CODE_SAMPLE
|
||||
if ($arrowFunctionParam->type instanceof Node) {
|
||||
return null;
|
||||
}
|
||||
if ($this->shouldSkip($arrowFunction)) {
|
||||
if (!$arrowFunction->expr instanceof ArrayDimFetch) {
|
||||
return null;
|
||||
}
|
||||
$paramName = $this->getName($arrowFunctionParam);
|
||||
if (!$this->isParamArrayDimFetched($arrowFunction, $paramName)) {
|
||||
$var = $arrowFunction->expr;
|
||||
while ($var instanceof ArrayDimFetch) {
|
||||
$var = $var->var;
|
||||
}
|
||||
if (!$this->nodeComparator->areNodesEqual($var, $arrowFunctionParam->var)) {
|
||||
return null;
|
||||
}
|
||||
$arrowFunctionParam->type = new Identifier('array');
|
||||
@ -79,27 +77,4 @@ CODE_SAMPLE
|
||||
{
|
||||
return PhpVersionFeature::SCALAR_TYPES;
|
||||
}
|
||||
private function isParamArrayDimFetched(ArrowFunction $arrowFunction, string $paramName) : bool
|
||||
{
|
||||
$nodeFinder = new NodeFinder();
|
||||
$arrayDimFetches = $nodeFinder->findInstanceOf($arrowFunction->expr, ArrayDimFetch::class);
|
||||
foreach ($arrayDimFetches as $arrayDimFetch) {
|
||||
if ($this->isName($arrayDimFetch->var, $paramName)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
private function shouldSkip(ArrowFunction $arrowFunction) : bool
|
||||
{
|
||||
$shouldSkip = \false;
|
||||
$this->traverseNodesWithCallable($arrowFunction->expr, function (Node $subNode) use(&$shouldSkip) : ?int {
|
||||
if ($subNode instanceof Class_ || $subNode instanceof FunctionLike || $subNode instanceof Ternary) {
|
||||
$shouldSkip = \true;
|
||||
return NodeVisitor::STOP_TRAVERSAL;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
return $shouldSkip;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '35c2c1cd3cc54da84c06e30d9e78b3f2f7e9f40a';
|
||||
public const PACKAGE_VERSION = 'd57daa7529d035667ca2bf03b19d4b68c07d401d';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2025-04-05 14:38:59';
|
||||
public const RELEASE_DATE = '2025-04-05 14:51:35';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user