comparison vendor/symfony/console/Input/InputArgument.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
29 private $mode; 29 private $mode;
30 private $default; 30 private $default;
31 private $description; 31 private $description;
32 32
33 /** 33 /**
34 * @param string $name The argument name 34 * @param string $name The argument name
35 * @param int $mode The argument mode: self::REQUIRED or self::OPTIONAL 35 * @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
36 * @param string $description A description text 36 * @param string $description A description text
37 * @param mixed $default The default value (for self::OPTIONAL mode only) 37 * @param string|string[]|null $default The default value (for self::OPTIONAL mode only)
38 * 38 *
39 * @throws InvalidArgumentException When argument mode is not valid 39 * @throws InvalidArgumentException When argument mode is not valid
40 */ 40 */
41 public function __construct($name, $mode = null, $description = '', $default = null) 41 public function __construct($name, $mode = null, $description = '', $default = null)
42 { 42 {
43 if (null === $mode) { 43 if (null === $mode) {
44 $mode = self::OPTIONAL; 44 $mode = self::OPTIONAL;
45 } elseif (!is_int($mode) || $mode > 7 || $mode < 1) { 45 } elseif (!\is_int($mode) || $mode > 7 || $mode < 1) {
46 throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode)); 46 throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
47 } 47 }
48 48
49 $this->name = $name; 49 $this->name = $name;
50 $this->mode = $mode; 50 $this->mode = $mode;
84 } 84 }
85 85
86 /** 86 /**
87 * Sets the default value. 87 * Sets the default value.
88 * 88 *
89 * @param mixed $default The default value 89 * @param string|string[]|null $default The default value
90 * 90 *
91 * @throws LogicException When incorrect default value is given 91 * @throws LogicException When incorrect default value is given
92 */ 92 */
93 public function setDefault($default = null) 93 public function setDefault($default = null)
94 { 94 {
96 throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); 96 throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
97 } 97 }
98 98
99 if ($this->isArray()) { 99 if ($this->isArray()) {
100 if (null === $default) { 100 if (null === $default) {
101 $default = array(); 101 $default = [];
102 } elseif (!is_array($default)) { 102 } elseif (!\is_array($default)) {
103 throw new LogicException('A default value for an array argument must be an array.'); 103 throw new LogicException('A default value for an array argument must be an array.');
104 } 104 }
105 } 105 }
106 106
107 $this->default = $default; 107 $this->default = $default;
108 } 108 }
109 109
110 /** 110 /**
111 * Returns the default value. 111 * Returns the default value.
112 * 112 *
113 * @return mixed The default value 113 * @return string|string[]|null The default value
114 */ 114 */
115 public function getDefault() 115 public function getDefault()
116 { 116 {
117 return $this->default; 117 return $this->default;
118 } 118 }