| @@ -35,22 +35,27 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 | protected function formatSyntax(Syntax $s) : string | 
| 37 | 37 |      { | 
| 38 | - if ($s instanceof ObjectSyntax) | |
| 39 | - return implode($s->separator(), array_keys($s->fields())); | |
| 40 | - if ($s instanceof ArraySyntax) | |
| 41 | - return $this->formatSyntax($s->syntax()) . $s->separator() . '...'; | |
| 42 | - if ($s instanceof OptionalSyntax) | |
| 43 | - return $this->formatSyntax($s->syntax()); | |
| 38 | +        if ($s instanceof ObjectSyntax) { | |
| 39 | + return implode($s->separator(), array_keys($s->fields())); | |
| 40 | + } | |
| 41 | +        if ($s instanceof ArraySyntax) { | |
| 42 | + return $this->formatSyntax($s->syntax()) . $s->separator() . '...'; | |
| 43 | + } | |
| 44 | +        if ($s instanceof OptionalSyntax) { | |
| 45 | + return $this->formatSyntax($s->syntax()); | |
| 46 | + } | |
| 44 | 47 | |
| 45 | 48 | return (string) $s; | 
| 46 | 49 | } | 
| 47 | 50 | |
| 48 | 51 | protected function getFields(Syntax $s) : array | 
| 49 | 52 |      { | 
| 50 | - if ($s instanceof ObjectSyntax) | |
| 51 | - return $s->fields(); | |
| 52 | - if ($s instanceof ArraySyntax || $s instanceof OptionalSyntax) | |
| 53 | - return $this->getFields($s->syntax()); | |
| 53 | +        if ($s instanceof ObjectSyntax) { | |
| 54 | + return $s->fields(); | |
| 55 | + } | |
| 56 | +        if ($s instanceof ArraySyntax || $s instanceof OptionalSyntax) { | |
| 57 | + return $this->getFields($s->syntax()); | |
| 58 | + } | |
| 54 | 59 | return []; | 
| 55 | 60 | } | 
| 56 | 61 | |
| @@ -58,10 +63,11 @@ discard block | ||
| 58 | 63 |      { | 
| 59 | 64 |          $tabs = str_repeat('<tab>', $level); | 
| 60 | 65 | $optional = ($s instanceof OptionalSyntax); | 
| 61 | - if ($optional) | |
| 62 | - $default = 'default: ' . json_encode($s->getDefault()); | |
| 63 | - else | |
| 64 | - $default = 'required'; | |
| 66 | +        if ($optional) { | |
| 67 | + $default = 'default: ' . json_encode($s->getDefault()); | |
| 68 | +        } else { | |
| 69 | + $default = 'required'; | |
| 70 | + } | |
| 65 | 71 | $description = $this->parent()->describe($prefix.$name); | 
| 66 | 72 | $syntax = $this->formatSyntax($s); | 
| 67 | 73 |          $this->console()->line("{$tabs}<warn>{$name}</warn> <success>{$syntax}</success> {$description} <info>({$default})</info>"); | 
| @@ -87,8 +87,9 @@ | ||
| 87 | 87 | $found = []; | 
| 88 | 88 |          foreach ($files as $file) { | 
| 89 | 89 | $ext = $file->extension(); | 
| 90 | - if (!in_array($ext, $supportedExtensions)) | |
| 91 | - continue; | |
| 90 | +            if (!in_array($ext, $supportedExtensions)) { | |
| 91 | + continue; | |
| 92 | + } | |
| 92 | 93 | $found[] = [ | 
| 93 | 94 | 'name' => substr($file->path(), $fsPathLength), | 
| 94 | 95 | 'extension' => $ext | 
| @@ -41,24 +41,27 @@ | ||
| 41 | 41 | |
| 42 | 42 | public function stdin(ReaderInterface $in = null) | 
| 43 | 43 |      { | 
| 44 | - if (null === $in) | |
| 45 | - return $this->in; | |
| 44 | +        if (null === $in) { | |
| 45 | + return $this->in; | |
| 46 | + } | |
| 46 | 47 | $this->in = $in; | 
| 47 | 48 | return $this; | 
| 48 | 49 | } | 
| 49 | 50 | |
| 50 | 51 | public function stdout(WriterInterface $out = null) | 
| 51 | 52 |      { | 
| 52 | - if (null === $out) | |
| 53 | - return $this->out; | |
| 53 | +        if (null === $out) { | |
| 54 | + return $this->out; | |
| 55 | + } | |
| 54 | 56 | $this->out = $out; | 
| 55 | 57 | return $this; | 
| 56 | 58 | } | 
| 57 | 59 | |
| 58 | 60 | public function stderr(WriterInterface $err = null) | 
| 59 | 61 |      { | 
| 60 | - if (null === $err) | |
| 61 | - return $this->err; | |
| 62 | +        if (null === $err) { | |
| 63 | + return $this->err; | |
| 64 | + } | |
| 62 | 65 | $this->err = $err; | 
| 63 | 66 | return $this; | 
| 64 | 67 | } | 
| @@ -7,7 +7,6 @@ | ||
| 7 | 7 | use Tarsana\IO\Interfaces\Resource\Writer as WriterInterface; | 
| 8 | 8 | use Tarsana\IO\Resource\Reader; | 
| 9 | 9 | use Tarsana\IO\Resource\Writer; | 
| 10 | -use Tarsana\Syntax\Syntax; | |
| 11 | 10 | |
| 12 | 11 |  class Console implements ConsoleInterface { | 
| 13 | 12 | |
| @@ -35,8 +35,9 @@ discard block | ||
| 35 | 35 | |
| 36 | 36 |      public static function create(callable $action = null) { | 
| 37 | 37 | $command = new Command; | 
| 38 | - if (null !== $action) | |
| 39 | - $command->action($action); | |
| 38 | +        if (null !== $action) { | |
| 39 | + $command->action($action); | |
| 40 | + } | |
| 40 | 41 | return $command; | 
| 41 | 42 | } | 
| 42 | 43 | |
| @@ -122,8 +123,9 @@ discard block | ||
| 122 | 123 | */ | 
| 123 | 124 | public function syntax(string $syntax = null) | 
| 124 | 125 |      { | 
| 125 | - if (null === $syntax) | |
| 126 | - return $this->syntax; | |
| 126 | +        if (null === $syntax) { | |
| 127 | + return $this->syntax; | |
| 128 | + } | |
| 127 | 129 | |
| 128 | 130 |          $this->syntax = S::syntax()->parse("{{$syntax}| }"); | 
| 129 | 131 | return $this; | 
| @@ -142,8 +144,9 @@ discard block | ||
| 142 | 144 | } | 
| 143 | 145 | |
| 144 | 146 | $this->options = []; | 
| 145 | - foreach($options as $option) | |
| 146 | - $this->options[$option] = false; | |
| 147 | +        foreach($options as $option) { | |
| 148 | + $this->options[$option] = false; | |
| 149 | + } | |
| 147 | 150 | |
| 148 | 151 | return $this; | 
| 149 | 152 | } | 
| @@ -156,8 +159,9 @@ discard block | ||
| 156 | 159 | */ | 
| 157 | 160 | public function option(string $name) | 
| 158 | 161 |      { | 
| 159 | - if (!array_key_exists($name, $this->options)) | |
| 160 | -            throw new \InvalidArgumentException("Unknown option '{$name}'"); | |
| 162 | +        if (!array_key_exists($name, $this->options)) { | |
| 163 | +                    throw new \InvalidArgumentException("Unknown option '{$name}'"); | |
| 164 | + } | |
| 161 | 165 | return $this->options[$name]; | 
| 162 | 166 | } | 
| 163 | 167 | |
| @@ -205,8 +209,9 @@ discard block | ||
| 205 | 209 |          if (null === $value) { | 
| 206 | 210 | return $this->fs; | 
| 207 | 211 | } | 
| 208 | - if (is_string($value)) | |
| 209 | - $value = new Filesystem($value); | |
| 212 | +        if (is_string($value)) { | |
| 213 | + $value = new Filesystem($value); | |
| 214 | + } | |
| 210 | 215 | $this->fs = $value; | 
| 211 | 216 |          foreach ($this->commands as $name => $command) { | 
| 212 | 217 | $command->fs = $value; | 
| @@ -235,8 +240,9 @@ discard block | ||
| 235 | 240 | } | 
| 236 | 241 | |
| 237 | 242 |      public function template(string $name) { | 
| 238 | - if (null === $this->templatesLoader) | |
| 239 | -            throw new \Exception("Please initialize the templates loader before trying to load templates!"); | |
| 243 | +        if (null === $this->templatesLoader) { | |
| 244 | +                    throw new \Exception("Please initialize the templates loader before trying to load templates!"); | |
| 245 | + } | |
| 240 | 246 | return $this->templatesLoader->load($name); | 
| 241 | 247 | } | 
| 242 | 248 | |
| @@ -258,8 +264,9 @@ discard block | ||
| 258 | 264 | public function command(string $name, Command $command = null) | 
| 259 | 265 |      { | 
| 260 | 266 |          if (null === $command) { | 
| 261 | - if (!array_key_exists($name, $this->commands)) | |
| 262 | -                throw new \InvalidArgumentException("subcommand '{$name}' not found!"); | |
| 267 | +            if (!array_key_exists($name, $this->commands)) { | |
| 268 | +                            throw new \InvalidArgumentException("subcommand '{$name}' not found!"); | |
| 269 | + } | |
| 263 | 270 | return $this->commands[$name]; | 
| 264 | 271 | } | 
| 265 | 272 | $this->commands[$name] = $command; | 
| @@ -274,9 +281,10 @@ discard block | ||
| 274 | 281 | |
| 275 | 282 | public function describe(string $name, string $description = null) | 
| 276 | 283 |      { | 
| 277 | - if (null === $description) | |
| 278 | - return array_key_exists($name, $this->descriptions) | |
| 284 | +        if (null === $description) { | |
| 285 | + return array_key_exists($name, $this->descriptions) | |
| 279 | 286 | ? $this->descriptions[$name] : ''; | 
| 287 | + } | |
| 280 | 288 |          if (substr($name, 0, 2) == '--' && array_key_exists($name, $this->options())) { | 
| 281 | 289 | $this->descriptions[$name] = $description; | 
| 282 | 290 | return $this; | 
| @@ -312,16 +320,18 @@ discard block | ||
| 312 | 320 |              } else { | 
| 313 | 321 | $this->args = (object) $args; | 
| 314 | 322 |                  foreach ($options as $name) { | 
| 315 | - if (!array_key_exists($name, $this->options)) | |
| 316 | -                        throw new \Exception("Unknown option '{$name}'"); | |
| 323 | +                    if (!array_key_exists($name, $this->options)) { | |
| 324 | +                                            throw new \Exception("Unknown option '{$name}'"); | |
| 325 | + } | |
| 317 | 326 | $this->options[$name] = true; | 
| 318 | 327 | } | 
| 319 | 328 | } | 
| 320 | 329 | |
| 321 | - if (null === $this->action) | |
| 322 | - $this->execute(); | |
| 323 | - else | |
| 324 | - ($this->action)($this); | |
| 330 | +            if (null === $this->action) { | |
| 331 | + $this->execute(); | |
| 332 | +            } else { | |
| 333 | + ($this->action)($this); | |
| 334 | + } | |
| 325 | 335 |          } catch (\Exception $e) { | 
| 326 | 336 | $this->handleError($e); | 
| 327 | 337 | } | 
| @@ -344,10 +354,11 @@ discard block | ||
| 344 | 354 | |
| 345 | 355 | $arguments = []; | 
| 346 | 356 |          foreach ($args as &$arg) { | 
| 347 | - if (array_key_exists($arg, $this->options)) | |
| 348 | - $this->options[$arg] = true; | |
| 349 | - else | |
| 350 | - $arguments[] = $arg; | |
| 357 | +            if (array_key_exists($arg, $this->options)) { | |
| 358 | + $this->options[$arg] = true; | |
| 359 | +            } else { | |
| 360 | + $arguments[] = $arg; | |
| 361 | + } | |
| 351 | 362 | } | 
| 352 | 363 | $arguments = T::join($arguments, ' '); | 
| 353 | 364 | $this->args = $this->syntax->parse($arguments); | 
| @@ -18,8 +18,9 @@ discard block | ||
| 18 | 18 | */ | 
| 19 | 19 | public function print(\Exception $e) : string | 
| 20 | 20 |      { | 
| 21 | - if ($e instanceof ParseException) | |
| 22 | - return $this->printParseException($e); | |
| 21 | +        if ($e instanceof ParseException) { | |
| 22 | + return $this->printParseException($e); | |
| 23 | + } | |
| 23 | 24 | |
| 24 | 25 |          return "<error>{$e}</error>"; | 
| 25 | 26 | } | 
| @@ -36,10 +37,12 @@ discard block | ||
| 36 | 37 | $error = ''; | 
| 37 | 38 |          if ($syntax instanceof ObjectSyntax) { | 
| 38 | 39 | $i = $e->extra(); | 
| 39 | - if ($i['type'] == 'invalid-field') | |
| 40 | -                $error = "{$i['field']} is invalid!"; | |
| 41 | - if ($i['type'] == 'missing-field') | |
| 42 | -                $error = "{$i['field']} is missing!"; | |
| 40 | +            if ($i['type'] == 'invalid-field') { | |
| 41 | +                            $error = "{$i['field']} is invalid!"; | |
| 42 | + } | |
| 43 | +            if ($i['type'] == 'missing-field') { | |
| 44 | +                            $error = "{$i['field']} is missing!"; | |
| 45 | + } | |
| 43 | 46 |              if ($i['type'] == 'additional-items') { | 
| 44 | 47 | $items = implode($syntax->separator(), $i['items']); | 
| 45 | 48 |                  $error = "additional items {$items}"; | 
| @@ -48,8 +51,9 @@ discard block | ||
| 48 | 51 | $syntax = $this->printSyntax($e->syntax()); | 
| 49 | 52 | |
| 50 | 53 |          $output = "<reset>Failed to parse <warn>'{$e->input()}'</warn> as <info>{$syntax}</info>"; | 
| 51 | -        if ('' != $error) | |
| 52 | -            $output .= " <error>{$error}</error>"; | |
| 54 | +        if ('' != $error) { | |
| 55 | +                    $output .= " <error>{$error}</error>"; | |
| 56 | + } | |
| 53 | 57 | |
| 54 | 58 | $previous = $e->previous(); | 
| 55 | 59 |          if ($previous) { | 
| @@ -62,11 +66,15 @@ discard block | ||
| 62 | 66 | protected function printSyntax(Syntax $s, bool $short = false) : string | 
| 63 | 67 |      { | 
| 64 | 68 |          if ($s instanceof ObjectSyntax) { | 
| 65 | - if ($short) return 'object'; | |
| 69 | +            if ($short) { | |
| 70 | + return 'object'; | |
| 71 | + } | |
| 66 | 72 | return implode($s->separator(), array_keys($s->fields())); | 
| 67 | 73 | } | 
| 68 | 74 |          if ($s instanceof ArraySyntax) { | 
| 69 | - if ($short) return 'array'; | |
| 75 | +            if ($short) { | |
| 76 | + return 'array'; | |
| 77 | + } | |
| 70 | 78 | return $this->printSyntax($s->syntax()).$s->separator().'...'; | 
| 71 | 79 | } | 
| 72 | 80 | return (string) $s; |