MigrationVersionService   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 26.67 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 8
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getLastMigrationVersion() 8 8 2

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
 * This file is part of the StfalconStudioDoctrineRedisCacheBundle.
4
 *
5
 * (c) Stfalcon LLC <stfalcon.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace StfalconStudio\DoctrineRedisCacheBundle\Service\Migration;
14
15
use Doctrine\Migrations\Finder\MigrationFinder;
16
17
/**
18
 * MigrationVersionService.
19
 *
20
 * @author Artem Henvald <[email protected]>
21
 */
22
class MigrationVersionService
23
{
24
    /** @var string */
25
    private $migrationDirectory;
26
27
    /** @var MigrationFinder */
28
    private $migrationFinder;
29
30
    /**
31
     * @param string          $migrationDirectory
32
     * @param MigrationFinder $migrationFinder
33
     */
34
    public function __construct(string $migrationDirectory, MigrationFinder $migrationFinder)
35
    {
36
        $this->migrationDirectory = $migrationDirectory;
37
        $this->migrationFinder = $migrationFinder;
38
    }
39
40
    /**
41
     * @return string
42
     */
43 View Code Duplication
    public function getLastMigrationVersion(): string
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45
        $migrations = $this->migrationFinder->findMigrations($this->migrationDirectory);
46
        $versions = \array_keys($migrations);
47
        $latest = \end($versions);
48
49
        return false !== $latest ? (string) $latest : '0';
50
    }
51
}
52