Skip to content

Commit 8bc39ac

Browse files
authored
Upgrade ruleset.xml to PSR12 (#47)
1 parent c30d6e2 commit 8bc39ac

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ PHP_Codesniffer
3838

3939
[PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) coding standard, rule set
4040
and sniff token parsing classes for the [Yii 2 Web Framework](https://github.com/yiisoft/yii2/). Overally rules
41-
are based on PSR-2 standard with some minor exceptions and changes. Rules derived from PSR-2 standard and excluded
41+
are based on PSR-12 standard with some minor exceptions and changes. Rules derived from PSR-12 standard and excluded
4242
in Yii2 standard were implemented (or planned to be) as sniff classes.
4343

4444
Rules could also be used for checking code style of an existing Yii2 applications.
@@ -54,6 +54,30 @@ After CodeSniffer is installed you can launch it with custom code style using th
5454
$ ./vendor/bin/phpcs --extensions=php --standard=Yii2 /home/resurtm/work/Yii2MegaApp/
5555
```
5656

57+
Installation can be also be done automatically with this tool:
58+
59+
```bash
60+
composer require --dev dealerdirect/phpcodesniffer-composer-installer
61+
```
62+
63+
When using Composer 2.2 or higher, Composer will [ask for your permission](https://blog.packagist.com/composer-2-2/#more-secure-plugin-execution) to allow this plugin to execute code. For this plugin to be functional, permission needs to be granted.
64+
65+
When permission has been granted, the following snippet will automatically be added to your `composer.json` file by Composer:
66+
```json
67+
{
68+
"config": {
69+
"allow-plugins": {
70+
"dealerdirect/phpcodesniffer-composer-installer": true
71+
}
72+
}
73+
}
74+
```
75+
76+
When using Composer < 2.2, you can add the permission flag ahead of the upgrade to Composer 2.2, by running:
77+
```bash
78+
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
79+
```
80+
5781
If you're using PhpStorm you can configure it to use CodeSniffer using Settings → PHP → Code Sniffer.
5882
Yii2 code style can be specified at Inspections → PHP → PHP Code Sniffer validation.
5983

@@ -66,7 +90,7 @@ Yii2 code style can be specified at Inspections → PHP → PHP Code Sniffer val
6690
PhpStorm
6791
--------
6892

69-
Yii uses PSR-1 and PSR-2 as code style standards. You can choose these via `Settings``Code Style``PHP``Set from...``Predefined Style``PSR1/PSR2`.
93+
Yii uses PSR-12 as code style standard. You can choose these via `Settings``Code Style``PHP``Set from...``Predefined Style``PSR12`.
7094

7195
ADDITIONAL NOTES
7296
----------------

Yii2/ruleset.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ruleset name="Yii2">
33
<description>Yii 2 Web Application Framework Coding Standard</description>
44

5-
<rule ref="PSR2">
5+
<rule ref="PSR12">
66
<!-- Property names MUST start with an initial underscore if they are private. -->
77
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
88

@@ -18,6 +18,12 @@
1818
<exclude name="PSR2.ControlStructures.SwitchDeclaration"/>
1919
</rule>
2020

21+
<!-- display progress -->
22+
<arg value="p"/>
23+
<!-- Show error codes -->
24+
<arg value="s"/>
25+
<arg name="colors"/>
26+
2127
<!-- Property declaration rules. -->
2228
<!-- TODO: -->
2329

0 commit comments

Comments
 (0)