Passed
Push — master ( 5d5c93...4556a9 )
by Daniel
02:35
created

SplitRepositoryInitAllCommand::execute()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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