8 Ways PHPStorm Can Improve Drupal Development

December 18
blog author

Appno Blogger

Appnovation Coop

Although being a software developer has always been what I wanted to do and where I wanted to be in life, my route to my current position hasn't been a direct one. They say "do what you love and you'll succeed" and that's the best advice I've ever taken. Along the road I have worn different hats and one of them was being a machinist apprentice. Although I did enjoy the work, living with metal and carbon dust didn't really appeal to me. One thing I've taken away from that experience is the importance of tools. When you're working with precision measurements that require accuracies of within a thousandth of an inch, the precision and effectiveness of your tools makes all the difference in getting good results. Although the end result always depends on the skill of the wielder, good tools can help elevate quality of work as well as reduce errors and time spent on tasks.
 
I was first introduced to PHPStorm in it's Java incarnation, IntelliJ. I found it to be very helpful when coding Java, in particular its code completion, code analysis, and easy to use refactoring. It also had powerful version control integration that allowed you to manage your versioning within the IDE. IntelliJ also makes it easy to setup and run tests. When I moved back from Java to Drupal development, I was saddened to have to lose this great tool. When I learned of PHPStorm, which is basically IntelliJ configured with PHP flavour, I was elated. PHPStorm allowed me to retain all the functionality I had gotten used to with IntelliJ in my PHP development. I was even more impressed when I learned that PHPStorm now has Drupal and Drush integration.
 
Version control integration
When I was introduced to git, it was refreshing to deal with a version control system that was so lightweight and flexible. Git allows you to concentrate on development instead of worrying about how to integrate your changes back into the main repository. Git's power lay in its easily created and easily merged branches. No longer do you have to worry about your changes causing conflicts with another developer's changes. Although conflicts can still occur, they are much less frequent and much more easily resolved. PHPStorm gives you even more power to manage your changes and to see where they occur, and what the changes are. You have the power to revert changes before committing, by file, by section of code, and by line.
When you do have conflicts, PHPStorm allows you to view the changes from both sides of the conflict. You can select your version or the other version or you can merge both versions. Where PHPStorm differs is that you can do this selectively within the individual files and lines of code. For each section you can select your version, the other conflicted version, both versions, or remove both changes. This is a very powerful tool and can save you a lot of headache.
 
1) Easily resolve conflicts (local changes on left, remote changes on the right, and merge result in the middle)
 
 
 
2) Identify new and modified code
 
 
3) Selectively revert changes by file and by line
     a) by file
 
 
     b) by line
 
 -
Code completion
PHPStorm also has code completion, which is very handy if you are looking for a function that you can't remember the name of, as well as saving you some time typing. Entering the first few letters of the function will cause PHPStorm to show you a list of functions that match the letters you have typed. Can't remember the function name?  No problem, just type what you remember and PHPStorm will come up with a list of suggestions. For example if you are looking for the form_set_value function, it will find it even if you enter partial values for the function. Here we type "forsetva" and that finds the function we were looking for as well as suggesting other functions matching the same criteria. This is very helpful when you are looking for functions and can't remember or don't know the exact name.   
 
4) Finding functions using partially typed function names
 
 
Hook awareness
Drupal has many hooks and although it's possible to remember the main ones it's unlikely that you would have them all memorized.  PHPStorm lets you know if you are looking at a function that implements a hook (this functionality is available only in *.module files). Mousing over the h symbol in the gutter will give you information about the hook, and clicking it will take to you to the hook function being implemented.
 
5) Labelling hooks and being able to go to the definition of implemented hooks
drupal hook awareness
 
 
Debugging
PHPStorm allows you to debug your code. You can set up debugging by configuring a debugging engine such as XDebug to allow you to set breakpoints and step through your code. You can set it to start at your first breakpoint or you can have it break at the first line of code. This makes it possible for you to got through the entire execution of code for each request you make. You're able to see not only the final values of your variables, as dpm() will show you ( dsm() is a legacy function and is now a wrapper function for dpm() ), you now can see the variables as they change from line to line of your code.  This is very handy for finding out where, how, and why a variable is changing. In a framework such as drupal where there can be many modules changing the same value, it helps to be able to see what is going on at the code level.  You are also able to view the stack and see how we have arrived at a specific line in the code, as well as seeing the variable for each level of the stack, and the function that is calling the next level of the stack. 
 
6) Breakpoints
breakpoints
 
 
 
7) Inspect variables
inspecting drupal variables at breakpoints
 
 
 
8) Being able to view the stack
view the drupal stack at a breakpoint
 
 
Although knowledge and experience are the keys to success as Drupal developers, we can use tools to make our experience easier and more productive. PHPStorm is one of the tools that I find useful and makes working with drupal more enjoyable. I hope you find it useful too.