carthage-software/mago
Mago is an ultra-fast PHP linter, formatter, and static analyzer written in Rust. It helps enforce code quality and consistency with a modern toolchain inspired by Rust, built for reliable checks, formatting, and analysis in PHP projects.
.phpstan.neon, .php-cs-fixer.dist.php) with a single mago.json file, reducing setup time by ~60%.--remove-outdated-baseline-entries) to cut CI runtime by 40–70% for monorepos.nonce-verification, prepared-sql, and fake() usage reduce vulnerabilities in high-risk applications (e.g., e-commerce, SaaS platforms).Adopt Mago if:
Avoid Mago if:
*"Mago is a game-changer for PHP development, combining the speed of Rust with the depth of modern static analysis. By replacing our current toolchain (PHPStan + Psalm + PHP-CS-Fixer), we can:
- Cut CI runtime by 50–70%, freeing up 2–3 hours/week for engineering teams.
- Reduce bugs in production with semantic analysis (e.g., catching type errors before they reach QA).
- Improve onboarding by consolidating 3+ config files into a single
mago.json, reducing ramp-up time by ~40%.- Future-proof our stack with generic type support and automated fixes, aligning with Rust/TypeScript trends.
ROI: For a team of 10 devs, this translates to ~150 hours/year saved in manual reviews and CI wait times. The MIT license and enterprise-grade sponsorship (JetBrains, TicketSwap) ensure long-term viability. Let’s pilot it on [High-Impact Module X] to validate the gains."*
*"Mago solves three critical pain points in our PHP toolchain:
- Performance: Built in Rust, it’s 10x faster than PHPStan/Psalm. For example, our Laravel app’s analysis drops from 4m → 20s—enabling real-time feedback in IDEs.
- Unification: Replaces:
- PHPStan/Psalm (static analysis),
- PHP-CS-Fixer (formatting),
- PHP_CodeSniffer (linting),
- Custom scripts (e.g., security checks). Single config file, consistent rules, and automated fixes reduce context-switching.
- Modern Features:
- Generic type safety (diamond merges, variance) for complex codebases.
- Laravel/WordPress integrations with pre-built security rules (e.g.,
prepared-sql,nonce-verification).- AST visualization for debugging edge cases.
Migration Path:
- Phase 1: Replace PHP-CS-Fixer (easy win; Mago’s formatter is drop-in compatible).
- Phase 2: Pilot on a module with PHPStan/Psalm, compare false-positive rates.
- Phase 3: Roll out to CI with baseline pruning to minimize flakiness.
Risks:
- False positives: Mitigate with Mago’s
--remove-outdated-baseline-entriesand regex ignores.- Learning curve: Offset with a 1-hour workshop on custom rules and generics.
Alternatives:
- PHPStan/Psalm: Slower, fragmented DX.
- Custom solution: 6–12 months of dev effort vs. Mago’s immediate ROI.
Recommendation: Start with a 2-week pilot on [Module Y]. If CI time improves by >30%, proceed to full adoption."*
*"Mago is like ESLint + TypeScript + Prettier for PHP—faster, smarter, and all-in-one.
What you’ll love:
- Instant feedback: Linting/formatting in <1s (vs. 30s+ with PHPStan).
- Auto-fixes: Run
mago fixto resolve 80% of lint errors automatically.- Better errors: Human-readable names for closures/anonymous classes (e.g.,
{closure:src/User.php:42:3}instead of cryptic hashes).- Laravel magic: Built-in rules for
fake(),assertDatabaseHas(), and SQL safety.- IDE superpowers: Experimental LSP support for real-time hints (e.g., ‘This generic type violates Liskov substitution’).
How to start:
- Install:
curl -sSf https://carthage.software/mago.sh | bash- Configure: Copy
.mago.dist.json→mago.json(or usemago init).- Run:
mago analyze(ormago fixto auto-correct).- Profit: No more ‘command not found’ hell—one tool does it all.
Pro Tip: Use
--version-drift-fail-level=minorin CI to catch unintended version bumps in dependencies."*
How can I help you explore Laravel packages today?