LatestCommand::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 3.1105

Importance

Changes 0
Metric Value
dl 21
loc 21
ccs 10
cts 13
cp 0.7692
rs 9.584
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 3.1105
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 View Code Duplication
final class LatestCommand extends DoctrineCommand
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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');
25
26 1
        parent::configure();
27 1
    }
28
29 1
    protected 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
        $this->io->text(sprintf(
43 1
            "<info>%s</info>%s\n",
44 1
            $version,
45 1
            $description !== '' ? ' - ' . $description : ''
46
        ));
47
48 1
        return 0;
49
    }
50
}
51