cakephp-ide-helper
cakephp-ide-helper copied to clipboard
_joinData typehinting
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.
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.
See https://github.com/dereuromark/cakephp-ide-helper/pull/350