Skip to content

Incorrect Behavior of RemoveDeadZeroAndOneOperationRector #9666

@lphilps

Description

@lphilps

Bug Report

Subject Details
Rector version 2.3.6

RemoveDeadZeroAndOneOperationRector is incorrectly simplifying a round up operation into a constant.

The example below is extracted from some complicated logic to graph data and the bit the rector is mis-handling is the bit that's iterating over a dataset an determining the value for the y-axis by calculating the nearest multiple of 500 "above" the largest value in the set.

In the demo I've cut down the logic to the smallest amount of code that reproduces the problem in which RemoveDeadZeroAndOneOperationRector is incorrectly changing

$stats->maxRange = (intval(($stats->maxRange + 1) / 500) + 1) * 500;

to

$stats->maxRange = 500;

Minimal PHP Code Causing Issue

https://getrector.com/demo/18c48e12-a68b-4019-ae1c-a6104a25d4de

Expected Behaviour

If you run the code in the example, it will print

 300:  500
 500: 1000
 900: 1000
1001: 1500

The rector is incorrectly changing the logic causing the function to return 500 unconditionally.

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