psalm-plugin-symfony
psalm-plugin-symfony copied to clipboard
not getting QueryBuilderSetParameter exception when using complex psalm-param
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();
}