Skip to content

Commit

Permalink
Updated Rector to commit 24fb5874905da56065ef38d9cfe9bff77cb04cac
Browse files Browse the repository at this point in the history
rectorphp/rector-src@24fb587 [TypeDeclaration] Skip isset and empty with index on param variable on StrictArrayParamDimFetchRector (#6227)
  • Loading branch information
TomasVotruba committed Aug 12, 2024
1 parent 39ccd68 commit 267b6cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Isset_;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
Expand Down Expand Up @@ -112,11 +113,11 @@ private function isParamAccessedArrayDimFetch(Param $param, $functionLike) : boo
}
$paramName = $this->getName($param);
$isParamAccessedArrayDimFetch = \false;
$this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use($paramName, &$isParamAccessedArrayDimFetch) : ?int {
$this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use($param, $paramName, &$isParamAccessedArrayDimFetch) : ?int {
if ($node instanceof Class_ || $node instanceof FunctionLike) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if ($this->shouldStop($node, $paramName)) {
if ($this->shouldStop($node, $param, $paramName)) {
// force set to false to avoid too early replaced
$isParamAccessedArrayDimFetch = \false;
return NodeTraverser::STOP_TRAVERSAL;
Expand Down Expand Up @@ -162,9 +163,21 @@ private function isEchoed(Node $node, string $paramName) : bool
}
return \false;
}
private function shouldStop(Node $node, string $paramName) : bool
private function shouldStop(Node $node, Param $param, string $paramName) : bool
{
$nodeToCheck = null;
if (!$param->default instanceof Expr) {
if ($node instanceof Isset_) {
foreach ($node->vars as $var) {
if ($var instanceof ArrayDimFetch && $var->var instanceof Variable && $var->var->name === $paramName) {
return \true;
}
}
}
if ($node instanceof Empty_ && $node->expr instanceof ArrayDimFetch && $node->expr->var instanceof Variable && $node->expr->var->name === $paramName) {
return \true;
}
}
if ($node instanceof FuncCall && !$node->isFirstClassCallable() && $this->isNames($node, ['is_array', 'is_string', 'is_int', 'is_bool', 'is_float'])) {
$firstArg = $node->getArgs()[0];
$nodeToCheck = $firstArg->value;
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '67238d841a46b5fecc9ef204ffef4ba773e82cb9';
public const PACKAGE_VERSION = '24fb5874905da56065ef38d9cfe9bff77cb04cac';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-08-08 13:51:11';
public const RELEASE_DATE = '2024-08-12 22:00:07';
/**
* @var int
*/
Expand Down

0 comments on commit 267b6cc

Please sign in to comment.