Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class EmptyIndex
{
public function run($param): void
{
if (! empty($param['index'])) {
$index = $param['index'];
} else {
$index = 100;
}
}
}

?>
-----
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector\Fixture;

final class EmptyIndex
{
public function run(array $param): void
{
if (! empty($param['index'])) {
$index = $param['index'];
} else {
$index = 100;
}
}
}

?>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ private function isParamAccessedArrayDimFetch(Param $param, ClassMethod|Function

$isParamAccessedArrayDimFetch = false;
$this->traverseNodesWithCallable($functionLike->stmts, function (Node $node) use (
$param,
$paramName,
&$isParamAccessedArrayDimFetch,
): int|null {
if ($node instanceof Class_ || $node instanceof FunctionLike) {
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}

if ($this->shouldStop($node, $param, $paramName)) {
if ($this->shouldStop($node, $paramName)) {
// force set to false to avoid too early replaced
$isParamAccessedArrayDimFetch = false;
return NodeVisitor::STOP_TRAVERSAL;
Expand Down Expand Up @@ -209,16 +208,11 @@ private function isEchoed(Node $node, string $paramName): bool
return false;
}

private function shouldStop(Node $node, Param $param, string $paramName): bool
private function shouldStop(Node $node, string $paramName): bool
{
$nodeToCheck = null;

if (! $param->default instanceof Expr && ($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()
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