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.
Install Mago via the official installer:
curl --proto '=https' --tlsv1.2 -sSf https://carthage.software/mago.sh | bash
Or via Composer:
composer require carthage-software/mago --dev
Initialize Configuration: Run in your Laravel project root:
mago init
This generates a mago.toml file with Laravel-specific defaults.
First Lint Run:
mago lint
Fix critical issues immediately:
mago lint --fix
Enable framework-specific rules in mago.toml:
[linter]
integrations = ["laravel", "phpunit"]
CI/CD Pipeline:
Add to .github/workflows/lint.yml:
- name: Lint with Mago
run: mago lint --minimum-fail-level=error
Pre-Commit Hook:
Use mago lint --fix in a pre-commit hook (via husky or pre-commit):
mago lint --fix --dry-run # Preview changes
IDE Integration:
Configure your IDE (PHPStorm/VSCode) to run mago lint on save via:
Settings > Tools > PHP > Run inspection bymago lint --fix --rule=prefer-static-closure
[linter.rules]
no-global = { exclude = ["tests/**"] }
mago lint --baseline=baseline.toml
Route/Controller Rules: Enable Laravel’s route validation rules:
[linter.rules]
laravel-route-return-type = { level = "warning" }
Migration Checks: Exclude generated migrations:
[linter]
excludes = ["database/migrations/*_timestamp.php"]
Service Container Rules: Detect unused service bindings:
mago lint --rule=unused-service-binding
Performance Spikes:
RUSTFLAGS in CI:
export RUSTFLAGS="-C target-cpu=native"
False Positives in Legacy Code:
no-goto may flag legacy header()/exit() calls.[linter.rules]
no-goto = { exclude = ["src/Legacy/**"] }
Baseline Drift:
--baseline-variant=loose for CI:
mago lint --baseline=baseline.toml --baseline-variant=loose
mago lint --verbose
mago lint --explain cyclomatic-complexity
mago ast --file=app/Http/Controllers/ExampleController.php
Custom Rules: Write Rust-based rules using Mago’s rule SDK.
Laravel-Specific Rules:
Extend the laravel integration by contributing to Mago’s integrations.
CI-Specific Configs: Use environment variables to override configs:
MAGO_MINIMUM_FAIL_LEVEL=warning mago lint
Facade Static Calls:
Mago may flag Route::get() as "ambiguous". Suppress with:
[linter.rules]
ambiguous-function-call = { exclude = ["routes/**"] }
Dynamic Properties:
Rules like no-dynamic-properties may conflict with Laravel’s dynamic properties (e.g., $request->input()). Exclude:
[linter.rules]
no-dynamic-properties = { exclude = ["app/Http/**"] }
Service Provider Boot Methods:
Mago’s unused-method rule may flag boot() methods. Whitelist:
[linter.rules]
unused-method = { exclude = ["**/Providers/*Provider.php"] }
How can I help you explore Laravel packages today?