The PSR specification is a good thing

Team development conventions use the PSR-2 coding style specification, but not everyone commits code strictly to PSR-2

The biggest reason is the oral binding is very limited, but team of editors don’t you use the unified, use Php Storm (https://www.oschina.net/p/php), there are also using VS Code, etc., and various editor has its own formatting rules, So uniform code style is a problem

In the previous article, PHPCBF scripts were used to automatically correct the code format. Very few developers develop their code solely on the terminal, usually using an editor. This article introduce in PhpStorm integrated PHP CBF (https://www.oschina.net/p/php), PHP (https://www.oschina.net/p/php) cs

Make the editor use the PSR-2 standard

1, open [Php] (https://www.oschina.net/p/php) Storm Settings page (File – > Setting or Ctrl + Alt + s). To page Code Style (PHP) choose the Style of PSR1/2 (https://www.oschina.net/p/php)

2, to page Code sniffers, path is Setting – > Languages and Frameworks – > (PHP) (https://www.oschina.net/p/php) – > Code sniffers, Set (PHP) (https://www.oschina.net/p/php) the path of the cs

Go to the conforms page, path Setting->Editor-> CONFORMS, PHP on the right, check the following two PHP, and select PSR2

I have another one down here, and I want to select it

Now use (Php) (https://www.oschina.net/p/php) Storm formatting, will automatically be formatted into PSR – 2 style

After the above operations, Php (https://www.oschina.net/p/php) Storm code formatting rules and basic (Php) (https://www.oschina.net/p/php), the rules of the cs are basically identical, But there are also a small number of inconsistencies, so later in use (PHP) (https://www.oschina.net/p/php) cs and PHP CBF (https://www.oschina.net/p/php)

If it takes a lot of time to execute at the terminal every time, in order to improve work efficiency, Can be in (Php) (https://www.oschina.net/p/php) Storm integration PHP CBF (https://www.oschina.net/p/php), (PHP) (https://www.oschina.net/p/php) the function of the cs test specification

Set path: Tools -> External Tools

Integrated PHPCS

Integrated PHPCBF

Program is a file in your PHP root directory, Windows is a.bat file

Arguments $FileDir$/$FileName$

Working directory is $ProjectFileDir$

The following Open the console for tool output refers to the information to the console, printing detection (PHP) (https://www.oschina.net/p/php), we’re going to see cs detection CBF/PHP (https://www.oschina.net/p/php) doesn’t have to, so you don’t have to check

How do you use it?

Tools->External Tools to see the two widgets we just added, directly click to use

Buy me a cup of coffee 🙂