Skip to content

Commit f607f53

Browse files
committed
CS/markdownlint: use fenced codeblocks everywhere
This makes it easier to copy/paste updated output to the wiki docs.
1 parent 029f1c9 commit f607f53

File tree

6 files changed

+709
-559
lines changed

6 files changed

+709
-559
lines changed

wiki/Advanced-Usage.md

Lines changed: 81 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
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.
2323

2424
To only check .php files:
25-
26-
$ phpcs --extensions=php /path/to/code
25+
```bash
26+
$ phpcs --extensions=php /path/to/code
27+
```
2728

2829
To check .php, .inc and .lib files:
29-
30-
$ phpcs --extensions=php,inc,lib /path/to/code
30+
```bash
31+
$ phpcs --extensions=php,inc,lib /path/to/code
32+
```
3133

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

@@ -36,8 +38,9 @@ To check .php, .inc and .lib files:
3638
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.
3739

3840
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.
39-
40-
$ phpcs --ignore=*/tests/*,*/data/* /path/to/code
41+
```bash
42+
$ phpcs --ignore=*/tests/*,*/data/* /path/to/code
43+
```
4144

4245
> [!IMPORTANT]
4346
> 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.
@@ -178,12 +181,14 @@ By default, PHP_CodeSniffer will check your code using all sniffs in the specifi
178181
> All sniffs specified on the command line must be used in the coding standard you are using to check your files.
179182
180183
The following example will only run two sniffs over the code instead of all sniffs in the PEAR standard:
181-
182-
$ phpcs --standard=PEAR --sniffs=Generic.PHP.LowerCaseConstant,PEAR.WhiteSpace.ScopeIndent /path/to/code
184+
```bash
185+
$ phpcs --standard=PEAR --sniffs=Generic.PHP.LowerCaseConstant,PEAR.WhiteSpace.ScopeIndent /path/to/code
186+
```
183187

184188
The following example will run all sniffs in the PEAR standard except for the two specified:
185-
186-
$ phpcs --standard=PEAR --exclude=Generic.PHP.LowerCaseConstant,PEAR.WhiteSpace.ScopeIndent /path/to/code
189+
```bash
190+
$ phpcs --standard=PEAR --exclude=Generic.PHP.LowerCaseConstant,PEAR.WhiteSpace.ScopeIndent /path/to/code
191+
```
187192

188193
> [!WARNING]
189194
> If you use both the `--sniffs` and `--exclude` command line arguments together, the `--exclude` list will be ignored.
@@ -195,14 +200,16 @@ The following example will run all sniffs in the PEAR standard except for the tw
195200
By default, PHP_CodeSniffer assigns a severity of 5 to all errors and warnings. Standards may change the severity of some messages so they are hidden by default or even so that they are raised to indicate greater importance. PHP_CodeSniffer allows you to decide what the minimum severity level must be to show a message in its report using the `--severity` command line argument.
196201

197202
To hide errors and warnings with a severity less than 3:
198-
199-
$ phpcs --severity=3 /path/to/code
203+
```bash
204+
$ phpcs --severity=3 /path/to/code
205+
```
200206

201207
You can specify different values for errors and warnings using the `--error-severity` and `--warning-severity` command line arguments.
202208

203209
To show all errors, but only warnings with a severity of 8 or more:
204-
205-
$ phpcs --error-severity=1 --warning-severity=8 /path/to/code
210+
```bash
211+
$ phpcs --error-severity=1 --warning-severity=8 /path/to/code
212+
```
206213

207214
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.
208215

@@ -215,8 +222,9 @@ This feature is particularly useful during manual code reviews. During normal de
215222
Most of the sniffs written for PHP_CodeSniffer do not support the usage of tabs for indentation and alignment. You can write your own sniffs that check for tabs instead of spaces, but you can also get PHP_CodeSniffer to convert your tabs into spaces before a file is checked. This allows you to use the existing space-based sniffs on your tab-based files.
216223

217224
In the following example, PHP_CodeSniffer will replace all tabs in the files being checked with between 1 and 4 spaces, depending on the column the tab indents to.
218-
219-
$ phpcs --tab-width=4 /path/to/code
225+
```bash
226+
$ phpcs --tab-width=4 /path/to/code
227+
```
220228

221229
> [!NOTE]
222230
> 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.
@@ -226,16 +234,18 @@ In the following example, PHP_CodeSniffer will replace all tabs in the files bei
226234

227235
## Specifying an Encoding
228236
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.
229-
230-
$ phpcs --encoding=windows-1251 /path/to/code
237+
```bash
238+
$ phpcs --encoding=windows-1251 /path/to/code
239+
```
231240

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

234243

235244
## Using a Bootstrap File
236245
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.
237-
238-
$ phpcs --bootstrap=/path/to/boostrap.1.inc,/path/to/bootstrap.2.inc /path/to/code
246+
```bash
247+
$ phpcs --bootstrap=/path/to/boostrap.1.inc,/path/to/bootstrap.2.inc /path/to/code
248+
```
239249

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

@@ -257,11 +267,15 @@ The `phpcs.xml` file has exactly the same format as a normal [[ruleset.xml file|
257267
## Specifying php.ini Settings
258268
PHP_CodeSniffer allows you to set temporary php.ini settings during a run using the `-d` command line argument. The name of the php.ini setting must be specified on the command line, but the value is optional. If no value is set, the php.ini setting will be given a value of TRUE.
259269

260-
$ phpcs -d memory_limit=32M /path/to/code
270+
```bash
271+
$ phpcs -d memory_limit=32M /path/to/code
272+
```
261273

262274
You can also specific multiple values:
263275

264-
$ phpcs -d memory_limit=32M -d include_path=.:/php/includes /path/to/code
276+
```bash
277+
$ phpcs -d memory_limit=32M -d include_path=.:/php/includes /path/to/code
278+
```
265279

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

@@ -271,11 +285,15 @@ PHP_CodeSniffer has some configuration options that can be set. Individual codin
271285

272286
To set a configuration option, use the `--config-set` command line argument.
273287

274-
$ phpcs --config-set <option> <value>
288+
```bash
289+
$ phpcs --config-set <option> <value>
290+
```
275291

276292
Configuration options are written to a global configuration file. If you want to set them for a single run only, use the `--runtime-set` command line argument.
277293

278-
$ phpcs --runtime-set <option> <value> /path/to/code
294+
```bash
295+
$ phpcs --runtime-set <option> <value> /path/to/code
296+
```
279297

280298
> [!NOTE]
281299
> Not all configuration options can be set using the `--runtime-set` command line argument. Configuration options that provide defaults for command line arguments, such as the default standard or report type, can not be used with `--runtime-set`. To set these values for a single run only, use the dedicated CLI arguments that PHP_CodeSniffer provides. The [[Configuration Options|Configuration Options]] list provides an alternative CLI argument for each configuration option not supported by `--runtime-set`.
@@ -288,20 +306,24 @@ PHP_CodeSniffer allows you to delete any configuration option, reverting it to i
288306

289307
To delete a configuration option, use the `--config-delete` command line argument.
290308

291-
$ phpcs --config-delete <option>
309+
```bash
310+
$ phpcs --config-delete <option>
311+
```
292312

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

295315

296316
## Viewing Configuration Options
297317
To view the currently set configuration options, use the `--config-show` command line argument.
298318

299-
$ phpcs --config-show
300-
Array
301-
(
302-
[default_standard] => PEAR
303-
[zend_ca_path] => /path/to/ZendCodeAnalyzer
304-
)
319+
```bash
320+
$ phpcs --config-show
321+
Array
322+
(
323+
[default_standard] => PEAR
324+
[zend_ca_path] => /path/to/ZendCodeAnalyzer
325+
)
326+
```
305327

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

@@ -316,14 +338,16 @@ The output of the PHP_CodeSniffer tokeniser shows the step-by-step creation of t
316338
### The Scope Map
317339
The scope map is best explained with an example. For the following file:
318340

319-
<?php
320-
if ($condition) {
321-
echo 'Condition was true';
322-
}
323-
?>
341+
```php
342+
<?php
343+
if ($condition) {
344+
echo 'Condition was true';
345+
}
346+
?>
347+
```
324348

325349
The scope map output is:
326-
350+
```text
327351
*** START SCOPE MAP ***
328352
Start scope map at 1: T_IF => if
329353
Process token 2 []: T_WHITESPACE =>
@@ -342,7 +366,8 @@ The scope map output is:
342366
Process token 15 [opener:7;]: T_CLOSE_CURLY_BRACKET => }
343367
=> Found scope closer for 1 (T_IF)
344368
*** END SCOPE MAP ***
345-
369+
```
370+
346371
The scope map output above shows the following pieces of information about the file:
347372
* A scope token `if` was found at token 1 (note that token 0 is the open PHP tag).
348373
* The opener for the if statement, the open curly brace, was found at token 7.
@@ -354,14 +379,16 @@ The scope map output is most useful when debugging PHP_CodeSniffer's scope map,
354379
### The Level Map
355380
The level map is best explained with an example. For the following file:
356381

357-
<?php
358-
if ($condition) {
359-
echo 'Condition was true';
360-
}
361-
?>
382+
```php
383+
<?php
384+
if ($condition) {
385+
echo 'Condition was true';
386+
}
387+
?>
388+
```
362389

363390
The level map output is:
364-
391+
```text
365392
*** START LEVEL MAP ***
366393
Process token 0 on line 1 [lvl:0;]: T_OPEN_TAG => <?php\n
367394
Process token 1 on line 2 [lvl:0;]: T_IF => if
@@ -388,8 +415,8 @@ The level map output is:
388415
Process token 16 on line 4 [lvl:0;]: T_WHITESPACE => \n
389416
Process token 17 on line 5 [lvl:0;]: T_CLOSE_TAG => ?>\n
390417
*** END LEVEL MAP ***
418+
```
391419

392-
393420
The level map output above shows the following pieces of information about the file:
394421
* A scope opener, an open curly brace, was found at token 7 and opened the scope for an if statement, defined at token 1.
395422
* Tokens 8 - 15 are all included in the scope set by the scope opener at token 7, the open curly brace. All these tokens are at level 1, indicating that they are enclosed in 1 scope condition, and all these tokens are enclosed in a single condition; an if statement.
@@ -406,14 +433,16 @@ PHP_CodeSniffer contains multiple verbosity levels. Level 3 (indicated by the co
406433

407434
The token processing output is best explained with an example. For the following file:
408435

409-
<?php
410-
if ($condition) {
411-
echo 'Condition was true';
412-
}
413-
?>
436+
```php
437+
<?php
438+
if ($condition) {
439+
echo 'Condition was true';
440+
}
441+
?>
442+
```
414443

415444
The token processing output is:
416-
445+
```text
417446
*** START TOKEN PROCESSING ***
418447
Process token 0: T_OPEN_TAG => <?php\n
419448
Processing PEAR_Sniffs_Commenting_FileCommentSniff... DONE in 0 seconds
@@ -451,6 +480,7 @@ The token processing output is:
451480
Processing Generic_Sniffs_WhiteSpace_DisallowTabIndentSniff... DONE in 0 seconds
452481
Process token 17: T_CLOSE_TAG => ?>\n
453482
*** END TOKEN PROCESSING ***
483+
```
454484

455485
Every token processed is shown, along with its ID, type and contents. For each token, all sniffs that were executed on the token are displayed, along with the running time.
456486

0 commit comments

Comments
 (0)