Completed
Push — master ( 9573eb...833af1 )
by Amine
11s
created
examples/tests/RepeatCommandTest.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -9,54 +9,54 @@
 block discarded – undo
9 9
     public function test_it_repeats_word_three_times()
10 10
     {
11 11
         $this->command(new RepeatCommand, ['foo'])
12
-             ->argsEqual((object) [
12
+                ->argsEqual((object) [
13 13
                 'word' => 'foo',
14 14
                 'count' => 3
15
-             ])
16
-             ->optionsEqual([
15
+                ])
16
+                ->optionsEqual([
17 17
                 '--upper' => false
18
-             ])
19
-             ->printsExactly("foofoofoo<br>");
18
+                ])
19
+                ->printsExactly("foofoofoo<br>");
20 20
     }
21 21
 
22 22
     public function test_it_repeats_word_n_times()
23 23
     {
24 24
         $this->command(new RepeatCommand, ['bar', '5'])
25
-             ->argsEqual((object) [
25
+                ->argsEqual((object) [
26 26
                 'word' => 'bar',
27 27
                 'count' => 5
28
-             ])
29
-             ->optionsEqual([
28
+                ])
29
+                ->optionsEqual([
30 30
                 '--upper' => false
31
-             ])
32
-             ->printsExactly("barbarbarbarbar<br>");
31
+                ])
32
+                ->printsExactly("barbarbarbarbar<br>");
33 33
     }
34 34
 
35 35
     public function test_it_repeats_word_n_times_uppercase()
36 36
     {
37 37
         $this->command(new RepeatCommand, ['bar', '5', '--upper'])
38
-             ->argsEqual((object) [
39
-               'word' => 'bar',
40
-               'count' => 5
41
-             ])
42
-             ->optionsEqual([
43
-               '--upper' => true
44
-             ])
45
-             ->printsExactly("BARBARBARBARBAR<br>");
38
+                ->argsEqual((object) [
39
+                'word' => 'bar',
40
+                'count' => 5
41
+                ])
42
+                ->optionsEqual([
43
+                '--upper' => true
44
+                ])
45
+                ->printsExactly("BARBARBARBARBAR<br>");
46 46
     }
47 47
 
48 48
     public function test_it_runs_interatively()
49 49
     {
50 50
         $this->withStdin("Yo\n\n\n")
51
-             ->command(new RepeatCommand, ['-i'])
52
-             ->argsEqual((object) [
53
-               'word' => 'Yo',
54
-               'count' => 3
55
-             ])
56
-             ->optionsEqual([
57
-               '--upper' => false
58
-             ])
59
-             ->prints("YoYoYo<br>");
51
+                ->command(new RepeatCommand, ['-i'])
52
+                ->argsEqual((object) [
53
+                'word' => 'Yo',
54
+                'count' => 3
55
+                ])
56
+                ->optionsEqual([
57
+                '--upper' => false
58
+                ])
59
+                ->prints("YoYoYo<br>");
60 60
     }
61 61
 
62 62
 }
Please login to merge, or discard this patch.
src/Command.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,15 +44,15 @@  discard block
 block discarded – undo
44 44
     public function __construct()
45 45
     {
46 46
         $this->commands([])
47
-             ->name('Unknown')
48
-             ->version('1.0.0')
49
-             ->description('...')
50
-             ->descriptions([])
51
-             ->options([])
52
-             ->console(new Console)
53
-             ->fs(new Filesystem('.'))
54
-             ->setupSubCommands()
55
-             ->init();
47
+                ->name('Unknown')
48
+                ->version('1.0.0')
49
+                ->description('...')
50
+                ->descriptions([])
51
+                ->options([])
52
+                ->console(new Console)
53
+                ->fs(new Filesystem('.'))
54
+                ->setupSubCommands()
55
+                ->init();
56 56
     }
57 57
 
58 58
     /**
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
     protected function setupSubCommands()
300 300
     {
301 301
         return $this->command('--help', new HelpCommand($this))
302
-             ->command('--version', new VersionCommand($this))
303
-             ->command('-i', new InteractiveCommand($this));
302
+                ->command('--version', new VersionCommand($this))
303
+                ->command('-i', new InteractiveCommand($this));
304 304
     }
305 305
 
306 306
     public function describe(string $name, string $description = null)
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         }
144 144
 
145 145
         $this->options = [];
146
-        foreach($options as $option)
146
+        foreach ($options as $option)
147 147
             $this->options[$option] = false;
148 148
 
149 149
         return $this;
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
     protected function clear()
366 366
     {
367 367
         $this->args = null;
368
-        foreach($this->options as $name => $value) {
368
+        foreach ($this->options as $name => $value) {
369 369
             $this->options[$name] = false;
370 370
         }
371 371
     }
Please login to merge, or discard this patch.
Braces   +32 added lines, -22 removed lines patch added patch discarded remove patch
@@ -36,8 +36,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/Commands/InteractiveCommand.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
     protected function init()
27 27
     {
28 28
         $this->name('Interactive')
29
-             ->description('Reads the command arguments and options interactively.');
29
+                ->description('Reads the command arguments and options interactively.');
30 30
         $this->helper = SyntaxHelper::instance();
31 31
         $this->confirmSyntax = S::optional(S::boolean(), false);
32 32
     }
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
         $description = $this->parent->describe($name);
99 99
         $this->console->out(
100 100
             "<success>{$name}</success> <warn>{$text}</warn>"
101
-          . " {$description} <warn>{$default}</warn><br>"
101
+            . " {$description} <warn>{$default}</warn><br>"
102 102
         );
103 103
     }
104 104
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
         $options = array_keys($parent->options());
46 46
         $chosen = [];
47
-        foreach($options as $option) {
47
+        foreach ($options as $option) {
48 48
             $bool = $this->read($this->confirmSyntax, $option, true);
49 49
             $parent->options[$option] = $bool;
50 50
             if ($bool) {
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
         $done = false;
144 144
         $text = '';
145 145
         $result = null;
146
-        while (! $done) {
146
+        while (!$done) {
147 147
             $c = $this->readChar();
148
-            switch($c) {
148
+            switch ($c) {
149 149
                 case 'enter':
150 150
                     $done = true;
151 151
                 break;
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -104,8 +104,9 @@  discard block
 block discarded – undo
104 104
     protected function readObject(ObjectSyntax $syntax, string $prefix)
105 105
     {
106 106
         $result = [];
107
-        if ($prefix != '')
108
-            $prefix .= '.';
107
+        if ($prefix != '') {
108
+                    $prefix .= '.';
109
+        }
109 110
         foreach ($syntax->fields() as $name => $s) {
110 111
             $fullname = $prefix . $name;
111 112
             $result[$name] = $this->read($s, $fullname, true);
@@ -132,8 +133,9 @@  discard block
 block discarded – undo
132 133
         $this->console->out("<color:252>{$default}<column:1><reset>");
133 134
         $n = ord($this->console->char());
134 135
         $this->console->out('<column:1><clearLine>');
135
-        if (array_key_exists($n, static::KEYS) && static::KEYS[$n] == 'enter')
136
-            return $syntax->getDefault();
136
+        if (array_key_exists($n, static::KEYS) && static::KEYS[$n] == 'enter') {
137
+                    return $syntax->getDefault();
138
+        }
137 139
         return $this->read($syntax->syntax(), $prefix);
138 140
     }
139 141
 
@@ -175,8 +177,9 @@  discard block
 block discarded – undo
175 177
     protected function readChar() : string
176 178
     {
177 179
         $c = $this->console->char();
178
-        if (ctype_print($c))
179
-            return $c;
180
+        if (ctype_print($c)) {
181
+                    return $c;
182
+        }
180 183
         $n = ord($c);
181 184
         if (
182 185
             array_key_exists($n, static::KEYS)
Please login to merge, or discard this patch.
src/Commands/HelpCommand.php 3 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     protected function init()
15 15
     {
16 16
         $this->name('Help')
17
-             ->description('Shows the help message.');
17
+                ->description('Shows the help message.');
18 18
         $this->helper = SyntaxHelper::instance();
19 19
     }
20 20
 
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
         $parent = $this->parent;
24 24
 
25 25
         $text = "<info>{$parent->name}</info> version <info>{$parent->version}</info>"
26
-              . "<br><br>{$parent->description}<br><br>"
27
-              . $this->syntaxHelp()
28
-              . $this->optionsHelp()
29
-              . $this->subCommandsHelp();
26
+                . "<br><br>{$parent->description}<br><br>"
27
+                . $this->syntaxHelp()
28
+                . $this->optionsHelp()
29
+                . $this->subCommandsHelp();
30 30
 
31 31
         $this->console()->out($text);
32 32
     }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -88,11 +88,11 @@
 block discarded – undo
88 88
             $default = 'default: ' . json_encode($s->getDefault());
89 89
         else
90 90
             $default = 'required';
91
-        $description = $this->parent()->describe($prefix.$name);
91
+        $description = $this->parent()->describe($prefix . $name);
92 92
         $syntax = $this->helper->asString($s);
93 93
         $text   = "{$tabs}<warn>{$name}</warn> <success>{$syntax}</success>"
94 94
                 . " {$description} <info>({$default})</info><br>";
95
-        $level ++;
95
+        $level++;
96 96
         $prefix .= $name . '.';
97 97
         foreach ($this->helper->fields($s) as $field => $syntax) {
98 98
             $text .= $this->fieldHelp($field, $syntax, $prefix, $level);
Please login to merge, or discard this patch.
Braces   +5 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,10 +84,11 @@
 block discarded – undo
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>"
Please login to merge, or discard this patch.
src/Commands/VersionCommand.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@
 block discarded – undo
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()
Please login to merge, or discard this patch.
src/Helpers/SyntaxHelper.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,8 +9,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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(
Please login to merge, or discard this patch.