Skip to content

Required arguments and option can be null in interact #256

Closed
@alexander-schranz

Description

@alexander-schranz

In the interact method of the symfony console command its possible to ask for required attributes. In that context a required argument can still be null.

The following code will tell that the null check does not work:

e.g.:

    protected function configure(): void
    {
        $this->addArgument('market', InputArgument::REQUIRED);
    }
    
    protected function interact(InputInterface $input, OutputInterface $output): void
    {
        $market = $input->getArgument('market'); // here market can still be `null|string`

        if ($market === null) {
            $input->setArgument('market', $ui->ask('Which market you want to use for the import?'));
        }
    }
    protected function execute(InputInterface $input, OutputInterface $output): void
    {
        $market = $input->getArgument('market'); // here market can only be a string
    }

When using !$market rector will actually refractor it to $test === '' && $test === '0' so that is also not correct.

If possible it would be great that depending if the argument is used inside interact it should be nullable else it should be the same as currently. Not sure if that is possible via phpstan.

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