Autocomple for Objects from Factory


I think this should be a problem for many people (and so I hope, there is a solution.

We have a Factory in our Application. It is used like that:

$order_coo = MainFactory::create_object('Order');

So the $order_coo is an Instance of the Order-Class.

I know, that I can tell PHPStorm (or IntellJ :)) that with using PHPDoc like this:

/** @var Order $order */
= MainFactory::create_object('Order');

But is it possible to tell the Factory, that it will alway return an Object from the Class which is the parameter?

So I don't have to make every call from Manfactory wrap with that PHPDoc /** @var Order....


Comment actions Permalink

Well, that is solution for phpstorm but there is also php plugin for intelij IDEA - so can be that solution used (and if yes then what changes are required) in intelij IDEA


Please sign in to leave a comment.