Skip to content

Commit fb07dc4

Browse files
authored
skip is_array() on anything (#422)
1 parent 7207a72 commit fb07dc4

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Doctrine\Tests\TypedCollections\Rector\If_\RemoveIsArrayOnCollectionRector\Fixture;
4+
5+
use Doctrine\Common\Collections\Collection;
6+
7+
final class SkipIsArrayOnNonCollection
8+
{
9+
public $items;
10+
11+
public function someMethod()
12+
{
13+
return ! is_array($this->items) ? $this->items : [];
14+
}
15+
16+
public function nextMethod()
17+
{
18+
return is_array($this->items) ? $this->items : [];
19+
}
20+
21+
public function condition()
22+
{
23+
if (! is_array($this->items)) {
24+
return 'yes';
25+
}
26+
27+
return 'no';
28+
}
29+
}

rules/TypedCollections/Rector/If_/RemoveIsArrayOnCollectionRector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ private function refactorIf(If_ $if): array|int|null
8888
if ($if->cond instanceof BooleanNot) {
8989
$condition = $if->cond->expr;
9090

91-
if ($condition instanceof FuncCall && $this->isName($condition, 'is_array')) {
91+
if ($condition instanceof FuncCall && $this->isName(
92+
$condition,
93+
'is_array'
94+
) && $this->collectionTypeDetector->isCollectionType($condition->getArgs()[0] ->value)) {
9295
return $if->stmts;
9396
}
9497

0 commit comments

Comments
 (0)