Diagnostics¶
friendsofmago/mago-symfony defines six analyzer diagnostic codes. Five are enabled by default and one is opt-in.
Summary¶
| Code | Level | Default | Plugin | What it reports |
|---|---|---|---|---|
symfony/private-service-access |
error | On | symfony |
A throwing get() fetches a private service or alias from a public container. |
symfony/unknown-service-id |
error | Opt-in | symfony |
A throwing get() fetches a literal service ID missing from the compiled XML. |
symfony-tree-builder-root/invalid-root-node-method |
error | On | symfony-tree-builder-root |
A TreeBuilder with a literal non-array root calls a method not defined on its root node class. |
symfony/unknown-console-argument |
error | On | symfony |
getArgument('name') asks for an argument that configure() does not declare. |
symfony/unknown-console-option |
error | On | symfony |
getOption('name') asks for an option that configure() does not declare. |
symfony/invalid-console-input-definition |
error | On | symfony |
InputArgument or InputOption uses a name, shortcut, mode, default, or suggestion combination that Symfony rejects. |
symfony/private-service-access¶
Level error, plugin symfony, enabled by default when a compiled container XML dump is loaded.
Reports a call to ContainerInterface::get() or Container::get() with a literal service ID marked private in the compiled container XML.
Skipped for:
ContainerBuilder,ServiceLocator,ServiceProviderInterface, andTestContainerreceivers.- Calls inside subclasses of
PHPUnit\Framework\TestCase. - Calls passing a non-throwing
$invalidBehaviorflag, meaning any value other thanContainerInterface::EXCEPTION_ON_INVALID_REFERENCE.
// Reported when app.private_service is private in the compiled container XML.
$container->get('app.private_service');
symfony/unknown-service-id¶
Level error, plugin symfony, opt-in. Requires a loaded compiled container XML dump and MAGO_SYMFONY_STRICT_CONTAINER_SERVICES set to 1, true, yes, or on.
Reports a throwing ContainerInterface::get() or Container::get() call whose literal service ID is absent from the compiled container XML.
Skipped for the same receivers, test classes, and non-throwing $invalidBehavior flags as symfony/private-service-access.
// Reported when MAGO_SYMFONY_STRICT_CONTAINER_SERVICES=1 and app.missing is not in the XML.
$container->get('app.missing');
symfony-tree-builder-root/invalid-root-node-method¶
Level error, plugin symfony-tree-builder-root, enabled by default.
Reports a method call on TreeBuilder::getRootNode() when the called method does not exist on the concrete non-array root node class. Supported literal non-array root types are 'scalar', 'boolean', 'integer', 'float', 'string', 'enum', and 'variable'.
$treeBuilder = new TreeBuilder('my_config', 'scalar');
// Reported because ScalarNodeDefinition does not define children().
$treeBuilder->getRootNode()->children();
symfony/unknown-console-argument¶
Level error, plugin symfony, enabled by default.
Reports a literal $input->getArgument('name') call inside a Symfony\Component\Console\Command\Command subclass when configure() does not declare 'name'.
Skipped for:
- The built-in
'command'argument. - Commands where
configure()callsparent::configure()or delegates input registration to dynamic helpers. - Commands whose constructor registers inputs.
- Commands extending a custom
Commandsubclass whenconfigure()declares no arguments. - Direct variable lookups guarded by
$input->hasArgument('name').
protected function configure(): void
{
$this->addArgument('username', InputArgument::REQUIRED);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Reported because configure() declares username, not user_name.
$input->getArgument('user_name');
return Command::SUCCESS;
}
symfony/unknown-console-option¶
Level error, plugin symfony, enabled by default.
Reports a literal $input->getOption('name') call inside a Symfony\Component\Console\Command\Command subclass when 'name' is neither declared in configure() nor a default application option.
Skipped for:
- Default options from
Symfony\Component\Console\Application:help,quiet,verbose,version,ansi,no-ansi,no-interaction, and, on Symfony 7.2 and newer,silent. WhenFrameworkBundleis included,Applicationalso definesenv,no-debug, andprofile. - Negatable options declared with
InputOption::VALUE_NEGATABLE. - Commands where
configure()callsparent::configure()or delegates input registration to dynamic helpers. - Commands whose constructor registers inputs.
- Commands extending a custom
Commandsubclass whenconfigure()declares no options. - Direct variable lookups guarded by
$input->hasOption('name').
protected function configure(): void
{
$this->addOption('dry-run', null, InputOption::VALUE_NONE);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
// Reported because configure() declares dry-run, not dry_run.
$input->getOption('dry_run');
return Command::SUCCESS;
}
symfony/invalid-console-input-definition¶
Level error, plugin symfony, enabled by default.
Reports statically analyzable InputArgument or InputOption declarations in Command::configure() that Symfony rejects at runtime:
- An option name that is empty or
'0'. - An option shortcut whose normalized value is empty or dash-only, such as
'-','--','|', or['-']. - An
InputArgumentorInputOptionmode bitmask outside Symfony's valid range. InputArgument::REQUIREDpaired with a non-null default value.InputArgument::IS_ARRAYpaired with a default value that is neither an array nornull.InputOption::VALUE_NONEpaired with a non-null default value.InputOption::VALUE_IS_ARRAYwithoutVALUE_REQUIREDorVALUE_OPTIONAL, or with a default value that is neither an array nornull.InputOption::VALUE_NEGATABLEcombined withVALUE_REQUIREDorVALUE_OPTIONAL.- Suggested values passed to an option that does not accept a value.
protected function configure(): void
{
// Reported because VALUE_NONE cannot declare a non-null default.
$this->addOption('force', null, InputOption::VALUE_NONE, '', true);
}
Suppressing diagnostics¶
To silence a diagnostic across a project or directory, add its code to [analyzer] ignore in mago.toml:
[analyzer]
ignore = [
"symfony/private-service-access",
{ code = "symfony/unknown-console-option", in = "src/Legacy/" },
]
To silence a single line, place @mago-ignore directly above the expression:
// @mago-ignore analysis:symfony/private-service-access
$container->get('app.private_service');