PHPCompatInfo – Check the minimum requirement of your php code

Questo articolo è stato scritto oltre 1 years, il contenuto potrebbe essere datato.

PHPCompatInfo is a powered tool that analysis a folder with php files and report about the minimum version of php runtime required.

Very useful for test a project before the release on production!

How to install

wget http://bartlett.laurent-laville.org/get/phpcompatinfo-3.2.0.phar

mv phpcompatinfo-3.2.0.phar /usr/local/bin/phpcompatinfo

chmod +x /usr/local/bin/phpcompatinfo

After this in your project folder is required a phpcompat.json file, this file contain the plugin used for check the code, the path and other info. This is an example complete with all the plugin.

{
    "source-providers": [
        {
            "in": ". as current",
            "name": "/\\.(php|inc|phtml)$/"
        }
    ],
    "plugins": [
        {
            "name": "Analyser",
            "class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
        }
    ],
    "analysers" : [
        {
            "name": "Namespace",
            "class": "Bartlett\\CompatInfo\\Analyser\\NamespaceAnalyser"
        },
        {
            "name": "Extension",
            "class": "Bartlett\\CompatInfo\\Analyser\\ExtensionAnalyser"
        },
        {
            "name": "Interface",
            "class": "Bartlett\\CompatInfo\\Analyser\\InterfaceAnalyser"
        },
        {
            "name": "Trait",
            "class": "Bartlett\\CompatInfo\\Analyser\\TraitAnalyser"
        },
        {
            "name": "Class",
            "class": "Bartlett\\CompatInfo\\Analyser\\ClassAnalyser"
        },
        {
            "name": "Function",
            "class": "Bartlett\\CompatInfo\\Analyser\\FunctionAnalyser"
        },
        {
            "name": "Constant",
            "class": "Bartlett\\CompatInfo\\Analyser\\ConstantAnalyser"
        },
        {
            "name": "Summary",
            "class": "Bartlett\\CompatInfo\\Analyser\\SummaryAnalyser"
        },
        {
            "name": "Structure",
            "class": "Bartlett\\Reflect\\Analyser\\StructureAnalyser"
        }
    ]
}

After this you can use this fantastic tool!

phpcompatinfo analyser:run . –php=”>= 5.2″

Documentation?

The developers of this project have written a complete documentation on http://php5.laurent-laville.org/compatinfo/manual/3.2/en/getting-started.html

Example

Data Source Analysed

Directories                                         28
Files                                                   50

Summary Analysis

Summary
Extensions                                          6
Namespaces                                       1
Interfaces                                            0
Traits                                                   0
Classes                                               39
Methods                                          299
Functions                                          27
Constants                                          31
Internal Functions                            79

Versions
PHP min                                          5.2.0
PHP max

Why the PHP min 5.2 in this example?

In PHP 5.3 has been added support for the anonymous function and WordPress minimum requirement is PHP 5.2.
If you want create a plugin for WordPress that have a big support need to support PHP 5.2.

PS: I use Debian Sid for the development, PHP 5.6 RC3. Yeah! Yes i like the development version, and i have never noticed about this minimum requirement of WordPress until someone opened a ticket.

Conclusion

This is a new tool for my PHP swiss knife with other:

  • PHP CodeSniffer
  • PHP CodeSniffer Fixer
  • PHP MD
  • PHP Unit
  • XDebug
  • Apigen
  • Composer
  • WP CLI
  • Wordmove
  • WP Scan
  • Netbeans
  • My Brain – this is not on Github

PS: Netbeans i want an integration for this. I warned you 😀

Liked it? Take a second to support Mte90 on Patreon!
Become a patron at Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *