@@ -27,7 +27,7 @@ |
||
27 | 27 | /** |
28 | 28 | * Converts a parse exception to a string. |
29 | 29 | * |
30 | - * @param Tarsana\Syntax\Exceptions\ParseException $e |
|
30 | + * @param ParseException $e |
|
31 | 31 | * @return string |
32 | 32 | */ |
33 | 33 | public function printParseException(ParseException $e) : string |
@@ -62,7 +62,7 @@ |
||
62 | 62 | } |
63 | 63 | if ($s instanceof ArraySyntax) { |
64 | 64 | if ($short) return 'array'; |
65 | - return $this->printSyntax($s->syntax()).$s->separator().'...'; |
|
65 | + return $this->printSyntax($s->syntax()) . $s->separator() . '...'; |
|
66 | 66 | } |
67 | 67 | return (string) $s; |
68 | 68 | } |
@@ -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, true); |
|
21 | + if ($e instanceof ParseException) { |
|
22 | + return $this->printParseException($e, true); |
|
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(', ', $i['items']); |
45 | 48 | $error = "additional items {$items}"; |
@@ -57,11 +60,15 @@ discard block |
||
57 | 60 | protected function printSyntax(Syntax $s, bool $short = false) : string |
58 | 61 | { |
59 | 62 | if ($s instanceof ObjectSyntax) { |
60 | - if ($short) return 'object'; |
|
63 | + if ($short) { |
|
64 | + return 'object'; |
|
65 | + } |
|
61 | 66 | return implode($s->separator(), array_keys($s->fields())); |
62 | 67 | } |
63 | 68 | if ($s instanceof ArraySyntax) { |
64 | - if ($short) return 'array'; |
|
69 | + if ($short) { |
|
70 | + return 'array'; |
|
71 | + } |
|
65 | 72 | return $this->printSyntax($s->syntax()).$s->separator().'...'; |
66 | 73 | } |
67 | 74 | return (string) $s; |
@@ -69,7 +69,7 @@ |
||
69 | 69 | * or if many exists. |
70 | 70 | * |
71 | 71 | * @param string $name |
72 | - * @return Tarsana\Command\Interfaces\TemplateInterface |
|
72 | + * @return TemplateInterface |
|
73 | 73 | * @throws Tarsana\Command\Exceptions\TemplateNotFound |
74 | 74 | * @throws Tarsana\Command\Exceptions\TemplateNameConflict |
75 | 75 | */ |
@@ -73,7 +73,7 @@ |
||
73 | 73 | * @throws Tarsana\Command\Exceptions\TemplateNotFound |
74 | 74 | * @throws Tarsana\Command\Exceptions\TemplateNameConflict |
75 | 75 | */ |
76 | - public function load (string $name) : TemplateInterface |
|
76 | + public function load(string $name) : TemplateInterface |
|
77 | 77 | { |
78 | 78 | $supportedExtensions = array_keys(self::$providers); |
79 | 79 |
@@ -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 |
@@ -62,11 +62,11 @@ |
||
62 | 62 | $default = 'default: ' . json_encode($s->getDefault()); |
63 | 63 | else |
64 | 64 | $default = 'required'; |
65 | - $description = $this->parent()->describe($prefix.$name); |
|
65 | + $description = $this->parent()->describe($prefix . $name); |
|
66 | 66 | $syntax = $this->formatSyntax($s); |
67 | 67 | $this->console()->line("{$tabs}<warn>{$name}</warn> <success>{$syntax}</success> {$description} <info>({$default})</info>"); |
68 | 68 | |
69 | - $level ++; |
|
69 | + $level++; |
|
70 | 70 | $prefix .= $name . '.'; |
71 | 71 | foreach ($this->getFields($s) as $field => $syntax) { |
72 | 72 | $this->printField($field, $syntax, $prefix, $level); |
@@ -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>"); |
@@ -44,14 +44,14 @@ discard block |
||
44 | 44 | { |
45 | 45 | $this->commands = []; |
46 | 46 | $this->setupSubCommands() |
47 | - ->name('Unknown') |
|
48 | - ->version('1.0.0') |
|
49 | - ->description('...') |
|
50 | - ->descriptions([]) |
|
51 | - ->options([]) |
|
52 | - ->console(new Console) |
|
53 | - ->fs(new Filesystem('.')) |
|
54 | - ->init(); |
|
47 | + ->name('Unknown') |
|
48 | + ->version('1.0.0') |
|
49 | + ->description('...') |
|
50 | + ->descriptions([]) |
|
51 | + ->options([]) |
|
52 | + ->console(new Console) |
|
53 | + ->fs(new Filesystem('.')) |
|
54 | + ->init(); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | protected function setupSubCommands() |
270 | 270 | { |
271 | 271 | return $this->command('--help', new HelpCommand($this)) |
272 | - ->command('--version', new VersionCommand($this)); |
|
272 | + ->command('--version', new VersionCommand($this)); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | public function describe(string $name, string $description = null) |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | } |
143 | 143 | |
144 | 144 | $this->options = []; |
145 | - foreach($options as $option) |
|
145 | + foreach ($options as $option) |
|
146 | 146 | $this->options[$option] = false; |
147 | 147 | |
148 | 148 | return $this; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | public function clear() |
331 | 331 | { |
332 | 332 | $this->args = null; |
333 | - foreach($this->options as $name => $value) { |
|
333 | + foreach ($this->options as $name => $value) { |
|
334 | 334 | $this->options[$name] = false; |
335 | 335 | } |
336 | 336 | } |
@@ -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); |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected $data; |
18 | 18 | |
19 | - public function __construct ($twig) |
|
19 | + public function __construct($twig) |
|
20 | 20 | { |
21 | 21 | $this->twig = $twig; |
22 | 22 | $this->data = []; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | * @param array $data |
29 | 29 | * @return self |
30 | 30 | */ |
31 | - public function bind (array $data) : TemplateInterface |
|
31 | + public function bind(array $data) : TemplateInterface |
|
32 | 32 | { |
33 | 33 | $this->data = array_merge($this->data, $data); |
34 | 34 | return $this; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return self |
54 | 54 | */ |
55 | - public function clean () : TemplateInterface |
|
55 | + public function clean() : TemplateInterface |
|
56 | 56 | { |
57 | 57 | $this->data = []; |
58 | 58 | return $this; |
@@ -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 | } |