8000 Incorrect behavior of SimplifyUselessVariableRector · Issue #9179 · rectorphp/rector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content {"props":{"docsUrl":"https://docs.github.com/get-started/accessibility/keyboard-shortcuts"}}
Incorrect behavior of SimplifyUselessVariableRector #9179
Closed
rectorphp/rector-src
#6913
@thePanz

Description

@thePanz

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/fc7539a2-8d8c-458a-a974-7ddcefc85e5b

<?php

class Demo {
    public function run(?string $maybe, string $part): string
    { 
       $address = $maybe;
       $address .= $address ? ' - ' . $part : $part;

       return $address;
    }
    
    function a(): void {
        echo "maybe - part";
        echo $this->run('maybe', 'part');
    }
    
    
    function b(): void {
        echo "part";
        echo $this->run(null, 'part');
    }
}

Responsible rules

  • SimplifyUselessVariableRector

Expected Behavior

Should be: https://3v4l.org/HUZJP

Adapted code by Rector which breaks the business logig: https://3v4l.org/nemWM

The . operator has precedence over ?:

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

      0