Skip to content

Commit cb303f0

Browse files
authored
Merge pull request #6 from PHPCompatibility/feature/update-for-phpcompatibility-9.0-and-new-rulesets
Version 2.0.0 / Update for PHPCompatibility 9.0.0
2 parents 9e06ec4 + 9b20115 commit cb303f0

File tree

7 files changed

+90
-68
lines changed

7 files changed

+90
-68
lines changed

.gitattributes

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
/.gitattributes export-ignore
66
/.gitignore export-ignore
77
/.travis.yml export-ignore
8-
/.github export-ignore
8+
/.github/ export-ignore
9+
/Test/ export-ignore
910

1011
#
1112
# Auto detect text files and perform LF normalization

.github/issue_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This repository is only for the WordPress PHPCompatibility ruleset, which preven
33
44
If your issue is related to the PHPCompatibility sniffs, please open an issue in the PHPCompatibility repository: https://github.com/PHPCompatibility/PHPCompatibility/issues
55
6-
Before opening a new issue, please search for duplicate issues to prevent opening a duplicate. If there is already an open issue, please leave a comment there.
6+
Before opening a new issue, please search for your issue to prevent opening a duplicate. If there is already an open issue, please leave a comment there.
77
88
If you are opening an issue to get a new back-fill / poly-fill which was added to WordPress excluded, please include links to the WordPress source code and the related Trac ticket to substantiate your request.
99

.travis.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ language: php
1010
## Cache composer downloads.
1111
cache:
1212
directories:
13-
# Cache directory for older Composer versions.
14-
- $HOME/.composer/cache/files
15-
# Cache directory for more recent Composer versions.
1613
- $HOME/.cache/composer/files
1714

1815
matrix:
@@ -30,6 +27,7 @@ before_install:
3027
- if [[ $COVERALLS_VERSION == "notset" ]]; then phpenv config-rm xdebug.ini || echo 'No xdebug config.'; fi
3128
- export XMLLINT_INDENT=" "
3229
- composer install
30+
- vendor/bin/phpcs -i
3331

3432
script:
3533
- |
@@ -42,6 +40,9 @@ script:
4240
diff -B ./PHPCompatibilityWP/ruleset.xml <(xmllint --format "./PHPCompatibilityWP/ruleset.xml")
4341
fi
4442
43+
# Test the ruleset.
44+
- vendor/bin/phpcs ./Test/WPTest.php --standard=PHPCompatibilityWP --runtime-set testVersion 5.2
45+
4546
# Validate the composer.json file.
4647
# @link https://getcomposer.org/doc/03-cli.md#validate
4748
- composer validate --no-check-all --strict

PHPCompatibilityWP/ruleset.xml

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,37 @@
44

55
<!--
66
The WordPress minimum PHP requirement is PHP 5.2.4.
7-
Add the following in your project PHPCS ruleset to enforce this:
7+
Add the following in your project PHP_CodeSniffer ruleset to enforce this:
88
<config name="testVersion" value="5.2-"/>
9-
9+
1010
This directive is not included in this ruleset as individual projects may use
1111
a different (higher) minimum PHP version.
1212
-->
1313

1414
<rule ref="PHPCompatibility">
1515
<!-- Contained in /wp-includes/compat.php. -->
16-
<exclude name="PHPCompatibility.PHP.NewFunctions.hash_hmacFound"/>
17-
<exclude name="PHPCompatibility.PHP.NewFunctions.json_encodeFound"/>
18-
<exclude name="PHPCompatibility.PHP.NewFunctions.json_decodeFound"/>
19-
<exclude name="PHPCompatibility.PHP.NewFunctions.hash_equalsFound"/>
20-
<exclude name="PHPCompatibility.PHP.NewConstants.json_pretty_printFound"/>
21-
<exclude name="PHPCompatibility.PHP.NewFunctions.json_last_error_msgFound"/>
22-
<exclude name="PHPCompatibility.PHP.NewInterfaces.jsonserializableFound"/>
23-
<exclude name="PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound"/>
24-
<exclude name="PHPCompatibility.PHP.NewFunctions.is_iterableFound"/>
25-
<exclude name="PHPCompatibility.PHP.NewFunctions.is_countableFound"/>
16+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_hmacFound"/>
17+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_encodeFound"/>
18+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_decodeFound"/>
19+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_equalsFound"/>
20+
<exclude name="PHPCompatibility.Constants.NewConstants.json_pretty_printFound"/>
21+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_last_error_msgFound"/>
22+
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.jsonserializableFound"/>
23+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_replace_recursiveFound"/>
24+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.is_iterableFound"/>
25+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.is_countableFound"/>
2626

2727
<!-- Contained in /wp-includes/spl-autoload-compat.php. -->
28-
<exclude name="PHPCompatibility.PHP.NewFunctions.spl_autoload_registerFound"/>
29-
<exclude name="PHPCompatibility.PHP.NewFunctions.spl_autoload_unregisterFound"/>
30-
<exclude name="PHPCompatibility.PHP.NewFunctions.spl_autoload_functionsFound"/>
31-
32-
<!-- Contained in /wp-includes/random_compat/random.php. -->
33-
<exclude name="PHPCompatibility.PHP.NewConstants.php_version_idFound"/>
34-
35-
<!-- Contained in /wp-includes/random_compat/*.php (various files). -->
36-
<exclude name="PHPCompatibility.PHP.NewFunctions.random_bytesFound"/>
37-
38-
<!-- Contained in /wp-includes/random_compat/random_int.php. -->
39-
<exclude name="PHPCompatibility.PHP.NewFunctions.random_intFound"/>
40-
41-
<!-- Contained in /wp-includes/random_compat/error_polyfill.php. -->
42-
<exclude name="PHPCompatibility.PHP.NewClasses.errorFound"/>
43-
<exclude name="PHPCompatibility.PHP.NewClasses.typeerrorFound"/>
28+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_registerFound"/>
29+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_unregisterFound"/>
30+
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_functionsFound"/>
4431
</rule>
4532

33+
<!-- Contained in /wp-includes/random_compat/ -->
34+
<rule ref="PHPCompatibilityParagonieRandomCompat"/>
35+
4636
<!-- Whitelist the WP Core mysql_to_rfc3339() function. -->
47-
<rule ref="PHPCompatibility.PHP.RemovedExtensions">
37+
<rule ref="PHPCompatibility.Extensions.RemovedExtensions">
4838
<properties>
4939
<!-- Contained in /wp-includes/functions.php. -->
5040
<property name="functionWhitelist" type="array" value="mysql_to_rfc3339"/>

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
[![Latest Stable Version](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/v/stable.png)](https://packagist.org/packages/PHPCompatibility/phpcompatibility-wp)
2-
[![Latest Unstable Version](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/v/unstable.png)](https://packagist.org/packages/PHPCompatibility/phpcompatibility-wp)
3-
[![License](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/license.png)](https://github.com/PHPCompatibility/PHPCompatibilityWP/blob/master/LICENSE)
1+
[![Latest Stable Version](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/v/stable.png)](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)
2+
[![Latest Unstable Version](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/v/unstable.png)](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)
3+
[![License](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/license.png)](https://github.com/PHPCompatibility/PHPCompatibilityWP/blob/master/LICENSE)
44
[![Build Status](https://travis-ci.org/PHPCompatibility/PHPCompatibilityWP.svg?branch=master)](https://travis-ci.org/PHPCompatibility/PHPCompatibilityWP)
55

66
# PHPCompatibilityWP
77

8-
Using the PHPCompatibilityWP standard, you can analyse the codebase of a WordPress-based project for PHP cross-version compatibility.
8+
Using PHPCompatibilityWP, you can analyse the codebase of a WordPress-based project for PHP cross-version compatibility.
99

1010

1111
## What's in this repo ?
1212

13-
A PHPCompatibility ruleset for projects based on the WordPress CMS.
13+
A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects based on the WordPress CMS.
1414

1515
This WordPress specific ruleset prevents false positives from the [PHPCompatibility standard](https://github.com/PHPCompatibility/PHPCompatibility) by excluding back-fills and poly-fills which are provided by WordPress.
1616

@@ -22,21 +22,22 @@ This WordPress specific ruleset prevents false positives from the [PHPCompatibil
2222
* PHP 5.4+ for use with [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 3.0.2+.
2323

2424
Use the latest stable release of PHP_CodeSniffer for the best results.
25-
The minimum _recommended_ version of PHP_CodeSniffer is PHPCS 2.6.0.
26-
* [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility).
25+
The minimum _recommended_ version of PHP_CodeSniffer is version 2.6.0.
26+
* [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) 9.0.0+.
27+
* [PHPCompatibilityParagonie](https://github.com/PHPCompatibility/PHPCompatibilityParagonie) 1.0.0+.
2728

2829

2930
## Installation instructions
3031

31-
### Installation instructions using Composer
32+
The only supported installation method is via [Composer](https://getcomposer.org/).
3233

3334
If you don't have a Composer plugin installed to manage the `installed_paths` setting for PHP_CodeSniffer, run the following from the command-line:
3435
```bash
3536
composer require --dev dealerdirect/phpcodesniffer-composer-installer:^0.4.3 phpcompatibility/phpcompatibility-wp:*
3637
composer install
3738
```
3839

39-
If you already have a Composer PHPCS plugin installed, run:
40+
If you already have a Composer PHP_CodeSniffer plugin installed, run:
4041
```bash
4142
composer require --dev phpcompatibility/phpcompatibility-wp:*
4243
composer install
@@ -46,35 +47,14 @@ Next, run:
4647
```bash
4748
vendor/bin/phpcs -i
4849
```
49-
If all went well, you will now see that the PHPCompatibility and PHPCompatibilityWP standards are installed for PHP_CodeSniffer.
50-
51-
### Installation instructions without Composer (unsupported)
52-
53-
* Install [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) via [your preferred method](https://github.com/squizlabs/PHP_CodeSniffer#installation).
54-
55-
PHP CodeSniffer offers a variety of installation methods to suit your work-flow: Composer, [PEAR](http://pear.php.net/PHP_CodeSniffer), a Phar file, zipped/tarred release archives or checking the repository out using Git.
56-
57-
* Install [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) by [cloning the PHPCompatibility repository](https://github.com/PHPCompatibility/PHPCompatibility#installation-via-a-git-check-out-to-an-arbitrary-directory-method-2).
58-
59-
* Install [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP) by cloning this repository.
60-
61-
* Add the paths to the directories in which you placed your copies of the PHPCompatibility repo and the PHPCompatibilityWP repo to the PHP CodeSniffer configuration using the below command from the command line:
62-
```bash
63-
phpcs --config-set installed_paths /path/to/PHPCompatibility,/path/to/PHPCompatibilityWP
64-
```
65-
For more information, see the PHP CodeSniffer wiki on the [`installed_paths` configuration variable](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Configuration-Options#setting-the-installed-standard-paths).
66-
67-
* Verify that the PHPCompatibility standard is registered correctly by running `phpcs -i` on the command line. PHPCompatibility should be listed as one of the available standards.
50+
If all went well, you will now see that the `PHPCompatibility`, `PHPCompatibilityWP` and some more PHPCompatibility standards are installed for PHP_CodeSniffer.
6851

6952

7053
## How to use
7154

7255
Now you can use the following command to inspect your code:
7356
```bash
7457
./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP
75-
76-
# Or if you installed without using Composer:
77-
phpcs -p . --standard=PHPCompatibilityWP
7858
```
7959

8060
By default, you will only receive notifications about deprecated and/or removed PHP features.
@@ -83,16 +63,36 @@ To get the most out of the PHPCompatibilityWP standard, you should specify a `te
8363

8464
The minimum PHP requirement of the WordPress project at this time is PHP 5.2.4. If you want to enforce this, either add `--runtime-set testVersion 5.2-` to your command-line command or add `<config name="testVersion" value="5.2-"/>` to your [custom ruleset](https://github.com/PHPCompatibility/PHPCompatibility#using-a-custom-ruleset).
8565

66+
For example:
67+
```bash
68+
# For a project which should be compatible with PHP 5.2 and higher:
69+
./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP --runtime-set testVersion 5.2-
70+
```
71+
8672
For more detailed information about setting the `testVersion`, see the README of the generic [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions) standard.
8773

8874

75+
### Testing PHP files only
76+
77+
By default PHP_CodeSniffer will analyse PHP, JavaScript and CSS files. As the PHPCompatibility sniffs only target PHP code, you can make the run slightly faster by telling PHP_CodeSniffer to only check PHP files, like so:
78+
```bash
79+
./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 5.2-
80+
```
81+
8982
## License
9083

9184
All code within the PHPCompatibility organisation is released under the GNU Lesser General Public License (LGPL). For more information, visit https://www.gnu.org/copyleft/lesser.html
9285

9386

9487
## Changelog
9588

89+
### 2.0.0 - 2018-10-07
90+
91+
- Ruleset: Updated for compatibility with PHPCompatibility 9.0+.
92+
- Composer: Added dependency for a dedicated polyfill-based PHPCompatibility ruleset.
93+
- CI: Added a test for the ruleset.
94+
- Readme: Removed the installation instructions for a non-Composer based install.
95+
9696
### 1.0.0 - 2018-07-17
9797

9898
Initial release of the PHPCompatibilityWP ruleset.

Test/WPTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*
3+
* Test file to run PHP_CodeSniffer against to make sure the polyfills are correctly excluded.
4+
*
5+
* This file should only test the polyfills provided by WordPress itself.
6+
* The polyfills provided via dependencies will be tested via the repo containing
7+
* the dedicated ruleset(s) for those dependencies.
8+
*/
9+
$a = hash_hmac();
10+
$a = json_encode();
11+
$a = json_decode();
12+
$a = hash_equals();
13+
14+
echo JSON_PRETTY_PRINT;
15+
$a = json_last_error_msg();
16+
class ABC implements JsonSerializable {}
17+
18+
$a = array_replace_recursive();
19+
$a = is_iterable();
20+
$a = is_countable();
21+
22+
$a = spl_autoload_register();
23+
$a = spl_autoload_unregister();
24+
$a = spl_autoload_functions();
25+
26+
$a = mysql_to_rfc3339();

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "phpcompatibility/phpcompatibility-wp",
3-
"description" : "A set of sniffs for PHP_CodeSniffer that checks for PHP version compatibility for WordPress projects.",
3+
"description" : "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.",
44
"type" : "phpcodesniffer-standard",
55
"keywords" : [ "compatibility", "phpcs", "standards", "wordpress" ],
66
"homepage" : "http://phpcompatibility.com/",
@@ -18,10 +18,14 @@
1818
"source" : "https://github.com/PHPCompatibility/PHPCompatibilityWP"
1919
},
2020
"require" : {
21-
"phpcompatibility/php-compatibility" : "^8.1"
21+
"phpcompatibility/php-compatibility" : "^9.0",
22+
"phpcompatibility/phpcompatibility-paragonie" : "^1.0"
23+
},
24+
"require-dev" : {
25+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3"
2226
},
2327
"suggest" : {
24-
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.",
28+
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
2529
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
2630
},
2731
"prefer-stable" : true

0 commit comments

Comments
 (0)