@@ -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>"); |
@@ -11,7 +11,7 @@ |
||
11 | 11 | protected function init() |
12 | 12 | { |
13 | 13 | $this->name('Help') |
14 | - ->description('Shows the help message'); |
|
14 | + ->description('Shows the help message'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | protected function execute() |
@@ -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); |
@@ -43,15 +43,15 @@ discard block |
||
43 | 43 | public function __construct() |
44 | 44 | { |
45 | 45 | $this->commands([]) |
46 | - ->name('Unknown') |
|
47 | - ->version('1.0.0') |
|
48 | - ->description('...') |
|
49 | - ->descriptions([]) |
|
50 | - ->options([]) |
|
51 | - ->console(new Console) |
|
52 | - ->fs(new Filesystem('.')) |
|
53 | - ->setupSubCommands() |
|
54 | - ->init(); |
|
46 | + ->name('Unknown') |
|
47 | + ->version('1.0.0') |
|
48 | + ->description('...') |
|
49 | + ->descriptions([]) |
|
50 | + ->options([]) |
|
51 | + ->console(new Console) |
|
52 | + ->fs(new Filesystem('.')) |
|
53 | + ->setupSubCommands() |
|
54 | + ->init(); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | protected function setupSubCommands() |
299 | 299 | { |
300 | 300 | return $this->command('--help', new HelpCommand($this)) |
301 | - ->command('--version', new VersionCommand($this)); |
|
301 | + ->command('--version', new VersionCommand($this)); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | public function describe(string $name, string $description = null) |
@@ -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); |
|
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; |
@@ -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 |
@@ -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 clear () : TemplateInterface |
|
55 | + public function clear() : TemplateInterface |
|
56 | 56 | { |
57 | 57 | $this->data = []; |
58 | 58 | return $this; |
@@ -7,7 +7,7 @@ |
||
7 | 7 | protected function init() |
8 | 8 | { |
9 | 9 | $this->name('Version') |
10 | - ->description('Shows the version'); |
|
10 | + ->description('Shows the version'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | protected function execute() |
@@ -7,13 +7,13 @@ |
||
7 | 7 | protected function init () |
8 | 8 | { |
9 | 9 | $this->name('Repeat') |
10 | - ->version('1.0.0') |
|
11 | - ->description('Repeats a word a number of times') |
|
12 | - ->syntax('word: string, count: (number: 3)') |
|
13 | - ->options(['--upper']) |
|
14 | - ->describe('word', 'The word to repeat') |
|
15 | - ->describe('count', 'The number of times to repeat the word') |
|
16 | - ->describe('--upper', 'Converts the result to uppercase'); |
|
10 | + ->version('1.0.0') |
|
11 | + ->description('Repeats a word a number of times') |
|
12 | + ->syntax('word: string, count: (number: 3)') |
|
13 | + ->options(['--upper']) |
|
14 | + ->describe('word', 'The word to repeat') |
|
15 | + ->describe('count', 'The number of times to repeat the word') |
|
16 | + ->describe('--upper', 'Converts the result to uppercase'); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | protected function execute() |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | class RepeatCommand extends Command { |
6 | 6 | |
7 | - protected function init () |
|
7 | + protected function init() |
|
8 | 8 | { |
9 | 9 | $this->name('Repeat') |
10 | 10 | ->version('1.0.0') |
@@ -19,8 +19,9 @@ |
||
19 | 19 | protected function execute() |
20 | 20 | { |
21 | 21 | $result = str_repeat($this->args->word, $this->args->count); |
22 | - if ($this->option('--upper')) |
|
23 | - $result = strtoupper($result); |
|
22 | + if ($this->option('--upper')) { |
|
23 | + $result = strtoupper($result); |
|
24 | + } |
|
24 | 25 | $this->console->line($result); |
25 | 26 | } |
26 | 27 |
@@ -7,12 +7,12 @@ |
||
7 | 7 | protected function init () |
8 | 8 | { |
9 | 9 | $this->name('Render') |
10 | - ->version('1.0.0') |
|
11 | - ->description('Renders the hello template.') |
|
12 | - ->syntax('name: (string:You)') |
|
13 | - ->describe('name', 'Your name.') |
|
14 | - ->templatesPath(TEMPLATES_PATH); |
|
15 | - // this points to /tests/resources/templates |
|
10 | + ->version('1.0.0') |
|
11 | + ->description('Renders the hello template.') |
|
12 | + ->syntax('name: (string:You)') |
|
13 | + ->describe('name', 'Your name.') |
|
14 | + ->templatesPath(TEMPLATES_PATH); |
|
15 | + // this points to /tests/resources/templates |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | protected function execute() |
@@ -4,7 +4,7 @@ |
||
4 | 4 | |
5 | 5 | class RenderCommand extends Command { |
6 | 6 | |
7 | - protected function init () |
|
7 | + protected function init() |
|
8 | 8 | { |
9 | 9 | $this->name('Render') |
10 | 10 | ->version('1.0.0') |