About
PHP CompatInfo is a library that can find the minimum version and the extensions required for a piece of code to run.
Running on PHP greater or equal than 7.4 for parsing source code in a format PHP 5.2 to PHP 8.2
Features
- Parse source code in format PHP 5.2 to PHP 8.2
- Detect PHP features for each Major/minor versions
- Detect versions of all directives, constants, functions, classes, interfaces of 100 extensions and more
- Display/Inspect list of extensions, and their versions supported
Components
-
Parsing PHP 5, PHP 7 or PHP 8 code into an abstract syntax tree (AST) is provided by the PHP-Parser library.
-
Contextual elements and minimum PHP versions detection provided by following node visitors.
PHP-Parser Node Visitors
- Parent references with the
ParentContextVisitor
- Name Resolution with the
NameResolverVisitor
- Version Resolution with the
VersionResolverVisitor
Profiler
- Data Collector(s) with common
DataCollector
and specializedVersionDataCollector
classes - Data Collector(s) contract with the
CollectorInterface
- Collector Handler for both Profile and Profiler with
CollectorTrait
- Profile information for a single data source with
Profile
Sniffs
They are grouped by categories to solve PHP features (from 4.0 to 8.2)
- Arrays (3)
- Attributes (1)
- Classes (10)
- Constants (3)
- ControlStructures (4)
- Enumerations (1)
- Expressions (3)
- Fibers (1)
- FunctionCalls (1)
- FunctionDeclarations (7)
- Generators (1)
- Keywords (1)
- Numbers (2)
- Operators (5)
- TextProcessing (1)
- UseDeclarations (2)
Extensions
PHPCompatInfo can be extended by registering objects that implement one or more of the following interfaces:
BeforeAnalysisInterface
AfterAnalysisInterface
BeforeFileAnalysisInterface
AfterFileAnalysisInterface
BeforeTraverseAstInterface
AfterTraverseAstInterface
BeforeProcessNodeInterface
AfterProcessNodeInterface
BeforeSetupSniffInterface
AfterTearDownSniffInterface
BeforeProcessSniffInterface
AfterProcessSniffInterface
Furthermore, extensions may implement the Symfony\Component\EventDispatcher\EventSubscriberInterface
in order to have its event handlers automatically registered with the EventDispatcher when the extension is loaded.
Polyfills
They are identified by services that implements the Bartlett\CompatInfo\Application\Polyfills\PolyfillInterface
.
Configuration(s)
Load a config for CLI Application with the --config
option.
Read How to Load --config With Services in Symfony Console to learn more.
Conditional Code
Learn what code is consider as conditional, detected or not (with CompatInfo 5.4)
Exclude folder(s)
Sometimes you don't want to scan a certain directory while analysing data source.
Learn how to do from console (CLI) or php script (API).