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

Setup::doExecute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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