Passed
Push — master ( b95edc...42d472 )
by Timm
02:04
created

cli-app-options.php$0 ➔ setup()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 25
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 33
rs 9.52
1
#!/usr/bin/php
2
<?php
3
4
require __DIR__ . '/../vendor/autoload.php';
5
6
use Stefaminator\Cli\App;
7
use Stefaminator\Cli\AppParser;
8
use Stefaminator\Cli\Cmd;
9
use Stefaminator\Cli\Color;
10
11
AppParser::run(
12
    (new class extends App {
13
14
        public function setup(): Cmd {
15
            return Cmd::root()
16
                ->addOption('v|verbose', [
17
                    'description' => 'Flag to enable verbose output'
18
                ])
19
                ->addOption('name:', [
20
                    'description' => 'Name option. This option requires a value.',
21
                    'isa' => 'string',
22
                    'default' => 'World'
23
                ])
24
                ->setCallable(static function (Cmd $cmd) {
25
26
                    $name = $cmd->optionResult->get('name');
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
                    /** @scrutinizer ignore-call */ 
27
                    $name = $cmd->optionResult->get('name');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28
                    self::eol();
29
                    self::echo(sprintf('Hello %s', $name), Color::FOREGROUND_COLOR_YELLOW);
30
                    self::eol();
31
32
                    if($cmd->optionResult->has('verbose')) {
33
                        $keys = array_keys($cmd->optionResult->keys);
34
                        self::eol();
35
                        self::echo('--- VERBOSE OUTPUT ---' . APP::EOL, Color::FOREGROUND_COLOR_GREEN);
36
                        self::eol();
37
                        self::echo('  All current options...' . APP::EOL, Color::FOREGROUND_COLOR_GREEN);
38
                        foreach($keys as $k) {
39
                            self::echo('    ' . $k . ': ' . $cmd->optionResult->get($k) . APP::EOL, Color::FOREGROUND_COLOR_GREEN);
40
                        }
41
                        self::eol();
42
43
                        self::echo('  All current arguments...' . APP::EOL, Color::FOREGROUND_COLOR_GREEN);
44
                        $args = $cmd->arguments;
45
                        foreach($args as $a) {
46
                            self::echo('    ' . $a . APP::EOL, Color::FOREGROUND_COLOR_GREEN);
47
                        }
48
49
                    }
50
51
                });
52
        }
53
54
    })
55
);
56