Skip to content

Incorrect behavior of BooleanInIfConditionRuleFixerRector #8980

@jderusse

Description

@jderusse

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/4f18d4d4-73c3-4c41-a163-d9185dcd6b14

<?php

function getList(): array
{
    return [];
}

if ($items = getList()) {
    echo $items[0];
}

Responsible rules

  • BooleanInIfConditionRuleFixerRector

Expected Behavior

Similar to #8973

The rector converts $items = getList() into $items = getList() !== [].

The issue is, that the precedence is not the same: $items = getList() !== [] is evaluated as $items = (getList() !== []) instead of (expected) ($items = getList()) !== []

see https://3v4l.org/5OQRl for precedence

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions