Skip to content

Commit 1a41c1e

Browse files
committed
Usage, Advanced Usage: improve readability and clarity
1 parent 0e7cc28 commit 1a41c1e

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

wiki/Advanced-Usage.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525

2626
By default, PHP_CodeSniffer will check any file it finds with a `.inc`, `.php`, `.js` or `.css` extension, although not all standards will actually check all these file types. Sometimes, this means that PHP_CodeSniffer is not checking enough of your files. Sometimes, the opposite is true. PHP_CodeSniffer allows you to specify a list of valid file extensions using the `--extensions` command line argument. Extensions are separated by commas.
2727

28-
To only check .php files:
28+
To only check `.php` files:
2929
```bash
3030
$ phpcs --extensions=php /path/to/code
3131
```
3232

33-
To check .php, .inc and .lib files:
33+
To check `.php`, `.inc` and `.lib` files:
3434
```bash
3535
$ phpcs --extensions=php,inc,lib /path/to/code
3636
```
@@ -42,15 +42,15 @@ $ phpcs --extensions=php,inc,lib /path/to/code
4242

4343
Sometimes you want PHP_CodeSniffer to run over a very large number of files, but you want some files and folders to be skipped. The `--ignore` command line argument can be used to tell PHP_CodeSniffer to skip files and folders that match one or more patterns.
4444

45-
In the following example, PHP_CodeSniffer will skip all files inside the package's tests and data directories. This is useful if you are checking a package but don't want your test or data files to conform to your coding standard.
45+
In the following example, PHP_CodeSniffer will skip all files inside the package's `tests` and `data` directories. This is useful if you are checking a package but don't want your test or data files to conform to your coding standard.
4646
```bash
4747
$ phpcs --ignore=*/tests/*,*/data/* /path/to/code
4848
```
4949

5050
> [!IMPORTANT]
51-
> The ignore patterns are treated as regular expressions. If you do specify a regular expression, be aware that `*` is converted to `.*` for the convenience in simple patterns, like those used in the example above. So use `*` anywhere you would normally use `.*`. Also ensure you escape any `.` characters that you want treated as a literal dot, such as when checking file extensions. So if you are checking for `.inc` in your ignore pattern, use `\.inc` instead.
51+
> The ignore patterns are treated as regular expressions. If you do specify a regular expression, be aware that `*` is converted to `.*` for convenience in simple patterns, like those used in the example above. So use `*` anywhere you would normally use `.*`. Also ensure you escape any `.` characters that you want treated as a literal dot, such as when checking file extensions. So if you are checking for `.inc` in your ignore pattern, use `\.inc` instead.
5252
53-
You can also tell PHP_CodeSniffer to ignore a file using a special comment inserted at the top of the file. This will stop the file being checked even if it does not match the ignore pattern.
53+
You can also tell PHP_CodeSniffer to ignore a file using a special comment inserted at the top of the file. This will stop the file from being checked, even if it does not match the ignore pattern.
5454

5555
```php
5656
<?php
@@ -61,9 +61,10 @@ $xmlPackage->send();
6161
```
6262

6363
> [!NOTE]
64-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreFile` instead of `// phpcs:ignoreFile`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
64+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreFile` instead of `// phpcs:ignoreFile`.
65+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
6566
66-
> [!NOTE]
67+
> [!TIP]
6768
> The `phpcs:ignoreFile` comment syntax does not allow for a specific set of sniffs to be ignored for a file. Use the `phpcs:disable` comment syntax if you want to disable a specific set of sniffs for the entire file.
6869
6970
If required, you can add a note explaining why the file is being ignored by using the `--` separator.
@@ -95,7 +96,8 @@ $xmlPackage->send();
9596
```
9697

9798
> [!NOTE]
98-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreStart` instead of `// phpcs:disable`, and use `// @codingStandardsIgnoreEnd` instead of `// phpcs:enable`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
99+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreStart` instead of `// phpcs:disable`, and use `// @codingStandardsIgnoreEnd` instead of `// phpcs:enable`.
100+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
99101
100102
If you don't want to disable all coding standard errors, you can selectively disable and re-enable specific error message codes, sniffs, categories of sniffs, or entire coding standards. The following example disables the specific `Generic.Commenting.Todo.Found` message and then re-enables all checks at the end.
101103

@@ -141,7 +143,8 @@ bar($foo, false);
141143
```
142144

143145
> [!NOTE]
144-
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreLine` instead of `// phpcs:ignore`. The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
146+
> Before PHP_CodeSniffer version 3.2.0, use `// @codingStandardsIgnoreLine` instead of `// phpcs:ignore`.
147+
> The `@codingStandards` syntax is deprecated and will be removed in PHP_CodeSniffer version 4.0.
145148
146149
Again, you can selectively ignore one or more specific error message codes, sniffs, categories of sniffs, or entire standards.
147150

@@ -219,9 +222,9 @@ To show all errors, but only warnings with a severity of 8 or more:
219222
$ phpcs --error-severity=1 --warning-severity=8 /path/to/code
220223
```
221224

222-
Setting the severity of warnings to `0` is the same as using the `-n` command line argument. If you set the severity of errors to `0` PHP_CodeSniffer will not show any errors, which may be useful if you just want to show warnings.
225+
Setting the severity of warnings to `0` is the same as using the `-n` command line argument. If you set the severity of errors to `0`, PHP_CodeSniffer will not show any errors, which may be useful if you just want to show warnings.
223226

224-
This feature is particularly useful during manual code reviews. During normal development, or an automated build, you may want to only check code formatting issues. But while during a code review, you may wish to show less severe errors and warnings that may need manual peer review.
227+
This feature is particularly useful during manual code reviews. During normal development, or an automated build, you may want to only check code formatting issues, while during a code review, you may wish to show less severe errors and warnings that may need manual peer review.
225228

226229
<p align="right"><a href="#table-of-contents">back to top</a></p>
227230

@@ -236,14 +239,16 @@ $ phpcs --tab-width=4 /path/to/code
236239
```
237240

238241
> [!NOTE]
239-
> The [included sniff](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/WhiteSpace/DisallowTabIndentSniff.php) that enforces space indentation will still generate errors even if you have replaced tabs with spaces using the `--tab-width` setting. This sniff looks at the unmodified version of the code to check line indentation and so must be disabled in a [[custom ruleset.xml file|Annotated ruleset]] if you want to use tab indentation.
242+
> The `Generic.WhiteSpace.DisallowTabIndent` and `Generic.WhiteSpace.DisallowSpaceIndent` sniffs, which enforce space or tab indentation respectively, will still generate errors, even if you have replaced tabs with spaces using the `--tab-width` setting. These sniffs looks at the unmodified version of the code to check line indentation.
243+
> When using a [[custom ruleset.xml file|Annotated ruleset]], only enable one of these two sniffs, never both.
240244
241245
<p align="right"><a href="#table-of-contents">back to top</a></p>
242246

243247

244248
## Specifying an Encoding
245249

246250
By default, PHP_CodeSniffer will treat all source files as if they use UTF-8 encoding. If you need your source files to be processed using a specific encoding, you can specify the encoding using the `--encoding` command line argument.
251+
247252
```bash
248253
$ phpcs --encoding=windows-1251 /path/to/code
249254
```
@@ -254,6 +259,7 @@ $ phpcs --encoding=windows-1251 /path/to/code
254259
## Using a Bootstrap File
255260

256261
PHP_CodeSniffer can optionally include one or more custom bootstrap files before beginning the run. Bootstrap files are included after command line arguments and rulesets have been parsed, and right before files begin to process. These custom files may be used to perform such taks as manipulating the internal settings of PHP_CodeSniffer that are not exposed through command line arguments. Multiple bootstrap files are seperated by commas.
262+
257263
```bash
258264
$ phpcs --bootstrap=/path/to/boostrap.1.inc,/path/to/bootstrap.2.inc /path/to/code
259265
```

wiki/Usage.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Processing OpeningBraceSameLineSniff.php [936 tokens in 123 lines]... DONE in 26
268268

269269
PHP_CodeSniffer can have multiple coding standards installed to allow a single installation to be used with multiple projects. When checking PHP code, PHP_CodeSniffer can be told which coding standard to use. This is done using the `--standard` command line argument.
270270

271-
The example below checks the `myfile.inc` file for violations of the _PEAR_ coding standard (installed by default).
271+
The example below checks the `myfile.inc` file for violations against the _PEAR_ coding standard (installed by default).
272272

273273
```bash
274274
$ phpcs --standard=PEAR /path/to/code/myfile.inc
@@ -303,7 +303,7 @@ The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and
303303

304304
## Listing Sniffs Inside a Coding Standard
305305

306-
PHP_CodeSniffer can print you a list of the sniffs that a coding standard includes by specifying the `-e` command line argument along with the `--standard` argument. This allows you to see what checks will be applied when you use a given standard.
306+
PHP_CodeSniffer can print you a list of the sniffs that a coding standard includes by specifying the `-e` (="explain") command line argument along with the `--standard` argument. This allows you to see what checks will be applied when you use a given standard.
307307

308308
```bash
309309
$ phpcs --standard=PSR1 -e

0 commit comments

Comments
 (0)