@@ -15,7 +15,7 @@ the coding standards can be checked via:
15
15
vendor/bin/phpcs --standard=" Inpsyde" < path>
16
16
```
17
17
18
- Where ` <path> ` is at least one file or directory to check, e.g. :
18
+ Here, ` <path> ` is at least one file or directory to check, for example :
19
19
20
20
``` shell
21
21
vendor/bin/phpcs --standard=" Inpsyde" ./src/ ./my-plugin.php
@@ -30,7 +30,7 @@ vendor/bin/phpcs --help
30
30
31
31
## Configuration File
32
32
33
- A ` phpcs.xml.dist ` can be used to avoid passing many arguments via command line.
33
+ A ` phpcs.xml.dist ` file can be used to avoid passing many arguments via the command line.
34
34
For example:
35
35
36
36
``` xml
@@ -47,11 +47,11 @@ For example:
47
47
48
48
<config name =" testVersion" value =" 7.4-" />
49
49
<config name =" text_domain" value =" my-project" />
50
-
50
+
51
51
<rule ref =" Inpsyde" >
52
- <exclude name =" WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize" />
52
+ <exclude name =" WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize" />
53
53
</rule >
54
-
54
+
55
55
<rule ref =" Inpsyde.CodeQuality.Psr4" >
56
56
<properties >
57
57
<property
@@ -67,55 +67,57 @@ For example:
67
67
</ruleset >
68
68
```
69
69
70
- Such a configuration allows to run the code style check with only :
70
+ Such a configuration allows to run the code style check like so :
71
71
72
72
``` shell
73
73
vendor/bin/phpcs
74
74
```
75
75
76
- Moreover, thanks to the ` text_domain ` setting, Code Sniffer will also check that all WP
76
+ Moreover, thanks to the ` text_domain ` setting, PHP_CodeSniffer will also check that all WordPress
77
77
internationalization functions are called with the proper text domain.
78
78
79
79
---
80
80
81
81
# Included rules
82
82
83
- For the detailed lists of included rules refers to [ `ruleset.xml] ( ./Inpsyde/ruleset.xml ) .
83
+ For the detailed lists of included rules, refer to [ ` ruleset.xml ` ] ( ./Inpsyde/ruleset.xml ) .
84
84
85
85
## PSR-1, PSR-2, PSR-12
86
86
87
- See https://www.php-fig.org/psr/psr-1 , https://www.php-fig.org/psr/psr-2 ,
88
- https://www.php-fig.org/psr/psr-12
87
+ For more information about included rules from PHP Standards Recommendations (PSR), refer to the
88
+ official documentation:
89
+
90
+ - [ PSR-1] ( https://www.php-fig.org/psr/psr-1 )
91
+ - [ PSR-2] ( https://www.php-fig.org/psr/psr-2 )
92
+ - [ PSR-12] ( https://www.php-fig.org/psr/psr-12 )
89
93
90
- ## WordPress Coding Standard
94
+ ## WordPress Coding Standards
91
95
92
- To ensure code quality, and compatibility with wp.com VIP, several WordPress Coding Standard rules
93
- have been"cherry-picked" from
94
- [ WP coding standards ] ( https://github.com/WordPress-Coding-Standards /WordPress-Coding-Standards ) and
95
- [ VIP coding standard ] ( https://github.com/Automattic/VIP-Coding-Standards/ )
96
+ To ensure code quality, and compatibility with WordPress VIP, some rules have been included from:
97
+
98
+ - [ WordPress Coding Standards ] ( https://github.com/WordPress/WordPress-Coding-Standards )
99
+ - [ VIP Coding Standards ] ( https://github.com/Automattic/VIP-Coding-Standards )
96
100
97
101
## Slevomat
98
102
99
- A few rules are cherry-picked from [ " Slevomat" coding standard ] ( https://github.com/slevomat/coding-standard ) .
103
+ A few rules have been included from the [ Slevomat Coding Standard ] ( https://github.com/slevomat/coding-standard ) .
100
104
101
105
## PHPCompatibility
102
106
103
- See https://github.com/wimg/PHPCompatibility .
104
-
105
- It allows to analyse code for compatibility with higher and lower versions of PHP.
106
- The default target version is PHP 7.0+.
107
+ For PHP cross-version compatibility checks, the full [ PHP Compatibility Coding Standard for PHP CodeSniffer] ( https://github.com/PHPCompatibility/PHPCompatibility )
108
+ standard has been included.
107
109
108
- Target version can be changed via custom ` phpcs.xml ` .
110
+ The target PHP version (range) can be changed via a [ custom ` phpcs.xml ` file ] ( https://github.com/PHPCompatibility/PHPCompatibility/blob/9.3.5/README.md#using-a-custom-ruleset ) .
109
111
110
112
## Generic Rules
111
113
112
- Some rules are also included from PHPCS itself and [ PHPCS Extra ] ( https://github.com/PHPCSStandards/PHPCSExtra ) .
114
+ Some rules are also included from PHP_CodeSniffer itself, as well as [ PHPCSExtra ] ( https://github.com/PHPCSStandards/PHPCSExtra ) .
113
115
114
116
## Custom Rules
115
117
116
- Some custom rules are also in use. They are :
118
+ The following custom rules are in use:
117
119
118
- | Sniff name | Description | Has Config | Auto-Fixable |
120
+ | Sniff Name | Description | Has Config | Auto-Fixable |
119
121
| :---------------------------| :-----------------------------------------------------------------------------------------------| :----------:| :------------:|
120
122
| ` ArgumentTypeDeclaration ` | Enforce argument type declaration. | | |
121
123
| ` DisableCallUserFunc ` | Disable usage of ` call_user_func ` . | | |
@@ -140,7 +142,8 @@ Some custom rules are also in use. They are:
140
142
| ` StaticClosure ` | Points closures that can be ` static ` . | | ✓ |
141
143
| ` VariablesName ` | Check variable (and properties) names | ✓ | |
142
144
143
- For ** notes and configuration** see [ ` /inpsyde-custom-sniffs.md ` ] ( /inpsyde-custom-sniffs.md ) file in this repo.
145
+ For ** notes and configuration** , refer to the [ ` inpsyde-custom-sniffs.md ` ] ( /inpsyde-custom-sniffs.md )
146
+ file in this repository.
144
147
145
148
---
146
149
@@ -153,12 +156,12 @@ The recommended way to use the `InpsydeTemplates` ruleset is as follows:
153
156
154
157
``` xml
155
158
<ruleset >
156
- <file >./src/</file >
157
- <file >./tests</file >
159
+ <file >./src</file >
158
160
<file >./templates</file >
161
+ <file >./tests</file >
159
162
<file >./views</file >
160
163
161
- <rule ref =" Inpsyde" />
164
+ <rule ref =" Inpsyde" />
162
165
163
166
<rule ref =" InpsydeTemplates" >
164
167
<include-pattern >*/templates/*</include-pattern >
@@ -167,137 +170,114 @@ The recommended way to use the `InpsydeTemplates` ruleset is as follows:
167
170
</ruleset >
168
171
```
169
172
170
- The following templates -specific rules are available:
173
+ The following template -specific rules are available:
171
174
172
- | Sniff name | Description | Has Config | Auto-Fixable |
175
+ | Sniff Name | Description | Has Config | Auto-Fixable |
173
176
| :--------------------| :--------------------------------------------------| :----------:| :------------:|
174
177
| ` TrailingSemicolon ` | Remove trailing semicolon before closing PHP tag. | | ✓ |
175
178
176
179
# Removing or Disabling Rules
177
180
178
181
## Rules Tree
179
182
180
- Sometimes it is necessary to don't follow some rules. To avoid error reporting it is possible to:
183
+ Sometimes it is necessary not to follow some rules. To avoid error reporting, it is possible to:
181
184
182
- - Removing rules for an entire project via configuration
183
- - Disabling rules from code, only is specific places
185
+ - remove rules for an entire project via configuration;
186
+ - disable rules from code, only is specific places.
184
187
185
- In both cases it is possible to remove or disable:
188
+ In both cases, it is possible to remove or disable:
186
189
187
- - a whole standard
188
- - a standard subset
189
- - a single sniff
190
- - a single rules
190
+ - a complete standard;
191
+ - a standard subset;
192
+ - a single sniff;
193
+ - a single rule.
191
194
192
- The for things above are in hierarchical relationship: a _ standard _ is made of one or more _ subset _ ,
193
- each subset contains one or more _ sniff _ and each sniff contains one or more rule .
195
+ These things are in a hierarchical relationship: _ standards _ are made of one or more _ subsets _ ,
196
+ which contain one or more _ sniffs _ , which in turn contain one or more _ rules _ .
194
197
195
- ## Remove rules via configuration file
198
+ ## Removing Rules via Configuration File
196
199
197
- Rules can be removed for the entire project by using a custom ` phpcs.xml ` , with a syntax like this:
200
+ Rules can be removed for the entire project by using a custom ` phpcs.xml ` file, like this:
198
201
199
202
``` xml
200
203
<?xml version =" 1.0" ?>
201
204
<ruleset name =" MyProjectCodingStandard" >
202
205
203
- <rule ref =" Inpsyde" >
204
- <exclude name =" PSR1.Classes.ClassDeclaration" />
205
- </rule >
206
+ <rule ref =" Inpsyde" >
207
+ <exclude name =" PSR1.Classes.ClassDeclaration" />
208
+ </rule >
206
209
207
210
</ruleset >
208
211
```
209
212
210
- In the example above, the _ sniff _ ` PSR1.Classes.ClassDeclaration ` (and all the rules it contains)
213
+ In the example above, the ` PSR1.Classes.ClassDeclaration ` sniff (and all the rules it contains)
211
214
has been removed.
212
215
213
- Replacing ` PSR1.Classes.ClassDeclaration ` with just ` PSR1 ` had been possible to
214
- remove the whole standard, while replacing it with ` PSR1.Classes.ClassDeclaration.MultipleClasses `
215
- only the single rule is removed.
216
-
217
- ## Remove rules via code comments
218
-
219
- If it is necessary to remove a rule/sniff/standard subset/standard only in specific place in the
220
- code, it is possible to use special comments that starts with ` // phpcs:disable ` followed by the
221
- name of the sniff to disable.
222
-
223
- For example: ` // phpcs:disable PSR1.Classes.ClassDeclaration ` .
216
+ By using ` PSR1 ` instead of ` PSR1.Classes.ClassDeclaration ` , one would remove the entire ` PSR1 `
217
+ standard, whereas using ` PSR1.Classes.ClassDeclaration.MultipleClasses ` would remove this one rule
218
+ only, but no other rules in the ` PSR1.Classes.ClassDeclaration ` sniff.
224
219
225
- From the point the comment is encountered to the end of the file, the requested rule/sniff/standard
226
- subset/standard is not checked anymore.
220
+ ## Removing Rules via Code Comments
227
221
228
- To re-enable it is necessary to use a similar syntax, but this time using ` phpcs:enable ` instead of
229
- ` phpcs:disable ` .
222
+ Removing a rule/sniff/subset/standard only for a specific file or a part of it can be done by using
223
+ special ` phpcs ` annotations/comments, for example, ` // phpcs:disable ` followed by an optional name
224
+ of a standard/subset/sniff/rule. Like so:
230
225
231
- It is worth noting:
232
-
233
- - ` phpcs:disable ` and ` phpcs:enable ` can be used without specifying the rule name, in this case the
234
- check for * all* rules are disabled/enabled.
235
- - Disabling / enabling comments could be embedded in doc block comments at file/class/method level.
236
- For example:
237
-
238
226
``` php
239
- class Foo
240
- {
241
- /**
242
- * @param mixed $a
243
- * @param mixed $b
244
- *
245
- * phpcs:disable NeutronStandard.Functions.TypeHint.NoArgumentType
246
- */
247
- public function test($a, $b)
248
- {
249
- // phpcs:enable
250
- }
251
- }
227
+ // phpcs:disable PSR1.Classes.ClassDeclaration
252
228
```
253
229
230
+ For more information about ignoring files, please refer to the official [ PHP_CodeSniffer Wiki] ( https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file ) .
231
+
254
232
---
255
233
256
- # IDE integration
234
+ # IDE Integration
257
235
258
236
## PhpStorm
259
237
260
- After having installed the package as explained above in the _ "Installation"_ section,
261
- open PhpStorm settings, and navigate to
238
+ After installing the package as explained above, open PhpStorm settings, and navigate to
262
239
263
240
` Language & Frameworks ` -> ` PHP ` -> ` Quality Tools ` -> ` PHP_CodeSniffer `
264
241
265
242
Choose _ "Local"_ in the _ "Configuration"_ dropdown.
266
243
267
- Click the _ "..."_ button next to the dropdown, it will show a dialog
268
- where you need to specify the path for the Code Sniffer executable.
244
+ Click the _ "..."_ button next to the dropdown. It will show a dialog where you need to specify
245
+ the path for the PHP_CodeSniffer executable.
269
246
270
- Open the file selection dialog, navigate to ` vendor/bin/ ` in your project and select ` phpcs `
271
- ( ` phpcs.bat ` on Windows).
247
+ Open the file selection dialog, navigate to ` vendor/bin/ ` in your project, and select ` phpcs ` .
248
+ On Windows, choose ` phpcs.bat ` .
272
249
273
- Click the _ "Validate"_ button next to the path input field, if everything is fine
274
- a success message will be shown at the bottom of the window.
250
+ Click the _ "Validate"_ button next to the path input field. If everything is working fine, a
251
+ success message will be shown at the bottom of the window.
275
252
276
- Navigate PhpStorm settings to:
253
+ Still in the PhpStorm settings, navigate to:
277
254
278
255
` Editor ` -> ` Inspections `
279
256
280
- Type ` codesniffer ` in the search field before the list of inspections,
281
- select ` PHP ` -> ` Quality Tools ` -> ` PHP_CodeSniffer validation ` and enable it using the checkbox in
282
- the list, press _ "Apply"_ .
257
+ Type ` codesniffer ` in the search field before the list of inspections, then select:
258
+
259
+ ` PHP ` -> ` Quality Tools ` -> ` PHP_CodeSniffer validation `
260
+
261
+ Enable it using the checkbox in the list, press _ "Apply"_ .
283
262
284
- Select _ "PHP_CodeSniffer validation"_ , press the refresh icon next to the _ "Coding standard"_
285
- dropdown on the right and choose ` Inpsyde ` .
263
+ Select _ "PHP_CodeSniffer validation"_ , click the refresh icon next to the _ "Coding standard"_
264
+ dropdown on the right, and choose ` Inpsyde ` .
286
265
287
- If you do not see ` Inpsyde ` here, you may need to specify ` phpcs.xml ` file by selecting _ "Custom" _
288
- as standard and using the _ "..."_ button next to the dropdown.
266
+ If you don't see ` Inpsyde ` here, you may need to specify the ` phpcs.xml ` file by selecting
267
+ _ "Custom" _ as standard and then use the _ "..."_ button next to the dropdown.
289
268
290
- Now PhpStorm integration is complete, and errors in the code style will be shown in the IDE editor
291
- allowing to detect them without running any commands at all .
269
+ Once the PhpStorm integration is complete, warnings and errors in your code will automatically be
270
+ shown in your IDE editor .
292
271
293
272
---
294
273
295
274
# Installation
296
275
297
- Via Composer, require as dev- dependency:
276
+ Via Composer, require as development dependency:
298
277
299
278
``` shell
300
279
composer require " inpsyde/php-coding-standards:^2@dev" --dev
301
280
```
302
281
303
- _ (the ` @dev ` can be removed as soon as the stable 2.0.0 will be released, or if root package minimum stability is "dev")._
282
+ _ (Please note that ` @dev ` can be removed as soon as a stable 2.0.0 version has been released, or if
283
+ your root package minimum stability is ` dev ` )._
0 commit comments