| Conditions | 5 |
| Paths | 5 |
| Total Lines | 24 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace nyx\console\input\parameter\values; |
||
| 33 | public function set($name, $value) : core\collections\interfaces\Map |
||
| 34 | { |
||
| 35 | $option = $this->assertIsDefined($name); |
||
| 36 | |||
| 37 | // Handle value expectations appropriately. |
||
| 38 | if (!$expected = $option->getValue()) { |
||
| 39 | if (isset($value)) { |
||
| 40 | throw new \RuntimeException("The option [--$name] does not take any values."); |
||
| 41 | } |
||
| 42 | } elseif (isset($value)) { |
||
| 43 | if ($expected->is(input\Value::REQUIRED)) { |
||
| 44 | throw new \RuntimeException("The option [--$name] requires a value."); |
||
| 45 | } |
||
| 46 | |||
| 47 | // Grab the default value in this case, since we're dealing with an optional value that was |
||
| 48 | // not explicitly set. |
||
| 49 | $value = $expected->getDefault(); |
||
| 50 | } |
||
| 51 | |||
| 52 | // Slight overhead, because the parent will grab the definition again, but at the same time |
||
| 53 | // it handles multiple value parameters for us. Setting boolean true here if $value is still |
||
| 54 | // not set, which covers Options which do not accept values but still get set (ie. flags). |
||
| 55 | return parent::set($name, $value ?? true); |
||
| 56 | } |
||
| 57 | } |
||
| 58 |