-
-
Notifications
You must be signed in to change notification settings - Fork 738
Closed
rectorphp/rector-src
#3390Labels
Description
Bug Report
| Subject | Details |
|---|---|
| Rector version | last dev-main |
| Installed as | composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/e1b4cf4e-c34f-466d-ac1a-4ecdbffca61c
<?php
final class DemoFile
{
public function run(Item $yes)
{
while (true !== false) {
}
$a = [];
if ($b = $yes) {
$a[] = 'test';
}
return $a;
}
}More real-world example:
See https://getrector.com/demo/c74cd93b-9c55-41d6-b831-24f952405737
<?php
final class Item
{
private $parent;
/**
* @return Item
*/
public function getParent()
{
return $this->parent;
}
}
final class DemoFile
{
private function create()
{
return [];
}
public function run(Item $yes)
{
while (($yes = $yes->getParent()) !== null) {
}
$a = $this->create();
if ($b = $yes) {
$a[] = 'test';
}
return $a;
}
}Responsible rules
AddDefaultValueForUndefinedVariableRector
Expected Behavior
Rector shouldn't "fix" this. The variable is always set. Removing the while makes Rector think the code is correct.