rector icon indicating copy to clipboard operation
rector copied to clipboard

Remove unnecessary filter_var with FILTER_VALIDATE_BOOLEAN option

Open Harfusha opened this issue 1 year ago • 1 comments

Feature Request

When variable is always boolean it is unnecessary to run it trough filter_var with FILTER_VALIDATE_BOOLEAN option.

Diff

function test(bool $isTest): bool {
-    if (filter_var($isTest, FILTER_VALIDATE_BOOLEAN)) {
+    if ($isTest) {
        return true;
    }

    return false;
}

Harfusha avatar Oct 30 '24 09:10 Harfusha

filter_var is 7x slower than simple boolean check

Harfusha avatar Oct 31 '24 18:10 Harfusha

Looking into this...

TomasVotruba avatar Mar 20 '25 10:03 TomasVotruba