carthage-software/mago
Mago is an extremely fast PHP linter, formatter, and static analyzer written in Rust. It helps teams catch issues early, enforce consistent style, and improve code quality across projects, with multiple install options like script, Homebrew, Composer, and Cargo.
Strengths:
--fix with dry-run support aligns with Laravel’s emphasis on developer productivity.Challenges:
mago.toml) and rule granularity may overwhelm teams accustomed to simpler tools like PHP-CS-Fixer.HasFactory).baseline to ignore existing violations during migration.no-undefined-route).mago.toml in .git)?Route::controller)?php-cs-fixer, phpstan, and psalm with a single mago lint command.composer.json scripts (e.g., pre-commit) and IDE hooks.--semantics for quick PHP syntax validation during developer setup.integrations = ["symfony"] for Laravel’s Symfony-based components (e.g., routing, HTTP kernel).use App\Models\* imports, HasFactory trait usage).Phase 1: Linting/Formatting
mago lint --fix.mago.toml to mirror existing .php-cs-fixer.dist.php rules.no_unused_imports vs. unused-import) require mapping.Phase 2: Static Analysis
mago lint --semantics for type safety.baseline to ignore existing type errors during transition.app() helper).Phase 3: Framework Integrations
integrations = ["symfony", "laravel"] (if available) for framework-specific checks.Route::resource validation).composer require carthage-software/mago.mago lint in pre-commit (faster than PHPStan).php-cs-fixer, phpstan, and psalm jobs with a single mago lint job.mago.toml rules to match IDE expectations (e.g., level = "warning" for IDE-friendly errors).| Step | Action | Dependencies |
|---|---|---|
| 1 | Install Mago globally via mago.sh or Composer. |
Rust toolchain (if not using binary). |
| 2 | Generate baseline: mago lint --baseline > mago-baseline.toml. |
Existing codebase. |
| 3 | Configure mago.toml with Laravel-specific rules. |
Laravel’s code structure. |
| 4 | Replace PHP-CS-Fixer with mago lint --fix. |
Baseline committed. |
| 5 | Add to CI: mago lint --minimum-fail-level=error. |
Phase 1 success. |
| 6 | Enable static analysis: mago lint --semantics. |
Phase 2 readiness. |
| 7 | Customize rules for Laravel idioms (e.g., exclude = ["routes/**"]). |
Feedback from team. |
mago.toml replaces .php-cs-fixer.dist.php, phpstan.neon, and psalm.xml.--semantics provides a low-friction entry point for new devs.--explain for rule-specific help.--fix with --dry-run reduces fear of breaking changes.| Scenario | Impact | Mitigation |
|---|---|---|
| Rust Toolchain Issues | Build failures in CI/CD. | Use pre-built binaries (mago.sh). |
| **False Pos |
How can I help you explore Laravel packages today?