A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/PHPCompatibility/PHPCompatibility/ below:

PHPCompatibility/PHPCompatibility: PHP Compatibility check for PHP_CodeSniffer

PHP Compatibility Coding Standard for PHP CodeSniffer

This is a set of sniffs for PHP CodeSniffer that checks for PHP cross-version compatibility. It will allow you to analyse your code for compatibility with higher and lower versions of PHP.

The project aims to cover all PHP compatibility changes introduced since PHP 5.0 up to the latest PHP release. This is an ongoing process and coverage is not yet 100% (if, indeed, it ever could be). Progress is tracked on our GitHub issue tracker.

Pull requests that check for compatibility issues in PHP 4 code - in particular between PHP 4 and PHP 5.0 - are very welcome as there are still situations where people need help upgrading legacy systems. However, coverage for changes introduced before PHP 5.1 will remain patchy as sniffs for this are not actively being developed at this time.

The sniffs are designed to give the same results regardless of which PHP version you are using to run PHP CodeSniffer. You should get consistent results independently of the PHP version used in your test environment, though for the best results it is recommended to run the sniffs on a recent PHP version in combination with a recent PHP_CodeSniffer version.

As of version 8.0.0, the PHPCompatibility standard can also be used with PHP CodeSniffer 3.x. As of version 9.0.0, support for PHP CodeSniffer 1.5.x and low 2.x versions < 2.3.0 has been dropped. As of version 10.0.0, support for PHP < 5.4 and PHP CodeSniffer < 3.13.0 has been dropped.

Thanks to all contributors for their valuable contributions.

Thanks to WP Engine for their support on the PHP 7.0 sniffs.

⚠️ Upgrading to PHPCompatibility 9.0.0 ⚠️

This library has been reorganized. All sniffs have been placed in categories and a significant number of sniffs have been renamed.

If you use the complete PHPCompatibility standard without exclude directives in a custom ruleset and do not (yet) use the new-style PHP_CodeSniffer annotation as introduced in PHP_CodeSniffer 3.2.0, this will have no noticeable effect and everything should work as before.

However, if you do use exclude directives for PHPCompatibility sniffs in a custom ruleset or if you use the new-style PHP_CodeSniffer inline annotations, you will need to update these when upgrading. This should be a one-time only change. The changelog contains detailed information about all the sniff renames.

Please read the changelog for version 9.0.0 carefully before upgrading.

Installation in a Composer project (method 1) Installation via a git check-out to an arbitrary directory (method 2) Sniffing your code for compatibility with specific PHP version(s) Using a framework/CMS/polyfill specific ruleset

As of mid 2018, a limited set of framework/CMS specific rulesets is available. These rulesets are hosted in their own repositories.

Since the autumn of 2018, there are also a number of PHP polyfill specific rulesets available:

If you want to make sure you have all PHPCompatibility rulesets available at any time, you can use the PHPCompatibilityAll package GitHub | Packagist.

IMPORTANT: Framework/CMS/Polyfill specific rulesets do not set the minimum PHP version for your project, so you will still need to pass a testVersion to get the most accurate results.

Like with any PHP CodeSniffer standard, you can add PHPCompatibility to a custom PHP CodeSniffer ruleset.

<?xml version="1.0"?>
<ruleset name="Custom ruleset">
    <description>My rules for PHP CodeSniffer</description>

    <!-- Run against the PHPCompatibility ruleset -->
    <rule ref="PHPCompatibility"/>

    <!-- Run against a second ruleset -->
    <rule ref="PSR2"/>

</ruleset>

You can also set the testVersion from within the ruleset:

    <!-- Check for cross-version support for PHP 5.6 and higher. -->
    <config name="testVersion" value="5.6-"/>

Other advanced options, such as changing the message type or severity of select sniffs, as described in the PHPCS Annotated ruleset wiki page are, of course, also supported.

testVersion in the ruleset versus command-line

In PHPCS 3.2.0 and lower, once you set the testVersion in the ruleset, you could not overrule it from the command-line anymore. Starting with PHPCS 3.3.0, a testVersion set via the command-line will overrule the testVersion in the ruleset.

This allows for more flexibility when, for instance, your project needs to comply with PHP 5.5-, but you have a bootstrap file which needs to be compatible with PHP 5.2-.

PHPCompatibility specific options

At this moment, there are two sniffs which have a property which can be set via the ruleset. More custom properties may become available in the future.

The PHPCompatibility.Extensions.RemovedExtensions sniff checks for removed extensions based on the function prefix used for these extensions. This might clash with userland functions using the same function prefix.

To whitelist userland functions, you can pass a comma-delimited list of function names to the sniff.

    <!-- Whitelist the mysql_to_rfc3339() and mysql_another_function() functions. -->
    <rule ref="PHPCompatibility.Extensions.RemovedExtensions">
        <properties>
            <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function"/>
        </properties>
    </rule>

The PHPCompatibility.Interfaces.RemovedSerializable sniff needs to know about all interfaces which extend the Serializable interface to provide the most reliable results. The sniff will warn when it encounters an interface extending the Serializable interface which is unknown to the sniff and recommend for the interface name to be added to the property.

To inform the sniff about additional interfaces providing the Serializable interface, add a snippet along the lines of the below to your custom ruleset:

    <rule ref="PHPCompatibility.Interfaces.RemovedSerializable">
        <properties>
            <property name="serializableInterfaces" type="array">
                <element value="MyCustomSerializableInterface"/>
                <element value="AnotherSerializableInterface"/>
            </property>
        </properties>
    </rule>
Projects extending PHPCompatibility

There are hundreds of public projects using PHPCompatibility or extending on top of it. A short list of some that you might know or have a look at :

Contributions are very welcome. Please read the CONTRIBUTING documentation to get started.

This code is released under the GNU Lesser General Public License (LGPL). For more information, visit http://www.gnu.org/copyleft/lesser.html


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4