Passed
Pull Request — master (#79)
by Dave
02:42
created

UpgradeBaseLineCommand::execute()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 11
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 16
rs 9.9
1
<?php
2
3
/**
4
 * Static Analysis Results Baseliner (sarb).
5
 *
6
 * (c) Dave Liddament
7
 *
8
 * For the full copyright and licence information please view the LICENSE file distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Command;
14
15
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Command\internal\BaseLineFileHelper;
16
use DaveLiddament\StaticAnalysisResultsBaseliner\Framework\Command\internal\ErrorReporter;
17
use DaveLiddament\StaticAnalysisResultsBaseliner\Legacy\BaselineUpgrader;
18
use Symfony\Component\Console\Command\Command;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
use Throwable;
22
23
class UpgradeBaseLineCommand extends Command
24
{
25
    public const COMMAND_NAME = 'upgrade-from-version-0';
26
27
    /**
28
     * @var string|null
29
     */
30
    protected static $defaultName = self::COMMAND_NAME;
31
32
    /**
33
     * @var BaselineUpgrader
34
     */
35
    private $baselineUpgrader;
36
37
    public function __construct(
38
        BaselineUpgrader $baselineUpgrader
39
    ) {
40
        parent::__construct(self::COMMAND_NAME);
41
        $this->baselineUpgrader = $baselineUpgrader;
42
    }
43
44
    protected function configure(): void
45
    {
46
        $this->setDescription('Upgrades a baseline created by version 0.x of SARB to version 1');
47
48
        BaseLineFileHelper::configureBaseLineFileArgument($this);
49
    }
50
51
    protected function execute(InputInterface $input, OutputInterface $output): int
52
    {
53
        try {
54
            $baselineFile = BaseLineFileHelper::getBaselineFile($input);
55
            $identifier = $this->baselineUpgrader->upgrade($baselineFile);
56
            $output->writeln('<info>Baseline updated.</info>');
57
            $output->writeln(
58
                sprintf(
59
                    "Update the command to remove baseline results to:\n%s | sarb remove",
60
                    $identifier->getToolCommand()
61
                )
62
            );
63
64
            return 0;
65
        } catch (Throwable $throwable) {
66
            return ErrorReporter::reportError($output, $throwable);
67
        }
68
    }
69
}
70