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

anonymous//examples/cli-app-subcommands.php$0   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A cli-app-subcommands.php$0 ➔ setup() 0 32 1
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