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).
Installation:
curl --proto '=https' --tlsv1.2 -sSf https://carthage.software/mago.sh | bash
Verify with:
mago --version
First Use Case: Run a basic lint check on your Laravel project:
mago lint app/
Configuration:
Create a mago.php config file in your project root:
<?php
return [
'rules' => [
'no-unused-vars' => true,
'no-deprecated' => true,
],
'paths' => ['app', 'config', 'routes'],
];
| Command | Purpose |
|---|---|
mago lint |
Run linter on configured paths |
mago fmt |
Auto-format code |
mago analyze |
Static analysis with type checks |
mago fmt --check |
Dry-run formatting check |
CI Integration:
Add to .github/workflows/laravel.yml:
- name: Run Mago
run: |
mago lint --reporting-format=github
mago analyze --reporting-format=github
mago fmt --check
Pre-Commit Hooks:
Add to .git/hooks/pre-commit:
#!/bin/sh
mago lint --paths=app/config/routes
Service Provider Integration:
// app/Providers/AppServiceProvider.php
public function boot()
{
if ($this->app->environment('local')) {
Artisan::call('mago:lint');
}
}
mago lint --paths=app/Http/Controllers for targeted checksmago.php:
'rules' => [
'no-unused-vars' => ['severity' => 'warning'],
'custom-rule' => true,
]
container: ghcr.io/carthage-software/mago:1
False Positives in Analysis:
mago analyzevendor/ to excluded paths in mago.php if neededPerformance Issues:
storage/, tests/) from analysis--parallel flag for large codebasesConfiguration Conflicts:
.magoignore files (similar to .gitignore)~/.config/mago.php) overrides project configmago lint -v
mago explain --rule=no-unused-vars
mago ast app/Http/Controllers/Controller.php
Custom Rules: Create Rust-based rules by extending the Mago CLI:
// src/rules/mod.rs
pub fn register_custom_rules(registry: &mut RuleRegistry) {
registry.register(Rule::new("custom-rule", CustomRule::new()));
}
PHP Integration:
Use the mago/analyzer facade in Laravel:
$results = \Mago\Analyzer::analyze(app_path());
Reporting Formats: Generate JSON reports for custom processing:
mago lint --reporting-format=json > mago-report.json
bootstrap/cache/ from analysismago make:command MagoCheckCommand
How can I help you explore Laravel packages today?