Completed
Push — master ( c49b49...ed25aa )
by Artem
01:11
created

StfalconStudioDoctrineRedisCacheExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 23.08 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 9
loc 39
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 7 1
A getLastMigrationVersion() 9 9 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\DependencyInjection;
14
15
use Doctrine\Migrations\Finder\RecursiveRegexFinder;
16
use Symfony\Component\Config\FileLocator;
17
use Symfony\Component\DependencyInjection\ContainerBuilder;
18
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
19
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
20
21
/**
22
 * This is the class that loads and manages StfalconStudioDoctrineRedisCacheBundle configuration.
23
 *
24
 * @author Artem Henvald <[email protected]>
25
 */
26
class StfalconStudioDoctrineRedisCacheExtension extends Extension
27
{
28
    /** @var RecursiveRegexFinder */
29
    private $migrationFinder;
30
31
    /**
32
     * Constructor.
33
     */
34
    public function __construct()
35
    {
36
        $this->migrationFinder = new RecursiveRegexFinder();
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function load(array $configs, ContainerBuilder $container): void
43
    {
44
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
45
        $loader->load('services.yaml');
46
47
        $container->setParameter('cache_prefix_seed', $this->getLastMigrationVersion($container->getParameter('doctrine_migrations.dir_name')));
48
    }
49
50
    /**
51
     * @param string $dir
52
     *
53
     * @return string
54
     */
55 View Code Duplication
    public function getLastMigrationVersion(string $dir): 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...
56
    {
57
        $migrations = $this->migrationFinder->findMigrations($dir);
58
59
        $versions = \array_keys($migrations);
60
        $latest = \end($versions);
61
62
        return false !== $latest ? (string) $latest : '0';
63
    }
64
}
65