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
The information about the `Diff` report was included in the "Fixing errors automatically" page, but is kind of dated as the `phpcbf` script has by now existed for a fair number of years.
This changes the "Fixing errors" page to focus on the `phpcbf` tool and moves the information about the "Diff" report to the "Reporting" page.
PHP_CodeSniffer is able to fix many errors and warnings automatically. The `diff` report can be used to generate a diff that can be applied using the `patch` command. Alternatively, the PHP Code Beautifier and Fixer (`phpcbf`) can be used instead of `phpcs` to automatically generate and apply the diff for you.
11
+
PHP_CodeSniffer is able to fix many errors and warnings automatically. The PHP Code Beautifier and Fixer (`phpcbf`) can be used instead of `phpcs` to automatically generate and apply the fixes for you.
13
12
14
-
Screen-based reports, such as the [full](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports), [summary](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports) and [source](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-a-source-report) reports, provide information about how many errors and warnings are found. If any of the issues can be fixed automatically by `phpcbf`, additional information will be printed:
13
+
Screen-based reports, such as the [full](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports), [summary](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-full-and-summary-reports) and [source](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Reporting#printing-a-source-report) reports, provide information about how many errors and warnings are found. If any of the issues can be fixed automatically by `phpcbf`, this will be annotated in the report with the `[x]` markings:
15
14
16
15
```bash
17
16
$ phpcs /path/to/code/myfile.php
@@ -34,45 +33,9 @@ PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
34
33
<palign="right"><ahref="#table-of-contents">back to top</a></p>
35
34
36
35
37
-
## Printing a Diff Report
38
-
39
-
PHP_CodeSniffer can output a diff file that can be applied using the `patch` command. The suggested changes will fix some of the sniff violations that are present in the source code. To print a diff report, use the `--report=diff` command line argument. The output will look like this:
40
-
41
-
```bash
42
-
$ phpcs --report=diff /path/to/code
43
-
44
-
--- /path/to/code/file.php
45
-
+++ PHP_CodeSniffer
46
-
@@ -1,8 +1,8 @@
47
-
<?php
48
-
49
-
-if ($foo === FALSE) {
50
-
+if ($foo === false) {
51
-
+ echo'hi';
52
-
echo'hi';
53
-
- echo'hi';
54
-
}
55
-
56
-
functionfoo() {
57
-
```
58
-
59
-
Diff reports are more straight-forward to use when output to a file. They can then be applied using the `patch` command:
> The `*nix``diff`command is required forgenerating reportsin`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`.
69
-
70
-
<p align="right"><a href="#table-of-contents">back to top</a></p>
71
-
72
-
73
36
## Using the PHP Code Beautifier and Fixer
74
37
75
-
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.
38
+
To automatically fix as many sniff violations as possible, use the `phpcbf` command instead 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.
<p align="right"><a href="#table-of-contents">back to top</a></p>
300
300
301
301
302
+
## Printing a Diff Report
303
+
304
+
> [!TIP]
305
+
> Use the [`phpcbf` script](wiki/Fixing-Errors-Automatically) instead to automatically fix scanned files.
306
+
307
+
PHP_CodeSniffer can output a diff file that can be applied using the `patch` command. The suggested changes will fix some of the sniff violations that are present in the source code. To print a diff report, use the `--report=diff` command line argument. The output will look like this:
308
+
309
+
```bash
310
+
$ phpcs --report=diff /path/to/code
311
+
312
+
--- /path/to/code/file.php
313
+
+++ PHP_CodeSniffer
314
+
@@ -1,8 +1,8 @@
315
+
<?php
316
+
317
+
-if ($foo === FALSE) {
318
+
+if ($foo === false) {
319
+
+ echo 'hi';
320
+
echo 'hi';
321
+
- echo 'hi';
322
+
}
323
+
324
+
function foo() {
325
+
```
326
+
327
+
Diff reports are more straight-forward to use when output to a file. They can then be applied using the `patch` command:
> 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`.
337
+
338
+
<p align="right"><a href="#table-of-contents">back to top</a></p>
339
+
340
+
302
341
## Printing an Emacs Report
303
342
304
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:
0 commit comments