Skip to content

[Command] getOption return types #36

Closed
@mcfedr

Description

@mcfedr

This is a question, I'd be interested in implementing this, but not sure if its possible with Phpstan, so a point in the right direction would be useful.

In Symfony commands options (and arguments) are added in configure function, and this affects the return type of $input->getOption later.

class MyCommand {
    
    protected function configure(): void
    {
        $this
            ->addOption('str', null, InputOption::VALUE_REQUIRED, 'This option will be ?string')
            ->addOption('bool', null, InputOption::VALUE_NONE, 'this option will be bool')
            ->addOption('arra', null, InputOption::VALUE_IS_ARRAY, 'this option will be ?(string[])')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $str = $input->getOption('str');
    }
}

So can I change the return type of getOption, according to the options that are configured?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions