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

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

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 27
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 32
rs 9.488
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
                ->setCallable(static function (Cmd $cmd) {
17
                    $cmd->help();
18
                })
19
                ->addSubCmd(
20
                    Cmd::extend('show')
21
                        ->setDescription('This command is used to show something. Take a look at the subcommands.')
22
                        ->setCallable(static function(Cmd $cmd) {
23
                            error_reporting(E_ALL);
24
                            $cmd->help();
25
                        })
26
                        ->addSubCmd(
27
                            Cmd::extend('hello')
28
                                ->setDescription('Displays hello world.')
29
                                ->setCallable(static function(Cmd $cmd) {
0 ignored issues
show
Unused Code introduced by
The parameter $cmd is not used and could be removed. ( Ignorable by Annotation )

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

29
                                ->setCallable(static function(/** @scrutinizer ignore-unused */ Cmd $cmd) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
                                    self::eol();
31
                                    self::echo('  Hello world!', Color::FOREGROUND_COLOR_CYAN);
32
                                    self::eol();
33
                                    self::eol();
34
                                })
35
                        )
36
                        ->addSubCmd(
37
                            Cmd::extend('phpversion')
38
                                ->setDescription('Displays the current php version of your cli.')
39
                                ->setCallable(static function(Cmd $cmd) {
0 ignored issues
show
Unused Code introduced by
The parameter $cmd is not used and could be removed. ( Ignorable by Annotation )

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

39
                                ->setCallable(static function(/** @scrutinizer ignore-unused */ Cmd $cmd) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
                                    self::eol();
41
                                    self::echo('  Your PHP version is:', Color::FOREGROUND_COLOR_YELLOW);
42
                                    self::eol();
43
                                    self::echo('  ' . PHP_VERSION);
44
                                    self::eol();
45
                                    self::eol();
46
                                })
47
                        )
48
                );
49
        }
50
51
    }
52
);
53