phpstan-doctrine icon indicating copy to clipboard operation
phpstan-doctrine copied to clipboard

queryBuilderClass: parameter in .neon is not enough when several sub-class of querybuilder

Open allan-simon opened this issue 3 years ago • 2 comments

first thanks for this awesome project and all the time you're putting into it, having DQL validation is just mind blowing.

related to #243 we have in our project several subclass of Querybuilder (for some entities) in order to add helper method in a fluent way

like

use Doctrine\ORM\QueryBuilder;

class AdvancePaymentQueryBuilder extends QueryBuilder
{

    public function forCurrentPayPeriod(Company $company): self
    {
        $this
            ->andWhere('a.payPeriod = :payPeriod')
            ->setParameter('payPeriod', $company->getCurrentPayPeriod()->format('Y-m-d 00:00:00+00'))
        ;

        return $this;
    }
}

and phpstan-doctrine does not recognize them to validate DQL, and as we have several of them, and also we often use the base querybuilder , we can't simply use the queryBuilderClass property in phpstan.neon

allan-simon avatar Jun 02 '22 07:06 allan-simon

If you remove the queryBuilderClass custom setting completely, what kind of errors are you experiencing in your codebase, along with some code samples? Thanks.

ondrejmirtes avatar Jun 02 '22 07:06 ondrejmirtes

@ondrejmirtes actually, i have nothing set right now, sorry if my previous message was ambigous, I was saying that at first I thought it could have helped but not as it is limited to 1 class.

For error messages, I don't have any, which is actually my problem, as it that phpstan is ignoring DQL made with these sub-class, and so does not detect syntax error in the DQL that are normally caught when using the standard query builder.

I will put together a reproducing example tomorrow

allan-simon avatar Jun 06 '22 20:06 allan-simon