php-cs-fixer

php-cs-fixer remove unnecessary variable


I would like to have the code below adjusted via php-cs-fixer. The variable $aExample is not needed in this case and could therefore be returned immediately.

Does anyone know if there is an option for that?

public function example(): array
    {
        $aExample = $this->oModel->example();

        return $aExample;
    }

Changed to:

public function example(): array
    {
        return $this->oModel->example();

    }

Solution

  • You are looking for a rule return_assignment.

    https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/v3.48.0/doc/rules/return_notation/return_assignment.rst