Passed
Push — master ( 064793...c708b1 )
by Peter
02:48
created

Setup   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A doExecute() 0 8 3
A addSubCommand() 0 3 1
A define() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Console\Commands\AbterPhp;
6
7
use AbterPhp\Framework\Console\Commands\Oauth2\GenerateKeys;
8
use Opulence\Console\Commands\Command;
9
use Opulence\Console\Responses\IResponse;
10
11
class Setup extends Command
12
{
13
    const NAME = 'abterphp:setup';
14
15
    const DESCRIPTION = 'Setup Abterphp';
16
17
    /** @var array */
18
    protected $subCommands = [
19
        /** @see GenerateKeys::doExecute() */
20
        GenerateKeys::NAME,
21
    ];
22
23
    /**
24
     * @inheritdoc
25
     */
26
    protected function define()
27
    {
28
        $this->setName(static::NAME)
29
            ->setDescription(static::DESCRIPTION);
30
    }
31
32
    /**
33
     * @param string $subCommand
34
     */
35
    public function addSubCommand(string $subCommand)
36
    {
37
        $this->subCommands[] = $subCommand;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    protected function doExecute(IResponse $response)
44
    {
45
        foreach ($this->subCommands as $subCommand) {
46
            try {
47
                $this->commandCollection->call($subCommand, $response);
48
            } catch (\Exception $e) {
49
                $response->writeln(sprintf('<error>%s@execute failed</error>', $subCommand));
50
                $response->writeln(sprintf('<fatal>%s</fatal>', $e->getMessage()));
51
            }
52
        }
53
    }
54
}
55