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

LatestCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 34
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A execute() 0 20 3
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