Skip to content

Incorrect behavior of SimplifyIfReturnBoolRector #9136

@simonschaufi

Description

@simonschaufi

Bug Report

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/b02bb8b6-ffa4-44d6-ac94-a893250c2ff0

<?php

final class DemoFile
{
    public static function isLeapyear(int $year): bool
    {
        if (($year % 400) == 0 || (($year & 4) == 0 && ($year % 100) != 0)) {
            return true;
        }
        return false;
    }
}

Responsible rules

  • SimplifyIfReturnBoolRector

Expected Behavior

Rector should keep the brackets like so:

<?php

final class DemoFile
{
    public static function isLeapyear(int $year): bool
    {
        return (($year % 400) == 0 || (($year & 4) == 0 && ($year % 100) != 0));
    }
}

instead of dropping them:

<?php

final class DemoFile
{
    public static function isLeapyear(int $year): bool
    {
        return (($year % 400) == 0 || ($year & 4) == 0 && ($year % 100) != 0);
    }
}

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