|
1 |
| -# Brianvarskonst CodeSniffer Ruleset |
| 1 | +# Brianvarskonst Coding Standard |
2 | 2 |
|
3 | 3 | Provides a PHP CodeSniffer ruleset for the Brianvarskonst coding standard
|
4 | 4 |
|
5 | 5 | [](https://github.com/brianvarskonst/coding-standard/actions)
|
6 | 6 |
|
7 |
| -[](https://packagist.org/packages/brianvarskonst/coding-standard) |
8 |
| -[](https://packagist.org/packages/brianvarskonst/coding-standard) |
9 |
| -[](https://packagist.org/packages/brianvarskonst/coding-standard) |
10 |
| -[](https://packagist.org/packages/brianvarskonst/coding-standard) |
| 7 | +[](https://packagist.org/packages/brianvarskonst/coding-standard)[](https://packagist.org/packages/brianvarskonst/coding-standard) |
| 8 | +[](https://packagist.org/packages/brianvarskonst/coding-standard) |
| 9 | +[](https://packagist.org/packages/brianvarskonst/coding-standard) |
11 | 10 |
|
12 |
| -[](https://github.com/brianvarskonst/coding-standard/actions?query=workflow%3ABuild+branch%3Amain) |
| 11 | +[](https://packagist.org/packages/brianvarskonst/coding-standard) |
13 | 12 | 
|
| 13 | +[](https://packagist.org/packages/brianvarskonst/coding-standard) |
14 | 14 |
|
15 |
| -[](https://packagist.org/packages/brianvarskonst/coding-standard) |
16 |
| - |
| 15 | +[](https://packagist.org/packages/brianvarskonst/coding-standard) |
17 | 16 |
|
18 | 17 | ## Overview
|
19 | 18 |
|
20 | 19 | The Brianvarskonst Coding Standard is an extension of the [Symfony Coding Standard](http://symfony.com/doc/current/contributing/code/standards.html) and adds specific rules for ensuring code quality and consistency.
|
21 | 20 |
|
| 21 | +> PHP 8.0+ coding standard |
| 22 | +
|
22 | 23 | ## Rules
|
23 | 24 |
|
24 | 25 | ### Brianvarskonst.Array.ArrayDoubleArrowAlignment
|
@@ -267,13 +268,40 @@ E.g. by excluding `Brianvarskonst\ExcludeThis` things like `Brianvarskonst\Exclu
|
267 | 268 | To make sure what's excluded is a namespace, and not a class with same name, just use `\` as last
|
268 | 269 | character.
|
269 | 270 |
|
| 271 | +### Included rules |
270 | 272 |
|
271 |
| -### Additional Rules |
272 |
| - |
273 |
| -Further rules are imported from other standards, detailed in `Brianvarskonst/ruleset.xml`. |
| 273 | +Further rules are imported from other standards, detailed in [`ruleset.xml`](Brianvarskonst/ruleset.xml). |
274 | 274 |
|
275 | 275 | Most of the issues can be auto-fixed with `phpcbf`.
|
276 | 276 |
|
| 277 | +#### PSR-1, PSR-2, PSR-12 |
| 278 | + |
| 279 | +For more information about included rules from PHP Standards Recommendations (PSR), refer to the |
| 280 | +official documentation: |
| 281 | + |
| 282 | +- [PSR-1](https://www.php-fig.org/psr/psr-1) |
| 283 | +- [PSR-2](https://www.php-fig.org/psr/psr-2) |
| 284 | +- [PSR-12](https://www.php-fig.org/psr/psr-12) |
| 285 | + |
| 286 | +#### Slevomat |
| 287 | + |
| 288 | +A few rules have been included from the [Slevomat Coding Standard](https://github.com/slevomat/coding-standard). |
| 289 | + |
| 290 | +#### Symfony |
| 291 | + |
| 292 | +A few rules have been included from the [Symfony Coding Standard](https://github.com/djoos/Symfony-coding-standard). |
| 293 | + |
| 294 | +#### PHPCompatibility |
| 295 | + |
| 296 | +For PHP cross-version compatibility checks, the full [PHP Compatibility Coding Standard for PHP CodeSniffer](https://github.com/PHPCompatibility/PHPCompatibility) |
| 297 | +standard has been included. |
| 298 | + |
| 299 | +The target PHP version (range) can be changed via a [custom `phpcs.xml` file](https://github.com/PHPCompatibility/PHPCompatibility/blob/9.3.5/README.md#using-a-custom-ruleset). |
| 300 | + |
| 301 | +#### Generic Rules |
| 302 | + |
| 303 | +Some rules are also included from PHP_CodeSniffer itself, as well as [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra). |
| 304 | + |
277 | 305 | ## Requirements
|
278 | 306 |
|
279 | 307 | * [PHP](http://php.net)
|
@@ -340,6 +368,89 @@ $ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst
|
340 | 368 | If `phpcs` complains that `Brianvarskonst` coding standard is not installed, please check the installed coding standards with
|
341 | 369 | `phpcs -i` and that `installed_paths` is set correctly with `phpcs --config-show`
|
342 | 370 |
|
| 371 | +Certainly! Here is the professionalized section with markdown syntax for easy copying: |
| 372 | + |
| 373 | +--- |
| 374 | + |
| 375 | +## Removing or Disabling Rules |
| 376 | + |
| 377 | +### Rules Tree |
| 378 | + |
| 379 | +Sometimes it is necessary to not follow certain rules. To avoid error reporting, you can: |
| 380 | + |
| 381 | +- Remove rules for an entire project via configuration. |
| 382 | +- Disable rules from code, only in specific places. |
| 383 | + |
| 384 | +In both cases, it is possible to remove or disable: |
| 385 | + |
| 386 | +- A complete standard |
| 387 | +- A standard subset |
| 388 | +- A single sniff |
| 389 | +- A single rule |
| 390 | + |
| 391 | +These elements are in a hierarchical relationship: `standards` consist of one or more `subsets`, |
| 392 | +which contain one or more `sniffs`, which in turn contain one or more `rules`. |
| 393 | + |
| 394 | +### Removing Rules via Configuration File |
| 395 | + |
| 396 | +Rules can be removed for the entire project by using a custom `phpcs.xml` file, like this: |
| 397 | + |
| 398 | +```xml |
| 399 | +<?xml version="1.0"?> |
| 400 | +<ruleset name="MyProjectCodingStandard"> |
| 401 | + |
| 402 | + <rule ref="Brianvarskonst"> |
| 403 | + <exclude name="PSR1.Classes.ClassDeclaration"/> |
| 404 | + </rule> |
| 405 | + |
| 406 | +</ruleset> |
| 407 | +``` |
| 408 | + |
| 409 | +In the example above, the `PSR1.Classes.ClassDeclaration` sniff (and all the rules it contains) has been removed. |
| 410 | + |
| 411 | +By using `PSR1` instead of `PSR1.Classes.ClassDeclaration`, you would remove the entire `PSR1` standard. Whereas using `PSR1.Classes.ClassDeclaration.MultipleClasses` would remove this one rule only, without affecting other rules in the `PSR1.Classes.ClassDeclaration` sniff. |
| 412 | + |
| 413 | +### Removing Rules via Code Comments |
| 414 | + |
| 415 | +Removing a rule/sniff/subset/standard only for a specific file or part of it can be done using special `phpcs` annotations/comments. For example, `// phpcs:disable` followed by an optional name of a standard/subset/sniff/rule. Like so: |
| 416 | + |
| 417 | +```php |
| 418 | +// phpcs:disable PSR1.Classes.ClassDeclaration |
| 419 | +``` |
| 420 | + |
| 421 | +For more information about ignoring files, please refer to the official [PHP_CodeSniffer Wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file). |
| 422 | + |
| 423 | +## IDE Integration |
| 424 | + |
| 425 | +### PhpStorm |
| 426 | + |
| 427 | +After installing the coding standard package as described above, configure PhpStorm to use PHP_CodeSniffer by following these steps: |
| 428 | + |
| 429 | +1. Open PhpStorm settings and navigate to: |
| 430 | +> `Language & Frameworks` -> `PHP` -> `Quality Tools` -> `PHP_CodeSniffer`. |
| 431 | +
|
| 432 | +2. In the `Configuration` dropdown, select `Local`. |
| 433 | + |
| 434 | +3. Click the `...` button next to the dropdown to open a dialog for specifying the path to the PHP_CodeSniffer executable. |
| 435 | + |
| 436 | +4. In the file selection dialog, navigate to `vendor/bin/` in your project directory and select `phpcs`. On Windows, select `phpcs.bat`. |
| 437 | + |
| 438 | +5. Click the `Validate` button next to the path input field. If everything is set up correctly, a success message will appear at the bottom of the window. |
| 439 | + |
| 440 | +6. Still in the PhpStorm settings, navigate to: |
| 441 | +> `Editor` -> `Inspections` |
| 442 | +
|
| 443 | +7. In the search field, type `codesniffer` and then select: |
| 444 | +> `PHP` -> `Quality Tools` -> `PHP_CodeSniffer validation` |
| 445 | +
|
| 446 | +8. Enable it by checking the corresponding checkbox and clicking `Apply`. |
| 447 | + |
| 448 | +9. Select `PHP_CodeSniffer validation`, then click the refresh icon next to the `Coding standard` dropdown on the right and choose `Brianvarskonst`. |
| 449 | + |
| 450 | + - If `Brianvarskonst` is not listed, select `Custom` as the standard and use the `...` button next to the dropdown to specify the `phpcs.xml` file. |
| 451 | + |
| 452 | +Once PhpStorm is integrated with PHP_CodeSniffer, warnings and errors will automatically be highlighted in your IDE editor. |
| 453 | + |
343 | 454 | ## Dependencies
|
344 | 455 |
|
345 | 456 | * [PHP CodeSniffer](https://github.com/phpcsstandards/PHP_CodeSniffer)
|
|
0 commit comments