You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'm running PHPStan on our Craft CMS project. One of the issues I ran into is the following:
Call to an undefined method craft\queue\QueueInterface::push().
This is the result of Craft::$app->getQueue()->push()-calls.
So, PHPStan follows Craft::$app->getQueue() and sees in the PHPDoc that a union type is declared: @return Queue|QueueInterface The queue service. This means that getQueue() can return either a craft\queue\Queue instance or a implementation of craft\queue\QueueInterface. The latter does not define a push() method, which is why PHPStan throws this error.
I can solve this in my code by using inline PHPDoc to mark the exact type, but then I would have to do this all over my code. I can also create a stub file I think to override the PHPDoc only for PHPStan.
But perhaps Craft CMS itself could be updated? Either by adding to the interface methods that would be presumed to exist always (push() would make sense always I think, how else to queue something?) or change the PHPDocs to an intersection type - Queue&QueueInterface. This would indicate that this method returns an instance that is both types. I think the first suggestion would actually make most sense?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi, I'm running PHPStan on our Craft CMS project. One of the issues I ran into is the following:
Call to an undefined method craft\queue\QueueInterface::push().
This is the result of
Craft::$app->getQueue()->push()
-calls.So, PHPStan follows
Craft::$app->getQueue()
and sees in the PHPDoc that a union type is declared:@return Queue|QueueInterface The queue service
. This means thatgetQueue()
can return either acraft\queue\Queue
instance or a implementation ofcraft\queue\QueueInterface
. The latter does not define apush()
method, which is why PHPStan throws this error.I can solve this in my code by using inline PHPDoc to mark the exact type, but then I would have to do this all over my code. I can also create a stub file I think to override the PHPDoc only for PHPStan.
But perhaps Craft CMS itself could be updated? Either by adding to the interface methods that would be presumed to exist always (
push()
would make sense always I think, how else to queue something?) or change the PHPDocs to an intersection type - Queue&QueueInterface. This would indicate that this method returns an instance that is both types. I think the first suggestion would actually make most sense?Thoughts on this?
Beta Was this translation helpful? Give feedback.
All reactions