ReleaseAllCommand::execute()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 12
c 1
b 0
f 1
nc 4
nop 2
dl 0
loc 22
rs 9.8666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dandelion\Console\Command;
6
7
use Dandelion\Operation\ReleaserInterface;
8
use Dandelion\Operation\Result\MessageInterface;
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 ReleaseAllCommand extends Command
19
{
20
    public const NAME = 'release:all';
21
    public const DESCRIPTION = 'Releases all packages.';
22
23
    /**
24
     * @var \Dandelion\Operation\ReleaserInterface
25
     */
26
    protected $releaser;
27
28
    /**
29
     * @param \Dandelion\Operation\ReleaserInterface $releaser
30
     */
31
    public function __construct(
32
        ReleaserInterface $releaser
33
    ) {
34
        parent::__construct();
35
        $this->releaser = $releaser;
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('Releasing monorepo packages:');
66
        $output->writeln('---------------------------------');
67
68
        $result = $this->releaser->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