psalm-plugin-symfony icon indicating copy to clipboard operation
psalm-plugin-symfony copied to clipboard

not getting QueryBuilderSetParameter exception when using complex psalm-param

Open michnovka opened this issue 3 years ago • 0 comments

After https://github.com/psalm/psalm-plugin-symfony/issues/269 was closed, I was fixing my code to comply with doctrine recommendations and noticed that the exception is not thrown if the parameter type is defined inside an array:

The below code does give the exception QueryBuilderSetParameter: To improve performance set explicit type for objects

public function getInvoiceTransactions(Invoice $invoice): ?array
    {
        $query = $this->createQueryBuilder('t');
        $query->where('t.invoice = :invoice')->setParameter('invoice', $invoice);
        return $query->getQuery()->getResult();
    }

but this code does not:

    /**
     * @psalm-param array{
     *   invoice: Invoice
     * } $invoice
     */
    public function getInvoiceTransactions(array $invoice): ?array
    {
        $query = $this->createQueryBuilder('t');
        $query->where('t.invoice = :invoice')->setParameter('invoice', $invoice['invoice']);
        return $query->getQuery()->getResult();
    }

michnovka avatar Jul 22 '22 15:07 michnovka