Skip to content

[CodingStyle] Deprecate CountArrayToEmptyArrayComparisonRector - #8274

Merged
TomasVotruba merged 2 commits into
mainfrom
deprecate-count-array-to-empty-array-comparison
Aug 3, 2026
Merged

[CodingStyle] Deprecate CountArrayToEmptyArrayComparisonRector#8274
TomasVotruba merged 2 commits into
mainfrom
deprecate-count-array-to-empty-array-comparison

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecate CountArrayToEmptyArrayComparisonRector and remove it from the coding style level.

The rule only swaps one equivalent check for another - no real win, it is a coding standard preference. Better left to a coding standard tool.

-count($array) === 0;
-count($array) > 0;
-! count($array);
+$array === [];
+$array !== [];
+$array === [];

@TomasVotruba
TomasVotruba merged commit 0e8debc into main Aug 3, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-count-array-to-empty-array-comparison branch August 3, 2026 12:40
@simonschaufi

Copy link
Copy Markdown
Contributor

Which coding standard tool would help me rewrite this? I have applied this rule plenty of times already.

@TomasVotruba

Copy link
Copy Markdown
Member Author

Goal of this rule was to gain performance, but there is none. It also removes the intent of count and implies general preference. This rule was very often skipped to avoid pointless cosmetic changes.
See this post on similar note https://tideways.com/profiler/blog/new-in-php-8.6-narrowing-the-array_map-vs-foreach-performance-gap

@simonschaufi

Copy link
Copy Markdown
Contributor

I totally understand that people want to skip this rule but wouldn't it then be good enough to just remove it from the set and leave it in the code base for people who still want to use it (like me)? Now I need to copy the rule to my own code base instead of just reference it.

@TomasVotruba

Copy link
Copy Markdown
Member Author

Having it here in basic sets would suggest it's a best practise to do, which is not. This is why it fits better as custom rule, that are now very cheap to make.

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.

3 participants