Skip to content

System error: "Trying to replace statement (Stmt_Return) with expression (Expr_BooleanNot). Are you missing a Stmt_Expression wrapper? #8044

@canvural

Description

@canvural

Bug Report

Subject Details
Rector version 0.17.3

Not sure which rule it is exactly. But the following snippet causes an internal PHPParser error.

<?php

namespace App;

use Illuminate\Support\Facades\Auth;
use User;

class Foo
{
    public function getUser(?User $user = null): ?User
    {
        return $user ?? (Auth::check() ? Auth::user() : null);
    }


    public function doFoo(
        ?User $user = null
    ): bool {
        $user = $this->getUser($user);

        if (!$user) {
            return false;
        }

        return $user->isFoo() || $user->isBar();
    }

}

Error: System error: "Trying to replace statement (Stmt_Return) with expression (Expr_BooleanNot). Are you missing a Stmt_Expression wrapper?

Minimal PHP Code Causing Issue

https://getrector.com/demo/44c449cb-8ecf-420a-b7ef-00018292a101

Expected Behaviour

No errors.

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