Passed
Push — master ( 229462...d74785 )
by Andreas
02:20 queued 14s
created

LatestCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Migrations\Tools\Console\Command;
6
7
use Doctrine\Migrations\Exception\NoMigrationsToExecute;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use function sprintf;
11
12
/**
13
 * The LatestCommand class is responsible for outputting what your latest version is.
14
 */
15
class LatestCommand extends DoctrineCommand
16
{
17
    /** @var string */
18
    protected static $defaultName = 'migrations:latest';
19
20 1
    protected function configure() : void
21
    {
22
        $this
23 1
            ->setAliases(['latest'])
24 1
            ->setDescription('Outputs the latest version number');
25
26 1
        parent::configure();
27 1
    }
28
29 1
    public function execute(InputInterface $input, OutputInterface $output) : ?int
30
    {
31 1
        $aliasResolver = $this->getDependencyFactory()->getVersionAliasResolver();
32
33
        try {
34 1
            $version            = $aliasResolver->resolveVersionAlias('latest');
35 1
            $availableMigration = $this->getDependencyFactory()->getMigrationRepository()->getMigration($version);
36 1
            $description        = $availableMigration->getMigration()->getDescription();
37
        } catch (NoMigrationsToExecute $e) {
38
            $version     = '0';
39
            $description = '';
40
        }
41
42 1
        $output->writeln(sprintf(
43 1
            '<info>%s</info>%s',
44 1
            $version,
45 1
            $description !== '' ? ' - ' . $description : ''
46
        ));
47
48 1
        return 0;
49
    }
50
}
51