Skip to content

Commit bc64ea7

Browse files
committed
Fixing errors/Reporting: move Diff report info
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.
1 parent 9fbac4f commit bc64ea7

File tree

2 files changed

+43
-41
lines changed

2 files changed

+43
-41
lines changed

wiki/Fixing-Errors-Automatically.md

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
## Table of contents
22

33
* [About Automatic Fixing](#about-automatic-fixing)
4-
* [Printing a Diff Report](#printing-a-diff-report)
54
* [Using the PHP Code Beautifier and Fixer](#using-the-php-code-beautifier-and-fixer)
65
* [Viewing Debug Information](#viewing-debug-information)
76

87
***
98

109
## About Automatic Fixing
1110

12-
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.
1312

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:
1514

1615
```bash
1716
$ phpcs /path/to/code/myfile.php
@@ -34,45 +33,9 @@ PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
3433
<p align="right"><a href="#table-of-contents">back to top</a></p>
3534

3635

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-
function foo() {
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:
60-
61-
```bash
62-
$ phpcs --report-diff=/path/to/changes.diff /path/to/code
63-
$ patch -p0 -ui /path/to/changes.diff
64-
patching file /path/to/code/file.php
65-
```
66-
67-
> [!NOTE]
68-
> 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`.
69-
70-
<p align="right"><a href="#table-of-contents">back to top</a></p>
71-
72-
7336
## Using the PHP Code Beautifier and Fixer
7437

75-
To automatically fix as many sniff violations as possible, use the `phpcbf` command in 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.
7639
```text
7740
Usage:
7841
phpcbf [options] <file|directory>

wiki/Reporting.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* [Checkstyle](#printing-a-checkstyle-report)
66
* [Code](#printing-a-code-report)
77
* [CSV](#printing-a-csv-report)
8-
* Diff
8+
* [Diff](#printing-a-diff-report)
99
* [Emacs](#printing-an-emacs-report)
1010
* [Git Blame](#printing-a-git-blame-report)
1111
* HG Blame
@@ -299,6 +299,45 @@ File,Line,Column,Type,Message,Source,Severity,Fixable
299299
<p align="right"><a href="#table-of-contents">back to top</a></p>
300300
301301
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:
328+
329+
```bash
330+
$ phpcs --report-diff=/path/to/changes.diff /path/to/code
331+
$ patch -p0 -ui /path/to/changes.diff
332+
patching file /path/to/code/file.php
333+
```
334+
335+
> [!NOTE]
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/` subdirectory to the Windows system `PATH`.
337+
338+
<p align="right"><a href="#table-of-contents">back to top</a></p>
339+
340+
302341
## Printing an Emacs Report
303342
304343
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

Comments
 (0)