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.
Mago’s Rust-based toolchain is a highly performant alternative to PHP-native tools (e.g., PHPStan, Psalm, PHP-CS-Fixer) and aligns well with Laravel’s need for speed, scalability, and maintainability. Key strengths for Laravel:
fake() usage) reduces custom rule overhead.Potential misfit:
composer require carthage-software/mago, with minimal setup (e.g., mago init).--fail-level=error).Blockers:
| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Performance overhead | Low | Rust binary is lightweight; benchmarks show sub-second runs for 10K+ LOC. |
| Configuration complexity | Medium | Start with default config; incrementally customize rules. |
| False positives | Medium | Leverage baseline files and regex ignores (e.g., pattern = "..."). |
| Tooling fragmentation | Low | Mago replaces PHPStan, PHP-CS-Fixer, etc., reducing tool sprawl. |
| PHP version support | Low | Officially supports PHP 8.1+; Laravel’s minimum version (8.0+) is compatible. |
Key questions for the team:
--fail-level) integrate with existing pipelines?Mago is optimized for modern PHP/Laravel stacks:
composer.json and Laravel’s dependency management.Compatibility:
Phase 1: Pilot (2–4 weeks)
auth or api).composer require carthage-software/mago --dev
npx mago init
mago.php with Laravel-specific rules:
return [
'rules' => [
'laravel.test-assertions' => true,
'laravel.query-validation' => true,
],
];
# GitHub Actions example
- name: Run Mago
run: npx mago analyze --fail-level=error
Phase 2: Gradual Rollout (4–8 weeks)
mago analyze --generate-baseline to capture false positives.no-redundant-variable, prefer-fake-helper).Phase 3: Full Adoption
composer.json.mago format to pre-commit hooks.| Component | Compatibility Notes |
|---|---|
| Laravel | Built-in rules for test assertions, queries, fake(), and validation. |
| PHPStan/Psalm | Mago’s type system is more advanced (e.g., generic variance, Liskov substitution). |
| PHP-CS-Fixer | Formatting rules are compatible but faster (e.g., mago format vs. php-cs-fixer). |
| IDE (VS Code) | Experimental LSP support; requires mago language-server (if stable). |
| CI Systems | Works with GitHub Actions, GitLab CI, CircleCI (CLI-based). |
Sequencing:
mago lint.mago analyze.mago format.mago.php with Laravel rules.--fail-level=warning (gradual enforcement).Effort Estimate:
| Task | Frequency | Effort (Person-Hours) |
|---|---|---|
| Baseline updates | Monthly | 2–4 |
| Rule configuration tuning | Quarterly | 4–6 |
| CI/CD pipeline updates | Per release | 1–2 |
| Debugging false positives | Ad-hoc | 1–3 per incident |
Common Support Needs:
mago analyze --generate-baseline to suppress known issues.mago.php or create custom rules via Rust (advanced).--parallel or --memory-limit for large codebases.--parallel=N for multi-core execution.--memory-limit=2G).mago.baseline in repo to ensure consistency.How can I help you explore Laravel packages today?