Passed
Pull Request — master (#9)
by John
02:59
created

InitializeCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 18
rs 9.9332
1
<?php
2
3
namespace Dandelion\Console\Command;
4
5
use Dandelion\Operation\InitializerInterface;
6
use Dandelion\Operation\Result\MessageInterface;
7
use InvalidArgumentException;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
class InitializeCommand extends Command
13
{
14
    public const NAME = 'init';
15
    public const DESCRIPTION = 'Initialize all repos'; // TODO: Add better description
16
17
    /**
18
     * @var \Dandelion\Operation\AbstractOperation
19
     */
20
    protected $splitter;
21
    /**
22
     * @var \Dandelion\Operation\InitializerInterface
23
     */
24
    private $initializer;
25
26
    /**
27
     * @param \Dandelion\Operation\InitializerInterface $initializer
28
     */
29
    public function __construct(
30
        InitializerInterface $initializer
31
    ) {
32
        parent::__construct();
33
        $this->initializer = $initializer;
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    protected function configure(): void
40
    {
41
        parent::configure();
42
43
        $this->setName(static::NAME);
44
        $this->setDescription(static::DESCRIPTION);
45
    }
46
47
    /**
48
     * @param \Symfony\Component\Console\Input\InputInterface $input
49
     * @param \Symfony\Component\Console\Output\OutputInterface $output
50
     *
51
     * @return int
52
     */
53
    protected function execute(InputInterface $input, OutputInterface $output): int
54
    {
55
        $output->writeln('Initialize...');
56
        $output->writeln('---------------------------------');
57
58
        $output->writeln('Add Git remotes:');
59
        $result = $this->initializer->addGitRemotes();
60
61
        foreach ($result->getMessages() as $message) {
62
            $symbol = $message->getType() === MessageInterface::TYPE_INFO ? '<fg=green>✔</>' : '<fg=red>✗</>';
63
            $output->writeln(sprintf('%s %s', $symbol, $message->getText()));
64
        }
65
66
        $output->writeln('---------------------------------');
67
        $output->writeln('Finished');
68
69
70
        return 0;
71
    }
72
}
73