From 7c229de5b2148d2fa91b1ef185c8f47a9890f503 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Aug 2025 15:30:50 +0700 Subject: [PATCH] [CodeQuality] Skip next inside array_filter() on SimplifyEmptyArrayCheckRector --- .../Fixture/fixture.php.inc | 10 --------- .../skip_right_inside_array_filter.php.inc | 14 +++++++++++++ .../SimplifyEmptyArrayCheckRector.php | 21 +++++++------------ 3 files changed, 21 insertions(+), 24 deletions(-) create mode 100644 rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/skip_right_inside_array_filter.php.inc diff --git a/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/fixture.php.inc b/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/fixture.php.inc index bd906325176..8aeb13550e4 100644 --- a/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/fixture.php.inc +++ b/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/fixture.php.inc @@ -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)); - } } ?> @@ -37,11 +32,6 @@ final class Fixture { return $values === []; } - - public function functionCallInsideEmpty($values): bool - { - return array_filter($values) === []; - } } ?> diff --git a/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/skip_right_inside_array_filter.php.inc b/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/skip_right_inside_array_filter.php.inc new file mode 100644 index 00000000000..1917c2fb212 --- /dev/null +++ b/rules-tests/CodeQuality/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector/Fixture/skip_right_inside_array_filter.php.inc @@ -0,0 +1,14 @@ +getArgs()[0]); + if (isset($node->getArgs()[0])) { + return $node->getArgs()[0]->value instanceof Variable; + } + + return false; }, // empty(...) function (Node $node): bool { @@ -103,19 +108,7 @@ function (Node $node): bool { 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; } ); }