Issue Bug Closed

#96507PHPStan issue with QueryBuilder annotations

Elias Häußler 01/11/22, 11:50 updated 10/04/22, 14:14

Description

The change in #96457 causes problems with PHPStan after updating to 11.5.5.

Given this code:

$qb = $this->connection->createQueryBuilder();
$result = $qb
    // ...
    ->where(
        // returns string
        $qb->expr()->eq('CType', $qb->createNamedParameter($someVariable)
    )
    ->execute()
;

we now get an error

> Parameter #1 …$predicates of method TYPO3\CMS\Core\Database\Query\QueryBuilder::where() expects array<int mixed>|Doctrine\DBAL\Query\Expression\CompositeExpression, string given.</int>

because |CompositeExpression was added. I made a short comparison:

A possible solution would be to

  1. either move the |CompositeExpression to the existing array: https://phpstan.org/r/3f42d413-f44d-4b4e-b82a-57a231a7f69e or
  2. resolve the array: https://phpstan.org/r/915d50c1-6bb8-48be-88f7-21b147049acd

PHPStan documents the usage of variadic arguments in https://phpstan.org/writing-php-code/phpdocs-basics#variadic-functions

Reviews 3