Completed
Push — master ( c8ccae...53133f )
by Asmir
16s queued 14s
created

CurrentCommand::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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
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\MigrationClassNotFound;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use function sprintf;
11
12
/**
13
 * The CurrentCommand class is responsible for outputting what your current version is.
14
 */
15
final class CurrentCommand extends DoctrineCommand
16
{
17
    /** @var string */
18
    protected static $defaultName = 'migrations:current';
19
20 3
    protected function configure() : void
21
    {
22
        $this
23 3
            ->setAliases(['current'])
24 3
            ->setDescription('Outputs the current version');
25
26 3
        parent::configure();
27 3
    }
28
29 3
    protected function execute(InputInterface $input, OutputInterface $output) : int
30
    {
31 3
        $aliasResolver = $this->getDependencyFactory()->getVersionAliasResolver();
32
33 3
        $version = $aliasResolver->resolveVersionAlias('current');
34 3
        if ((string) $version === '0') {
35 1
            $description = '(No migration executed yet)';
36
        } else {
37
            try {
38 2
                $availableMigration = $this->getDependencyFactory()->getMigrationRepository()->getMigration($version);
39 1
                $description        = $availableMigration->getMigration()->getDescription();
40 1
            } catch (MigrationClassNotFound $e) {
41 1
                $description = '(Migration info not available)';
42
            }
43
        }
44
45 3
        $output->writeln(sprintf(
46 3
            '<info>%s</info>%s',
47 3
            (string) $version,
48 3
            $description !== '' ? ' - ' . $description : ''
49
        ));
50
51 3
        return 0;
52
    }
53
}
54