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

namespace Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;

final class SkipArrayDimFetchKey
{
public function run(array $data)
{
return str_replace('a', 'b', $data['key']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Cast\Int_ as CastInt_;
use PhpParser\Node\Expr\Cast\String_ as CastString_;
use PhpParser\Node\Expr\FuncCall;
Expand Down Expand Up @@ -120,6 +121,11 @@ public function convertIfNull(

private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string $targetType): bool
{
// array dim fetch value is mixed, null is not known - skip to avoid wrong (string) cast
if ($expr instanceof ArrayDimFetch) {
return true;
}

if ($this->isPropertyFetchOnClassWithMagicGet($expr)) {
return true;
}
Expand Down
Loading