Skip to content

Commit 38e68e6

Browse files
authored
[TypeDeclaration] Skip integer index on string on AddArrowFunctionParamArrayWhereDimFetchRector (#7178)
* [TypeDeclaration] Skip integer index on string on AddArrowFunctionParamArrayWhereDimFetchRector * [TypeDeclaration] Skip integer index on string on AddArrowFunctionParamArrayWhereDimFetchRector * [TypeDeclaration] Skip integer index on string on AddArrowFunctionParamArrayWhereDimFetchRector
1 parent e8f4c73 commit 38e68e6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\FuncCall\AddArrowFunctionParamArrayWhereDimFetchRector\Fixture;
4+
5+
final class SkipIntegerIndexOnString
6+
{
7+
public function run()
8+
{
9+
$username = 'john.doe';
10+
11+
$initials = implode(
12+
'',
13+
array_map(
14+
static fn ($name): string => strtoupper((string) $name[0]),
15+
explode('.', $username),
16+
),
17+
);
18+
}
19+
}

rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ private function resolveDimFetchVariableNames(Closure|ArrowFunction $closureExpr
146146

147147
foreach ($arrayDimFetches as $arrayDimFetch) {
148148
if ($arrayDimFetch->var instanceof Variable) {
149+
$type = $this->nodeTypeResolver->getNativeType($arrayDimFetch->var);
150+
151+
if ($type->isString()->yes()) {
152+
continue;
153+
}
154+
149155
$usedDimFetchVariableNames[] = (string) $this->getName($arrayDimFetch->var);
150156
}
151157
}

0 commit comments

Comments
 (0)