Phpstorm configure phpcs to enable psr12

Time:2020-9-15

####Note: the configuration item is divided into two steps. Only one type can be configured without affecting the use. After the first step of configuration, you can use the phpstorm shortcut key to format the file, and the second step will prompt that the code does not conform to the specification

1. Set photostorm code style

Open phpstrom settings, editor > code style > PHP, set from in the upper right corner, and select psr12, as shown in Figure 1

You can choose not to configure this option. After configuration, you can directly use the phpstorm shortcut key to format the file

Figure 1

Phpstorm configure phpcs to enable psr12

2. Configure phpcs

  1. Pull PHP_ Codesniffer project

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

  2. Configure PHP quality tools

    See Figure 2 and figure 3 for details

    PHP_ Codesniffer path is the phpcs file in bin directory of clone project in step 1

    Path to phpcbf is the phpcbf file in the bin directory of the clone project in the first step

    Figure 2

Phpstorm configure phpcs to enable psr12

Figure 3

Phpstorm configure phpcs to enable psr12

  1. After the configuration is successful, the following four prompts will appear. Click to jump directly, or you can find editor > inspections > PHP > quality tools according to figure 5 and check PHP_ Code buffer validation, and select PSR 12 as the coding standard on the right

    Figure 4

Phpstorm configure phpcs to enable psr12

Figure 5

Phpstorm configure phpcs to enable psr12


laradock