New inspections in PhpStorm 2018.2
Every PhpStorm release brings new inspections among other features, and PhpStorm 2018.2 is no exception.
The new inspections will detect extensions that are not listed in composer.json, highlight the non-canonical order of elements in PHPDoc annotations, and warn you when an optional parameter is used in a method declaration before the required one.
Let’s take look at them in more detail.
Missing PHP extensions in composer.json
The new Extension is missing in composer.json inspection will detect the usages of functions, constants, and classes that rely on PHP extensions not currently listed in composer.json.
The best explanation why listing required extensions is a good idea comes from Composer itself:
Now, as soon as an unlisted usage is detected in your code, PhpStorm will display a warning. You can press Alt+Enter and use the Open composer.json in editor intention action to address the issue right away:
Non-canonical order of PHPDoc elements
When adding the @property , @param , or @var tags to a PHPDoc block, a widely accepted standard is to provide the element’s type before its name. While doing the opposite won’t produce an error, keeping docblocks in your code consistent is certainly a good thing.
The new Non-canonical order of elements inspection and the corresponding quick-fix will aid with that. Simply press Alt+Enter and invoke the quick-fix to flip the elements’ order:
Note that the inspection is disabled by default. To enable it, locate it under Preferences | Editor | Inspections | PHP | PHPDoc and select the checkbox next to it.
Using optional parameters before the required ones
A function in PHP can be declared with some of its arguments having default values. When such a function is called, providing these arguments is optional: in this case, their default values are used.
There’s a catch though: you only need to declare such optional arguments after the required ones. Doing the opposite will eventually lead to problems.
PhpStorm 2018.2 includes the new Optional before required parameter inspection, which will highlight such problematic function declarations for you:
One more thing
PhpStorm provides paths completion for functions using file paths as arguments (for example, require or include ). And in situations when such a path cannot be resolved, the Unresolved include inspection has got you covered.
In the previous PhpStorm versions, however, the commonly used $_SERVER[‘DOCUMENT_ROOT’] expression has always resolved to the project root, which in many cases didn’t reflect the actual project structure and resulted in false positive errors. PhpStorm 2018.2 handles this issue: navigate to Preferences | Preferences | Languages & Frameworks | PHP. Then, switch to the Analysis tab and set the document root to any folder of your choice:
Your JetBrains PhpStorm Team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
Qodana Clone Finder: Early Access Program
In December 2020, we announced the EAP for Qodana, which is rapidly evolving into a comprehensive platform that allows companies to perform multi-level evaluations of the quality of code they own, contract, or purchase. Qodana helps you detect bugs without relying on an IDE, either on a local machi…
PhpStorm 2020.2 EAP #3
The Early Access Program for PhpStorm 2020.2 is in full swing and today we’ve got the third build of the 2020.2 EAP for you. In this blog post, you can read about improvements for Git installed in WSL2 and Search Everywhere. Download PhpStorm 2020.2 EAP (more…)…
PhpStorm 2019.3.3 Preview
We’ve just rolled out a preview for the third minor update for PhpStorm 2019.3. Please give the PhpStorm 2019.3.3 Preview build 193.6494.5 a try and share your feedback with us. (more…)…
How to Upgrade to PHP 7.4 with PhpStorm
Check out our fresh video with a few nice tips and tricks on how to update your codebase to PHP 7.4. It combines materials from the PhpStorm 2019.2 and PhpStorm 2019.3 releases, with a few cool bonuses to boot. Nikita drew our attention to the fact that setters are slower than assigning prop…