Skip to content

Commit 5021c33

Browse files
committed
4.0 | Wiki: updates for change of the default standard from PEAR to PSR12
1 parent d9df730 commit 5021c33

File tree

9 files changed

+40
-44
lines changed

9 files changed

+40
-44
lines changed

.github/workflows/basic-qa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676

7777
# Note: if less issues than expected were found, these numbers should be updated in the PR which fixes the issues!
7878
- name: Fail the build when more spelling issues were found than expected
79-
if: ${{ always() && ( steps.spellcheck.outputs.number_of_issues != 5 || steps.spellcheck.outputs.number_of_files_with_issues != 3 ) }}
79+
if: ${{ always() && ( steps.spellcheck.outputs.number_of_issues != 4 || steps.spellcheck.outputs.number_of_files_with_issues != 2 ) }}
8080
run: exit 1
8181

8282
shellcheck:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* File docblock.
4+
*/
5+
6+
namespace Foo;
7+
8+
class Bar {
9+
public function baz(Type $param)
10+
{
11+
echo 'hello' . 'world and a lot more text to make this line way too long - trying to reach 120 characters, but that takes work';
12+
return FALSE;
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
NAMESPACE Foo;
4+
5+
if ($foo) {
6+
} else if ($bar) {
7+
}

wiki/About-Standards-for-PHP_CodeSniffer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ You may also find the [Customisable Sniff Properties](https://github.com/PHPCSSt
5050
3. If no (project) ruleset file is found, PHP_CodeSniffer will check if a default standard has been set via `--config-set default_standard [Name]`.
5151
If so, PHP_CodeSniffer will use that standard.
5252
:warning: Setting the default standard is a user-specific setting, so should not be relied upon.
53-
4. If no system-default standard was set, PHP_CodeSniffer will apply the PEAR standard.
53+
4. If no system-default standard was set, PHP_CodeSniffer will apply the PSR12 standard.
5454

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

wiki/Advanced-Usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ To view the currently set configuration options, use the `--config-show` command
326326
$ phpcs --config-show
327327
Array
328328
(
329-
[default_standard] => PEAR
329+
[default_standard] => PSR12
330330
[report_width] => 150
331331
)
332332
```

wiki/Configuration-Options.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
## Setting the default coding standard
99

10-
By default, PHP_CodeSniffer will use the PEAR coding standard if no standard is supplied on the command line. You can change the default standard by setting the `default_standard` configuration option.
10+
By default, PHP_CodeSniffer will use the PSR12 coding standard if no standard is supplied on the command line. You can change the default standard by setting the `default_standard` configuration option.
1111

1212
```bash
1313
$ phpcs --config-set default_standard Squiz
@@ -16,6 +16,9 @@ $ phpcs --config-set default_standard Squiz
1616
> [!NOTE]
1717
> This configuration option cannot be set using the `--runtime-set` command line argument. To set the coding standard for a single run only, use the `--standard` command line argument.
1818
19+
> [!NOTE]
20+
> Prior to PHP_CodeSniffer 4.0.0, PHP_CodeSniffer would default to the PEAR coding standard.
21+
1922
<p align="right"><a href="#table-of-contents">back to top</a></p>
2023

2124

wiki/Home.md

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,21 @@ PHP_CodeSniffer is an essential development tool that ensures your code remains
66

77
A coding standard in PHP_CodeSniffer is a collection of sniff files. Each sniff file checks one part of the coding standard only. Each sniff can yield multiple error codes, a different one for each aspect of the code which was checked and found non-compliant.
88

9-
Multiple coding standards can be used within PHP_CodeSniffer so that the one installation can be used across multiple projects. The default coding standard used by PHP_CodeSniffer is the PEAR coding standard.
9+
Multiple coding standards can be used within PHP_CodeSniffer so that the one installation can be used across multiple projects.
10+
As of PHP_CodeSniffer 4.0.0, the default coding standard used by PHP_CodeSniffer is the PSR12 coding standard (previously, this was the PEAR standard).
1011

1112
## Example
1213

13-
To check a file against the PEAR coding standard, simply specify the file's location.
14+
To check a file against the PSR12 coding standard, simply specify the file's location.
1415

1516
```bash
16-
$ phpcs /path/to/code/myfile.php
17-
18-
FILE: /path/to/code/myfile.php
19-
--------------------------------------------------------------------------------
20-
FOUND 5 ERROR(S) AFFECTING 2 LINE(S)
21-
--------------------------------------------------------------------------------
22-
2 | ERROR | Missing file doc comment
23-
20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
24-
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
25-
51 | ERROR | Missing function doc comment
26-
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
27-
--------------------------------------------------------------------------------
17+
$ phpcs path/to/code/fileA.php
18+
{{COMMAND-OUTPUT "phpcs --parallel=1 --basepath=build/wiki-code-samples/home --no-colors build/wiki-code-samples/home/path/to/code/fileA.php"}}
2819
```
2920

3021
Or, if you wish to check an entire directory, you can specify the directory location instead of a file.
3122

3223
```bash
3324
$ phpcs /path/to/code
34-
35-
FILE: /path/to/code/myfile.php
36-
--------------------------------------------------------------------------------
37-
FOUND 5 ERROR(S) AFFECTING 5 LINE(S)
38-
--------------------------------------------------------------------------------
39-
2 | ERROR | Missing file doc comment
40-
20 | ERROR | PHP keywords must be lowercase; expected "false" but found "FALSE"
41-
47 | ERROR | Line not indented correctly; expected 4 spaces but found 1
42-
51 | ERROR | Missing function doc comment
43-
88 | ERROR | Line not indented correctly; expected 9 spaces but found 6
44-
--------------------------------------------------------------------------------
45-
46-
FILE: /path/to/code/yourfile.php
47-
--------------------------------------------------------------------------------
48-
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
49-
--------------------------------------------------------------------------------
50-
21 | ERROR | PHP keywords must be lowercase; expected "false" but found
51-
| | "FALSE"
52-
21 | WARNING | Equals sign not aligned with surrounding assignments
53-
--------------------------------------------------------------------------------
25+
{{COMMAND-OUTPUT "phpcs --parallel=1 --basepath=build/wiki-code-samples/home --no-colors build/wiki-code-samples/home/path/to/code"}}
5426
```

wiki/Reporting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ To use PHP_CodeSniffer with Emacs, make sure you have installed PHP mode for Ema
357357
```emacs
358358
(require 'compile)
359359
(defun my-php-hook-function ()
360-
(set (make-local-variable 'compile-command) (format "phpcs --report=emacs --standard=PEAR %s" (buffer-file-name))))
360+
(set (make-local-variable 'compile-command) (format "phpcs --report=emacs --standard=PSR12 %s" (buffer-file-name))))
361361
(add-hook 'php-mode-hook 'my-php-hook-function)
362362
```
363363

wiki/Usage.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Running PHP_CodeSniffer with the `-h` or `--help` command line arguments will pr
1414
```
1515

1616
> [!NOTE]
17-
> The `--standard` command line argument is optional, even if you have more than one coding standard installed. If no coding standard is specified, PHP_CodeSniffer will default to checking against the _PEAR_ coding standard, or the standard you have set as the default. [View instructions for setting the default coding standard](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-default-coding-standard).
17+
> The `--standard` command line argument is optional, even if you have more than one coding standard installed. If no coding standard is specified, PHP_CodeSniffer will default to checking against the _PSR12_ coding standard, or the standard you have set as the default. [View instructions for setting the default coding standard](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-default-coding-standard).
1818
1919
<p align="right"><a href="#table-of-contents">back to top</a></p>
2020

@@ -148,7 +148,7 @@ With verbose output enabled, PHP_CodeSniffer will print the file that it is chec
148148
```bash
149149
$ phpcs /path/to/code/CodeSniffer -v
150150

151-
Registering sniffs in PEAR standard... DONE (28 sniffs registered)
151+
Registering sniffs in PSR12 standard... DONE (60 sniffs registered)
152152
Creating file list... DONE (158 files in queue)
153153
Changing into directory src/Standards/Generic/Sniffs/Arrays
154154
Processing ArrayIndentSniff.php [1409 tokens in 193 lines]... DONE in 39ms (4 errors, 20 warnings)
@@ -167,10 +167,10 @@ Processing OpeningBraceSameLineSniff.php [936 tokens in 123 lines]... DONE in 26
167167

168168
PHP_CodeSniffer can have multiple coding standards installed to allow a single installation to be used with multiple projects. When checking PHP code, PHP_CodeSniffer can be told which coding standard to use. This is done using the `--standard` command line argument.
169169

170-
The example below checks the `myfile.inc` file for violations against the _PEAR_ coding standard (installed by default).
170+
The example below checks the `myfile.inc` file for violations against the _PSR12_ coding standard (installed by default).
171171

172172
```bash
173-
$ phpcs --standard=PEAR /path/to/code/myfile.inc
173+
$ phpcs --standard=PSR12 /path/to/code/myfile.inc
174174
```
175175

176176
You can also tell PHP_CodeSniffer to use an external standard by specifying the full path to the standard's root directory on the command line. An external standard is one that is stored outside of PHP_CodeSniffer's `Standards` directory.
@@ -182,7 +182,7 @@ $ phpcs --standard=/path/to/MyStandard /path/to/code/myfile.inc
182182
Multiple coding standards can be checked at the same time by passing a list of comma separated standards on the command line. A mix of external and installed coding standards can be passed if required.
183183

184184
```bash
185-
$ phpcs --standard=PEAR,Squiz,/path/to/MyStandard /path/to/code/myfile.inc
185+
$ phpcs --standard=PSR12,Squiz,/path/to/MyStandard /path/to/code/myfile.inc
186186
```
187187

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

0 commit comments

Comments
 (0)