From 9b20115927d42f131f1f9bb4ba07b0dff9ac3a98 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 27 Sep 2018 19:07:06 +0200 Subject: [PATCH] Version 2.0.0 / Update for PHPCompatibility 9.0.0 This update accounts for the following changes: * Ruleset: - Updated sniff error codes for compatibility with PHPCompatibility 9.0.0. - Defer to the dedicated polyfill rulesets for polyfills provided by project dependencies. * Composer: - Require relevant dedicated polyfill ruleset. - Require `dev` the DealerDirect PHPCS Composer plugin to sort out the `installed_paths` so Travis can test the ruleset. - Improved the project description. * Travis/Tests: - Added testing of the ruleset. * Issue template: minor textual tweak. * Readme: - Minor textual improvements to the project description. - Added information about the dependency on the polyfill ruleset. - Removed non-Composer installation instructions. As there are now more dependencies for this project, installation without using Composer, while of course still possible, is no longer _supported_. - Added section about only testing PHP files. - Added changelog for version 2.0.0. Additionally, in all user-facing texts, the abbreviation `PHPCS` has been expanded to read `PHP_CodeSniffer`. --- .gitattributes | 3 +- .github/issue_template.md | 2 +- .travis.yml | 7 ++-- PHPCompatibilityWP/ruleset.xml | 48 +++++++++++--------------- README.md | 62 +++++++++++++++++----------------- Test/WPTest.php | 26 ++++++++++++++ composer.json | 10 ++++-- 7 files changed, 90 insertions(+), 68 deletions(-) create mode 100644 Test/WPTest.php diff --git a/.gitattributes b/.gitattributes index 63cce26..e1a04bb 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,7 +5,8 @@ /.gitattributes export-ignore /.gitignore export-ignore /.travis.yml export-ignore -/.github export-ignore +/.github/ export-ignore +/Test/ export-ignore # # Auto detect text files and perform LF normalization diff --git a/.github/issue_template.md b/.github/issue_template.md index c59c693..9a83da1 100644 --- a/.github/issue_template.md +++ b/.github/issue_template.md @@ -3,7 +3,7 @@ This repository is only for the WordPress PHPCompatibility ruleset, which preven If your issue is related to the PHPCompatibility sniffs, please open an issue in the PHPCompatibility repository: https://github.com/PHPCompatibility/PHPCompatibility/issues -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. +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. 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. diff --git a/.travis.yml b/.travis.yml index f9a6132..c561687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,6 @@ language: php ## Cache composer downloads. cache: directories: - # Cache directory for older Composer versions. - - $HOME/.composer/cache/files - # Cache directory for more recent Composer versions. - $HOME/.cache/composer/files matrix: @@ -30,6 +27,7 @@ before_install: - if [[ $COVERALLS_VERSION == "notset" ]]; then phpenv config-rm xdebug.ini || echo 'No xdebug config.'; fi - export XMLLINT_INDENT=" " - composer install + - vendor/bin/phpcs -i script: - | @@ -42,6 +40,9 @@ script: diff -B ./PHPCompatibilityWP/ruleset.xml <(xmllint --format "./PHPCompatibilityWP/ruleset.xml") fi + # Test the ruleset. + - vendor/bin/phpcs ./Test/WPTest.php --standard=PHPCompatibilityWP --runtime-set testVersion 5.2 + # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate - composer validate --no-check-all --strict diff --git a/PHPCompatibilityWP/ruleset.xml b/PHPCompatibilityWP/ruleset.xml index 8d7f4bc..a47477a 100644 --- a/PHPCompatibilityWP/ruleset.xml +++ b/PHPCompatibilityWP/ruleset.xml @@ -4,47 +4,37 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + - + diff --git a/README.md b/README.md index d7d72be..279c044 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,16 @@ -[![Latest Stable Version](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/v/stable.png)](https://packagist.org/packages/PHPCompatibility/phpcompatibility-wp) -[![Latest Unstable Version](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/v/unstable.png)](https://packagist.org/packages/PHPCompatibility/phpcompatibility-wp) -[![License](https://poser.pugx.org/PHPCompatibility/phpcompatibility-wp/license.png)](https://github.com/PHPCompatibility/PHPCompatibilityWP/blob/master/LICENSE) +[![Latest Stable Version](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/v/stable.png)](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp) +[![Latest Unstable Version](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/v/unstable.png)](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp) +[![License](https://poser.pugx.org/phpcompatibility/phpcompatibility-wp/license.png)](https://github.com/PHPCompatibility/PHPCompatibilityWP/blob/master/LICENSE) [![Build Status](https://travis-ci.org/PHPCompatibility/PHPCompatibilityWP.svg?branch=master)](https://travis-ci.org/PHPCompatibility/PHPCompatibilityWP) # PHPCompatibilityWP -Using the PHPCompatibilityWP standard, you can analyse the codebase of a WordPress-based project for PHP cross-version compatibility. +Using PHPCompatibilityWP, you can analyse the codebase of a WordPress-based project for PHP cross-version compatibility. ## What's in this repo ? -A PHPCompatibility ruleset for projects based on the WordPress CMS. +A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects based on the WordPress CMS. 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. @@ -22,13 +22,14 @@ This WordPress specific ruleset prevents false positives from the [PHPCompatibil * PHP 5.4+ for use with [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 3.0.2+. Use the latest stable release of PHP_CodeSniffer for the best results. - The minimum _recommended_ version of PHP_CodeSniffer is PHPCS 2.6.0. -* [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility). + The minimum _recommended_ version of PHP_CodeSniffer is version 2.6.0. +* [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) 9.0.0+. +* [PHPCompatibilityParagonie](https://github.com/PHPCompatibility/PHPCompatibilityParagonie) 1.0.0+. ## Installation instructions -### Installation instructions using Composer +The only supported installation method is via [Composer](https://getcomposer.org/). 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: ```bash @@ -36,7 +37,7 @@ composer require --dev dealerdirect/phpcodesniffer-composer-installer:^0.4.3 php composer install ``` -If you already have a Composer PHPCS plugin installed, run: +If you already have a Composer PHP_CodeSniffer plugin installed, run: ```bash composer require --dev phpcompatibility/phpcompatibility-wp:* composer install @@ -46,25 +47,7 @@ Next, run: ```bash vendor/bin/phpcs -i ``` -If all went well, you will now see that the PHPCompatibility and PHPCompatibilityWP standards are installed for PHP_CodeSniffer. - -### Installation instructions without Composer (unsupported) - -* Install [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) via [your preferred method](https://github.com/squizlabs/PHP_CodeSniffer#installation). - - 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. - -* 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). - -* Install [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP) by cloning this repository. - -* 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: - ```bash - phpcs --config-set installed_paths /path/to/PHPCompatibility,/path/to/PHPCompatibilityWP - ``` - 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). - -* 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. +If all went well, you will now see that the `PHPCompatibility`, `PHPCompatibilityWP` and some more PHPCompatibility standards are installed for PHP_CodeSniffer. ## How to use @@ -72,9 +55,6 @@ If all went well, you will now see that the PHPCompatibility and PHPCompatibilit Now you can use the following command to inspect your code: ```bash ./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP - -# Or if you installed without using Composer: -phpcs -p . --standard=PHPCompatibilityWP ``` By default, you will only receive notifications about deprecated and/or removed PHP features. @@ -83,9 +63,22 @@ To get the most out of the PHPCompatibilityWP standard, you should specify a `te 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 `` to your [custom ruleset](https://github.com/PHPCompatibility/PHPCompatibility#using-a-custom-ruleset). +For example: +```bash +# For a project which should be compatible with PHP 5.2 and higher: +./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP --runtime-set testVersion 5.2- +``` + 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. +### Testing PHP files only + +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: +```bash +./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP --extensions=php --runtime-set testVersion 5.2- +``` + ## License 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 @@ -93,6 +86,13 @@ All code within the PHPCompatibility organisation is released under the GNU Less ## Changelog +### 2.0.0 - 2018-10-07 + +- Ruleset: Updated for compatibility with PHPCompatibility 9.0+. +- Composer: Added dependency for a dedicated polyfill-based PHPCompatibility ruleset. +- CI: Added a test for the ruleset. +- Readme: Removed the installation instructions for a non-Composer based install. + ### 1.0.0 - 2018-07-17 Initial release of the PHPCompatibilityWP ruleset. diff --git a/Test/WPTest.php b/Test/WPTest.php new file mode 100644 index 0000000..7e249ce --- /dev/null +++ b/Test/WPTest.php @@ -0,0 +1,26 @@ +