Skip to content

Add rule to improve performance checking on empty array #7485

@JohJohan

Description

@JohJohan

Feature Request

Just like https://github.com/rectorphp/rector/blob/main/docs/rector_rules_overview.md#countarraytoemptyarraycomparisonrector i think it would be good performance to change empty() function call on array values to [] check example:

Diff

$array = [];

-if (empty($array)) {}; 
+if ([] === $array) {};
-if (!empty($array)) {}; 
+ if ([] !== $array) {};

This can only be done if we know that the variable is array. So for typed properties, function arguments or function return types

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions