@@ -79,7 +79,9 @@ |
||
79 | 79 | function getStringBetween($string, $start, $end) { |
80 | 80 | $string = ' ' . $string; |
81 | 81 | $ini = strpos($string, $start); |
82 | - if ($ini == 0) return ''; |
|
82 | + if ($ini == 0) { |
|
83 | + return ''; |
|
84 | + } |
|
83 | 85 | $ini += strlen($start); |
84 | 86 | $len = strpos($string, $end, $ini) - $ini; |
85 | 87 | return substr($string, $ini, $len); |
@@ -273,8 +273,9 @@ discard block |
||
273 | 273 | $this->init(); |
274 | 274 | |
275 | 275 | if ($namespace == null) { |
276 | - if (!$this->commandLoader) |
|
277 | - return $this->commands; |
|
276 | + if (!$this->commandLoader) { |
|
277 | + return $this->commands; |
|
278 | + } |
|
278 | 279 | |
279 | 280 | $commands = array(); |
280 | 281 | foreach ($this->commandLoader->getNames() as $name) { |
@@ -364,14 +365,15 @@ discard block |
||
364 | 365 | } |
365 | 366 | |
366 | 367 | $exact = in_array($namespace, $namespaces, true); |
367 | - if (count($namespaces) > 1 && !$exact) |
|
368 | - throw new NamespaceNotFoundException( |
|
368 | + if (count($namespaces) > 1 && !$exact) { |
|
369 | + throw new NamespaceNotFoundException( |
|
369 | 370 | sprintf( |
370 | 371 | "The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s", |
371 | 372 | $namespace, |
372 | 373 | $this->getAbbreviationSuggestions(array_values($namespaces))), |
373 | 374 | array_values($namespaces) |
374 | 375 | ); |
376 | + } |
|
375 | 377 | |
376 | 378 | return $exact ? $namespace : reset($namespaces); |
377 | 379 | } |
@@ -483,8 +485,9 @@ discard block |
||
483 | 485 | class_exists($class) |
484 | 486 | && $class != $excludeClass |
485 | 487 | && is_subclass_of($class, $excludeClass) |
486 | - ) |
|
487 | - $classes[] = new $class(); |
|
488 | + ) { |
|
489 | + $classes[] = new $class(); |
|
490 | + } |
|
488 | 491 | } |
489 | 492 | } |
490 | 493 |
@@ -108,8 +108,9 @@ discard block |
||
108 | 108 | private function register(Command $command) |
109 | 109 | { |
110 | 110 | // add to registered commands if not already registered. |
111 | - if(!$this->has($command->getName())) |
|
112 | - $this->registeredCommands[$command->getName()] = $command; |
|
111 | + if(!$this->has($command->getName())) { |
|
112 | + $this->registeredCommands[$command->getName()] = $command; |
|
113 | + } |
|
113 | 114 | } |
114 | 115 | |
115 | 116 | /** |
@@ -126,8 +127,9 @@ discard block |
||
126 | 127 | if(class_exists($file)) { |
127 | 128 | $tempClass = new $file; |
128 | 129 | |
129 | - if($tempClass instanceof Command) |
|
130 | - return new $file; |
|
130 | + if($tempClass instanceof Command) { |
|
131 | + return new $file; |
|
132 | + } |
|
131 | 133 | } |
132 | 134 | return false; |
133 | 135 | } |
@@ -22,11 +22,13 @@ discard block |
||
22 | 22 | { |
23 | 23 | $width = getenv('COLUMNS'); |
24 | 24 | |
25 | - if ($width !== false) |
|
26 | - return (int) trim($width); |
|
25 | + if ($width !== false) { |
|
26 | + return (int) trim($width); |
|
27 | + } |
|
27 | 28 | |
28 | - if(self::$width === null) |
|
29 | - self::initDimensions(); |
|
29 | + if(self::$width === null) { |
|
30 | + self::initDimensions(); |
|
31 | + } |
|
30 | 32 | |
31 | 33 | return self::$width ?: 80; |
32 | 34 | } |
@@ -35,11 +37,13 @@ discard block |
||
35 | 37 | { |
36 | 38 | $height = getenv('ROWS'); |
37 | 39 | |
38 | - if($height !== false) |
|
39 | - return (int) $height; |
|
40 | + if($height !== false) { |
|
41 | + return (int) $height; |
|
42 | + } |
|
40 | 43 | |
41 | - if(self::$height !== false) |
|
42 | - self::initDimensions(); |
|
44 | + if(self::$height !== false) { |
|
45 | + self::initDimensions(); |
|
46 | + } |
|
43 | 47 | |
44 | 48 | return self::$height ?: 60; |
45 | 49 | } |
@@ -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 |
@@ -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,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) { |
@@ -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 | } |
@@ -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 | } |