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/FAQ.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,30 @@
1
+
## Table of contents
2
+
3
+
*[Does PHP_CodeSniffer perform any code coverage or unit testing?](#does-php_codesniffer-perform-any-code-coverage-or-unit-testing)
4
+
*[My code is fine! Why do I need PHP_CodeSniffer?](#my-code-is-fine-why-do-i-need-php_codesniffer)
5
+
*[Does PHP_CodeSniffer parse my code to ensure it will execute?](#does-php_codesniffer-parse-my-code-to-ensure-it-will-execute)
6
+
*[I don't agree with your coding standards! Can I make PHP_CodeSniffer enforce my own?](#i-dont-agree-with-your-coding-standards-can-i-make-php_codesniffer-enforce-my-own)
7
+
*[How come PHP_CodeSniffer reported errors, I fixed them, now I get even more?](#how-come-php_codesniffer-reported-errors-i-fixed-them-now-i-get-even-more)
8
+
*[What does PHP_CodeSniffer use to tokenize my code?](#what-does-php_codesniffer-use-to-tokenize-my-code)
9
+
10
+
***
11
+
1
12
## Does PHP_CodeSniffer perform any code coverage or unit testing?
2
13
3
14
No. PHP_CodeSniffer is not a tool for testing that your PHP application works correctly. All PHP_CodeSniffer will do is ensure your PHP code meets the standards that you are following.
4
15
16
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
17
+
18
+
5
19
## My code is fine! Why do I need PHP_CodeSniffer?
6
20
7
21
Maybe you don't, but if you want to ensure you adhere to a set of coding standards, PHP_CodeSniffer is a quick and easy way to do that. PHP_CodeSniffer is a replacement for the more manual task of checking coding standards in code reviews. With PHP_CodeSniffer, you can reserve code reviews for the checking of code correctness.
8
22
9
23
Coding standards are a good thing. They will make your code easier to read and maintain, especially when multiple developers are working on the same application. Consider using coding standards if you don't already.
10
24
25
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
26
+
27
+
11
28
## Does PHP_CodeSniffer parse my code to ensure it will execute?
12
29
13
30
No. PHP_CodeSniffer does not actually parse your code, and so cannot accurately tell if your code contains parse errors. PHP_CodeSniffer does know about some parse errors and will warn you if it finds code that it is unable to sniff correctly due to a suspected parse error. However, as there is no actual parsing taking place, PHP_CodeSniffer may return an incorrect number of errors when checking code that does contain parse errors.
No syntax errors detected in /path/to/code/myfile.inc
20
37
```
21
38
39
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
40
+
41
+
22
42
## I don't agree with your coding standards! Can I make PHP_CodeSniffer enforce my own?
23
43
24
44
Yes. At its core, PHP_CodeSniffer is just a framework for enforcing coding standards. PHP_CodeSniffer is released with some sample coding standards to help developers get started on projects where there is no standard defined. If you want to write your own standard, read the tutorial on creating coding standards.
25
45
46
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
47
+
48
+
26
49
## How come PHP_CodeSniffer reported errors, I fixed them, now I get even more?
27
50
28
51
Sometimes, errors mask the existence of other errors, or new errors are created as you fix others. For example, PHP_CodeSniffer might tell you that an inline IF statement needs to be defined with braces. Once you make this change, PHP_CodeSniffer may report that the braces you added are not correctly aligned.
29
52
30
53
Always run PHP_CodeSniffer until you get a passing result. Once you've made the changes PHP_CodeSniffer recommends, run PHP_CodeSniffer again to ensure no new errors have been added.
31
54
55
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
56
+
57
+
32
58
## What does PHP_CodeSniffer use to tokenize my code?
33
59
34
60
For PHP files, PHP_CodeSniffer uses [PHP's inbuilt tokenizer functions](http://www.php.net/tokenizer) to parse your code. It then modifies that output to include much more data about the file, such as matching function braces to function keywords.
35
61
36
62
For all other file types, PHP_CodeSniffer includes a custom tokenizer that either makes use of PHP's inbuilt tokenizer or emulates it. In both cases, the token array must be checked and changed manually before all the standard PHP_CodeSniffer matching rules are applied, making tokenizing a bit slower for these file types.
63
+
64
+
<palign="right"><ahref="#table-of-contents">back to top</a></p>
Copy file name to clipboardExpand all lines: wiki/Fixing-Errors-Automatically.md
+23-1Lines changed: 23 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,15 @@
1
-
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 in place of `phpcs` to automatically generate and apply the diff for you.
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.
2
13
3
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:
4
15
@@ -20,6 +31,9 @@ PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
<palign="right"><ahref="#table-of-contents">back to top</a></p>
35
+
36
+
23
37
## Printing a Diff Report
24
38
25
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:
> 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`.
55
69
70
+
<p align="right"><a href="#table-of-contents">back to top</a></p>
71
+
72
+
56
73
## Using the PHP Code Beautifier and Fixer
57
74
58
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.
@@ -157,6 +174,9 @@ Fixed 2 files
157
174
Time: 2.55 secs, Memory: 25.00Mb
158
175
```
159
176
177
+
<p align="right"><a href="#table-of-contents">back to top</a></p>
178
+
179
+
160
180
## Viewing Debug Information
161
181
162
182
To see the fixes that are being made to a file, specify the `-vv`command line argument when generating a diff report. There is quite a lot of debug output concerning the standard being used and the tokenizing of the file, but the end of the output will look like this:
0 commit comments