You have two options here, which depend on each other.
Install PHP_CodeSniffer
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
Configure PhpStorm to use PHP_CodeSniffer
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.
![PHP_CodeSniffer setting]()
Now click on OK.
Enable the Inspections
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.
![Enable PHPCS]()
Conclusion
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.