LatestCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 36
loc 36
ccs 15
cts 18
cp 0.8333
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 1
A execute() 21 21 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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