phpstan / phpstan-nette

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

Call to undefined method when using Nette Events #29

Open Lukeluha opened 5 years ago

Lukeluha commented 5 years ago

I am trying to use phpstan with nette and I have a problem with not recognizing Nette Events (even if this should be supported according to README).

My code looks like this:

trait CommonTrait
{
    use SmartObject;

    /** @var array  */
    public $onUpdate = [];
...
        public function insert($data) {
                ...
                $this->onUpdate($data);
        }

But after running PHP stan with Nette extension I am getting these errors: Call to an undefined method App\Model\Db\Languages::onUpdate() And it is the same with other classes using this trait.

I am using Nette 2.4 and the latest PHPStan shim and I have tried that the Nette extension loads correctly.

ondrejmirtes commented 5 years ago

This should work, but I'm not sure if it works with traits correctly. Feel free to debug the issue. The class responsible for this is: https://github.com/phpstan/phpstan-nette/blob/master/src/Reflection/Nette/NetteObjectClassReflectionExtension.php