paint-brush
How to Setup a Powerful PhpStorm Configuration to Improve Laravel Developmentby@dkhorev
3,462 reads
3,462 reads

How to Setup a Powerful PhpStorm Configuration to Improve Laravel Development

by Dmitry KhorevSeptember 3rd, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

PhpStorm is WebStorm + PHP so it provides the same utility as WebStorm for JavaScript development. It provides a list of inspections that will validate your code on the fly. It will use a combination of your own preferences + PHP Code Sniffer linter, a config that you can share with the team. It also provides a huge list of static code inspections. It is also possible to find bugs for you way before they even hit a Pull Request. The best tool (“Search Everywhere”) is one of the best tools to navigate your codebase when you do not recall exactly what the class is.
featured image - How to Setup a Powerful PhpStorm Configuration to Improve Laravel Development
Dmitry Khorev HackerNoon profile picture

As software engineers, our job is mainly to think a lot and write code (as little as possible). Writing code can be tedious, especially with Laravel where in many places it relies on pure “magic”, for example, model magic properties and methods, DB builder’s fluent API, and DI for interfaces.


You can’t always rely on your memory of what fields or relations each model at your project has, say 6 months after you finished initial development. Without good insight from your IDE, you’d feel lost in your older classes. So in this article, I want to share how I set up my Laravel projects within the PhpStorm IDE that boost my productivity levels by a lot.


Not only that — having IDE find possible bugs for you way before they even hit a Pull Request is priceless. Having an IDE hint to you where your code can be simplified and/or refactored — is priceless.


By just having the right IDE setup — you can learn and grow, meanwhile producing quality code and software.


What makes PhpStorm your perfect IDE for productivity?

Huge list of static code inspections

It provides a list of inspections that will validate your code on the fly. This is the list of mistakes you are not going to make thanks to a great IDE. Extensible with plugins.


Overview of available inspections for PHP and other tools


Examples of inspections you are going to have

Null pointer inspection


Ternary operator reduction inspection


If/else reduction inspection with two returns


Code auto-format and optimize imports

This is a really powerful tool, it will use a combination of your preferences + PHP Code Sniffer linter, a config that you can share with the team.


Auto-formatting settings


Auto-formatting and optimizing imports in PHP


Node.js development is also not a problem. PhpStorm under the hood is WebStorm + PHP so it provides the same utility as WebStorm for JavaScript development. Prettier or ESLint config is not a problem.


Auto-formatting and optimizing imports Node.js


Best IDE’s navigation tool (“Search Everywhere”)

Double Shift (Shift + Shift) — opens the “Search Everywhere” dialog, and type in the class or file name. Use Alt + Left/Right arrows to switch tabs to “Classes/Files/Symbols’’ to narrow the search. This is one of the best tools to navigate your codebase when you do not recall exactly what the class name is (or when you know exactly and go straight to the expected file).


Search Everywhere tool in action


Configurable common file and method templates


PHP class and test class creation in action


Unit test method creation in action


Laravel model/query integration use cases

Very nice thing to have for bigger projects. Automatic model properties discovery and hints while typing them in various array input/output situations.


Model properties auto-completion in code and in model factories when unit testing


Git integration

Git blame, visual interface for — commit and push, switching branches, merge conflict resolving, etc.


Git integration demo


This concludes the first part of my series for Laravel productivity with PhpStorm. In my next article, I will share the minimum viable local environment setup for Laravel development with PHP, Node.js, MySQL, and Redis.



Also published here.