Skip to content

Commit

Permalink
Upgrade ruleset.xml to PSR12 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
razvanphp authored Mar 15, 2024
1 parent c30d6e2 commit 8bc39ac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PHP_Codesniffer

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

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

Installation can be also be done automatically with this tool:

```bash
composer require --dev dealerdirect/phpcodesniffer-composer-installer
```

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.

When permission has been granted, the following snippet will automatically be added to your `composer.json` file by Composer:
```json
{
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
```

When using Composer < 2.2, you can add the permission flag ahead of the upgrade to Composer 2.2, by running:
```bash
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
```

If you're using PhpStorm you can configure it to use CodeSniffer using Settings → PHP → Code Sniffer.
Yii2 code style can be specified at Inspections → PHP → PHP Code Sniffer validation.

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

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`.
Yii uses PSR-12 as code style standard. You can choose these via `Settings``Code Style``PHP``Set from...``Predefined Style``PSR12`.

ADDITIONAL NOTES
----------------
Expand Down
8 changes: 7 additions & 1 deletion Yii2/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ruleset name="Yii2">
<description>Yii 2 Web Application Framework Coding Standard</description>

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

Expand All @@ -18,6 +18,12 @@
<exclude name="PSR2.ControlStructures.SwitchDeclaration"/>
</rule>

<!-- display progress -->
<arg value="p"/>
<!-- Show error codes -->
<arg value="s"/>
<arg name="colors"/>

<!-- Property declaration rules. -->
<!-- TODO: -->

Expand Down

0 comments on commit 8bc39ac

Please sign in to comment.