🔧 PHPCS: add a comprehensive PHPCompatibility exceptions ruleset

WordPress provides backfills for a number of PHP native functions and constants.
These can therefore be safely used in themes and plugins.

This commit adds a whitelist for the PHPCompatibility ruleset of the backfills currently provided by WP.

N.B.: At this moment, none of the whitelisted classes/constants/functions/interfaces are used in `_s`.
However, `_s` is also a teaching tool and an example for others, so having this whitelist block in there serves that purpose and allows for themes which are build onto `_s` to use these PHP features without having to worry about cross-version compatibility notices.
This commit is contained in:
jrfnl 2018-02-27 10:49:06 +01:00
parent cac65d8a54
commit cb7117a408
1 changed files with 30 additions and 1 deletions

View File

@ -103,5 +103,34 @@
<config name="testVersion" value="5.2-99.0"/>
<rule ref="PHPCompatibility"/>
<rule ref="PHPCompatibility">
<!-- Whitelist PHP native classes, interfaces, functions and constants which
are back-filled by WP.
Based on:
* /wp-includes/compat.php
* /wp-includes/random_compat/random.php
-->
<exclude name="PHPCompatibility.PHP.NewClasses.errorFound"/>
<exclude name="PHPCompatibility.PHP.NewClasses.typeerrorFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.json_pretty_printFound"/>
<exclude name="PHPCompatibility.PHP.NewConstants.php_version_idFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.hash_equalsFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.json_last_error_msgFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.random_intFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.random_bytesFound"/>
<exclude name="PHPCompatibility.PHP.NewFunctions.array_replace_recursiveFound"/>
<exclude name="PHPCompatibility.PHP.NewInterfaces.jsonserializableFound"/>
</rule>
<!-- Whitelist the WP Core mysql_to_rfc3339() function. -->
<rule ref="PHPCompatibility.PHP.RemovedExtensions">
<properties>
<property name="functionWhitelist" type="array" value="mysql_to_rfc3339"/>
</properties>
</rule>
</ruleset>