Skip to content

Commit e469e83

Browse files
Improve Readme and improve badges
1 parent 6bc1ad2 commit e469e83

File tree

1 file changed

+122
-11
lines changed

1 file changed

+122
-11
lines changed

README.md

Lines changed: 122 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
# Brianvarskonst CodeSniffer Ruleset
1+
# Brianvarskonst Coding Standard
22

33
Provides a PHP CodeSniffer ruleset for the Brianvarskonst coding standard
44

55
[![Build Status](https://github.com/brianvarskonst/coding-standard/actions/workflows/ci.yml/badge.svg)](https://github.com/brianvarskonst/coding-standard/actions)
66

7-
[![Latest Stable Version](https://poser.pugx.org/brianvarskonst/coding-standard/v/stable)](https://packagist.org/packages/brianvarskonst/coding-standard)
8-
[![Total Downloads](https://poser.pugx.org/brianvarskonst/coding-standard/downloads)](https://packagist.org/packages/brianvarskonst/coding-standard)
9-
[![Latest Unstable Version](https://poser.pugx.org/brianvarskonst/coding-standard/v/unstable)](https://packagist.org/packages/brianvarskonst/coding-standard)
10-
[![composer.lock](https://poser.pugx.org/brianvarskonst/coding-standard/composerlock)](https://packagist.org/packages/brianvarskonst/coding-standard)
7+
[![Latest Stable Version](http://poser.pugx.org/brianvarskonst/coding-standard/v)](https://packagist.org/packages/brianvarskonst/coding-standard)[![Total Downloads](https://poser.pugx.org/brianvarskonst/coding-standard/downloads)](https://packagist.org/packages/brianvarskonst/coding-standard)
8+
[![Latest Unstable Version](http://poser.pugx.org/brianvarskonst/coding-standard/v/unstable)](https://packagist.org/packages/brianvarskonst/coding-standard)
9+
[![Version](http://poser.pugx.org/brianvarskonst/coding-standard/version)](https://packagist.org/packages/brianvarskonst/coding-standard)
1110

12-
[![Build status](https://github.com/brianvarskonst/coding-standard/workflows/Build/badge.svg?branch=main)](https://github.com/brianvarskonst/coding-standard/actions?query=workflow%3ABuild+branch%3Amain)
11+
[![PHP Version Require](http://poser.pugx.org/brianvarskonst/coding-standard/require/php)](https://packagist.org/packages/brianvarskonst/coding-standard)
1312
![PHPStan](https://img.shields.io/badge/style-level%208-brightgreen.svg?&label=phpstan)
13+
[![composer.lock](http://poser.pugx.org/brianvarskonst/coding-standard/composerlock)](https://packagist.org/packages/brianvarskonst/coding-standard)
1414

15-
[![License](https://poser.pugx.org/brianvarskonst/coding-standard/license)](https://packagist.org/packages/brianvarskonst/coding-standard)
16-
![Awesome](https://img.shields.io/badge/awesome%3F-yes!-brightgreen.svg)
15+
[![License](http://poser.pugx.org/brianvarskonst/coding-standard/license)](https://packagist.org/packages/brianvarskonst/coding-standard)
1716

1817
## Overview
1918

2019
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.
2120

21+
> PHP 8.0+ coding standard
22+
2223
## Rules
2324

2425
### Brianvarskonst.Array.ArrayDoubleArrowAlignment
@@ -267,13 +268,40 @@ E.g. by excluding `Brianvarskonst\ExcludeThis` things like `Brianvarskonst\Exclu
267268
To make sure what's excluded is a namespace, and not a class with same name, just use `\` as last
268269
character.
269270

271+
### Included rules
270272

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).
274274

275275
Most of the issues can be auto-fixed with `phpcbf`.
276276

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+
277305
## Requirements
278306

279307
* [PHP](http://php.net)
@@ -340,6 +368,89 @@ $ ./vendor/bin/phpcs --config-set default_standard Brianvarskonst
340368
If `phpcs` complains that `Brianvarskonst` coding standard is not installed, please check the installed coding standards with
341369
`phpcs -i` and that `installed_paths` is set correctly with `phpcs --config-show`
342370

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+
343454
## Dependencies
344455

345456
* [PHP CodeSniffer](https://github.com/phpcsstandards/PHP_CodeSniffer)

0 commit comments

Comments
 (0)