@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function __construct(array $argv = null, InputDefinition $definition = null) |
47 | 47 | { |
48 | 48 | if (null === $argv) { |
49 | - $argv = $_SERVER['argv']; |
|
49 | + $argv = $_SERVER[ 'argv' ]; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | // strip the application name |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | public function getFirstArgument() |
64 | 64 | { |
65 | 65 | foreach ($this->tokens as $token) { |
66 | - if ($token && '-' === $token[0]) { |
|
66 | + if ($token && '-' === $token[ 0 ]) { |
|
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | return $token; |
@@ -128,11 +128,11 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function __toString() |
130 | 130 | { |
131 | - $tokens = array_map(function ($token) { |
|
131 | + $tokens = array_map(function($token) { |
|
132 | 132 | if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) { |
133 | - return $match[1].$this->escapeToken($match[2]); |
|
133 | + return $match[ 1 ].$this->escapeToken($match[ 2 ]); |
|
134 | 134 | } |
135 | - if ($token && '-' !== $token[0]) { |
|
135 | + if ($token && '-' !== $token[ 0 ]) { |
|
136 | 136 | return $this->escapeToken($token); |
137 | 137 | } |
138 | 138 | return $token; |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | { |
150 | 150 | $name = substr($token, 1); |
151 | 151 | if (strlen($name) > 1) { |
152 | - if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) { |
|
152 | + if ($this->definition->hasShortcut($name[ 0 ]) && $this->definition->getOptionForShortcut($name[ 0 ])->acceptValue()) { |
|
153 | 153 | // an option with a value (with no space) |
154 | - $this->addShortOption($name[0], substr($name, 1)); |
|
154 | + $this->addShortOption($name[ 0 ], substr($name, 1)); |
|
155 | 155 | } else { |
156 | 156 | $this->parseShortOptionSet($name); |
157 | 157 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | { |
172 | 172 | $len = strlen($name); |
173 | 173 | for ($i = 0; $i < $len; ++$i) { |
174 | - if (!$this->definition->hasShortcut($name[$i])) |
|
175 | - throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); |
|
174 | + if (!$this->definition->hasShortcut($name[ $i ])) |
|
175 | + throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[ $i ])); |
|
176 | 176 | |
177 | - $option = $this->definition->getOptionForShortcut($name[$i]); |
|
177 | + $option = $this->definition->getOptionForShortcut($name[ $i ]); |
|
178 | 178 | if ($option->acceptValue()) { |
179 | 179 | $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1)); |
180 | 180 | break; |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | // if input is expecting another argument, add it |
217 | 217 | if ($this->definition->hasArgument($c)) { |
218 | 218 | $arg = $this->definition->getArgument($c); |
219 | - $this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token; |
|
219 | + $this->arguments[ $arg->getName() ] = $arg->isArray() ? array($token) : $token; |
|
220 | 220 | |
221 | 221 | // if last argument isArray(), append token to last argument |
222 | 222 | } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) { |
223 | 223 | $arg = $this->definition->getArgument($c - 1); |
224 | - $this->arguments[$arg->getName()][] = $token; |
|
224 | + $this->arguments[ $arg->getName() ][ ] = $token; |
|
225 | 225 | |
226 | 226 | // unexpected argument |
227 | 227 | } else { |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | // if option accepts an optional or mandatory argument |
273 | 273 | // let's see if there is one provided |
274 | 274 | $next = array_shift($this->parsed); |
275 | - if ((isset($next[0]) && '-' !== $next[0]) || in_array($next, array('', null), true)) { |
|
275 | + if ((isset($next[ 0 ]) && '-' !== $next[ 0 ]) || in_array($next, array('', null), true)) { |
|
276 | 276 | $value = $next; |
277 | 277 | } else { |
278 | 278 | array_unshift($this->parsed, $next); |
@@ -289,9 +289,9 @@ discard block |
||
289 | 289 | } |
290 | 290 | |
291 | 291 | if ($option->isArray()) { |
292 | - $this->options[$name][] = $value; |
|
292 | + $this->options[ $name ][ ] = $value; |
|
293 | 293 | } else { |
294 | - $this->options[$name] = $value; |
|
294 | + $this->options[ $name ] = $value; |
|
295 | 295 | } |
296 | 296 | } |
297 | 297 | |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $parseOptions = false; |
311 | 311 | } elseif ($parseOptions && 0 === strpos($token, '--')) { |
312 | 312 | $this->parseLongOption($token); |
313 | - } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) { |
|
313 | + } elseif ($parseOptions && '-' === $token[ 0 ] && '-' !== $token) { |
|
314 | 314 | $this->parseShortOption($token); |
315 | 315 | } else { |
316 | 316 | $this->parseArgument($token); |
@@ -171,8 +171,9 @@ discard block |
||
171 | 171 | { |
172 | 172 | $len = strlen($name); |
173 | 173 | for ($i = 0; $i < $len; ++$i) { |
174 | - if (!$this->definition->hasShortcut($name[$i])) |
|
175 | - throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); |
|
174 | + if (!$this->definition->hasShortcut($name[$i])) { |
|
175 | + throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i])); |
|
176 | + } |
|
176 | 177 | |
177 | 178 | $option = $this->definition->getOptionForShortcut($name[$i]); |
178 | 179 | if ($option->acceptValue()) { |
@@ -243,8 +244,9 @@ discard block |
||
243 | 244 | */ |
244 | 245 | private function addShortOption($shortcut, $value) |
245 | 246 | { |
246 | - if (!$this->definition->hasShortcut($shortcut)) |
|
247 | - throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut)); |
|
247 | + if (!$this->definition->hasShortcut($shortcut)) { |
|
248 | + throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut)); |
|
249 | + } |
|
248 | 250 | |
249 | 251 | $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value); |
250 | 252 | } |
@@ -259,14 +261,16 @@ discard block |
||
259 | 261 | */ |
260 | 262 | private function addLongOption($name, $value) |
261 | 263 | { |
262 | - if (!$this->definition->hasOption($name)) |
|
263 | - throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name)); |
|
264 | + if (!$this->definition->hasOption($name)) { |
|
265 | + throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name)); |
|
266 | + } |
|
264 | 267 | |
265 | 268 | /**@var $option InputOption*/ |
266 | 269 | $option = $this->definition->getOption($name); |
267 | 270 | |
268 | - if (null !== $value && !$option->acceptValue()) |
|
269 | - throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); |
|
271 | + if (null !== $value && !$option->acceptValue()) { |
|
272 | + throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name)); |
|
273 | + } |
|
270 | 274 | |
271 | 275 | if (in_array($value, array('', null), true) && $option->acceptValue() && count($this->parsed)) { |
272 | 276 | // if option accepts an optional or mandatory argument |
@@ -280,11 +284,13 @@ discard block |
||
280 | 284 | } |
281 | 285 | |
282 | 286 | if (null === $value) { |
283 | - if ($option->isValueRequired()) |
|
284 | - throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name)); |
|
287 | + if ($option->isValueRequired()) { |
|
288 | + throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name)); |
|
289 | + } |
|
285 | 290 | |
286 | - if (!$option->isArray() && !$option->isValueOptional()) |
|
287 | - $value = true; |
|
291 | + if (!$option->isArray() && !$option->isValueOptional()) { |
|
292 | + $value = true; |
|
293 | + } |
|
288 | 294 | |
289 | 295 | } |
290 | 296 |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | * @param $default |
32 | 32 | * @param $description |
33 | 33 | */ |
34 | - public function __construct(string $name, int $mode = null, string $description= '', $default = null) |
|
34 | + public function __construct(string $name, int $mode = null, string $description = '', $default = null) |
|
35 | 35 | { |
36 | - if($mode === null) { |
|
36 | + if ($mode === null) { |
|
37 | 37 | $mode = self::OPTIONAL; |
38 | - } elseif($mode > 7 || $mode < 1) { |
|
38 | + } elseif ($mode > 7 || $mode < 1) { |
|
39 | 39 | throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid', $mode)); |
40 | 40 | } |
41 | 41 | |
@@ -113,13 +113,13 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function setDefault($default = null) |
115 | 115 | { |
116 | - if(self::REQUIRED === $this->mode && null !== $default) |
|
116 | + if (self::REQUIRED === $this->mode && null !== $default) |
|
117 | 117 | throw new \LogicException('Cannot set default value except for InputArgument::OPTIONAL mode.'); |
118 | 118 | |
119 | - if($this->isArray()) { |
|
120 | - if(null === $default) { |
|
119 | + if ($this->isArray()) { |
|
120 | + if (null === $default) { |
|
121 | 121 | $default = array(); |
122 | - } elseif(!is_array($default)) { |
|
122 | + } elseif (!is_array($default)) { |
|
123 | 123 | throw new \LogicException('A default value for an array option must be an array.'); |
124 | 124 | } |
125 | 125 | } |
@@ -113,8 +113,9 @@ |
||
113 | 113 | */ |
114 | 114 | public function setDefault($default = null) |
115 | 115 | { |
116 | - if(self::REQUIRED === $this->mode && null !== $default) |
|
117 | - throw new \LogicException('Cannot set default value except for InputArgument::OPTIONAL mode.'); |
|
116 | + if(self::REQUIRED === $this->mode && null !== $default) { |
|
117 | + throw new \LogicException('Cannot set default value except for InputArgument::OPTIONAL mode.'); |
|
118 | + } |
|
118 | 119 | |
119 | 120 | if($this->isArray()) { |
120 | 121 | if(null === $default) { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) |
38 | 38 | { |
39 | - if(empty($name)) |
|
39 | + if (empty($name)) |
|
40 | 40 | throw new \InvalidArgumentException('An option name cannot be empty.'); |
41 | 41 | |
42 | 42 | if (empty($shortcut)) |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | |
57 | 57 | } |
58 | 58 | |
59 | - if(null === $mode) { |
|
59 | + if (null === $mode) { |
|
60 | 60 | $mode = self::VALUE_NONE; |
61 | - } elseif($mode > 15 || $mode < 1) { |
|
61 | + } elseif ($mode > 15 || $mode < 1) { |
|
62 | 62 | throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode)); |
63 | 63 | } |
64 | 64 | |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function setDefault($default = null) |
163 | 163 | { |
164 | - if(self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) |
|
164 | + if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) |
|
165 | 165 | throw new \LogicException('Cannot set default value when using InputOption::VALUE_NONE mode.'); |
166 | 166 | |
167 | - if($this->isArray()) { |
|
168 | - if(null === $default) { |
|
167 | + if ($this->isArray()) { |
|
168 | + if (null === $default) { |
|
169 | 169 | $default = array(); |
170 | - } elseif(!is_array($default)) { |
|
170 | + } elseif (!is_array($default)) { |
|
171 | 171 | throw new \LogicException('A default value for an array option must be an array.'); |
172 | 172 | } |
173 | 173 | } |
@@ -36,23 +36,27 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) |
38 | 38 | { |
39 | - if(empty($name)) |
|
40 | - throw new \InvalidArgumentException('An option name cannot be empty.'); |
|
39 | + if(empty($name)) { |
|
40 | + throw new \InvalidArgumentException('An option name cannot be empty.'); |
|
41 | + } |
|
41 | 42 | |
42 | - if (empty($shortcut)) |
|
43 | - $shortcut = null; |
|
43 | + if (empty($shortcut)) { |
|
44 | + $shortcut = null; |
|
45 | + } |
|
44 | 46 | |
45 | 47 | |
46 | 48 | if (null !== $shortcut) { |
47 | - if (is_array($shortcut)) |
|
48 | - $shortcut = implode('|', $shortcut); |
|
49 | + if (is_array($shortcut)) { |
|
50 | + $shortcut = implode('|', $shortcut); |
|
51 | + } |
|
49 | 52 | |
50 | 53 | $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-')); |
51 | 54 | $shortcuts = array_filter($shortcuts); |
52 | 55 | $shortcut = implode('|', $shortcuts); |
53 | 56 | |
54 | - if (empty($shortcut)) |
|
55 | - throw new \InvalidArgumentException('An option shortcut cannot be empty.'); |
|
57 | + if (empty($shortcut)) { |
|
58 | + throw new \InvalidArgumentException('An option shortcut cannot be empty.'); |
|
59 | + } |
|
56 | 60 | |
57 | 61 | } |
58 | 62 | |
@@ -161,8 +165,9 @@ discard block |
||
161 | 165 | */ |
162 | 166 | public function setDefault($default = null) |
163 | 167 | { |
164 | - if(self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) |
|
165 | - throw new \LogicException('Cannot set default value when using InputOption::VALUE_NONE mode.'); |
|
168 | + if(self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { |
|
169 | + throw new \LogicException('Cannot set default value when using InputOption::VALUE_NONE mode.'); |
|
170 | + } |
|
166 | 171 | |
167 | 172 | if($this->isArray()) { |
168 | 173 | if(null === $default) { |
@@ -41,11 +41,11 @@ discard block |
||
41 | 41 | { |
42 | 42 | $arguments = array(); |
43 | 43 | $options = array(); |
44 | - foreach($definition as $item) { |
|
45 | - if($item instanceof InputOption) { |
|
46 | - $options[] = $item; |
|
44 | + foreach ($definition as $item) { |
|
45 | + if ($item instanceof InputOption) { |
|
46 | + $options[ ] = $item; |
|
47 | 47 | } else { |
48 | - $arguments[] = $item; |
|
48 | + $arguments[ ] = $item; |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function addArguments($arguments = array()) |
71 | 71 | { |
72 | - if($arguments !== null) { |
|
73 | - foreach($arguments as $argument) { |
|
72 | + if ($arguments !== null) { |
|
73 | + foreach ($arguments as $argument) { |
|
74 | 74 | $this->addArgument($argument); |
75 | 75 | } |
76 | 76 | } |
@@ -82,25 +82,25 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function addArgument(InputArgument $argument) |
84 | 84 | { |
85 | - if(isset($this->arguments[$argument->getName()])) |
|
85 | + if (isset($this->arguments[ $argument->getName() ])) |
|
86 | 86 | throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName())); |
87 | 87 | |
88 | - if($this->hasAnArrayArgument) |
|
88 | + if ($this->hasAnArrayArgument) |
|
89 | 89 | throw new \LogicException('Cannot add an argument after an array argument.'); |
90 | 90 | |
91 | - if($argument->isRequired() && $this->hasOptional) |
|
91 | + if ($argument->isRequired() && $this->hasOptional) |
|
92 | 92 | throw new \LogicException('Cannot add a required argument after an optional one.'); |
93 | 93 | |
94 | - if($argument->isArray()) |
|
94 | + if ($argument->isArray()) |
|
95 | 95 | $this->hasAnArrayArgument = true; |
96 | 96 | |
97 | - if($argument->isRequired()) { |
|
97 | + if ($argument->isRequired()) { |
|
98 | 98 | ++$this->requiredCount; |
99 | 99 | } else { |
100 | 100 | $this->hasOptional = true; |
101 | 101 | } |
102 | 102 | |
103 | - $this->arguments[$argument->getName()] = $argument; |
|
103 | + $this->arguments[ $argument->getName() ] = $argument; |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -112,12 +112,12 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function getArgument($name) |
114 | 114 | { |
115 | - if(!$this->hasArgument($name)) |
|
115 | + if (!$this->hasArgument($name)) |
|
116 | 116 | throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
117 | 117 | |
118 | 118 | $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments; |
119 | 119 | |
120 | - return $arguments[$name]; |
|
120 | + return $arguments[ $name ]; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | { |
131 | 131 | $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments; |
132 | 132 | |
133 | - return isset($arguments[$name]); |
|
133 | + return isset($arguments[ $name ]); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -166,9 +166,9 @@ discard block |
||
166 | 166 | public function getArgumentDefaults() |
167 | 167 | { |
168 | 168 | $values = array(); |
169 | - foreach($this->arguments as $argument) { |
|
169 | + foreach ($this->arguments as $argument) { |
|
170 | 170 | /**@var $argument InputArgument*/ |
171 | - $values[$argument->getName()] = $argument->getDefault(); |
|
171 | + $values[ $argument->getName() ] = $argument->getDefault(); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return $values; |
@@ -187,10 +187,10 @@ discard block |
||
187 | 187 | |
188 | 188 | public function getOption($name) |
189 | 189 | { |
190 | - if(!$this->hasOption($name)) |
|
190 | + if (!$this->hasOption($name)) |
|
191 | 191 | throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); |
192 | 192 | |
193 | - return $this->options[$name]; |
|
193 | + return $this->options[ $name ]; |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public function addOptions($options = array()) |
202 | 202 | { |
203 | - foreach($options as $option) { |
|
203 | + foreach ($options as $option) { |
|
204 | 204 | $this->addOption($option); |
205 | 205 | } |
206 | 206 | } |
@@ -212,10 +212,10 @@ discard block |
||
212 | 212 | public function addOption($option) |
213 | 213 | { |
214 | 214 | /**@var $option InputOption*/ |
215 | - if(isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) |
|
215 | + if (isset($this->options[ $option->getName() ]) && !$option->equals($this->options[ $option->getName() ])) |
|
216 | 216 | throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName())); |
217 | 217 | |
218 | - $this->options[$option->getName()] = $option; |
|
218 | + $this->options[ $option->getName() ] = $option; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function hasOption($name) |
231 | 231 | { |
232 | - return isset($this->options[$name]); |
|
232 | + return isset($this->options[ $name ]); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $values = array(); |
249 | 249 | foreach ($this->options as $option) { |
250 | 250 | /**@var $option InputOption*/ |
251 | - $values[$option->getName()] = $option->getDefault(); |
|
251 | + $values[ $option->getName() ] = $option->getDefault(); |
|
252 | 252 | } |
253 | 253 | |
254 | 254 | return $values; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | */ |
264 | 264 | public function hasShortcut($name) |
265 | 265 | { |
266 | - return isset($this->shortcuts[$name]); |
|
266 | + return isset($this->shortcuts[ $name ]); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | */ |
290 | 290 | private function shortcutToName($shortcut) |
291 | 291 | { |
292 | - if (!isset($this->shortcuts[$shortcut])) |
|
292 | + if (!isset($this->shortcuts[ $shortcut ])) |
|
293 | 293 | throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); |
294 | 294 | |
295 | - return $this->shortcuts[$shortcut]; |
|
295 | + return $this->shortcuts[ $shortcut ]; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | { |
307 | 307 | $elements = array(); |
308 | 308 | if ($short && $this->getOptions()) { |
309 | - $elements[] = '[options]'; |
|
309 | + $elements[ ] = '[options]'; |
|
310 | 310 | } elseif (!$short) { |
311 | 311 | foreach ($this->getOptions() as $option) { |
312 | 312 | /**@var $option InputOption*/ |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | ); |
321 | 321 | } |
322 | 322 | $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : ''; |
323 | - $elements[] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value); |
|
323 | + $elements[ ] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value); |
|
324 | 324 | } |
325 | 325 | } |
326 | 326 | if (count($elements) && $this->getArguments()) |
327 | - $elements[] = '[--]'; |
|
327 | + $elements[ ] = '[--]'; |
|
328 | 328 | |
329 | 329 | foreach ($this->getArguments() as $argument) { |
330 | 330 | $element = '<'.$argument->getName().'>'; |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | if ($argument->isArray()) |
339 | 339 | $element .= '...'; |
340 | 340 | |
341 | - $elements[] = $element; |
|
341 | + $elements[ ] = $element; |
|
342 | 342 | } |
343 | 343 | return implode(' ', $elements); |
344 | 344 | } |
@@ -82,17 +82,21 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function addArgument(InputArgument $argument) |
84 | 84 | { |
85 | - if(isset($this->arguments[$argument->getName()])) |
|
86 | - throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName())); |
|
85 | + if(isset($this->arguments[$argument->getName()])) { |
|
86 | + throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName())); |
|
87 | + } |
|
87 | 88 | |
88 | - if($this->hasAnArrayArgument) |
|
89 | - throw new \LogicException('Cannot add an argument after an array argument.'); |
|
89 | + if($this->hasAnArrayArgument) { |
|
90 | + throw new \LogicException('Cannot add an argument after an array argument.'); |
|
91 | + } |
|
90 | 92 | |
91 | - if($argument->isRequired() && $this->hasOptional) |
|
92 | - throw new \LogicException('Cannot add a required argument after an optional one.'); |
|
93 | + if($argument->isRequired() && $this->hasOptional) { |
|
94 | + throw new \LogicException('Cannot add a required argument after an optional one.'); |
|
95 | + } |
|
93 | 96 | |
94 | - if($argument->isArray()) |
|
95 | - $this->hasAnArrayArgument = true; |
|
97 | + if($argument->isArray()) { |
|
98 | + $this->hasAnArrayArgument = true; |
|
99 | + } |
|
96 | 100 | |
97 | 101 | if($argument->isRequired()) { |
98 | 102 | ++$this->requiredCount; |
@@ -112,8 +116,9 @@ discard block |
||
112 | 116 | */ |
113 | 117 | public function getArgument($name) |
114 | 118 | { |
115 | - if(!$this->hasArgument($name)) |
|
116 | - throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
|
119 | + if(!$this->hasArgument($name)) { |
|
120 | + throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); |
|
121 | + } |
|
117 | 122 | |
118 | 123 | $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments; |
119 | 124 | |
@@ -187,8 +192,9 @@ discard block |
||
187 | 192 | |
188 | 193 | public function getOption($name) |
189 | 194 | { |
190 | - if(!$this->hasOption($name)) |
|
191 | - throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); |
|
195 | + if(!$this->hasOption($name)) { |
|
196 | + throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); |
|
197 | + } |
|
192 | 198 | |
193 | 199 | return $this->options[$name]; |
194 | 200 | } |
@@ -212,8 +218,9 @@ discard block |
||
212 | 218 | public function addOption($option) |
213 | 219 | { |
214 | 220 | /**@var $option InputOption*/ |
215 | - if(isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) |
|
216 | - throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName())); |
|
221 | + if(isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) { |
|
222 | + throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName())); |
|
223 | + } |
|
217 | 224 | |
218 | 225 | $this->options[$option->getName()] = $option; |
219 | 226 | } |
@@ -289,8 +296,9 @@ discard block |
||
289 | 296 | */ |
290 | 297 | private function shortcutToName($shortcut) |
291 | 298 | { |
292 | - if (!isset($this->shortcuts[$shortcut])) |
|
293 | - throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); |
|
299 | + if (!isset($this->shortcuts[$shortcut])) { |
|
300 | + throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut)); |
|
301 | + } |
|
294 | 302 | |
295 | 303 | return $this->shortcuts[$shortcut]; |
296 | 304 | } |
@@ -323,8 +331,9 @@ discard block |
||
323 | 331 | $elements[] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value); |
324 | 332 | } |
325 | 333 | } |
326 | - if (count($elements) && $this->getArguments()) |
|
327 | - $elements[] = '[--]'; |
|
334 | + if (count($elements) && $this->getArguments()) { |
|
335 | + $elements[] = '[--]'; |
|
336 | + } |
|
328 | 337 | |
329 | 338 | foreach ($this->getArguments() as $argument) { |
330 | 339 | $element = '<'.$argument->getName().'>'; |
@@ -335,8 +344,9 @@ discard block |
||
335 | 344 | $element = $element.' ('.$element.')'; |
336 | 345 | } |
337 | 346 | |
338 | - if ($argument->isArray()) |
|
339 | - $element .= '...'; |
|
347 | + if ($argument->isArray()) { |
|
348 | + $element .= '...'; |
|
349 | + } |
|
340 | 350 | |
341 | 351 | $elements[] = $element; |
342 | 352 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public function __construct(InputDefinition $definition = null) |
24 | 24 | { |
25 | - if($definition === null) { |
|
25 | + if ($definition === null) { |
|
26 | 26 | $this->definition = new InputDefinition(); |
27 | 27 | } else { |
28 | 28 | $this->bind($definition); |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | $definition = $this->definition; |
56 | 56 | $givenArguments = $this->arguments; |
57 | 57 | |
58 | - $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) { |
|
58 | + $missingArguments = array_filter(array_keys($definition->getArguments()), function($argument) use ($definition, $givenArguments) { |
|
59 | 59 | return !array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired(); |
60 | 60 | }); |
61 | 61 | |
62 | - if(count($missingArguments) > 0) { |
|
63 | - throw new \RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(' ,', $missingArguments ))); |
|
62 | + if (count($missingArguments) > 0) { |
|
63 | + throw new \RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(' ,', $missingArguments))); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getArgument($name) |
95 | 95 | { |
96 | - if(!$this->definition->hasArgument($name)) |
|
96 | + if (!$this->definition->hasArgument($name)) |
|
97 | 97 | throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
98 | 98 | |
99 | - return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault(); |
|
99 | + return isset($this->arguments[ $name ]) ? $this->arguments[ $name ] : $this->definition->getArgument($name)->getDefault(); |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -104,10 +104,10 @@ discard block |
||
104 | 104 | */ |
105 | 105 | public function setArgument($name, $value) |
106 | 106 | { |
107 | - if(!$this->definition->hasArgument($name)) |
|
107 | + if (!$this->definition->hasArgument($name)) |
|
108 | 108 | throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
109 | 109 | |
110 | - $this->arguments[$name] = $value; |
|
110 | + $this->arguments[ $name ] = $value; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | if (!$this->definition->hasOption($name)) { |
135 | 135 | throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); |
136 | 136 | } |
137 | - return array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault(); |
|
137 | + return array_key_exists($name, $this->options) ? $this->options[ $name ] : $this->definition->getOption($name)->getDefault(); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | if (!$this->definition->hasOption($name)) { |
146 | 146 | throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name)); |
147 | 147 | } |
148 | - $this->options[$name] = $value; |
|
148 | + $this->options[ $name ] = $value; |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
@@ -93,8 +93,9 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function getArgument($name) |
95 | 95 | { |
96 | - if(!$this->definition->hasArgument($name)) |
|
97 | - throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
|
96 | + if(!$this->definition->hasArgument($name)) { |
|
97 | + throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
|
98 | + } |
|
98 | 99 | |
99 | 100 | return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault(); |
100 | 101 | } |
@@ -104,8 +105,9 @@ discard block |
||
104 | 105 | */ |
105 | 106 | public function setArgument($name, $value) |
106 | 107 | { |
107 | - if(!$this->definition->hasArgument($name)) |
|
108 | - throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
|
108 | + if(!$this->definition->hasArgument($name)) { |
|
109 | + throw new \InvalidArgumentException(sprintf('The "%s" arguments does not exist.', $name)); |
|
110 | + } |
|
109 | 111 | |
110 | 112 | $this->arguments[$name] = $value; |
111 | 113 | } |
@@ -63,10 +63,10 @@ |
||
63 | 63 | */ |
64 | 64 | function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') |
65 | 65 | { |
66 | - $pieces = []; |
|
66 | + $pieces = [ ]; |
|
67 | 67 | $max = mb_strlen($keyspace, '8bit') - 1; |
68 | 68 | for ($i = 0; $i < $length; ++$i) { |
69 | - $pieces []= $keyspace[random_int(0, $max)]; |
|
69 | + $pieces [ ] = $keyspace[ random_int(0, $max) ]; |
|
70 | 70 | } |
71 | 71 | return implode('', $pieces); |
72 | 72 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $name = null) |
39 | 39 | { |
40 | - if(!is_null($name)) |
|
40 | + if (!is_null($name)) |
|
41 | 41 | $this->setName($name); |
42 | 42 | |
43 | 43 | $this->definition = new InputDefinition(); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | |
153 | 153 | $replacements = array( |
154 | 154 | $name, |
155 | - $_SERVER['PHP_SELF'].' '.$name, |
|
155 | + $_SERVER[ 'PHP_SELF' ].' '.$name, |
|
156 | 156 | ); |
157 | 157 | |
158 | 158 | return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription()); |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function setCode(callable $code) |
172 | 172 | { |
173 | - if($code instanceof \Closure) { |
|
173 | + if ($code instanceof \Closure) { |
|
174 | 174 | $r = new \ReflectionFunction($code); |
175 | - if(null === $r->getClosureThis()) { |
|
175 | + if (null === $r->getClosureThis()) { |
|
176 | 176 | $code = \Closure::bind($code, $this); |
177 | 177 | } |
178 | 178 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | */ |
339 | 339 | private function validateName($name) |
340 | 340 | { |
341 | - if(!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) |
|
341 | + if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) |
|
342 | 342 | throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); |
343 | 343 | } |
344 | 344 | } |
@@ -37,8 +37,9 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function __construct(string $name = null) |
39 | 39 | { |
40 | - if(!is_null($name)) |
|
41 | - $this->setName($name); |
|
40 | + if(!is_null($name)) { |
|
41 | + $this->setName($name); |
|
42 | + } |
|
42 | 43 | |
43 | 44 | $this->definition = new InputDefinition(); |
44 | 45 | |
@@ -121,8 +122,9 @@ discard block |
||
121 | 122 | } |
122 | 123 | } |
123 | 124 | |
124 | - if ($input->isInteractive()) |
|
125 | - $this->interact($input); |
|
125 | + if ($input->isInteractive()) { |
|
126 | + $this->interact($input); |
|
127 | + } |
|
126 | 128 | |
127 | 129 | $input->validate(); |
128 | 130 | |
@@ -338,7 +340,8 @@ discard block |
||
338 | 340 | */ |
339 | 341 | private function validateName($name) |
340 | 342 | { |
341 | - if(!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) |
|
342 | - throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); |
|
343 | + if(!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) { |
|
344 | + throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name)); |
|
345 | + } |
|
343 | 346 | } |
344 | 347 | } |
@@ -18,8 +18,8 @@ |
||
18 | 18 | class ListCommand extends Command |
19 | 19 | { |
20 | 20 | /** |
21 | - * {@inheritdoc} |
|
22 | - */ |
|
21 | + * {@inheritdoc} |
|
22 | + */ |
|
23 | 23 | protected function configure() |
24 | 24 | { |
25 | 25 | $this |
@@ -36,14 +36,16 @@ |
||
36 | 36 | */ |
37 | 37 | public function __construct($stream, int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = null, OutputFormatterInterface $formatter = null) |
38 | 38 | { |
39 | - if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) |
|
40 | - throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
|
39 | + if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) { |
|
40 | + throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.'); |
|
41 | + } |
|
41 | 42 | |
42 | 43 | |
43 | 44 | $this->stream = $stream; |
44 | 45 | |
45 | - if (null === $decorated) |
|
46 | - $decorated = $this->hasColorSupport(); |
|
46 | + if (null === $decorated) { |
|
47 | + $decorated = $this->hasColorSupport(); |
|
48 | + } |
|
47 | 49 | |
48 | 50 | |
49 | 51 | parent::__construct($verbosity, $decorated, $formatter); |