Skip to content

TernaryToElvisRector loses parenthesis in the else case #9024

@robchett

Description

@robchett

Bug Report

Subject Details
Rector version 2.0.9

Minimal PHP Code Causing Issue

https://getrector.com/demo/30cf809d-fcf8-4424-8c7c-31ffe56b157e

-$a ? $a : ($a !== false ? $b : null);
+$a ?: $a !== false ? $b : null;

a second pass then sets it to

-$a = $a ?: $a !== false ? $b : null;
+$a = ($a ?: $a !== false) ? $b : null;

Expected Behaviour

TernaryToElvisRector should apply without removing parenthesis

-$a = $a ? $a : ($a !== false ? $b : null);
+$a = $a ?: ($a !== false ? $b : null);

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