Mago for Symfony¶
friendsofmago/mago-symfony adds Symfony static analysis to Mago. It resolves types and reports Symfony-specific mistakes across five areas:
- Container services and parameters. Resolves
ContainerInterface::get(),Container::get(), and parameter lookups from compiled container XML or a JSON map. Reports private service lookups and optional unknown service IDs. See Container. - Console commands. Types default helpers from
HelperSet::get()andCommand::getHelper(). Checksconfigure()definitions and literalgetArgument()andgetOption()calls. See Console. - Config TreeBuilder chains. Tracks parent and child node types across
TreeBuilder::getRootNode(),children(), prototypes,validate(),beforeNormalization(), andend(). Reports invalid method calls on non-array roots. See Config TreeBuilder. - HTTP, Form, Serializer, Messenger, and Security APIs. Narrows return types for
HeaderBag,ParameterBag,InputBag,Request,ResponseHeaderBag,ControllerEvent,FormInterface,SerializerInterface,DenormalizerInterface,WrappedExceptionsInterface, and SecuritygetUser(). See HTTP, Form, Serializer, and Security. - Lifecycle initializers and entry points. Recognizes Symfony lifecycle initializers, public
#[Required]properties, and framework method entry points. See Lifecycle and entry points.
Quick start¶
You need PHP 8.1 or newer, Mago ^1.60.2, and Symfony ^6.4 || ^7.0.
Install the package with Composer:
composer require --dev friendsofmago/mago-symfony
Add the worker and Symfony vendor includes to mago.toml:
[source]
includes = ["vendor/symfony", "vendor/psr"]
[extension-hosts.symfony]
command = ["php", "-d", "xdebug.mode=off", "-d", "pcov.enabled=0", "-d", "memory_limit=512M", "vendor/friendsofmago/mago-symfony/resources/worker.php"]
workers = 1
Validate the extension host and run the analyzer:
vendor/bin/mago extension validate
vendor/bin/mago analyze
Example diagnostic¶
Mago reports console typos before the command runs:
$this->addArgument('username', InputArgument::REQUIRED);
// ...
$input->getArgument('user_name'); // symfony/unknown-console-argument
Next steps¶
- Read Install for prerequisites and project layout options.
- Read Configuration for container XML, JSON map, Security user, and suppression settings.
- Read The worker for worker entry points, memory flags, and error output.
- Read Composing extensions to run
friendsofmago/mago-symfonyalongside other Mago extensions in one worker. - Browse Diagnostics for every error code the extension reports.