Can PHPStorm autocomplete be based on a parameter?

I'm working on a Symfony application and I created a Trait with some short methods to user Doctrine.

 

If I do, I receive the methods in EntityRepository:

$this->getService('doctrine.orm.entity_manager')-getRepository('RocketCommonBundle:Entity')->...;

But, if I do something like this:

 

public function getRepository($entity)
{
return $this->getService('doctrine.orm.entity_manager')-getRepository('RocketCommonBundle:' . ucfirst($entity));
}

$this->getRepository('Entity')->...;


I don't receive any completion... Is there a way of doing this?

Thank's.

 

1 comment
Comment actions Permalink

Hi there,

If you have original completion working then most likely it is provided by Symfony plugin (which uses function parameter ("RocketCommonBundle:Entity" in your case) to provide correct return type dynamically.

By using separate method + splitting the full parameter into parts (only "Entity" gets passed which you then join with common "RocketCommonBundle:" string) you are breaking such analysis capabilities of that plugin. Try passing whole entity id instead of splitting into parts ("RocketCommonBundle:Entity" instead of "Entity") and see if it will do any better.

I guess it could still be possible to have it working via Advanced Meta Data support in PhpStorm (done for frameworks/custom code that have no dedicated plugins like Symfony has) .. but you will have to try it yourself.

Maybe it's till possible to somehow tell Symfony plugin what that method does and what it should return .. but you better ask such question plugin authors directly -- https://github.com/Haehnchen/idea-php-symfony2-plugin

0

Please sign in to leave a comment.