carthage-software/mago
Mago is an extremely fast PHP linter, formatter, and static analyzer written in Rust. It brings Rust-inspired speed and reliability to PHP projects with a modern toolchain and great developer experience, plus multiple install options (script, Homebrew, Composer).
Mago's linter is a blazing-fast tool for finding and fixing stylistic issues, inconsistencies, and code smells in your PHP code. It helps you maintain a clean, readable, and consistent codebase with minimal effort.
While they both find issues, the analyzer and the linter operate at different levels of understanding.
The linter is a style editor. It looks at the structure of your code. It enforces your team's coding standards, flags redundant code, and suggests more modern syntax. It doesn't know what your code does, only what it looks like.
The analyzer is a fact-checker. It builds a deep, semantic understanding of your entire codebase. It knows what types your functions return, what properties your classes have, and what exceptions can be thrown. It finds logical impossibilities (e.g., "you're calling a method that doesn't exist on this object").
:::info Analogy If your code were an essay, the linter would be the grammar and style checker, while the analyzer would be the editor who checks your facts and ensures your arguments are logical. :::
Mago processes files in three stages: Parse -> Semantic check -> Lint.
Mago's parser is intentionally tolerant—it can parse syntax that the standard PHP compiler would reject, like features from a future PHP version.
The semantic checker is the crucial second step. Its job is to find syntax errors that Mago's parser allows but PHP would consider fatal. This includes things like:
enum Foo: array {})You can run just the first two stages using the --semantics (or -s) flag:
mago lint -s
This makes it a faster and more powerful replacement for php -l, allowing you to quickly validate the basic correctness of your files. It's a great way to start introducing Mago to your codebase incrementally.
--fix flag.mago lint command.How can I help you explore Laravel packages today?