Skip to content

\Symfony\Component\Console\Input\InputArgument::getArgument defines "incomplete" return type #28668

Closed
@chregu

Description

@chregu

Symfony version(s) affected: 3.4.16 (and master from the look of it)

Description
getArgument changed (here symfony/console@b6c275e) the return type from mixed to string|string[], but if I don't set a default value in '->addArgument()it returns null. (I guess I could also set that default value to falseor anything else, it's defined asmixed` in the doctype).

Now phpstan for example complains about that, when I check for null in my code to see, if it's set or not.

Is it wrong to check for "no argument set" in that way? What's the official way then?

How to reproduce
set up a command with

          ->addArgument(
                'prefix',
                InputArgument::OPTIONAL,
                'Table prefix (optional)'
            )

check for that

   if (null !== $input->getArgument('prefix')) {
           // do something
        }

and phpstan will complain

Possible Solution
expand the doctype to be able to return "null" or don't accept anything else as a defaultValue than a string (and make the default eg. '', but I guess, that would break some BC)

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