I have a project long time developed in PhpStorm and fully compatible with php 5.6. In any case it work and deployed on server with php 5.6.
How to inspect with PhpStorm 2018 this whole project to php 7.2 compatibility and only highlight those places where php code incompatible with 7.2 only?
You can set the language level for your project on the PHP page of the Settings/Preferences dialog ( Ctrl+Alt+S ).
Install the PHP version you want to test and run php -l file. php to test if the file passes the lint check. If PHP is unable to parse the file, it will tell you. In general, you should be aware of which features became available in which version.
With PhpStorm, you can develop applications in PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, PHP 7, PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0, and PHP 8.1. This topic outlines the coding assistance features available for each language version. You can set the language level for your project on the PHP page of the Settings/Preferences dialog ( Ctrl+Alt+S ).
For the complete list of code inspections available in PhpStorm, refer to Code inspection index. In the Settings/Preferences dialog ( Ctrl+Alt+S) , go to Editor | Inspections. You can also press Ctrl+Alt+Shift+H and select Configure Inspections in the popup that opens. Use to filter the inspections list.
If you’re looking for a “one-click” compatibility check, the PhpStorm IDE is your best option. 2. The PHP 7 Migration Assistant Report (MAR) The second easiest solution is the GitHub project called PHP 7 MAR. It’s a simple PHP project. Once you download it, you can use your own PHP environment to check any file or folder containing PHP.
Although the language version of each interpreter is detected automatically, you can still tell PhpStorm to provide you with coding assistance that corresponds to a different language level. However, if you attempt to use a code construct that is not supported by the specified language level, PhpStorm suggests a Switch to PHP <version> quick-fix.
You have two options here, which depend on each other.
To check your project for 7.2 compatibility I recommend the PHP CodeSniffer. This is a little yet powerful command line program which statically checks your code against predefined coding standards.
Install it via Composer from within your the root level of your project:
$ composer require --dev squizlabs/php_codesniffer
You can also install it globally or as a Phar. Please consult the documentation for alternate installation methods.
Once installed, you can call it via:
$ vendor/bin/phpcs --version
// This outputs you the version
As mentioned above, PHPCS comes with ready to use coding standards. Use
$ vendor/bin/phpcs -i
to list them.
To check if your code is PSR-2 compatible run:
$ vendor/bin/phpcs --standard=PSR2 .
As you like to check your project for PHP 7.2 compatibility, you have to install this standard: https://github.com/PHPCompatibility/PHPCompatibility
$ composer require --dev phpcompatibility/php-compatibility
Now register the standard in PHPCS. Open your composer.json
and add this lines to the scripts
section:
"scripts": {
"post-install-cmd": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility",
"post-update-cmd" : "\"vendor/bin/phpcs\" --config-set installed_paths vendor/phpcompatibility/php-compatibility"
}
This will take care if you install/update your dependencies. To register the standard right now, you have to call the script manually:
$ composer run-script post-install-cmd
To check if the new standard is successfully installed run:
$ vendor/bin/phpcs -i
Now you are able to run the check from the cli:
$ vendor/bin/phpcs -p . --standard=PHPCompatibility
As you already have configured the PHP Interpreter in PhpStorm, open your Preferences and to to PHP | Quality Tools | CodeSniffer. Click on the ...
and type the path to your PHP_CodeSniffer installation. In our case vendor/bin/phpcs
and hit Validate. It shows an tooltip with the current version.
Now click on OK.
Inside the Preferences go to Editor | Inspections | PHP | Quality tools. Enable the PHP Code Sniffer validation
checkbox. Then to the right you find the settings page. You have to select the PHPCompatibility
standard from the select field and hit the reload button next to the select. Once done, click OK
.
You should now see the errors inside the editor underlined. The severity and the color can be set in the configuration pane we just closed.
Now you have two ways to check your projects code. The CLI-way gives you a better overall overview about the state of your code where the IDE-way can help you while coding to be aware of not using old language constructs.
Enjoy :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With