SplitAllCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 61
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A execute() 0 22 4
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dandelion\Console\Command;
6
7
use Dandelion\Operation\Result\MessageInterface;
8
use Dandelion\Operation\SplitterInterface;
9
use InvalidArgumentException;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
use function is_string;
16
use function sprintf;
17
18
class SplitAllCommand extends Command
19
{
20
    public const NAME = 'split:all';
21
    public const DESCRIPTION = 'Splits all packages from mono to split.';
22
23
    /**
24
     * @var \Dandelion\Operation\SplitterInterface
25
     */
26
    protected $splitter;
27
28
    /**
29
     * @param \Dandelion\Operation\SplitterInterface $splitter
30
     */
31
    public function __construct(
32
        SplitterInterface $splitter
33
    ) {
34
        parent::__construct();
35
        $this->splitter = $splitter;
36
    }
37
38
    /**
39
     * @return void
40
     */
41
    protected function configure(): void
42
    {
43
        parent::configure();
44
45
        $this->setName(static::NAME);
46
        $this->setDescription(static::DESCRIPTION);
47
48
        $this->addArgument('branch', InputArgument::REQUIRED, 'Branch');
49
    }
50
51
    /**
52
     * @param \Symfony\Component\Console\Input\InputInterface $input
53
     * @param \Symfony\Component\Console\Output\OutputInterface $output
54
     *
55
     * @return int
56
     */
57
    protected function execute(InputInterface $input, OutputInterface $output): int
58
    {
59
        $branch = $input->getArgument('branch');
60
61
        if (!is_string($branch)) {
62
            throw new InvalidArgumentException('Unsupported type for given argument');
63
        }
64
65
        $output->writeln('Splitting monorepo packages:');
66
        $output->writeln('---------------------------------');
67
68
        $result = $this->splitter->executeForAllRepositories([$branch]);
69
70
        foreach ($result->getMessages() as $message) {
71
            $symbol = $message->getType() === MessageInterface::TYPE_INFO ? '<fg=green>✔</>' : '<fg=red>✗</>';
72
            $output->writeln(sprintf('%s %s', $symbol, $message->getText()));
73
        }
74
75
        $output->writeln('---------------------------------');
76
        $output->writeln('Finished');
77
78
        return 0;
79
    }
80
}
81