cakephp-ide-helper icon indicating copy to clipboard operation
cakephp-ide-helper copied to clipboard

_joinData typehinting

Open dereuromark opened this issue 6 years ago • 1 comments

Modules <= HABTM pivot table FeaturesModule => Features

PHPStan:

488    Access to an undefined property App\Model\Entity\Module::$_joinData.  

This requires the _joinData pivot property to be annotated for PHPStan to be happy:

 * @property \App\Model\Entity\FeaturesModule $_joinData !
 */
class Module extends Entity
{
    /**
     * @return bool
     */
    public function hasDependencyRelation(): bool
    {
        if (!isset($this->_joinData->relation)) {
            throw new RuntimeException('Missing property ->_joinData->relation for ' . $this->name);
        }

        return in_array($this->_joinData->relation, ..., true);
    }
}

The question is only: What if there are multiple pivot relations. which one is which? Or do we then just typehint the generic Entity?

PS: That would also be the fallback if the pivot entity doesnt exist.

dereuromark avatar Feb 13 '19 01:02 dereuromark

Current workaround would be to have

$article->get('_joinData')->quantity,

but, ideally we can do

$article->_joinData->quantity

by annotating the possible joinData object on the target relation.

dereuromark avatar Mar 26 '24 08:03 dereuromark

See https://github.com/dereuromark/cakephp-ide-helper/pull/350

dereuromark avatar May 26 '24 11:05 dereuromark