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
Copy file name to clipboardExpand all lines: wiki/About-Standards-for-PHP_CodeSniffer.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,14 +34,14 @@ The typical differences between project-specific rulesets and standards are:
34
34
| Will automatically be used when no standard is provided on the command line ? | Yes | No |
35
35
| Can have custom sniffs ? | No | Yes |
36
36
| Can be installed ? | No | Yes |
37
-
|Reusability by other projects ?| Limited | Yes |
37
+
|Re-usability by other projects ? | Limited | Yes |
38
38
39
-
For optimal reusability, it is in most cases a good idea for a standard to be in its own repository and to be maintained as a separate project.
39
+
For optimal re-usability, it is in most cases a good idea for a standard to be in its own repository and to be maintained as a separate project.
40
40
41
41
A `[.]phpcs.xml[.dist]` file and a `ruleset.xml` file can largely contain the same type of directives.
42
42
The [Annotated ruleset](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Annotated-Ruleset) page contains information on all the directives you can use.
43
43
44
-
Keep in mind that for a _standard_ to be optimally reusable, it should not contain project specific information, such as `<file>` directives or `<exclude-patterns>`, while a project specific `[.]phpcs.xml[.dist]` ruleset file _can_ contain that information.
44
+
Keep in mind that for a _standard_ to be optimally re-usable, it should not contain project specific information, such as `<file>` directives or `<exclude-patterns>`, while a project specific `[.]phpcs.xml[.dist]` ruleset file _can_ contain that information.
45
45
46
46
You may also find the [Customisable Sniff Properties](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties) page a handy reference for customisations which can be made to PHP_CodeSniffer native sniffs.
47
47
@@ -253,7 +253,7 @@ use PHP_CodeSniffer\Sniffs\Sniff;
253
253
class OperatorSpacingSniff implements Sniff {...}
254
254
```
255
255
256
-
:x: Not following the required directory structure (missing `[CategoryName]`subdirectory):
256
+
:x: Not following the required directory structure (missing `[CategoryName]`sub-directory):
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
+
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 tasks as manipulating the internal settings of PHP_CodeSniffer that are not exposed through command line arguments. Multiple bootstrap files are separated by commas.
<palign="right"><ahref="#table-of-contents">back to top</a></p>
@@ -351,13 +351,13 @@ Array
351
351
<palign="right"><ahref="#table-of-contents">back to top</a></p>
352
352
353
353
354
-
## Printing Verbose Tokeniser Output
354
+
## Printing Verbose Tokenizer Output
355
355
356
356
This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time.
357
357
358
-
PHP_CodeSniffer contains multiple verbosity levels. Level 2 (indicated by the command line argument `-vv`) will print all verbosity information for level 1 (file specific token and line counts with running times) as well as verbose tokeniser output.
358
+
PHP_CodeSniffer contains multiple verbosity levels. Level 2 (indicated by the command line argument `-vv`) will print all verbosity information for level 1 (file specific token and line counts with running times) as well as verbose tokenizer output.
359
359
360
-
The output of the PHP_CodeSniffer tokeniser shows the step-by-step creation of the scope map and the level map.
360
+
The output of the PHP_CodeSniffer tokenizer shows the step-by-step creation of the scope map and the level map.
361
361
362
362
### The Scope Map
363
363
@@ -456,7 +456,7 @@ The level map is most commonly used to determine indentation rules (e.g., a toke
456
456
457
457
This feature is provided for debugging purposes only. Using this feature will dramatically increase screen output and script running time.
458
458
459
-
PHP_CodeSniffer contains multiple verbosity levels. Level 3 (indicated by the command line argument `-vvv`) will print all verbosity information for level 1 (file specific token and line counts with running times), level 2 (tokeniser output) as well as token processing output with sniff running times.
459
+
PHP_CodeSniffer contains multiple verbosity levels. Level 3 (indicated by the command line argument `-vvv`) will print all verbosity information for level 1 (file specific token and line counts with running times), level 2 (tokenizer output) as well as token processing output with sniff running times.
460
460
461
461
The token processing output is best explained with an example. For the following file:
Copy file name to clipboardExpand all lines: wiki/Coding-Standard-Tutorial.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -121,7 +121,7 @@ final class DisallowHashCommentsSniff implements Sniff
121
121
}
122
122
```
123
123
124
-
By default, PHP_CodeSniffer assumes all sniffs are designed to check PHP code only. You can specify a list of tokenizers that your sniff supports, allowing it to be used wth PHP, JavaScript or CSS files, or any combination of the three. You do this by setting the `$supportedTokenizers` property in your sniff. Adding the following code to your sniff will tell PHP_CodeSniffer that it can be used to check both PHP and JavaScript code:
124
+
By default, PHP_CodeSniffer assumes all sniffs are designed to check PHP code only. You can specify a list of tokenizers that your sniff supports, allowing it to be used with PHP, JavaScript or CSS files, or any combination of the three. You do this by setting the `$supportedTokenizers` property in your sniff. Adding the following code to your sniff will tell PHP_CodeSniffer that it can be used to check both PHP and JavaScript code:
## Ignoring non-auto-fixable issues when generating the exit code (PHP_CodeSniffer >= 4.0.0)
240
240
241
-
By default, PHP_CodeSniffer will exit with a non-zero code if any errors or warnings are found, whethere these are auto-fixable or not.
242
-
If you want to display non-autofixable errors and warnings to the user, but still return with a zero exit code if non-auto-fixable issues are found, you can set the `ignore_non_auto_fixable_on_exit` configuration option.
241
+
By default, PHP_CodeSniffer will exit with a non-zero code if any errors or warnings are found, whether these are auto-fixable or not.
242
+
If you want to display non-auto-fixable errors and warnings to the user, but still return with a zero exit code if non-auto-fixable issues are found, you can set the `ignore_non_auto_fixable_on_exit` configuration option.
243
243
This option is typically used by automated build tools so that a `phpcbf` run can exit with `0`if it fixed all fixable issues, but there are still some non-auto-fixable issues remaining.
Copy file name to clipboardExpand all lines: wiki/Customisable-Sniff-Properties.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -103,7 +103,7 @@ This sniff ensures that parameters passed to a function are used within that fun
103
103
```php
104
104
public function execute(InputInterface $input, OutputInterface $output): int
105
105
{
106
-
$output->writeln('Hello World!');
106
+
$output->writeLine('Hello World!');
107
107
}
108
108
```
109
109
@@ -973,7 +973,7 @@ $rootNode
973
973
->end()
974
974
->end();
975
975
```
976
-
If you want to allow mutli-level indenting, set the `multilevel` property to `true`. This will allow each line to be indented 1 more or 1 less level than the previous line, while still ensuring that all lines are indented at least once.
976
+
If you want to allow multi-level indenting, set the `multilevel` property to `true`. This will allow each line to be indented 1 more or 1 less level than the previous line, while still ensuring that all lines are indented at least once.
> The `*nix` `diff` command is required for generating reports in `diff` format. Windows users may need to ensure that the `diff` command is available by either installing [DiffUtils](http://gnuwin32.sourceforge.net/packages/diffutils.htm) or, if available, adding the Git `/usr/bin/` subdirectory to the Windows system `PATH`.
336
+
> The `*nix` `diff` command is required for generating reports in `diff` format. Windows users may need to ensure that the `diff` command is available by either installing [DiffUtils](http://gnuwin32.sourceforge.net/packages/diffutils.htm) or, if available, adding the Git `/usr/bin/` sub-directory to the Windows system `PATH`.
337
337
338
338
<p align="right"><a href="#table-of-contents">back to top</a></p>
339
339
340
340
341
341
## Printing an Emacs Report
342
342
343
-
PHP_CodeSniffer can output a report in a format the compiler built into the GNU Emacs text editor can understand. This lets you use the built-in complier to run PHP_CodeSniffer on a file you are editing and navigate between errors and warnings within the file. To print an Emacs report, use the `--report=emacs` command line argument. The output will look like this:
343
+
PHP_CodeSniffer can output a report in a format the compiler built into the GNU Emacs text editor can understand. This lets you use the built-in compiler to run PHP_CodeSniffer on a file you are editing and navigate between errors and warnings within the file. To print an Emacs report, use the `--report=emacs` command line argument. The output will look like this:
344
344
345
345
```bash
346
346
$ phpcs --report=emacs /path/to/code
@@ -368,7 +368,7 @@ Now you can use the compile command and associated shortcuts to move between err
368
368
369
369
## Printing a Git Blame Report
370
370
371
-
PHP_CodeSniffer can make use of the `git blame` command to try and determine who committed each error and warning to a Git respository. To print a Git Blame report, use the `--report=gitblame` command line argument. The output will look like this:
371
+
PHP_CodeSniffer can make use of the `git blame` command to try and determine who committed each error and warning to a Git repository. To print a Git Blame report, use the `--report=gitblame` command line argument. The output will look like this:
372
372
373
373
```bash
374
374
$ phpcs --report=gitblame /path/to/code
@@ -437,7 +437,7 @@ A TOTAL OF 165 SNIFF VIOLATION(S) WERE COMMITTED BY 5 AUTHOR(S)
437
437
438
438
## Printing a JSON Report
439
439
440
-
PHP_CodeSniffer can output an JSON report to allow you to parse the output and use the results in your own scripts. To print a JSON report, use the `--report=json` command line argument. The output will look like this:
440
+
PHP_CodeSniffer can output a JSON report to allow you to parse the output and use the results in your own scripts. To print a JSON report, use the `--report=json` command line argument. The output will look like this:
441
441
442
442
```bash
443
443
$ phpcs --report=json /path/to/code
@@ -556,7 +556,7 @@ PHP_CodeSniffer can output a sniff performance report showing you which sniffs i
556
556
When the `--colors` option is enabled, sniffs which take more than twice the average run time per sniff will be displayed in orange and sniffs with a cumulative listener run time of more than three times the average run time per sniff will display in red.
557
557
558
558
> [!NOTE]
559
-
> The Performance report will only be useful when run without using the cache as otherwise the cache functionality will interfer with accurately measuring the runtime of sniffs.
559
+
> The Performance report will only be useful when run without using the cache as otherwise the cache functionality will interfere with accurately measuring the runtime of sniffs.
560
560
> So make sure to always use the `--no-cache` feature when running Performance reports.
Copy file name to clipboardExpand all lines: wiki/Version-3.0-Upgrade-Guide.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,7 +292,7 @@ public function generate(
292
292
293
293
### Supporting Concurrency
294
294
295
-
PHP_CodeSniffer version 3 supports processing multiple files concurrently, so reports can no longer rely on getting file results one at a time. Reports that used to write to local member vars can no longer do so as multiple forks of the PHP_CodeSniffer process will all be writing to a different instance of the report class at the same time and these cache values will never be merged. Instead, reports need to output their cached data directly. They will later be given a chance to read in the entire cached output and generate a final clean report.
295
+
PHP_CodeSniffer version 3 supports processing multiple files concurrently, so reports can no longer rely on getting file results one at a time. Reports that used to write to local member variables can no longer do so as multiple forks of the PHP_CodeSniffer process will all be writing to a different instance of the report class at the same time and these cache values will never be merged. Instead, reports need to output their cached data directly. They will later be given a chance to read in the entire cached output and generate a final clean report.
296
296
297
297
> [!NOTE]
298
298
> Reports that output content in a way where the order or formatting is not important do not need to worry about caching data and can continue to produce reports they way they do now. Examples of these reports include the CSV report and the XML report.
Copy file name to clipboardExpand all lines: wiki/Version-4.0-Developer-Upgrade-Guide.md
+12-12Lines changed: 12 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ There is a separate [[Upgrade Guide for Ruleset Maintainers and End-Users|Versio
52
52
It is highly recommended to upgrade external standards and integrations as soon as you are able.
53
53
54
54
Once PHP_CodeSniffer 4.0 has been released, the PHP_CodeSniffer 3.x branch will no longer receive updates, with the exception of security fixes and runtime compatibility fixes for new PHP versions.
55
-
This "limited support" will last a maximum of one year from the date of the PHP_Codesniffer 4.0.0 release.
55
+
This "limited support" will last a maximum of one year from the date of the PHP_CodeSniffer 4.0.0 release.
56
56
57
57
> [!IMPORTANT]
58
58
> This also means that support for new PHP syntaxes will only land in PHP_CodeSniffer 4.x and will **NOT** be backported to the 3.x branch.
@@ -64,9 +64,9 @@ There are basically two upgrade strategies:
64
64
1. Drop support for PHP_CodeSniffer 3.x completely and adopt support for PHP_CodeSniffer 4.x.
65
65
2. Make your package cross-version compatible with both PHP_CodeSniffer 3.x as well as 4.x.
66
66
67
-
Which strategy is best suited for your project will depend on your userbase.
67
+
Which strategy is best suited for your project will depend on your user-base.
68
68
69
-
If your userbase is known to often combine multiple external standards, making the package PHPCS cross-version compatible may be preferred to allow users to upgrade as soon as possible, while still benefitting from updates to your package if they can't upgrade to PHPCS 4.x yet.
69
+
If your user-base is known to often combine multiple external standards, making the package PHPCS cross-version compatible may be preferred to allow users to upgrade as soon as possible, while still benefiting from updates to your package if they can't upgrade to PHPCS 4.x yet.
70
70
71
71
The vast majority of the below upgrade tasks will need to be executed in both cases, but there are some upgrade tasks which can only be executed once support for PHP_CodeSniffer 3.x is being dropped.
72
72
@@ -150,10 +150,10 @@ Type casting for sniff property values set from within a ruleset has been made m
150
150
151
151
Search for sniff which have `public` properties which can be changed from within a ruleset.
152
152
153
-
* If the sniff has work-arounds in place to handle non-lowercase string `'true'` or `'false'` values for boolean properties, those work-arounds can be removed.
154
-
* If the sniff has work-arounds in place to handle (any case) string `'null'` values, those work-arounds can be removed.
153
+
* If the sniff has workarounds in place to handle non-lowercase string `'true'` or `'false'` values for boolean properties, those workarounds can be removed.
154
+
* If the sniff has workarounds in place to handle (any case) string `'null'` values, those workarounds can be removed.
155
155
* If the sniff explicitly expects only string values for array elements, the sniff may need to be updated.
156
-
* If the sniff has work-arounds in place to handle the type casting of `true`, `false` and/or `null` for array elements, those work-arounds can be removed.
156
+
* If the sniff has workarounds in place to handle the type casting of `true`, `false` and/or `null` for array elements, those workarounds can be removed.
157
157
158
158
<palign="right"><ahref="#table-of-contents">back to top</a></p>
159
159
@@ -228,8 +228,8 @@ Typically, this may impact projects which call `new Config` consecutive times pr
228
228
229
229
##### Upgrading
230
230
231
-
Typical work-arounds for the old behaviour will use `Reflection` to reset the `Config::$overriddenDefaults` property between instantiations.
232
-
These type of work-arounds can now be removed.
231
+
Typical workarounds for the old behaviour will use `Reflection` to reset the `Config::$overriddenDefaults` property between instantiations.
232
+
These type of workarounds can now be removed.
233
233
234
234
<p align="right"><a href="#table-of-contents">back to top</a></p>
235
235
@@ -304,7 +304,7 @@ The following tokens have been removed:
304
304
305
305
If these tokens are used in PHP-only sniffs, they can be safely removed.
306
306
If these tokens are used in JS/CSS only sniffs, as mentioned in ["Support for JS/CSS has been removed"](#support-for-jscss-has-been-removed): deprecate or remove the sniff.
307
-
If these tokens are used in mixed sniffs, which also scan PHP files, remove the CSS/JS specific code or, for cross-version compatibility, check for the existance of the tokens before using them.
307
+
If these tokens are used in mixed sniffs, which also scan PHP files, remove the CSS/JS specific code or, for cross-version compatibility, check for the existence of the tokens before using them.
308
308
309
309
<p align="right"><a href="#table-of-contents">back to top</a></p>
310
310
@@ -366,7 +366,7 @@ This re-tokenization has now been removed.
366
366
367
367
##### Upgrading
368
368
369
-
* Search your sniffs/code for `T_INSTANCEOF` and `'static'` to find any potential work-arounds in place for the old tokenization. Those can now be removed.
369
+
* Search your sniffs/code for `T_INSTANCEOF` and `'static'` to find any potential workarounds in place for the old tokenization. Those can now be removed.
370
370
371
371
<p align="right"><a href="#table-of-contents">back to top</a></p>
372
372
@@ -563,9 +563,9 @@ The Ruleset class now respects sniff selection via `--sniffs=...`, even when in
563
563
564
564
#### Upgrading
565
565
566
-
If your own test framework contained work-arounds to get round the previous restriction, it should now be safe to remove those work-arounds and to use the `--sniffs=...` argument when initiating the `Config` class.
566
+
If your own test framework contained workarounds to get round the previous restriction, it should now be safe to remove those workarounds and to use the `--sniffs=...` argument when initiating the `Config` class.
567
567
568
-
Typically, these type of work-around can be found by searching for calls to the `Ruleset::registerSniffs()` method.
568
+
Typically, these type of workarounds can be found by searching for calls to the `Ruleset::registerSniffs()` method.
569
569
570
570
<palign="right"><ahref="#table-of-contents">back to top</a></p>
0 commit comments