PhpStorm & Symfony project, can someone help me get started?


I recently started working on a Symfony2 project and I'm now evaluating PhpStorm. So far I really like it but I have an issue with the code warnings. Basically it doesn't seem to recognize a lot of the project's functions and a few of the native Symfony functions. I'm not sure where the problem is, maybe someone can help me get going.

The basics: It's a remote project that was already created and worked on for a while. Most of the classes/controllers/whathaveyou where crud generated and then adapted. I imported the project including the vendors dir, I only excluded cache, logs and web/js, web/css and web/images.

I've set up PhpStorm to work with Symfony2, I basically followed this tutorial

Edit: Ok, strange, for some reason, it suddenly does recognize the find statement, so never mind that. What doesn't work is my own declared repository methods, or the methods of relationships.

Repository function:

     * @param string $field
     * @param string $direction
     * @return array
    public function getCoursesSortedBy($field = null, $direction = null)
          $qb = $this->getCoursesSortedByQuery($field, $direction);
          $query  = $qb->getQuery();
          return $query->getResult();

In controller:

        $entities = $em->getRepository('VbitsVCoursesCoreBundle:Course')->getCoursesSortedBy(
        $request->query->get('sort',''), /* sort field */

Here, getCoursesSortedBy gives a method not found warning. The repository is declared properly in the Course entity class, and the function works fine.

One of the problems is certain Symfony2 functions, for example, it doesn't recognize 'find' in this statement:

        $entity = $em->getRepository('MyBundle:Course')->find($id);

I tried it so that the method isn't 'nested', but that doesn't make a difference:

        $course = $em->getRepository('MyBundle:Course');
        $entity = $course->find($id);

It also doesn't recognize any of the entity functions that are defined. Most of those where crud generated and properly commented.

This might have something to do with the first problem actually, because the entity variable is defined by a method it doesn't recognize, it makes sense it doesn't recognize the entity's methods either.

Another issue is found in the entities, first of all it says "Undefined class \User" (or any of the other entities) whenever a relationship is declared, for example:

     * @var \User
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="responsible_user_id", referencedColumnName="id")
     * })
    private $responsibleUser;

Later on in the entity class there are errors when a relationship's method are used, for example

          return $this->location->getCode() . ' ' . $this->code;

I'm probably missing something here, but I'm new to both Symfony2 and PhpStorm so if someone could point me in the right direction to fix these things, that would be great.

Message was edited by: Karin van den Berg

Comment actions Permalink

Hi there,

With all these edits I'm no longer sure what works and what does not.

Any way -- here are my guesses/ideas:

#1 (getRepositry)


There is currently no way for PhpStorm to tell for sure what getRepository('sometext') will return -- just because return type will be different based on actual parameter text. The ticket to watch after : (and maybe )

The current workaround: you need to use PHPDoc via intermediate variable to tell exact type of that variable, something like this:

/** @var \MyBundle\Course $course */
$course = $em->getRepository('MyBundle:Course');$entity = $course->find($id);

#2 (entities)
PhpStorm currently does not support Doctrine and Symfony annotations:

General Symfony framework support ticket:

Comment actions Permalink

Thanks so much, sorry for being unclear.

Thanks to your explanation I have managed to fix the relationships, instead of

     * @var \User

I now have

     * @var \MyBundle\Entity\User

Which also fixes the problem of the related entities' methods not being identified.

And managed to get the repository functions working like this:

/** @var \MyBundle\Repository\CourseRepository $courseRepos  */
$courseRepos = $em->getRepository('MyBundle:Course');
        $entities = $courseRepos->getCoursesSortedBy(

Comment actions Permalink

Hmm, there is something strange going on though.

The recognition of the standard symfony repository methods seems to go in and out. For a while they work fine, then all of a sudden the warnings reappear. I tested it, if I manually type out

$em = $this->getDoctrine()->getManager();

And wait for it to find those methods, it seems to 'find' the repository methods again, and the warnings for ->find(), findAll-> and so on dissappear, but later they might re-emerge.

Comment actions Permalink

I'm not working with Symfony myself, so cannot add any personal experience comments, I'm afraid.

Anyway, pleas tell:

  1. What version of PhpStorm do you use exactly  and what OS (Help | About) ?
  2. Where your project files are located (local HDD/SSD or network drive) ?
  3. Same question about your profile / home folder -- is it local or roaming ?
Comment actions Permalink

My PhpStorm version is 5.0.4 build PS-121.390

The project files are on a local SSD drive but it is a remote project (all the files are in C:\User\Myusername\PhpstormProjects\Myprojectname, the project is deployed on a remote development server and PhpStorm is set to upload changed files -> Always)

My profile folder is local, not roaming.

Comment actions Permalink

So files are local and drive is fast.

My only other suggestion then is to try upcoming v6 -- it may have better experience there.

You can get Preview version from this page:

Since config files are stored in separate folders, you can run both versions next to each other (on first run it will offer to import your settings from v5 -- you may just reinstall any custom plugins). Just backup your project settings (.idea subfolder) in case you want to go back to v5 later.

If you have Antivirus/non-stop-backup running, you may want to exclude such config/cache/project files from it -- that's in case if there is latency/delay issues with accessing those files.

Comment actions Permalink

Thanks for your reply.

I've found the issue is reproducible by closing PhpStorm and opening it again, it shows the Controller class file and will show the warnings for find, findAll, etc until I remove and replace the 'r' in getManager, then the warnings dissappear.

I tried excluding the project dir from my antivirus but the problem remains, and I also installed the EAP 6 version, exact same behavior I'm afraid...

I'll try and see if anything else might help, like turning off the antivirus briefly. However it is so consistent (when closing & reopening PhpStorm) that I'm not sure if latency is the problem here.

Comment actions Permalink

Did some more testing, a little more info

An example of the concerning lines

     $em = $this->getDoctrine()->getManager();

     $entity = $em->getRepository('MyBundle:Course')->find($id);

It's the 'find' function in this case that causes the warning.

- Same behavior in v5 and (EAP) v6
- Closing and reopening PhpStorm makes the problem recur (and sometimes when reopening files after a while).
- Replacing the 'r' in getManager makes all the warnings dissappear, in all (open) files
- Problem exists in files that were still open and when I open files after restarting

There must be something about the way it scans for the methods when starting up that isn't working quite right in this case. It only happens for the methods of the ObjectRepository interface in Doctrine/Common/Persistence, everything else works just fine.

Editted to add: When Doctrine/Common/Persistence/AbstractManager.php is loaded/open when starting PhpStorm (i.e. left it open while closing the program), the warnings do not appear.
This is where getManager and getRepository are declared.

I also tried adding an extra include path for just the Persistence dir (even though the files would already be included), just in case that made a difference but it didn't.

It would be great if this can be solved of course, for now the workaround is to leave that file open, I've pinned the tab, hopefully that will make it stay there.


Please sign in to leave a comment.