phpstan / phpstan-nette

Nette Framework class reflection extension for PHPStan & framework-specific rules
MIT License
100 stars 35 forks source link

Component type is not tracked when hyphen notation is used #147

Open mabar opened 2 months ago

mabar commented 2 months ago

Sub-components accessed via hyphen notation are treated as mixed

$this['document']['head'];
$this['document-head'];
$this->getComponent('document')->getComponent('head');
$this->getComponent('document-head');

Current result

  1     Dumped type: HeadControl
  2     Dumped type: mixed~null
  3     Dumped type: HeadControl
  4     Dumped type: mixed~null

Expected result:

All should return HeadControl. Or report that this syntax is not supported. Which variant would you prefer?

ondrejmirtes commented 2 months ago

The hyphen syntax should be easy to add. When this syntax is encountered, the extension could ask for type of getComponent('document')->getComponent('head'); internally.