Skip to content

Console

SymfonyPlugin narrows built-in console helper lookups and validates Symfony Console command input declarations and usages.

Default helper return types

ConsoleHelperReturnTypeProvider targets Symfony\Component\Console\Helper\HelperSet::get() and Symfony\Component\Console\Command\Command::getHelper().

When called with one of the four default helper names registered by Application::getDefaultHelperSet(), the provider returns the concrete helper class:

Helper name Return type
'formatter' Symfony\Component\Console\Helper\FormatterHelper
'debug_formatter' Symfony\Component\Console\Helper\DebugFormatterHelper
'process' Symfony\Component\Console\Helper\ProcessHelper
'question' Symfony\Component\Console\Helper\QuestionHelper

Custom helper names keep Symfony's declared HelperInterface return type.

Command input validation

ConsoleCommandArgumentsHook analyzes subclasses of Symfony\Component\Console\Command\Command that declare a configure() method.

Recognized declarations

The hook reads statically analyzable calls inside configure():

  • $this->addArgument(...)
  • $this->addOption(...)
  • $this->setDefinition([...]) and $this->setDefinition(new InputDefinition([...]))

The hook resolves constant names, aliased imports, and mode bitmasks on InputArgument and InputOption statically.

Default application options

Every command inherits the built-in command argument and the default options derived from the analyzed Application class:

  • Symfony\Component\Console\Application defines help, quiet, verbose, version, ansi, no-ansi, no-interaction, and, on Symfony 7.2 and newer, silent.
  • Symfony\Bundle\FrameworkBundle\Console\Application adds env, no-debug, and profile when present in [source] includes.

Negatable options declared with InputOption::VALUE_NEGATABLE also permit the corresponding no-<name> lookup where applicable.

In standalone Console applications without FrameworkBundle, exclude vendor/symfony/framework-bundle from [source] includes. Otherwise the hook treats env, no-debug, and profile as default options.

Cases skipped to prevent false positives

symfony/unknown-console-argument and symfony/unknown-console-option skip a command or call when any of these conditions apply:

  • configure() calls parent::configure() or delegates input registration to a dynamic helper method.
  • The command's __construct() configures inputs directly or through helper calls.
  • An enclosing $input->hasOption('foo') or $input->hasArgument('bar') check guards a direct $input->getOption('foo') or $input->getArgument('bar') lookup.
  • The command extends a custom Command subclass and its own configure() declares no arguments for argument checks, or no options for option checks.

Console diagnostics

Code Level Default Summary
symfony/unknown-console-argument error On Reports getArgument('name') when configure() does not declare 'name'.
symfony/unknown-console-option error On Reports getOption('name') when configure() does not declare 'name' and it is not a default application option.
symfony/invalid-console-input-definition error On Reports InputArgument or InputOption name, shortcut, mode, default, or suggested-value combinations that Symfony rejects at runtime.