Skip to content

Commit 2a0e3f8

Browse files
committed
Usage: use fenced code blocks
1 parent e9bebd7 commit 2a0e3f8

File tree

1 file changed

+105
-79
lines changed

1 file changed

+105
-79
lines changed

wiki/Usage.md

Lines changed: 105 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -123,44 +123,52 @@ The simplest way of using PHP_CodeSniffer is to provide the location of a file o
123123

124124
In the example below, the first command tells PHP_CodeSniffer to check the `myfile.inc` file for coding standard errors while the second command tells PHP_CodeSniffer to check all PHP files in the `my_dir` directory.
125125

126-
$ phpcs /path/to/code/myfile.inc
127-
$ phpcs /path/to/code/my_dir
126+
```bash
127+
$ phpcs /path/to/code/myfile.inc
128+
$ phpcs /path/to/code/my_dir
129+
```
128130

129131
You can also specify multiple files and folders to check. The command below tells PHP_CodeSniffer to check the `myfile.inc` file and all files in the `my_dir` directory.
130132

131-
$ phpcs /path/to/code/myfile.inc /path/to/code/my_dir
133+
```bash
134+
$ phpcs /path/to/code/myfile.inc /path/to/code/my_dir
135+
```
132136

133137
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:
134138

135-
$ phpcs /path/to/code/myfile.php
136-
137-
FILE: /path/to/code/myfile.php
138-
--------------------------------------------------------------------------------
139-
FOUND 5 ERROR(S) AND 1 WARNING(S) AFFECTING 5 LINE(S)
140-
--------------------------------------------------------------------------------
141-
2 | ERROR | Missing file doc comment
142-
20 | ERROR | PHP keywords must be lowercase; expected "false" but found
143-
| | "FALSE"
144-
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
145-
47 | WARNING | Equals sign not aligned with surrounding assignments
146-
51 | ERROR | Missing function doc comment
147-
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
148-
--------------------------------------------------------------------------------
139+
```
140+
$ phpcs /path/to/code/myfile.php
141+
142+
FILE: /path/to/code/myfile.php
143+
--------------------------------------------------------------------------------
144+
FOUND 5 ERROR(S) AND 1 WARNING(S) AFFECTING 5 LINE(S)
145+
--------------------------------------------------------------------------------
146+
2 | ERROR | Missing file doc comment
147+
20 | ERROR | PHP keywords must be lowercase; expected "false" but found
148+
| | "FALSE"
149+
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
150+
47 | WARNING | Equals sign not aligned with surrounding assignments
151+
51 | ERROR | Missing function doc comment
152+
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
153+
--------------------------------------------------------------------------------
154+
```
149155

150156
If you don't want warnings included in the output, specify the `-n` command line argument.
151157

152-
$ phpcs -n /path/to/code/myfile.php
153-
154-
FILE: /path/to/code/myfile.php
155-
--------------------------------------------------------------------------------
156-
FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
157-
--------------------------------------------------------------------------------
158-
2 | ERROR | Missing file doc comment
159-
20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
160-
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
161-
51 | ERROR | Missing function doc comment
162-
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
163-
--------------------------------------------------------------------------------
158+
```
159+
$ phpcs -n /path/to/code/myfile.php
160+
161+
FILE: /path/to/code/myfile.php
162+
--------------------------------------------------------------------------------
163+
FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
164+
--------------------------------------------------------------------------------
165+
2 | ERROR | Missing file doc comment
166+
20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
167+
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
168+
51 | ERROR | Missing function doc comment
169+
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
170+
--------------------------------------------------------------------------------
171+
```
164172

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

@@ -169,32 +177,36 @@ If you don't want warnings included in the output, specify the `-n` command line
169177

170178
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:
171179

172-
$ phpcs --report=summary /path/to/code
173-
174-
PHP CODE SNIFFER REPORT SUMMARY
175-
--------------------------------------------------------------------------------
176-
FILE ERRORS WARNINGS
177-
--------------------------------------------------------------------------------
178-
/path/to/code/myfile.inc 5 0
179-
/path/to/code/yourfile.inc 1 1
180-
/path/to/code/ourfile.inc 0 2
181-
--------------------------------------------------------------------------------
182-
A TOTAL OF 6 ERROR(S) AND 3 WARNING(S) WERE FOUND IN 3 FILE(S)
183-
--------------------------------------------------------------------------------
180+
```
181+
$ phpcs --report=summary /path/to/code
182+
183+
PHP CODE SNIFFER REPORT SUMMARY
184+
--------------------------------------------------------------------------------
185+
FILE ERRORS WARNINGS
186+
--------------------------------------------------------------------------------
187+
/path/to/code/myfile.inc 5 0
188+
/path/to/code/yourfile.inc 1 1
189+
/path/to/code/ourfile.inc 0 2
190+
--------------------------------------------------------------------------------
191+
A TOTAL OF 6 ERROR(S) AND 3 WARNING(S) WERE FOUND IN 3 FILE(S)
192+
--------------------------------------------------------------------------------
193+
```
184194

185195
As with the full report, you can suppress the printing of warnings with the `-n` command line argument.
186196

187-
$ phpcs -n --report=summary /path/to/code
188-
189-
PHP CODE SNIFFER REPORT SUMMARY
190-
--------------------------------------------------------------------------------
191-
FILE ERRORS
192-
--------------------------------------------------------------------------------
193-
/path/to/code/myfile.inc 5
194-
/path/to/code/yourfile.inc 1
195-
--------------------------------------------------------------------------------
196-
A TOTAL OF 6 ERROR(S) WERE FOUND IN 2 FILE(S)
197-
--------------------------------------------------------------------------------
197+
```
198+
$ phpcs -n --report=summary /path/to/code
199+
200+
PHP CODE SNIFFER REPORT SUMMARY
201+
--------------------------------------------------------------------------------
202+
FILE ERRORS
203+
--------------------------------------------------------------------------------
204+
/path/to/code/myfile.inc 5
205+
/path/to/code/yourfile.inc 1
206+
--------------------------------------------------------------------------------
207+
A TOTAL OF 6 ERROR(S) WERE FOUND IN 2 FILE(S)
208+
--------------------------------------------------------------------------------
209+
```
198210

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

@@ -212,34 +224,40 @@ With progress output enabled, PHP_CodeSniffer will print a single-character stat
212224

213225
Progress output will look like this:
214226

215-
$ phpcs /path/to/code/CodeSniffer -p
216-
......................S..................................... 60 / 572
217-
..........EEEE.E.E.E.E.E.E.E.E..W..EEE.E.E.E.EE.E.E.E.E.E.E. 120 / 572
218-
E.E.E.E.E.WWWW.E.W..EEE.E.................E.E.E.E...E....... 180 / 572
219-
E.E.E.E.....................E.E.E.E.E.E.E.E.E.E.W.E.E.E.E.E. 240 / 572
220-
E.W......................................................... 300 / 572
221-
..........................................E.E.E.E...E.E.E.E. 360 / 572
222-
E.E.E.E.E.E..E.E.E..E..E..E.E.WW.E.E.EE.E.E................. 420 / 572
223-
...................E.E.EE.E.E.E.S.E.EEEE.E...E...EE.E.E..EEE 480 / 572
224-
.E.EE.E.E..E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E..E..E..E.E.E..E 540 / 572
225-
.E.E....E.E.E...E.....E.E.ES....
227+
```
228+
$ phpcs /path/to/code/CodeSniffer -p
229+
230+
......................S..................................... 60 / 572
231+
..........EEEE.E.E.E.E.E.E.E.E..W..EEE.E.E.E.EE.E.E.E.E.E.E. 120 / 572
232+
E.E.E.E.E.WWWW.E.W..EEE.E.................E.E.E.E...E....... 180 / 572
233+
E.E.E.E.....................E.E.E.E.E.E.E.E.E.E.W.E.E.E.E.E. 240 / 572
234+
E.W......................................................... 300 / 572
235+
..........................................E.E.E.E...E.E.E.E. 360 / 572
236+
E.E.E.E.E.E..E.E.E..E..E..E.E.WW.E.E.EE.E.E................. 420 / 572
237+
...................E.E.EE.E.E.E.S.E.EEEE.E...E...EE.E.E..EEE 480 / 572
238+
.E.EE.E.E..E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E.E..E..E..E.E.E..E 540 / 572
239+
.E.E....E.E.E...E.....E.E.ES....
240+
```
226241

227242
> [!NOTE]
228243
> You can configure PHP_CodeSniffer to show progress information by default using [the configuration option](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#showing-progress-by-default)</link>.
229244
230245
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:
231246

232-
$ phpcs /path/to/code/CodeSniffer -v
233-
Registering sniffs in PEAR standard... DONE (24 sniffs registered)
234-
Creating file list... DONE (572 files in queue)
235-
Processing AbstractDocElement.php [1093 tokens in 303 lines]... DONE in < 1 second (0 errors, 1 warnings)
236-
Processing AbstractParser.php [2360 tokens in 558 lines]... DONE in 2 seconds (0 errors, 1 warnings)
237-
Processing ClassCommentParser.php [923 tokens in 296 lines]... DONE in < 1 second (2 errors, 0 warnings)
238-
Processing CommentElement.php [988 tokens in 218 lines]... DONE in < 1 second (1 error, 5 warnings)
239-
Processing FunctionCommentParser.php [525 tokens in 184 lines]... DONE in 1 second (0 errors, 6 warnings)
240-
Processing File.php [10968 tokens in 1805 lines]... DONE in 5 seconds (0 errors, 5 warnings)
241-
Processing Sniff.php [133 tokens in 94 lines]... DONE in < 1 second (0 errors, 0 warnings)
242-
Processing SniffException.php [47 tokens in 36 lines]... DONE in < 1 second (1 errors, 3 warnings)
247+
```
248+
$ phpcs /path/to/code/CodeSniffer -v
249+
250+
Registering sniffs in PEAR standard... DONE (24 sniffs registered)
251+
Creating file list... DONE (572 files in queue)
252+
Processing AbstractDocElement.php [1093 tokens in 303 lines]... DONE in < 1 second (0 errors, 1 warnings)
253+
Processing AbstractParser.php [2360 tokens in 558 lines]... DONE in 2 seconds (0 errors, 1 warnings)
254+
Processing ClassCommentParser.php [923 tokens in 296 lines]... DONE in < 1 second (2 errors, 0 warnings)
255+
Processing CommentElement.php [988 tokens in 218 lines]... DONE in < 1 second (1 error, 5 warnings)
256+
Processing FunctionCommentParser.php [525 tokens in 184 lines]... DONE in 1 second (0 errors, 6 warnings)
257+
Processing File.php [10968 tokens in 1805 lines]... DONE in 5 seconds (0 errors, 5 warnings)
258+
Processing Sniff.php [133 tokens in 94 lines]... DONE in < 1 second (0 errors, 0 warnings)
259+
Processing SniffException.php [47 tokens in 36 lines]... DONE in < 1 second (1 errors, 3 warnings)
260+
```
243261

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

@@ -250,15 +268,21 @@ PHP_CodeSniffer can have multiple coding standards installed to allow a single i
250268

251269
The example below checks the `myfile.inc` file for violations of the _PEAR_ coding standard (installed by default).
252270

253-
$ phpcs --standard=PEAR /path/to/code/myfile.inc
271+
```bash
272+
$ phpcs --standard=PEAR /path/to/code/myfile.inc
273+
```
254274

255275
You can also tell PHP_CodeSniffer to use an external standard by specifying the full path to the standard's root directory on the command line. An external standard is one that is stored outside of PHP_CodeSniffer's `Standards` directory.
256276

257-
$ phpcs --standard=/path/to/MyStandard /path/to/code/myfile.inc
277+
```bash
278+
$ phpcs --standard=/path/to/MyStandard /path/to/code/myfile.inc
279+
```
258280

259281
Multiple coding standards can be checked at the same time by passing a list of comma separated standards on the command line. A mix of external and installed coding standards can be passed if required.
260282

261-
$ phpcs --standard=PEAR,Squiz,/path/to/MyStandard /path/to/code/myfile.inc
283+
```bash
284+
$ phpcs --standard=PEAR,Squiz,/path/to/MyStandard /path/to/code/myfile.inc
285+
```
262286

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

@@ -267,8 +291,10 @@ Multiple coding standards can be checked at the same time by passing a list of c
267291

268292
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.
269293

270-
$ phpcs -i
271-
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and Zend
294+
```
295+
$ phpcs -i
296+
The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz and Zend
297+
```
272298

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

0 commit comments

Comments
 (0)