Skip to content

Commit f22992e

Browse files
ondrejmirteskukulich
authored andcommitted
Updated README for 4.0 release
1 parent d0ee451 commit f22992e

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

README.md

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
[![Code coverage](https://img.shields.io/coveralls/slevomat/coding-standard/master.svg?style=flat-square)](https://coveralls.io/github/slevomat/coding-standard?branch=master)
88
![PHPStan](https://img.shields.io/badge/style-level%206-brightgreen.svg?style=flat-square&label=phpstan)
99

10-
Slevomat Coding Standard for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) complements [Consistence Coding Standard](https://github.com/consistence/coding-standard) by providing sniffs with additional checks.
10+
Slevomat Coding Standard for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) provides sniffs that fall into three categories:
11+
12+
* Functional - improving the safety and behaviour of code
13+
* Cleaning - detecting dead code
14+
* Formatting - rules for consistent code looks
1115

1216
## Table of contents
1317

@@ -16,11 +20,12 @@ Slevomat Coding Standard for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_
1620
- [Cleaning - detecting dead code](#cleaning---detecting-dead-code)
1721
- [Formatting - rules for consistent code looks](#formatting---rules-for-consistent-code-looks)
1822
2. [Installation](#installation)
19-
3. [Using the standard as a whole](#using-the-standard-as-a-whole)
20-
4. [Using individual sniffs](#using-individual-sniffs)
21-
5. [Fixing errors automatically](#fixing-errors-automatically)
22-
6. [Suppressing sniffs locally](#suppressing-sniffs-locally)
23-
7. [Contributing](#contributing)
23+
3. [How to run the sniffs](#how-to-run-the-sniffs)
24+
- [Choose which sniffs to run](#choose-which-sniffs-to-run)
25+
- [Using all sniffs from the standard](#using-all-sniffs-from-the-standard)
26+
4. [Fixing errors automatically](#fixing-errors-automatically)
27+
5. [Suppressing sniffs locally](#suppressing-sniffs-locally)
28+
6. [Contributing](#contributing)
2429

2530
## Sniffs included in this standard
2631

@@ -383,89 +388,82 @@ The recommended way to install Slevomat Coding Standard is [through Composer](ht
383388
```JSON
384389
{
385390
"require-dev": {
386-
"slevomat/coding-standard": "~3.0"
391+
"slevomat/coding-standard": "~4.0"
387392
}
388393
}
389394
```
390395

391396
It's also recommended to install [jakub-onderka/php-parallel-lint](https://github.com/JakubOnderka/PHP-Parallel-Lint) which checks source code for syntax errors. Sniffs count on the processed code to be syntatically valid (no parse errors), otherwise they can behave unexpectedly. It is advised to run `PHP-Parallel-Lint` in your build tool before running `PHP_CodeSniffer` and exiting the build process early if `PHP-Parallel-Lint` fails.
392397

393-
## Using the standard as a whole
398+
## How to run the sniffs
394399

395-
If you want to use the whole coding standard, besides requiring `slevomat/coding-standard` in composer.json, require also Consistence Coding Standard:
400+
You can choose one of two ways to run only selected sniffs from the standard on your codebase:
396401

397-
```JSON
398-
{
399-
"require-dev": {
400-
"consistence/coding-standard": "~2.0"
401-
}
402-
}
403-
```
402+
### Choose which sniffs to run
404403

405-
Then mention both standards in `ruleset.xml`:
404+
Mention Slevomat Conding Standard in your project's `ruleset.xml`:
406405

407406
```xml
408407
<?xml version="1.0"?>
409408
<ruleset name="AcmeProject">
410-
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml" />
411-
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml" />
412-
<!-- additional settings -->
409+
<config name="installed_paths" value="../../slevomat/coding-standard"/><!-- relative path from PHPCS source location -->
413410
</ruleset>
414411
```
415412

416-
To check your code base for violations, run `PHP-Parallel-Lint` and `PHP_CodeSniffer` from the command line:
413+
When running `phpcs` [on the command line](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage), use the `--sniffs` option to list all the sniffs you want to use separated by a comma:
417414

418415
```
419-
vendor/bin/parallel-lint src tests
420-
vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
416+
vendor/bin/phpcs --standard=ruleset.xml \
417+
--sniffs=SlevomatCodingStandard.ControlStructures.DisallowYodaComparison,SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses \
418+
--extensions=php --encoding=utf-8 --tab-width=4 -sp src tests
421419
```
422420

423-
## Using individual sniffs
424-
425-
If you don't want to follow the whole standard, but find a handful of included sniffs useful, you can use them selectively.
426-
427-
You can choose one of two ways to run only selected sniffs from the standard on your codebase:
428-
429-
### List all sniffs to run
430-
431-
Mention Slevomat Conding Standard in your project's `ruleset.xml`:
421+
Or write your own ruleset.xml by referencing the selected sniffs. This is a sample ruleset.xml:
432422

433423
```xml
434424
<?xml version="1.0"?>
435425
<ruleset name="AcmeProject">
436-
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml" />
426+
<config name="installed_paths" value="../../slevomat/coding-standard"/><!-- relative path from PHPCS source location -->
427+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
428+
<!-- ...other sniffs to include... -->
437429
</ruleset>
438430
```
439431

440-
When running `phpcs` [on the command line](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage), use the `--sniffs` option to list all the sniffs you want to use separated by a comma:
432+
Then run the `phpcs` executable the usual way:
441433

442434
```
443-
vendor/bin/phpcs --standard=ruleset.xml \
444-
--sniffs=SlevomatCodingStandard.ControlStructures.DisallowYodaComparison,SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses \
445-
--extensions=php --encoding=utf-8 --tab-width=4 -sp src tests
435+
vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
446436
```
447437

448-
### Use all sniffs except for the unwanted ones
438+
### Using all sniffs from the standard
439+
440+
⚠️ This is no longer a recommended way to use Slevomat Coding Standard, because your build can break when moving between minor versions of the standard (which can happen if you use `^` or `~` version constraint in `composer.json`). We regularly add new sniffs even in minor versions meaning your code won't most likely comply with new minor versions of the package.
449441

450-
Mention Slevomat Conding Standard in your project's `ruleset.xml` and list all the excluded sniffs:
442+
If you want to use the whole coding standard, besides requiring `slevomat/coding-standard` in composer.json, require also Consistence Coding Standard:
443+
444+
```JSON
445+
{
446+
"require-dev": {
447+
"consistence/coding-standard": "~2.0"
448+
}
449+
}
450+
```
451+
452+
Then mention both standards in `ruleset.xml`:
451453

452454
```xml
453455
<?xml version="1.0"?>
454456
<ruleset name="AcmeProject">
455-
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml">
456-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedClassNameAfterKeyword"/>
457-
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedExceptions"/>
458-
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly"/>
459-
<exclude name="SlevomatCodingStandard.Namespaces.UseOnlyWhitelistedNamespaces"/>
460-
<exclude name="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces"/>
461-
<exclude name="SlevomatCodingStandard.Files.TypeNameMatchesFileName"/>
462-
</rule>
457+
<rule ref="vendor/consistence/coding-standard/Consistence/ruleset.xml" />
458+
<rule ref="vendor/slevomat/coding-standard/SlevomatCodingStandard/ruleset.xml" />
459+
<!-- additional settings -->
463460
</ruleset>
464461
```
465462

466-
Then run the remaining sniffs in the usual way:
463+
To check your code base for violations, run `PHP-Parallel-Lint` and `PHP_CodeSniffer` from the command line:
467464

468465
```
466+
vendor/bin/parallel-lint src tests
469467
vendor/bin/phpcs --standard=ruleset.xml --extensions=php --tab-width=4 -sp src tests
470468
```
471469

0 commit comments

Comments
 (0)