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,21 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;

final class SkipNestedDimFetch
{
public static function getData(): array
{
$data = [];

$data['info'] = [
'one' => 123,
];

$data['info']['nested'] = 123;

return $data;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ final class WithUnary
}
}

?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace Rector\CodeQuality\NodeAnalyzer;

use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\CodeQuality\ValueObject\KeyAndExpr;
use Rector\Exception\NotImplementedYetException;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\PhpParser\Node\Value\ValueResolver;

Expand Down Expand Up @@ -86,7 +88,11 @@ private function setNestedKeysExpr(array &$exprsByKeys, array $keys, Expr $expr)
$keys = array_reverse($keys);

foreach ($keys as $key) {
// create intermediate arrays automatically
if ($reference instanceof Array_) {
// currently it fails here with Cannot use object of type PhpParser\Node\Expr\Array_ as array
throw new NotImplementedYetException();
}

$reference = &$reference[$key];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PhpParser\Node\Stmt\Return_;
use Rector\CodeQuality\NodeAnalyzer\VariableDimFetchAssignResolver;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Exception\NotImplementedYetException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand Down Expand Up @@ -111,12 +112,18 @@ public function refactor(Node $node): ?Node
return null;
}

$keysAndExprsByKey = $this->variableDimFetchAssignResolver->resolveFromStmtsAndVariable(
$stmts,
$emptyArrayAssign,
);
try {
$keysAndExprsByKey = $this->variableDimFetchAssignResolver->resolveFromStmtsAndVariable(
$stmts,
$emptyArrayAssign,
);
} catch (NotImplementedYetException) {
// dim fetch assign of nested arrays is hard to resolve
return null;
}

if ($keysAndExprsByKey === []) {

return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function changeReturnTypeNode(
}

public function changeParamTypeNode(
ClassMethod $functionLike,
ClassMethod $classMethod,
PhpDocInfo $phpDocInfo,
Param $param,
string $paramName,
Expand All @@ -129,7 +129,7 @@ public function changeParamTypeNode(
$phpDocInfo->addTagValueNode($paramTagValueNode);
}

$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($classMethod);
}

public function changeReturnType(FunctionLike $functionLike, PhpDocInfo $phpDocInfo, Type $newType): bool
Expand Down
Loading