Skip to content

Commit 6f3e61d

Browse files
samsonasikTomasVotruba
authored andcommitted
add back return by array shape test
1 parent 1ca3c69 commit 6f3e61d

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector\Fixture;
4+
5+
class ReturnByArrayShapeType
6+
{
7+
/**
8+
* @param array<int, array{bar: int}> $values
9+
*/
10+
private function foo(array $values): void
11+
{
12+
$bars = array_map(fn($value) => $value['bar'], $values);
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector\Fixture;
21+
22+
class ReturnByArrayShapeType
23+
{
24+
/**
25+
* @param array<int, array{bar: int}> $values
26+
*/
27+
private function foo(array $values): void
28+
{
29+
$bars = array_map(fn($value): int => $value['bar'], $values);
30+
}
31+
}
32+
33+
?>

rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use PhpParser\Node\Expr\Instanceof_;
1313
use PhpParser\Node\Expr\Variable;
1414
use PhpParser\Node\Identifier;
15-
use PhpParser\Node\Scalar\String_;
1615
use PHPStan\Type\ArrayType;
1716
use Rector\PhpParser\Node\BetterNodeFinder;
1817
use Rector\Rector\AbstractRector;
@@ -149,8 +148,7 @@ private function resolveDimFetchVariableNames(Closure|ArrowFunction $closureExpr
149148
if ($arrayDimFetch->var instanceof Variable) {
150149
$type = $this->nodeTypeResolver->getNativeType($arrayDimFetch->var);
151150

152-
// skip string values
153-
if (! $arrayDimFetch->dim instanceof String_ && ($type->isString()->yes() || $type->isString()->maybe())) {
151+
if ($type->isString()->yes()) {
154152
continue;
155153
}
156154

0 commit comments

Comments
 (0)