phpstan-doctrine
phpstan-doctrine copied to clipboard
setHint returning invalid type
I am using doctrine/orm 2.14.1 and even though https://github.com/phpstan/phpstan-doctrine/issues/393 mentions it being fixed I think this was only for setLockMode.
Repro:
->getQuery()
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->getOneOrNullResult(AbstractQuery::HYDRATE_OBJECT);
Dumped type: mixed
While removing setHint I see proper type.
I have the same issue. It's related to setHint
.
In https://github.com/doctrine/orm/pull/10238 they only fix it for setHydrationMode
.
I think because \Doctrine\ORM\Query::setHint
inherits from \Doctrine\ORM\AbstractQuery::setHint. On the parent, it does do @return $this
. But somehow PHPStan doesn't understand the {@inheritDoc}
on the Query.
https://github.com/doctrine/orm/blob/212edaa80bf0669da6ccd7b4697d696e1ffceac8/lib/Doctrine/ORM/Query.php#L747-L755
https://github.com/doctrine/orm/blob/212edaa80bf0669da6ccd7b4697d696e1ffceac8/lib/Doctrine/ORM/AbstractQuery.php#L1023-L1036
When I manually add it to \Doctrine\ORM\Query::setHint
it does work.
@VincentLanglet Do you know what this could be? Should I create a PR for doctrine/orm where we change \Doctrine\ORM\Query::setHint
to this?
/**
* {@inheritDoc}
+ *
+ * @return $this
*/
public function setHint($name, $value): self
{
$this->state = self::STATE_DIRTY;
return parent::setHint($name, $value);
}
Or is there some interference somewhere else? Maybe a stub inside this repository?
I think because
\Doctrine\ORM\Query::setHint
inherits from \Doctrine\ORM\AbstractQuery::setHint. On the parent, it does do@return $this
. But somehow PHPStan doesn't understand the{@inheritDoc}
on the Query.doctrine/orm@
212edaa
/lib/Doctrine/ORM/Query.php#L747-L755doctrine/orm@
212edaa
/lib/Doctrine/ORM/AbstractQuery.php#L1023-L1036When I manually add it to
\Doctrine\ORM\Query::setHint
it does work.@VincentLanglet Do you know what this could be? Should I create a PR for doctrine/orm where we change
\Doctrine\ORM\Query::setHint
to this?
No idea, @ondrejmirtes certainly know better about such phpdoc interferences
I think this is no longer an issue, can you confirm?