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

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

final class DirectCoalesce
{
public function run($productOptions)
{
return $productOptions['list'] ?? 'default';
}
}

?>
-----
<?php

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

final class DirectCoalesce
{
public function run(array $productOptions)
{
return $productOptions['list'] ?? 'default';
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

final class SkipCoalesce
final class SkipCoalesceWithoutDimFetch
{
public function run($productOptions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private function shouldStop(Node $node, Param $param, string $paramName): bool
$nodeToCheck = $node->var;
}

if ($this->isMethodCallOrArrayDimFetch($paramName, $nodeToCheck)) {
if ($this->isMethodCall($paramName, $nodeToCheck)) {
return true;
}

Expand Down Expand Up @@ -295,16 +295,12 @@ private function isEmptyOrEchoedOrCasted(Node $node, string $paramName): bool
return $node instanceof Array_ && $node->expr instanceof Variable && $this->isName($node->expr, $paramName);
}

private function isMethodCallOrArrayDimFetch(string $paramName, ?Node $node): bool
private function isMethodCall(string $paramName, ?Node $node): bool
{
if ($node instanceof MethodCall) {
return $node->var instanceof Variable && $this->isName($node->var, $paramName);
}

if ($node instanceof ArrayDimFetch) {
return $node->var instanceof Variable && $this->isName($node->var, $paramName);
}

return false;
}

Expand Down