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
*[Potential Support Questions from your End-Users](#potential-support-questions-from-your-end-users)
27
28
*[Contributing](#contributing)
28
29
*[License](#license)
29
30
30
31
31
32
Features
32
33
-------------------------------------------
33
34
34
-
[PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils) is a set of utilities to aid developers of sniffs for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
35
+
[PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils) is a set of utilities to aid developers of sniffs for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) (or "PHPCS" for short).
35
36
36
37
This package offers the following features:
37
38
@@ -47,14 +48,14 @@ Now you won't have to anymore. This package allows you to use the latest version
47
48
48
49
These classes take most of the heavy lifting away for some frequently occurring sniff types.
49
50
50
-
### A collection of static properties for often-used token groups.
51
+
### A collection of static properties and methods for often-used token groups.
51
52
52
53
Collections of related tokens often-used and needed for sniffs.
53
54
These are additional "token groups" to compliment the ones available through the PHPCS native `PHP_CodeSniffer\Util\Tokens` class.
54
55
55
56
### An ever-growing number of utility functions for use with PHP_CodeSniffer.
56
57
57
-
Whether you need to split an `array` into the individual items, are trying to determine which variables are being assigned to in a `list()` or are figuring out whether a function has a DocBlock, PHPCSUtils has you covered!
58
+
Whether you need to split an `array` into the individual items, are trying to determine which variables are being assigned to in a `list()` or are figuring out whether a function has a DocBlock, PHPCSUtils has got you covered!
58
59
59
60
Includes improved versions of the PHPCS native utility functions and plenty of new utility functions.
60
61
@@ -80,6 +81,8 @@ Minimum Requirements
80
81
81
82
* PHP 5.4 or higher.
82
83
*[PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 2.6.0+, 3.1.0+ (with the exception of PHPCS 3.5.3).
84
+
* Recommended PHP extensions for optimal functionality:
85
+
- PCRE with Unicode support (normally enabled by default)
83
86
84
87
85
88
Integrating PHPCSUtils in your external PHPCS standard
@@ -121,7 +124,7 @@ In addition to that, add the following to the `ruleset.xml` file of your standar
121
124
<ruleref="PHPCS23Utils"/>
122
125
```
123
126
124
-
> :information_source: The `PHPCS23Utils` "standard" does not add any real sniffs, it just makes sure that the Utility functions will work in PHPCS 2.x as well.
127
+
> :information_source: The `PHPCS23Utils` "standard" does not add any real sniffs, it only makes sure that the Utility functions will work in PHPCS 2.x as well.
125
128
126
129
#### Running your unit tests
127
130
@@ -223,7 +226,7 @@ Frequently Asked Questions
223
226
224
227
#### Q: How does this all work without an external standard needing to register an autoloader?
225
228
226
-
A: As PHPCSUtils is registered with PHPCS as an external standard and PHPCSUtils complies with the naming requirements of PHPCS, the PHPCS native autoloader will automatically take care of loading the classes you use from PHPCSUtils.
229
+
A: As PHPCSUtils is registered with PHPCS as an external standard and PHPCSUtils complies with the naming requirements of PHPCS, the PHPCS native autoloader will automatically take care of loading the classes used from PHPCSUtils.
227
230
228
231
#### Q: What does the `PHPCS23Utils` standard do?
229
232
@@ -237,8 +240,58 @@ A: The backfill for PHP 7.4 numeric literals with underscores in PHP_CodeSniffer
237
240
238
241
The backfill was fixed in PHP_CodeSniffer 3.5.4.
239
242
243
+
#### Q: Any other problematic PHPCS versions?
244
+
245
+
A: Well, the arrow function backfill which was added in PHPCS 3.5.3 is still causing problems. In a very limited set of circumstances, it will even hang the Tokenizer. A fix for [one particular such problem](https://github.com/squizlabs/php_codesniffer/issues/2926) has been committed to `master`, but is not (yet) in a released version. It is expected to be released in PHP_CodeSniffer 3.5.6.
246
+
247
+
As the Tokenizer hanging is a problem unrelated to PHPCSUtils and not something which can be mitigated from within PHPCSUtils in any conceivable way, PHPCSUtils won't block installation in combination with PHPCS 3.5.4 and 3.5.5.
248
+
249
+
There are several other issues which can not be worked around, like scope closers being set incorrectly and throwing the scope setting off for the rest of the file, so not withstanding that PHPCSUtils can work around a lot of issues, it is still highly recommended to advise your end-users to always use the latest version of PHPCS for the most reliable results.
250
+
251
+
#### Q: Does using PHPCSUtils have any effect on the PHPCS native sniffs?
252
+
253
+
A: No. PHPCSUtils will only work for those sniffs which explicitly use the PHPCSUtils functionality.
254
+
255
+
If your standard includes both PHPCS native sniffs as well as your own sniffs, your own sniffs can benefit from the back-compat layer offered by PHPCSUtils, as well as from the additional utility functions. However, the PHPCS native sniffs will not receive those benefits, as PHPCS itself does not use PHPCSUtils.
256
+
257
+
#### Q: Do the utilities work with javascript/CSS files?
258
+
259
+
A: JS/CSS support will be removed from PHP_CodeSniffer in PHPCS 4.x.
260
+
While at this time, some of the utilies _may_ work with JS/CSS files, PHPCSUtils does not offer formal support for JS/CSS sniffing with PHP_CodeSniffer and will stop any existing support once PHPCS 4.x has been released.
261
+
262
+
#### Q: Are all file encodings supported?
263
+
264
+
A: No. The UTF-8 file encoding is the only officially supported encoding. Support for other encodings may incidentally work, but is not officially supported.
265
+
266
+
>**It is recommended to advise your users to save their files as UTF-8 encoded for the best results.**
267
+
268
+
PHP_CodeSniffer 3.x will default to UTF-8 as the expected file encoding.
269
+
If your standard supports PHP_CodeSniffer 2.x, it is recommended to set the expected encoding in the ruleset to `utf-8`, like so: `<arg name="encoding" value="utf-8"/>` or to advise users to use the CLI option `--encoding=utf-8`.
270
+
271
+
272
+
Potential Support Questions from your End-Users
273
+
-------
274
+
275
+
#### Q: A user reports a fatal "class not found" error for a class from PHPCSUtils.
276
+
277
+
1. Check that the version of PHPCSUtils the user has installed complies with the minimum version of PHPCSUtils your standard requires. If not, they will need to upgrade.
278
+
2. If the version is correct, this indicates that the end-user does not have PHPCSUtils installed and/or registered with PHP_CodeSniffer.
279
+
- Please review your standard's installation instructions to make sure that PHPCSUtils will be installed when those are followed.
280
+
- Inform the user to install PHPCSUtils and register it with PHP_CodeSniffer.
281
+
282
+
> :bulb: **Pro-tip**: if you want to prevent the fatal error and show a _friendlier_ error message instead, add `<rule ref="PHPCSUtils"/>` to your standard's `ruleset.xml` file.
283
+
>
284
+
> With that in place, PHP_CodeSniffer will show a _"ERROR: the "PHPCSUtils" coding standard is not installed."_ message if PHPCSUtils is missing as soon as the ruleset loading is finished.
285
+
286
+
> :bulb: **Pro-tip**: provide upgrade instructions for your end-users. For Composer-based installs, those should look like this:
Copy file name to clipboardExpand all lines: docs/index.md
+56-5Lines changed: 56 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ seo:
12
12
Features
13
13
-------------------------------------------
14
14
15
-
[PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils) is a set of utilities to aid developers of sniffs for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
15
+
[PHPCSUtils](https://github.com/PHPCSStandards/PHPCSUtils) is a set of utilities to aid developers of sniffs for [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) (or "PHPCS" for short).
16
16
17
17
This package offers the following features:
18
18
@@ -28,14 +28,14 @@ Now you won't have to anymore. This package allows you to use the latest version
28
28
29
29
These classes take most of the heavy lifting away for some frequently occurring sniff types.
30
30
31
-
### A collection of static properties for often-used token groups.
31
+
### A collection of static properties and methods for often-used token groups.
32
32
33
33
Collections of related tokens often-used and needed for sniffs.
34
34
These are additional "token groups" to compliment the ones available through the PHPCS native `PHP_CodeSniffer\Util\Tokens` class.
35
35
36
36
### An ever-growing number of utility functions for use with PHP_CodeSniffer.
37
37
38
-
Whether you need to split an `array` into the individual items, are trying to determine which variables are being assigned to in a `list()` or are figuring out whether a function has a DocBlock, PHPCSUtils has you covered!
38
+
Whether you need to split an `array` into the individual items, are trying to determine which variables are being assigned to in a `list()` or are figuring out whether a function has a DocBlock, PHPCSUtils has got you covered!
39
39
40
40
Includes improved versions of the PHPCS native utility functions and plenty of new utility functions.
41
41
@@ -61,6 +61,8 @@ Minimum Requirements
61
61
62
62
* PHP 5.4 or higher.
63
63
*[PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 2.6.0+, 3.1.0+ (with the exception of PHPCS 3.5.3).
64
+
* Recommended PHP extensions for optimal functionality:
65
+
- PCRE with Unicode support (normally enabled by default)
64
66
65
67
66
68
Integrating PHPCSUtils in your external PHPCS standard
@@ -102,7 +104,7 @@ In addition to that, add the following to the `ruleset.xml` file of your standar
102
104
<ruleref="PHPCS23Utils"/>
103
105
```
104
106
105
-
> :information_source: The `PHPCS23Utils` "standard" does not add any real sniffs, it just makes sure that the Utility functions will work in PHPCS 2.x as well.
107
+
> :information_source: The `PHPCS23Utils` "standard" does not add any real sniffs, it only makes sure that the Utility functions will work in PHPCS 2.x as well.
106
108
107
109
#### Running your unit tests
108
110
@@ -119,7 +121,7 @@ Frequently Asked Questions
119
121
120
122
#### Q: How does this all work without an external standard needing to register an autoloader?
121
123
122
-
A: As PHPCSUtils is registered with PHPCS as an external standard and PHPCSUtils complies with the naming requirements of PHPCS, the PHPCS native autoloader will automatically take care of loading the classes you use from PHPCSUtils.
124
+
A: As PHPCSUtils is registered with PHPCS as an external standard and PHPCSUtils complies with the naming requirements of PHPCS, the PHPCS native autoloader will automatically take care of loading the classes used from PHPCSUtils.
123
125
124
126
#### Q: What does the `PHPCS23Utils` standard do?
125
127
@@ -133,8 +135,57 @@ A: The backfill for PHP 7.4 numeric literals with underscores in PHP_CodeSniffer
133
135
134
136
The backfill was fixed in PHP_CodeSniffer 3.5.4.
135
137
138
+
#### Q: Any other problematic PHPCS versions?
139
+
140
+
A: Well, the arrow function backfill which was added in PHPCS 3.5.3 is still causing problems. In a very limited set of circumstances, it will even hang the Tokenizer. A fix for [one particular such problem](https://github.com/squizlabs/php_codesniffer/issues/2926) has been committed to `master`, but is not (yet) in a released version. It is expected to be released in PHP_CodeSniffer 3.5.6.
141
+
142
+
As the Tokenizer hanging is a problem unrelated to PHPCSUtils and not something which can be mitigated from within PHPCSUtils in any conceivable way, PHPCSUtils won't block installation in combination with PHPCS 3.5.4 and 3.5.5.
143
+
144
+
There are several other issues which can not be worked around, like scope closers being set incorrectly and throwing the scope setting off for the rest of the file, so not withstanding that PHPCSUtils can work around a lot of issues, it is still highly recommended to advise your end-users to always use the latest version of PHPCS for the most reliable results.
145
+
146
+
#### Q: Does using PHPCSUtils have any effect on the PHPCS native sniffs?
147
+
148
+
A: No. PHPCSUtils will only work for those sniffs which explicitly use the PHPCSUtils functionality.
149
+
150
+
If your standard includes both PHPCS native sniffs as well as your own sniffs, your own sniffs can benefit from the back-compat layer offered by PHPCSUtils, as well as from the additional utility functions. However, the PHPCS native sniffs will not receive those benefits, as PHPCS itself does not use PHPCSUtils.
151
+
152
+
#### Q: Do the utilities work with javascript/CSS files?
153
+
154
+
A: JS/CSS support will be removed from PHP_CodeSniffer in PHPCS 4.x.
155
+
While at this time, some of the utilies _may_ work with JS/CSS files, PHPCSUtils does not offer formal support for JS/CSS sniffing with PHP_CodeSniffer and will stop any existing support once PHPCS 4.x has been released.
156
+
157
+
#### Q: Are all file encodings supported?
158
+
159
+
A: No. The UTF-8 file encoding is the only officially supported encoding. Support for other encodings may incidentally work, but is not officially supported.
160
+
161
+
> **It is recommended to advise your users to save their files as UTF-8 encoded for the best results.**
162
+
163
+
PHP_CodeSniffer 3.x will default to UTF-8 as the expected file encoding.
164
+
If your standard supports PHP_CodeSniffer 2.x, it is recommended to set the expected encoding in the ruleset to `utf-8`, like so: `<arg name="encoding" value="utf-8"/>` or to advise users to use the CLI option `--encoding=utf-8`.
165
+
166
+
167
+
Potential Support Questions from your End-Users
168
+
-------
169
+
170
+
#### Q: A user reports a fatal "class not found" error for a class from PHPCSUtils.
171
+
172
+
1. Check that the version of PHPCSUtils the user has installed complies with the minimum version of PHPCSUtils your standard requires. If not, they will need to upgrade.
173
+
2. If the version is correct, this indicates that the end-user does not have PHPCSUtils installed and/or registered with PHP_CodeSniffer.
174
+
- Please review your standard's installation instructions to make sure that PHPCSUtils will be installed when those are followed.
175
+
- Inform the user to install PHPCSUtils and register it with PHP_CodeSniffer.
176
+
177
+
> :bulb:**Pro-tip**: if you want to prevent the fatal error and show a _friendlier_ error message instead, add `<rule ref="PHPCSUtils"/>` to your standard's `ruleset.xml` file.
178
+
>
179
+
> With that in place, PHP_CodeSniffer will show a _"ERROR: the "PHPCSUtils" coding standard is not installed."_ message if PHPCSUtils is missing as soon as the ruleset loading is finished.
180
+
181
+
> :bulb:**Pro-tip**: provide upgrade instructions for your end-users. For Composer-based installs, those should look like this:
0 commit comments