Awesome PHP AST
A curated list of amazingly awesome tools, articles and books about abstract syntax tree in PHP world. From parsing PHP, through traversing templates and configs through automated upgrades.
Note: this repository should not be list of tools that run on nikic/php-parser, but rather tools that main feature developer actually works with is abstract syntax tree.
- Good example - PHPStan, because you work with PHP nodes in every single rule.
- Bad example - Twig, it has structure in AST and has node visitors, but marginal number of developers use it. It's main feature is template compilation, filters and functions.
Do you miss a project, tool or article, that you consider useful to the broader AST PHP community? Send a pull-request, so we can check it.
Native PHP
Parsing
- https://github.com/nikic/PHP-Parser - A PHP parser written in PHP
- https://github.com/microsoft/tolerant-php-parser - PHP parser designed for IDE usage scenarios
Analyzing
- https://github.com/phpstan/phpstan - PHP Static Analysis Tool based on php-parser
- https://github.com/phan/phan - PHP Static Analysis Tool based on the php-ast extension
- https://leanpub.com/recipes-for-decoupling - Book about PHPStan & AST-based analysis
Modifying
- https://github.com/rectorphp/rector - Instant Upgrades and Automated Refactoring tool based on php-parser and PHPStan
- https://github.com/ajthinking/archetype - Edit PHP files programmatically with Fluent API and Abstract Syntax Tree QueryBuilder
- https://leanpub.com/rector-the-power-of-automated-refactoring - Book about Rector and AST-based manipulation
Templates
TWIG
- https://github.com/revealphp/reveal-twig - TWIG static analysis, that compiles TWIG template to PHP and run PHPStan on the result
- https://github.com/matthiasnoback/phpstan-twig-analysis - Twig static analysis based on Twig Node traversing
Latte
- https://github.com/revealphp/reveal-latte - Latte static analysis, that compiles Latte template to PHP and runs PHPStan on the result
- https://github.com/TomasVotruba/barista - "A PHPStan for Latte", traversing Latte files with native Latte 3 AST
Blade
- https://github.com/canvural/phpstan-blade-rule - Blade static analysis, that compiles Blade template to PHP and run PHPStan on the result
HTML
- https://github.com/TomasVotruba/html-parser - Simple HTML AST traverser based on Dom
Databases
- https://github.com/staabm/phpstan-dba - PHPStan static analysis and type inference for the database access layer
- https://github.com/phpmyadmin/sql-parser - A validating SQL lexer and parser with a focus on MySQL dialect
License
To the extent possible under law, Tomas Votruba has waived all copyright and related or neighboring rights to this work.