You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To automatically fix as many sniff violations as possible, use the `phpcbf`commandin place of the `phpcs` command. While most of the PHPCS command line arguments can be used by PHPCBF, some are specific to reporting and will be ignored. Running PHPCBF with the `-h` or `--help`command line arguments will print a list of commands that PHPCBF will respond to. The output of `phpcbf -h` is shown below.
Copy file name to clipboardExpand all lines: wiki/Usage.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@
13
13
14
14
Running PHP_CodeSniffer with the `-h` or `--help` command line arguments will print a list of commands that PHP_CodeSniffer will respond to. The output of `phpcs -h` is shown below.
After PHP_CodeSniffer has finished processing your files, you will get an error report. The report lists both errors and warnings for all files that violated the coding standard. The output looks like this:
140
140
141
-
```
141
+
```bash
142
142
$ phpcs /path/to/code/myfile.php
143
143
144
144
FILE: /path/to/code/myfile.php
@@ -157,7 +157,7 @@ FOUND 5 ERROR(S) AND 1 WARNING(S) AFFECTING 5 LINE(S)
157
157
158
158
If you don't want warnings included in the output, specify the `-n` command line argument.
159
159
160
-
```
160
+
```bash
161
161
$ phpcs -n /path/to/code/myfile.php
162
162
163
163
FILE: /path/to/code/myfile.php
@@ -179,7 +179,7 @@ FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
179
179
180
180
By default, PHP_CodeSniffer will print a complete list of all errors and warnings it finds. This list can become quite long, especially when checking a large number of files at once. To print a summary report that only shows the number of errors and warnings for each file, use the `--report=summary` command line argument. The output will look like this:
181
181
182
-
```
182
+
```bash
183
183
$ phpcs --report=summary /path/to/code
184
184
185
185
PHP CODE SNIFFER REPORT SUMMARY
@@ -196,7 +196,7 @@ A TOTAL OF 6 ERROR(S) AND 3 WARNING(S) WERE FOUND IN 3 FILE(S)
196
196
197
197
As with the full report, you can suppress the printing of warnings with the `-n` command line argument.
198
198
199
-
```
199
+
```bash
200
200
$ phpcs -n --report=summary /path/to/code
201
201
202
202
PHP CODE SNIFFER REPORT SUMMARY
@@ -220,7 +220,7 @@ By default, PHP_CodeSniffer will run quietly, only printing the report of errors
220
220
To enable progress reporting, use the `-p` command line argument.
221
221
With progress output enabled, PHP_CodeSniffer will print a single-character status for each file being checked, like so:
@@ -245,7 +245,7 @@ Legend for the progress indicators:
245
245
246
246
With verbose output enabled, PHP_CodeSniffer will print the file that it is checking, show you how many tokens and lines the file contains, and let you know how long it took to process. The output will look like this:
247
247
248
-
```
248
+
```bash
249
249
$ phpcs /path/to/code/CodeSniffer -v
250
250
251
251
Registering sniffs in PEAR standard... DONE (28 sniffs registered)
PHP_CodeSniffer can print you a list of the coding standards that are installed so that you can correctly specify a coding standard to use for testing. You can print this list by specifying the `-i` command line argument.
294
294
295
-
```
295
+
```bash
296
296
$ phpcs -i
297
297
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and Zend
298
298
```
@@ -304,7 +304,7 @@ The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and
304
304
305
305
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.
Copy file name to clipboardExpand all lines: wiki/Version-1.3.0-Upgrade-Guide.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ PHP_CodeSniffer version 1.3.0 contains an important backwards compatibility brea
4
4
> If you have not created your own coding standard, you do not need to follow this guide. Users of PHP_CodeSniffer that use one of the built-in standards can continue to check their code as normal.
5
5
6
6
This guide assumes your coding standard has the following directory structure:
7
-
```
7
+
```text
8
8
MyStandard
9
9
|_ MyStandardCodingStandard.php
10
10
|_ Sniffs
@@ -18,7 +18,7 @@ The only thing we need to do to upgrade a custom coding standard is convert the
18
18
### The Basics
19
19
20
20
The first thing you need to do is create a `ruleset.xml` file directly under your top-level directory. The name of the file must be `ruleset.xml`:
21
-
```
21
+
```bash
22
22
touch MyStandard/ruleset.xml
23
23
```
24
24
@@ -63,7 +63,7 @@ These rules would be replicated in a `ruleset.xml` file like this:
63
63
```
64
64
65
65
The two changes here are the use of the `rule` tag to include sniffs and standards, and also the way we reference an individual sniff. Instead of specifying the path to the sniff we instead specify the internal code that PHP_CodeSniffer gives it, which is based on the path. It's actually a pretty easy conversion. Just just drop the `Sniffs` directory, convert the slashes to periods and remove `Sniff.php` from the end. Here are some more examples to make sure it is clear.
0 commit comments