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

setHint returning invalid type

Open fliespl opened this issue 1 year ago • 3 comments

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.

fliespl avatar Jul 15 '23 19:07 fliespl

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?

ruudk avatar Nov 30 '23 11:11 ruudk

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-L755

doctrine/orm@212edaa/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?

No idea, @ondrejmirtes certainly know better about such phpdoc interferences

VincentLanglet avatar Nov 30 '23 11:11 VincentLanglet

I think this is no longer an issue, can you confirm?

janedbal avatar Jun 29 '24 11:06 janedbal