PHP

PHP

Made by DeepSource

Missing return statement in method/function PHP-E1004

Bug risk
Critical

This issue is raised if a method with a return type does not have a return statement of an appropriate type.

Bad practice

class User
{
    public function greet(): string
    {
        $message = 'Hello, there!';
        // missing return statement
    }
}
class User
{
    public function greet()
    {
        $message = function (): string {
            $message = 'Hello, there!';
            // missing return statement
        };

        return $message();
    }
}

Recommended

class User
{
    public function greet(): string
    {
        $message = 'Hello, there!';

        return $message;
    }
}
class User
{
    public function greet()
    {
        $message = function (): string {
            $message = 'Hello, there!';

            return $message;
        };

        return $message();
    }
}

References