'How to resolve Fatal error: Uncaught TypeError: Return value?

I have a very annoying problem to solve. I have a method that searches for a code of a sale, it is:

  public function findByCode(string $code, string $columns = "*"): ?Sales
    {
        $find = $this->find("code = :code", "code={$code}", $columns);
        return $find->fetch(true);
    }

When I try to call him that:

$sales = (new Sales())->findByCode(client()->code);

It shows me the following error:

Uncaught TypeError: Return value of Source\Models\Sales::findByCode() must be an instance of Source\Models\Sales or null, array returned in

How to solve this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source