Skip to content

Commit 8d84db7

Browse files
authored
[CodeQuality] Skip init not empty array on InlineArrayReturnAssignRector (#7276)
* [CodeQuality] Skip init not empty array on InlineArrayReturnAssignRector * fixed
1 parent c98145f commit 8d84db7

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector\Fixture;
4+
5+
final class SkipInitNotEmptyArray
6+
{
7+
public function some(SomeObject $someObject): array
8+
{
9+
$message = [
10+
'type' => 'type',
11+
'id' => (string) $someObject->getId(),
12+
];
13+
$message['link'] = $this->getSome($someObject);
14+
15+
return $message;
16+
}
17+
}

rules/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ private function resolveDefaultEmptyArrayAssign(array $stmts, string $returnedVa
215215
continue;
216216
}
217217

218+
if ($assign->expr->items !== []) {
219+
continue;
220+
}
221+
218222
return $assign;
219223
}
220224

0 commit comments

Comments
 (0)