Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ final class Fixture
{
return empty($values) && is_array($values);
}

public function functionCallInsideEmpty($values): bool
{
return is_array($values) && empty(array_filter($values));
}
}

?>
Expand All @@ -37,11 +32,6 @@ final class Fixture
{
return $values === [];
}

public function functionCallInsideEmpty($values): bool
{
return array_filter($values) === [];
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector\Fixture;

final class SkipRightInsideArrayFilter
{
public function example(mixed $value): bool {
if (is_array($value) && empty(array_filter($value))) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use Rector\NodeManipulator\BinaryOpManipulator;
use Rector\Php71\ValueObject\TwoNodeMatch;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -95,27 +96,19 @@ function (Node $node): bool {
return false;
}

return isset($node->getArgs()[0]);
if (isset($node->getArgs()[0])) {
return $node->getArgs()[0]->value instanceof Variable;
}

return false;
},
// empty(...)
function (Node $node): bool {
if (! $node instanceof Empty_) {
return false;
}

if ($node->expr instanceof FuncCall) {
if ($node->expr->isFirstClassCallable()) {
return false;
}

if (! $this->isName($node->expr, 'array_filter')) {
return false;
}

return isset($node->expr->getArgs()[0]);
}

return true;
return $node->expr instanceof Variable;
}
);
}
Expand Down
Loading