Skip to content

Argument and option definition defaults are documented but never applied #39

Description

@HafizMMoaz

The definition docblocks promise a default key and type casting:

Definitions keyed by position, each with optional "type", "required" and "default" keys
(src/Command.php:56-58)

Values declared with a type are cast when possible
(src/Command.php:326-327)

Neither happens. validateDefinitions() only reports errors, and nothing ever writes back into Console::$arguments or Console::$options.

protected array $argumentDefinitions = [1 => ['type' => 'string', 'default' => 'fallback']];
protected array $optionDefinitions   = ['name' => ['type' => 'string', 'default' => 'anon']];
php app typed 5
# getArgument(1) === null   (expected 'fallback')
# getOption('name')  === null   (expected 'anon')

Verified on PHP 8.4.19 against main (2c0159f).

Two ways out: implement defaults and casting so getArgument()/getOption() return the resolved value, or drop both claims from the docblocks. Implementing them is the more useful option, since it is what the definitions API implies. Casting also raises a design question worth settling here: getArgument() is typed ?string, so an int definition cannot return an int without a signature change or a separate typed accessor.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions