Skip to content

Commit

Permalink
minor #17707 Remove InputOption::VALUE_REQUIRED mode from $default pa…
Browse files Browse the repository at this point in the history
…rameter description (tomasliubinas)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #17707).

Discussion
----------

Remove InputOption::VALUE_REQUIRED mode from $default parameter description

Reopening previous PR, providing more information

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Remove InputOption::VALUE_REQUIRED mode from $default parameter description as InputOption::setDefault() throws an exception only when called with InputOption::VALUE_NONE mode.
In practice the $default not null value could be still used in VALUE_REQUIRED mode in case InputOption was never set but accessed from InputDefinition::getOption() method.

There is an important difference between 2 concepts. Not required Option AND not required option Value. When the not required Option is not provided the default value still could be taken from required option Value instance.

Relevant (correct) test case:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Tests/Input/InputOptionTest.php#L136

Commits
-------

3c06151 Remove InputOption::VALUE_REQUIRED mode from $default parameter description as InputOption::setDefault() throws an exception only when called in InputOption::VALUE_NONE mode. In practice the $default value could still be accessed in InputOption::VALUE_REQUIRED mode in case InputOption was never set but accessed from InputDefinition::getOption() method
  • Loading branch information
fabpot committed Feb 15, 2016
2 parents d4ac467 + 3c06151 commit f6e401a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Command/Command.php
Expand Up @@ -370,7 +370,7 @@ public function addArgument($name, $mode = null, $description = '', $default = n
* @param string $shortcut The shortcut (can be null)
* @param int $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for InputOption::VALUE_REQUIRED or InputOption::VALUE_NONE)
* @param mixed $default The default value (must be null for InputOption::VALUE_NONE)
*
* @return Command The current instance
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Input/InputOption.php
Expand Up @@ -36,7 +36,7 @@ class InputOption
* @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int $mode The option mode: One of the VALUE_* constants
* @param string $description A description text
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
* @param mixed $default The default value (must be null for self::VALUE_NONE)
*
* @throws \InvalidArgumentException If option mode is invalid or incompatible
*/
Expand Down

0 comments on commit f6e401a

Please sign in to comment.