File tree Expand file tree Collapse file tree
rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture
rules/CodeQuality/Rector/BooleanAnd Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,11 +13,6 @@ final class Fixture
1313 {
1414 return empty ($ values ) && is_array ($ values );
1515 }
16-
17- public function functionCallInsideEmpty ($ values ): bool
18- {
19- return is_array ($ values ) && empty (array_filter ($ values ));
20- }
2116}
2217
2318?>
@@ -37,11 +32,6 @@ final class Fixture
3732 {
3833 return $ values === [];
3934 }
40-
41- public function functionCallInsideEmpty ($ values ): bool
42- {
43- return array_filter ($ values ) === [];
44- }
4535}
4636
4737?>
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \Tests \CodeQuality \Rector \BooleanAnd \SimplifyEmptyArrayCheckRector \Fixture ;
4+
5+ final class SkipRightInsideArrayFilter
6+ {
7+ public function example (mixed $ value ): bool {
8+ if (is_array ($ value ) && empty (array_filter ($ value ))) {
9+ return true ;
10+ }
11+
12+ return false ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1010use PhpParser \Node \Expr \BinaryOp \Identical ;
1111use PhpParser \Node \Expr \Empty_ ;
1212use PhpParser \Node \Expr \FuncCall ;
13+ use PhpParser \Node \Expr \Variable ;
1314use Rector \NodeManipulator \BinaryOpManipulator ;
1415use Rector \Php71 \ValueObject \TwoNodeMatch ;
1516use Rector \Rector \AbstractRector ;
@@ -95,27 +96,19 @@ function (Node $node): bool {
9596 return false ;
9697 }
9798
98- return isset ($ node ->getArgs ()[0 ]);
99+ if (isset ($ node ->getArgs ()[0 ])) {
100+ return $ node ->getArgs ()[0 ]->value instanceof Variable;
101+ }
102+
103+ return false ;
99104 },
100105 // empty(...)
101106 function (Node $ node ): bool {
102107 if (! $ node instanceof Empty_) {
103108 return false ;
104109 }
105110
106- if ($ node ->expr instanceof FuncCall) {
107- if ($ node ->expr ->isFirstClassCallable ()) {
108- return false ;
109- }
110-
111- if (! $ this ->isName ($ node ->expr , 'array_filter ' )) {
112- return false ;
113- }
114-
115- return isset ($ node ->expr ->getArgs ()[0 ]);
116- }
117-
118- return true ;
111+ return $ node ->expr instanceof Variable;
119112 }
120113 );
121114 }
You can’t perform that action at this time.
0 commit comments