Skip to content

Commit d4eb82d

Browse files
committed
[Php81] Remove NullToStrictStringFuncCallArgRector from level set, skip array dim fetch args
1 parent e1283b9 commit d4eb82d

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

config/set/php81.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector;
1212
use Rector\Php81\Rector\Class_\SpatieEnumClassToEnumRector;
1313
use Rector\Php81\Rector\FuncCall\NullToStrictIntPregSlitFuncCallLimitArgRector;
14-
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
1514
use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector;
1615
use Rector\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector;
1716
use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector;
@@ -28,7 +27,6 @@
2827
ReadOnlyPropertyRector::class,
2928
SpatieEnumClassToEnumRector::class,
3029
SpatieEnumMethodCallToEnumConstRector::class,
31-
NullToStrictStringFuncCallArgRector::class,
3230
NullToStrictIntPregSlitFuncCallLimitArgRector::class,
3331

3432
ArrayToFirstClassCallableRector::class,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector\Fixture;
4+
5+
final class SkipArrayDimFetchKey
6+
{
7+
public function run(array $data)
8+
{
9+
return str_replace('a', 'b', $data['key']);
10+
}
11+
}

rules/Php81/NodeManipulator/NullToStrictStringIntConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpParser\Node\Arg;
88
use PhpParser\Node\Expr;
9+
use PhpParser\Node\Expr\ArrayDimFetch;
910
use PhpParser\Node\Expr\Cast\Int_ as CastInt_;
1011
use PhpParser\Node\Expr\Cast\String_ as CastString_;
1112
use PhpParser\Node\Expr\FuncCall;
@@ -120,6 +121,11 @@ public function convertIfNull(
120121

121122
private function shouldSkipValue(Expr $expr, Scope $scope, bool $isTrait, string $targetType): bool
122123
{
124+
// array dim fetch value is mixed, null is not known - skip to avoid wrong (string) cast
125+
if ($expr instanceof ArrayDimFetch) {
126+
return true;
127+
}
128+
123129
if ($this->isPropertyFetchOnClassWithMagicGet($expr)) {
124130
return true;
125131
}

0 commit comments

Comments
 (0)