Skip to content

Invalid output when running TernaryToElvisRector #2421

@JoyceBabu

Description

@JoyceBabu
Subject Details
Rector version v0.6.0
PHP version PHP 7.3.12
Full Command composer/bin/rector process rector/test.php -vvv

Current Behaviour

I was trying to upgrade a very old code. TernaryToElvisRector converts

$val = ($a - $b) ? ($a - $b) : $c;

to
$val = ($a - $b) ? () : $c;

1 file with changes
===================

1) rector/test.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -1,4 +1,4 @@
 <?php

-$val = ($a - $b) ? ($a - $b) : $c;
+$val = ($a - $b) ? () : $c;
    ----------- end diff -----------

Applied rules:

 * Rector\Php53\Rector\Ternary\TernaryToElvisRector

Minimal PHP Code Causing Issue

<?php

$val = ($a - $b) ? () : $c;

Expected Behaviour

$val = ($a - $b) ?: $c;

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