CurrentCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 39
loc 39
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 1
A execute() 24 24 4

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\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 View Code Duplication
final class CurrentCommand 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: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
        $this->io->text(sprintf(
46 3
            "<info>%s</info>%s\n",
47 3
            (string) $version,
48 3
            $description !== '' ? ' - ' . $description : ''
49
        ));
50
51 3
        return 0;
52
    }
53
}
54