drupal / mago
Mago extension for Drupal. Linter rules and analyzer plugins that know the Drupal conventions.
Requires
- php: ^8.1
- composer-runtime-api: ^2.0
- carthage-software/mago: ^1.58.1
- revolt/event-loop: ^1.0
- symfony/yaml: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^10.5 || ^11.5 || ^12.0 || ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
- amateescu/mago-drupal: 1.0.0-alpha1
This package is auto-updated.
Last update: 2026-11-13 17:51:40 UTC
README
An extension for Mago, the PHP linter, formatter and static analyzer. It adds Drupal's coding standards to Mago and gives its analyzer the types of Drupal's APIs.
It provides:
- Linter rules for the parts of Drupal's coding standards that aren't checked by Mago's own rules. Many of them have a fix.
- Analyzer plugins with the types of Drupal's services, entities, config and plugins, and checks for Drupal-specific mistakes, such as a service that doesn't exist.
- A config preset with Mago's settings for a Drupal project.
Documentation: https://project.pages.drupalcode.org/mago/
Installation
PHP 8.1 or later and Mago 1.58.1 or later are required.
composer require --dev carthage-software/mago "drupal/mago:^1.0@alpha"
Then create a mago.toml file next to composer.json:
extends = "vendor/drupal/mago/drupal.mago.toml"
# The lowest PHP version that the project supports.
php-version = "8.3"
[source]
# The project's own code.
paths = ["web/modules/custom", "web/themes/custom"]
# Read by the analyzer for their classes and functions, and not checked.
includes = ["vendor", "web/core", "web/modules/contrib"]
A module, theme or profile with its own repository uses paths = ["."] and
includes = ["vendor", "web"]. For a module cloned into a site and for a Drupal core checkout, see
Install.
Usage
Check the coding standards:
vendor/bin/mago lint
Fix the issues that have a fix:
vendor/bin/mago lint --fix
Run the static analysis:
vendor/bin/mago analyze
Documentation
The documentation covers:
- Setup: other project layouts, what the presets set, and the fix levels.
- Linter rules: every rule, with what it reports and what its fix does.
- Analyzer: the types and checks added to
mago analyze, and their limits. - Migrating from Coder: every sniff of Coder's standards and what takes its place.
- Migrating from PHPStan: every rule and extension of phpstan-drupal and what takes its place.
Contributing
Report bugs and request features in the issue queue on drupal.org. Changes go in as merge requests from an issue fork. See Development for the checks to run first.