Skip to content

[CodeQuality] Split ExplicitBoolCompareRector into array and object variants#8162

Merged
TomasVotruba merged 3 commits into
mainfrom
split-explicit-bool-compare-rector
Jul 9, 2026
Merged

[CodeQuality] Split ExplicitBoolCompareRector into array and object variants#8162
TomasVotruba merged 3 commits into
mainfrom
split-explicit-bool-compare-rector

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jul 9, 2026

Copy link
Copy Markdown
Member

Splits ExplicitBoolCompareRector into three focused rules, so array and object explicit-bool comparisons can be enabled or skipped independently.

ExplicitBoolCompareRector no longer touches array or object conditions; it now explicitly skips them, and the two new rules own those cases. The CodeQualityLevel keeps the same overall coverage, with the new rules ordered before the original so they run first.

Rule Handles
ArrayExplicitBoolCompareRector (new) array-type variable
ObjectExplicitBoolCompareRector (new) nullable object
ExplicitBoolCompareRector (narrowed) count(), string, int, float

ArrayExplicitBoolCompareRector

 public function run(array $items)
 {
-    if (!$items) {
+    if ($items === []) {
         return 'no items';
     }
 }

ObjectExplicitBoolCompareRector

 public function run(?\stdClass $item)
 {
-    if (!$item) {
+    if (!$item instanceof \stdClass) {
         return 'empty';
     }
 }

ExplicitBoolCompareRector

 public function run($items)
 {
-    if (!count($items)) {
+    if (count($items) === 0) {
         return 'no items';
     }
 }

@TomasVotruba TomasVotruba enabled auto-merge (squash) July 9, 2026 08:36
@TomasVotruba TomasVotruba merged commit 299ca8d into main Jul 9, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the split-explicit-bool-compare-rector branch July 9, 2026 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant