Skip to content

Commit cb5e9e7

Browse files
authored
Merge pull request WordPress#2616 from WordPress/feature/2612-deprecate-posix-sniff
PHP/POSIXFunctions: deprecate the sniff
2 parents 9839cbd + be1faba commit cb5e9e7

File tree

4 files changed

+78
-42
lines changed

4 files changed

+78
-42
lines changed

.github/CONTRIBUTING.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,16 @@ OK (60 tests, 6 assertions)
124124
125125
### Unit Testing conventions
126126
127-
If you look inside the `WordPress/Tests` subdirectory, you'll see the structure mimics the `WordPress/Sniffs` subdirectory structure. For example, the `WordPress/Sniffs/PHP/POSIXFunctionsSniff.php` sniff has its unit test class defined in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.php` which checks the `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc` test case file. See the file naming convention?
127+
If you look inside the `WordPress/Tests` subdirectory, you'll see the structure mimics the `WordPress/Sniffs` subdirectory structure. For example, the `WordPress/Sniffs/PHP/TypeCastsSniff.php` sniff has its unit test class defined in `WordPress/Tests/PHP/TypeCastsUnitTest.php` which checks the `WordPress/Tests/PHP/TypeCastsUnitTest.inc` test case file. See the file naming convention?
128128

129-
Lets take a look at what's inside `POSIXFunctionsUnitTest.php`:
129+
Lets take a look at what's inside `TypeCastsUnitTest.php`:
130130
131131
```php
132132
namespace WordPressCS\WordPress\Tests\PHP;
133133
134134
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
135135
136-
final class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
136+
final class TypeCastsUnitTest extends AbstractSniffUnitTest {
137137
138138
/**
139139
* Returns the lines where errors should occur.
@@ -142,53 +142,54 @@ final class POSIXFunctionsUnitTest extends AbstractSniffUnitTest {
142142
*/
143143
public function getErrorList() {
144144
return array(
145+
10 => 1,
146+
11 => 1,
145147
13 => 1,
146-
16 => 1,
147-
18 => 1,
148-
20 => 1,
149-
22 => 1,
150-
24 => 1,
151148
26 => 1,
149+
27 => 1,
150+
28 => 1,
152151
);
153152
}
154153
155154
...
156155
}
157156
```
158157
159-
Also note the class name convention. The method `getErrorList()` MUST return an array of line numbers indicating errors (when running `phpcs`) found in `WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc`. Similarly, the `getWarningList()` method must return an array of line numbers with the number of expected warnings.
158+
Also note the class name convention. The method `getErrorList()` MUST return an array of line numbers indicating errors (when running `phpcs`) found in `WordPress/Tests/PHP/TypeCastsUnitTest.inc`. Similarly, the `getWarningList()` method must return an array of line numbers with the number of expected warnings.
160159
161160
If you run the following from the root directory of your WordPressCS clone:
162161
163162
```sh
164-
$ "vendor/bin/phpcs" --standard=Wordpress -s ./WordPress/Tests/PHP/POSIXFunctionsUnitTest.inc --sniffs=WordPress.PHP.POSIXFunctions
165-
...
166-
--------------------------------------------------------------------------------
167-
FOUND 7 ERRORS AFFECTING 7 LINES
168-
--------------------------------------------------------------------------------
169-
13 | ERROR | ereg() has been deprecated since PHP 5.3 and removed in PHP 7.0,
170-
| | please use preg_match() instead.
171-
| | (WordPress.PHP.POSIXFunctions.ereg_ereg)
172-
16 | ERROR | eregi() has been deprecated since PHP 5.3 and removed in PHP 7.0,
173-
| | please use preg_match() instead.
174-
| | (WordPress.PHP.POSIXFunctions.ereg_eregi)
175-
18 | ERROR | ereg_replace() has been deprecated since PHP 5.3 and removed in
176-
| | PHP 7.0, please use preg_replace() instead.
177-
| | (WordPress.PHP.POSIXFunctions.ereg_replace_ereg_replace)
178-
20 | ERROR | eregi_replace() has been deprecated since PHP 5.3 and removed in
179-
| | PHP 7.0, please use preg_replace() instead.
180-
| | (WordPress.PHP.POSIXFunctions.ereg_replace_eregi_replace)
181-
22 | ERROR | split() has been deprecated since PHP 5.3 and removed in PHP 7.0,
182-
| | please use explode(), str_split() or preg_split() instead.
183-
| | (WordPress.PHP.POSIXFunctions.split_split)
184-
24 | ERROR | spliti() has been deprecated since PHP 5.3 and removed in PHP
185-
| | 7.0, please use explode(), str_split() or preg_split()
186-
| | instead. (WordPress.PHP.POSIXFunctions.split_spliti)
187-
26 | ERROR | sql_regcase() has been deprecated since PHP 5.3 and removed in
188-
| | PHP 7.0, please use preg_match() instead.
189-
| | (WordPress.PHP.POSIXFunctions.ereg_sql_regcase)
190-
--------------------------------------------------------------------------------
163+
$ "vendor/bin/phpcs" --standard=Wordpress -s ./WordPress/Tests/PHP/TypeCastsUnitTest.inc --sniffs=WordPress.PHP.TypeCasts
191164
...
165+
----------------------------------------------------------------------------------------------------
166+
FOUND 6 ERRORS AND 4 WARNINGS AFFECTING 10 LINES
167+
----------------------------------------------------------------------------------------------------
168+
10 | ERROR | [x] Normalized type keywords must be used; expected "(float)" but found "(double)"
169+
| | (WordPress.PHP.TypeCasts.DoubleRealFound)
170+
11 | ERROR | [x] Normalized type keywords must be used; expected "(float)" but found "(real)"
171+
| | (WordPress.PHP.TypeCasts.DoubleRealFound)
172+
13 | ERROR | [ ] Using the "(unset)" cast is forbidden as the type cast is removed in PHP 8.0.
173+
| | Use the "unset()" language construct instead.
174+
| | (WordPress.PHP.TypeCasts.UnsetFound)
175+
15 | WARNING | [ ] Using binary casting is strongly discouraged. Found: "(binary)"
176+
| | (WordPress.PHP.TypeCasts.BinaryFound)
177+
16 | WARNING | [ ] Using binary casting is strongly discouraged. Found: "b"
178+
| | (WordPress.PHP.TypeCasts.BinaryFound)
179+
17 | WARNING | [ ] Using binary casting is strongly discouraged. Found: "b"
180+
| | (WordPress.PHP.TypeCasts.BinaryFound)
181+
26 | ERROR | [x] Normalized type keywords must be used; expected "(float)" but found "(double)"
182+
| | (WordPress.PHP.TypeCasts.DoubleRealFound)
183+
27 | ERROR | [x] Normalized type keywords must be used; expected "(float)" but found "(real)"
184+
| | (WordPress.PHP.TypeCasts.DoubleRealFound)
185+
28 | ERROR | [ ] Using the "(unset)" cast is forbidden as the type cast is removed in PHP 8.0.
186+
| | Use the "unset()" language construct instead.
187+
| | (WordPress.PHP.TypeCasts.UnsetFound)
188+
29 | WARNING | [ ] Using binary casting is strongly discouraged. Found: "(binary)"
189+
| | (WordPress.PHP.TypeCasts.BinaryFound)
190+
----------------------------------------------------------------------------------------------------
191+
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
192+
----------------------------------------------------------------------------------------------------
192193
```
193194
You'll see the line number and number of ERRORs we need to return in the `getErrorList()` method.
194195

WordPress-Core/ruleset.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,10 +827,6 @@
827827
Ref: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#regular-expressions
828828
#############################################################################
829829
-->
830-
<!-- Covers rule: Perl compatible regular expressions should be used in preference
831-
to their POSIX counterparts. -->
832-
<rule ref="WordPress.PHP.POSIXFunctions"/>
833-
834830
<!-- Rule: Never use the /e switch, use preg_replace_callback instead.
835831
https://github.com/WordPress/WordPress-Coding-Standards/issues/632 -->
836832

WordPress/Sniffs/PHP/POSIXFunctionsSniff.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WordPressCS\WordPress\Sniffs\PHP;
1111

12+
use PHP_CodeSniffer\Sniffs\DeprecatedSniff;
1213
use WordPressCS\WordPress\AbstractFunctionRestrictionsSniff;
1314

1415
/**
@@ -22,8 +23,37 @@
2223
* `WordPress.VIP.RestrictedFunctions` and the
2324
* `WordPress.PHP.DiscouragedPHPFunctions` sniffs.
2425
* @since 0.13.0 Class name changed: this class is now namespaced.
26+
*
27+
* @deprecated 3.3.0 Use the PHPCompatibility standard instead.
2528
*/
26-
final class POSIXFunctionsSniff extends AbstractFunctionRestrictionsSniff {
29+
final class POSIXFunctionsSniff extends AbstractFunctionRestrictionsSniff implements DeprecatedSniff {
30+
31+
/**
32+
* Provide the version number in which the sniff was deprecated.
33+
*
34+
* @return string
35+
*/
36+
public function getDeprecationVersion() {
37+
return 'WordPressCS v3.3.0';
38+
}
39+
40+
/**
41+
* Provide the version number in which the sniff will be removed.
42+
*
43+
* @return string
44+
*/
45+
public function getRemovalVersion() {
46+
return 'WordPressCS v4.0.0';
47+
}
48+
49+
/**
50+
* Provide a custom message to display with the deprecation.
51+
*
52+
* @return string
53+
*/
54+
public function getDeprecationMessage() {
55+
return 'To scan for PHP cross-version compatibility issues, use the PHPCompatibility standard instead.';
56+
}
2757

2858
/**
2959
* Groups of functions to restrict.

WordPress/ruleset.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
<rule ref="WordPress-Core"/>
99
-->
1010
<rule ref="WordPress-Docs"/>
11-
<rule ref="WordPress-Extra"/>
11+
<rule ref="WordPress-Extra">
12+
<!--
13+
Exclude deprecated sniffs.
14+
15+
Note: While this exclusion has nothing to do with the included Extra ruleset, exclusions must be placed within a "rule"
16+
and as all sniffs from WordPressCS are automatically included, we don't have a "WordPress"
17+
rule in which to place the exclusion, so this will have to do for now.
18+
-->
19+
<exclude name="WordPress.PHP.POSIXFunctions"/>
20+
</rule>
1221

1322
</ruleset>

0 commit comments

Comments
 (0)