基础代码
This commit is contained in:
+165
@@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0"?>
|
||||
<ruleset name="PHPCompatibilityWP">
|
||||
<description>WordPress specific ruleset which checks for PHP cross version compatibility.</description>
|
||||
|
||||
<!--
|
||||
The WordPress minimum PHP requirement was 5.2.4 up to WP 5.1.
|
||||
As of WP 5.2, the new minimum PHP requirement is PHP 5.6.20.
|
||||
Add the following in your project PHP_CodeSniffer ruleset to enforce this:
|
||||
<config name="testVersion" value="5.6-"/>
|
||||
|
||||
This directive is not included in this ruleset as individual projects may use
|
||||
a different (higher) minimum PHP version.
|
||||
-->
|
||||
|
||||
<rule ref="PHPCompatibility">
|
||||
<!--
|
||||
Contained in /wp-includes/compat.php.
|
||||
|
||||
History of the polyfills in WP:
|
||||
* hash_hmac(): since WP 3.2.0.
|
||||
* json_encode() and json_decode(): since unknown.
|
||||
* hash_equals(): since WP 3.9.2.
|
||||
* JSON_PRETTY_PRINT: since WP 4.1.0.
|
||||
* json_last_error_msg(): since WP 4.4.0.
|
||||
* JsonSerializable: since WP 4.4.0.
|
||||
* array_replace_recursive(): since WP 4.5.3 up to 5.2.x. The polyfill was removed in WP 5.3.
|
||||
* is_iterable(): since WP 4.9.6
|
||||
* is_countable(): since WP 4.9.6
|
||||
-->
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_hmacFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_encodeFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_decodeFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.hash_equalsFound"/>
|
||||
<exclude name="PHPCompatibility.Constants.NewConstants.json_pretty_printFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.json_last_error_msgFound"/>
|
||||
<exclude name="PHPCompatibility.Interfaces.NewInterfaces.jsonserializableFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.array_replace_recursiveFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.is_iterableFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.is_countableFound"/>
|
||||
|
||||
<!--
|
||||
Contained in /wp-includes/spl-autoload-compat.php.
|
||||
|
||||
History of the polyfills in WP:
|
||||
* spl_autoload_register(), spl_autoload_unregister() and spl_autoload_functions() were
|
||||
introduced in WP 4.6.0 and available up to WP 5.2.x. The polyfills were removed in WP 5.3.
|
||||
-->
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_registerFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_unregisterFound"/>
|
||||
<exclude name="PHPCompatibility.FunctionUse.NewFunctions.spl_autoload_functionsFound"/>
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
The ParagonieSodiumCompat ruleset includes the ParagonieRandomCompat ruleset.
|
||||
|
||||
RancomCompat is contained in /wp-includes/random_compat/ since WP 4.4.0
|
||||
SodiumCompat is contained in /wp-includes/sodium_compat/ since WP 5.2.0
|
||||
-->
|
||||
<rule ref="PHPCompatibilityParagonieSodiumCompat"/>
|
||||
|
||||
<!-- Whitelist the WP Core mysql_to_rfc3339() function. -->
|
||||
<rule ref="PHPCompatibility.Extensions.RemovedExtensions">
|
||||
<properties>
|
||||
<!-- Contained in /wp-includes/functions.php. -->
|
||||
<property name="functionWhitelist" type="array" value="mysql_to_rfc3339"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
</ruleset>
|
||||
@@ -0,0 +1,116 @@
|
||||
[](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)
|
||||
[](https://packagist.org/packages/phpcompatibility/phpcompatibility-wp)
|
||||
[](https://github.com/PHPCompatibility/PHPCompatibilityWP/blob/master/LICENSE)
|
||||
[](https://github.com/PHPCompatibility/PHPCompatibilityWP/actions)
|
||||
|
||||
# PHPCompatibilityWP
|
||||
|
||||
Using PHPCompatibilityWP, you can analyse the codebase of a WordPress-based project for PHP cross-version compatibility.
|
||||
|
||||
|
||||
## What's in this repo ?
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Requirements
|
||||
|
||||
* [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer).
|
||||
* PHP 5.3+ for use with [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) 2.3.0+.
|
||||
* 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 version 2.6.0.
|
||||
* [PHPCompatibility](https://github.com/PHPCompatibility/PHPCompatibility) 9.0.0+.
|
||||
* [PHPCompatibilityParagonie](https://github.com/PHPCompatibility/PHPCompatibilityParagonie) 1.0.0+.
|
||||
|
||||
|
||||
## Installation instructions
|
||||
|
||||
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
|
||||
composer require --dev dealerdirect/phpcodesniffer-composer-installer:"^0.7" phpcompatibility/phpcompatibility-wp:*
|
||||
composer install
|
||||
```
|
||||
|
||||
If you already have a Composer PHP_CodeSniffer plugin installed, run:
|
||||
```bash
|
||||
composer require --dev phpcompatibility/phpcompatibility-wp:*
|
||||
composer install
|
||||
```
|
||||
|
||||
Next, run:
|
||||
```bash
|
||||
vendor/bin/phpcs -i
|
||||
```
|
||||
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
|
||||
|
||||
Now you can use the following command to inspect your code:
|
||||
```bash
|
||||
./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP
|
||||
```
|
||||
|
||||
By default, you will only receive notifications about deprecated and/or removed PHP features.
|
||||
|
||||
To get the most out of the PHPCompatibilityWP standard, you should specify a `testVersion` to check against. That will enable the checks for both deprecated/removed PHP features as well as the detection of code using new PHP features.
|
||||
|
||||
The minimum PHP requirement of the WordPress project up to WP 5.1 was 5.2.4. As of WP 5.2 it will be PHP 5.6.20. If you want to enforce this, either add `--runtime-set testVersion 5.6-` to your command-line command or add `<config name="testVersion" value="5.6-"/>` 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.6 and higher:
|
||||
./vendor/bin/phpcs -p . --standard=PHPCompatibilityWP --runtime-set testVersion 5.6-
|
||||
```
|
||||
|
||||
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.6-
|
||||
```
|
||||
|
||||
## 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
|
||||
|
||||
|
||||
## Changelog
|
||||
|
||||
### 2.1.1 - 2021-02-15
|
||||
|
||||
- The recommended version of the [Composer PHPCS plugin] is now `^0.7.0`, which offers compatibility with Composer 2.0.
|
||||
- The ruleset is now also tested against PHP 7.4 and 8.0.
|
||||
Note: full PHP 7.4 support is only available in combination with PHP_CodeSniffer >= 3.5.6.
|
||||
Note: runtime PHP 8.0 support is only available in combination with PHP_CodeSniffer >= 3.5.7, full support is expected in PHP_CodeSniffer 3.6.0.
|
||||
|
||||
### 2.1.0 - 2019-08-29
|
||||
|
||||
- Ruleset: Updated for the Sodium_Compat polyfill which is included in WordPress 5.2.
|
||||
- Composer: The recommended version of the [Composer PHPCS plugin] has been upped to `^0.5.0`.
|
||||
- Documentation: Updated the ruleset inline documentation and the Readme to reflect the change in minimum PHP requirements for WordPress as of WP 5.2.
|
||||
- Documentation: Updated the ruleset inline documentation to include information on when each polyfill was added to/removed from WordPress.
|
||||
- CI: The rulesets are now also tested against PHP 7.3.
|
||||
Note: full PHP 7.3 support is only available in combination with PHP_CodeSniffer 2.9.2 or 3.3.1+ due to an incompatibility within PHP_CodeSniffer itself.
|
||||
|
||||
### 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.
|
||||
|
||||
[Composer PHPCS plugin]: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name" : "phpcompatibility/phpcompatibility-wp",
|
||||
"description" : "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.",
|
||||
"type" : "phpcodesniffer-standard",
|
||||
"keywords" : [ "compatibility", "phpcs", "standards", "wordpress" ],
|
||||
"homepage" : "http://phpcompatibility.com/",
|
||||
"license" : "LGPL-3.0-or-later",
|
||||
"authors" : [ {
|
||||
"name" : "Wim Godden",
|
||||
"role" : "lead"
|
||||
},
|
||||
{
|
||||
"name" : "Juliette Reinders Folmer",
|
||||
"role" : "lead"
|
||||
} ],
|
||||
"support" : {
|
||||
"issues" : "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues",
|
||||
"source" : "https://github.com/PHPCompatibility/PHPCompatibilityWP"
|
||||
},
|
||||
"require" : {
|
||||
"phpcompatibility/php-compatibility" : "^9.0",
|
||||
"phpcompatibility/phpcompatibility-paragonie" : "^1.0"
|
||||
},
|
||||
"require-dev" : {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7"
|
||||
},
|
||||
"suggest" : {
|
||||
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.",
|
||||
"roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues."
|
||||
},
|
||||
"prefer-stable" : true
|
||||
}
|
||||
Reference in New Issue
Block a user