@@ -36,8 +36,9 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | public static function create(callable $action = null) { |
| 38 | 38 | $command = new Command; |
| 39 | - if (null !== $action) |
|
| 40 | - $command->action($action); |
|
| 39 | + if (null !== $action) { |
|
| 40 | + $command->action($action); |
|
| 41 | + } |
|
| 41 | 42 | return $command; |
| 42 | 43 | } |
| 43 | 44 | |
@@ -123,8 +124,9 @@ discard block |
||
| 123 | 124 | */ |
| 124 | 125 | public function syntax(string $syntax = null) |
| 125 | 126 | { |
| 126 | - if (null === $syntax) |
|
| 127 | - return $this->syntax; |
|
| 127 | + if (null === $syntax) { |
|
| 128 | + return $this->syntax; |
|
| 129 | + } |
|
| 128 | 130 | |
| 129 | 131 | $this->syntax = S::syntax()->parse("{{$syntax}| }"); |
| 130 | 132 | return $this; |
@@ -143,8 +145,9 @@ discard block |
||
| 143 | 145 | } |
| 144 | 146 | |
| 145 | 147 | $this->options = []; |
| 146 | - foreach($options as $option) |
|
| 147 | - $this->options[$option] = false; |
|
| 148 | + foreach($options as $option) { |
|
| 149 | + $this->options[$option] = false; |
|
| 150 | + } |
|
| 148 | 151 | |
| 149 | 152 | return $this; |
| 150 | 153 | } |
@@ -157,8 +160,9 @@ discard block |
||
| 157 | 160 | */ |
| 158 | 161 | public function option(string $name) |
| 159 | 162 | { |
| 160 | - if (!array_key_exists($name, $this->options)) |
|
| 161 | - throw new \InvalidArgumentException("Unknown option '{$name}'"); |
|
| 163 | + if (!array_key_exists($name, $this->options)) { |
|
| 164 | + throw new \InvalidArgumentException("Unknown option '{$name}'"); |
|
| 165 | + } |
|
| 162 | 166 | return $this->options[$name]; |
| 163 | 167 | } |
| 164 | 168 | |
@@ -206,8 +210,9 @@ discard block |
||
| 206 | 210 | if (null === $value) { |
| 207 | 211 | return $this->fs; |
| 208 | 212 | } |
| 209 | - if (is_string($value)) |
|
| 210 | - $value = new Filesystem($value); |
|
| 213 | + if (is_string($value)) { |
|
| 214 | + $value = new Filesystem($value); |
|
| 215 | + } |
|
| 211 | 216 | $this->fs = $value; |
| 212 | 217 | foreach ($this->commands as $name => $command) { |
| 213 | 218 | $command->fs = $value; |
@@ -242,8 +247,9 @@ discard block |
||
| 242 | 247 | } |
| 243 | 248 | |
| 244 | 249 | public function template(string $name) { |
| 245 | - if (null === $this->templatesLoader) |
|
| 246 | - throw new \Exception("Please initialize the templates loader before trying to load templates!"); |
|
| 250 | + if (null === $this->templatesLoader) { |
|
| 251 | + throw new \Exception("Please initialize the templates loader before trying to load templates!"); |
|
| 252 | + } |
|
| 247 | 253 | return $this->templatesLoader->load($name); |
| 248 | 254 | } |
| 249 | 255 | |
@@ -283,8 +289,9 @@ discard block |
||
| 283 | 289 | public function command(string $name, Command $command = null) |
| 284 | 290 | { |
| 285 | 291 | if (null === $command) { |
| 286 | - if (!array_key_exists($name, $this->commands)) |
|
| 287 | - throw new \InvalidArgumentException("subcommand '{$name}' not found!"); |
|
| 292 | + if (!array_key_exists($name, $this->commands)) { |
|
| 293 | + throw new \InvalidArgumentException("subcommand '{$name}' not found!"); |
|
| 294 | + } |
|
| 288 | 295 | return $this->commands[$name]; |
| 289 | 296 | } |
| 290 | 297 | $this->commands[$name] = $command; |
@@ -305,9 +312,10 @@ discard block |
||
| 305 | 312 | |
| 306 | 313 | public function describe(string $name, string $description = null) |
| 307 | 314 | { |
| 308 | - if (null === $description) |
|
| 309 | - return array_key_exists($name, $this->descriptions) |
|
| 315 | + if (null === $description) { |
|
| 316 | + return array_key_exists($name, $this->descriptions) |
|
| 310 | 317 | ? $this->descriptions[$name] : ''; |
| 318 | + } |
|
| 311 | 319 | if (substr($name, 0, 2) == '--' && array_key_exists($name, $this->options())) { |
| 312 | 320 | $this->descriptions[$name] = $description; |
| 313 | 321 | return $this; |
@@ -343,8 +351,9 @@ discard block |
||
| 343 | 351 | } else { |
| 344 | 352 | $this->args = (object) $args; |
| 345 | 353 | foreach ($options as $name) { |
| 346 | - if (!array_key_exists($name, $this->options)) |
|
| 347 | - throw new \Exception("Unknown option '{$name}'"); |
|
| 354 | + if (!array_key_exists($name, $this->options)) { |
|
| 355 | + throw new \Exception("Unknown option '{$name}'"); |
|
| 356 | + } |
|
| 348 | 357 | $this->options[$name] = true; |
| 349 | 358 | } |
| 350 | 359 | } |
@@ -379,10 +388,11 @@ discard block |
||
| 379 | 388 | |
| 380 | 389 | $arguments = []; |
| 381 | 390 | foreach ($args as &$arg) { |
| 382 | - if (array_key_exists($arg, $this->options)) |
|
| 383 | - $this->options[$arg] = true; |
|
| 384 | - else |
|
| 385 | - $arguments[] = $arg; |
|
| 391 | + if (array_key_exists($arg, $this->options)) { |
|
| 392 | + $this->options[$arg] = true; |
|
| 393 | + } else { |
|
| 394 | + $arguments[] = $arg; |
|
| 395 | + } |
|
| 386 | 396 | } |
| 387 | 397 | $arguments = T::join($arguments, ' '); |
| 388 | 398 | $this->args = $this->syntax->parse($arguments); |
@@ -105,8 +105,9 @@ discard block |
||
| 105 | 105 | protected function readObject(ObjectSyntax $syntax, string $prefix) |
| 106 | 106 | { |
| 107 | 107 | $result = []; |
| 108 | - if ($prefix != '') |
|
| 109 | - $prefix .= '.'; |
|
| 108 | + if ($prefix != '') { |
|
| 109 | + $prefix .= '.'; |
|
| 110 | + } |
|
| 110 | 111 | foreach ($syntax->fields() as $name => $s) { |
| 111 | 112 | $fullname = $prefix . $name; |
| 112 | 113 | $result[$name] = $this->read($s, $fullname, true); |
@@ -133,8 +134,9 @@ discard block |
||
| 133 | 134 | $this->console->out("<color:252>{$default}<column:3><reset>"); |
| 134 | 135 | $n = ord($this->console->char()); |
| 135 | 136 | $this->console->out('<column:1><clearLine>'); |
| 136 | - if (array_key_exists($n, static::KEYS) && static::KEYS[$n] == 'enter') |
|
| 137 | - return $syntax->getDefault(); |
|
| 137 | + if (array_key_exists($n, static::KEYS) && static::KEYS[$n] == 'enter') { |
|
| 138 | + return $syntax->getDefault(); |
|
| 139 | + } |
|
| 138 | 140 | return $this->read($syntax->syntax(), $prefix); |
| 139 | 141 | } |
| 140 | 142 | |
@@ -176,8 +178,9 @@ discard block |
||
| 176 | 178 | protected function readChar() : string |
| 177 | 179 | { |
| 178 | 180 | $c = $this->console->char(); |
| 179 | - if (ctype_print($c)) |
|
| 180 | - return $c; |
|
| 181 | + if (ctype_print($c)) { |
|
| 182 | + return $c; |
|
| 183 | + } |
|
| 181 | 184 | $n = ord($c); |
| 182 | 185 | if ( |
| 183 | 186 | array_key_exists($n, static::KEYS) |
@@ -84,10 +84,11 @@ |
||
| 84 | 84 | { |
| 85 | 85 | $tabs = str_repeat('<tab>', $level); |
| 86 | 86 | $optional = ($s instanceof OptionalSyntax); |
| 87 | - if ($optional) |
|
| 88 | - $default = 'default: ' . json_encode($s->getDefault()); |
|
| 89 | - else |
|
| 90 | - $default = 'required'; |
|
| 87 | + if ($optional) { |
|
| 88 | + $default = 'default: ' . json_encode($s->getDefault()); |
|
| 89 | + } else { |
|
| 90 | + $default = 'required'; |
|
| 91 | + } |
|
| 91 | 92 | $description = $this->parent()->describe($prefix.$name); |
| 92 | 93 | $syntax = $this->helper->asString($s); |
| 93 | 94 | $text = "{$tabs}<warn>{$name}</warn> <success>{$syntax}</success>" |
@@ -9,8 +9,9 @@ discard block |
||
| 9 | 9 | |
| 10 | 10 | public static function instance() : SyntaxHelper |
| 11 | 11 | { |
| 12 | - if (null === self::$instance) |
|
| 13 | - self::$instance = new SyntaxHelper; |
|
| 12 | + if (null === self::$instance) { |
|
| 13 | + self::$instance = new SyntaxHelper; |
|
| 14 | + } |
|
| 14 | 15 | return self::$instance; |
| 15 | 16 | } |
| 16 | 17 | |
@@ -25,8 +26,9 @@ discard block |
||
| 25 | 26 | public function asString(Syntax $syntax) : string |
| 26 | 27 | { |
| 27 | 28 | $type = $this->type($syntax); |
| 28 | - if ($type == 'optional') |
|
| 29 | - return $this->asString($syntax->syntax()); |
|
| 29 | + if ($type == 'optional') { |
|
| 30 | + return $this->asString($syntax->syntax()); |
|
| 31 | + } |
|
| 30 | 32 | switch ($type) { |
| 31 | 33 | case 'object': |
| 32 | 34 | return implode( |