How to write clean and beautiful code in PhpStorm using SonarLint and Code Sniffer plugins

26 October 2018

In this article, you will learn how to configure PhpStorm to write clean and beautiful code using SonarLint pluginhttps://www.sonarlint.org/ and Code Snifferhttps://github.com/squizlabs/PHP_CodeSniffer

1. SonarLint

Plugin for PhpStorm, which shows duplicate code, unused variables, commented code, sophisticated techniques that need to be optimized, variables that better rename and other "shitcode".

Installing plugin is very simple.

Go to PhpStorm: Preferences -> Plugins -> Browse repositories

And find the plugin SonarLint (see the screenshot below).

Click Install in the right panel, install and reboot PhpStorm.

After reboot, SonarLint tab will appear in the lower left corner.

Next, click on this tab and see what can be improved in the current file.

 

2. Code Sniffer

This is a console tool for monitoring and correcting code for PSR1 and PSR2 standards.

First you need to install PHP CodeSniffer.

The easiest way to simply clone from GitHub.

Link: https://github.com/squizlabs/PHP_CodeSniffer

___

git clone https://github.com/squizlabs/PHP_CodeSniffer.git

cd PHP_CodeSniffer

php bin/phpcs -h

php bin/phpcbf -h

___

If after the command to show something, then everything is OK.

Next connect to PhpStorm.

Step 1.

Go to Preferences -> Languages & Frameworks -> PHP -> CodeSniffer

Choosing path to the file phpcs

and click on Validate​

If message appeared as above, then everything is OK.

Step 2.

Go to Preferences -> Editor -> Inspections -> PHP -> PHP Code Sniffer validation

For php put a tick.

Looking for a Sniffer in search and choose the standard PSR12.

After rebooting PhpStorm will be highlighted and PSR1 PSR2 errors.

That's all.

Two simple plugins to help write clean and beautiful code. Implement!

___

Article by PHP-developer of Digital Agency VIS-A-VIS – Arthur Schablevsky

Did you like the article? - Share the link::