Skip to content

Commit 99725e9

Browse files
authored
[CodeQuality] Skip append from params on InlineArrayReturnAssignRector (#7273)
* [CodeQuality] Skip append from params on InlineArrayReturnAssignRector * Fix
1 parent a96c2d3 commit 99725e9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;
4+
5+
final class SkipAppendFromParams
6+
{
7+
public function run($person)
8+
{
9+
$person['name'] = 'Timmy';
10+
$person['id'] = 1;
11+
12+
return $person;
13+
}
14+
}

rules/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Expr\Assign;
1111
use PhpParser\Node\Expr\New_;
1212
use PhpParser\Node\Expr\Variable;
13+
use PhpParser\Node\FunctionLike;
1314
use PhpParser\Node\Stmt;
1415
use PhpParser\Node\Stmt\Expression;
1516
use PhpParser\Node\Stmt\Return_;
@@ -92,6 +93,14 @@ public function refactor(Node $node): ?Node
9293
return null;
9394
}
9495

96+
if ($node instanceof FunctionLike) {
97+
foreach ($node->getParams() as $param) {
98+
if ($this->isName($param->var, $returnedVariableName)) {
99+
return null;
100+
}
101+
}
102+
}
103+
95104
$emptyArrayAssign = $this->resolveDefaultEmptyArrayAssign($stmts, $returnedVariableName);
96105
if (! $this->areAssignExclusiveToDimFetchVariable($stmts, $emptyArrayAssign, $returnedVariableName)) {
97106
return null;

0 commit comments

Comments
 (0)