Completed
Pull Request — master (#141)
by Evgenij
06:31
created

DoctrineMigrationsCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B getChecks() 0 23 4
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use ZendDiagnostics\Check\CheckCollectionInterface;
7
use ZendDiagnostics\Check\CheckInterface;
8
use Doctrine\Common\Persistence\ConnectionRegistry;
9
10
/**
11
 * Class DoctrineMigrationsCollection
12
 */
13
class DoctrineMigrationsCollection implements CheckCollectionInterface
14
{
15
    /**
16
     * DI Container
17
     *
18
     * @var ContainerInterface
19
     */
20
    private $container;
21
22
    /**
23
     * Doctrine connection registry
24
     *
25
     * @var ConnectionRegistry
26
     */
27
    private $connectionRegistry;
28
29
    /**
30
     * Available checks
31
     *
32
     * @var CheckInterface[]
33
     */
34
    private $checks;
35
36
    /**
37
     * Migrations configuration
38
     *
39
     * @var array
40
     */
41
    private $migrations;
42
43
    /**
44
     * DoctrineMigrationsCollection constructor.
45
     *
46
     * @param ContainerInterface $container          DI container
47
     * @param ConnectionRegistry $connectionRegistry Connections registry
48
     * @param array[]            $migrations         Migrations configuration
49
     */
50
    public function __construct(
51
        ContainerInterface $container,
52
        ConnectionRegistry $connectionRegistry,
53
        array $migrations
54
    ) {
55
        $this->container          = $container;
56
        $this->connectionRegistry = $connectionRegistry;
57
        $this->migrations         = $migrations;
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getChecks()
64
    {
65
        if ($this->checks === null) {
66
            $this->checks = [];
67
            foreach ($this->migrations as $key => $migration) {
68
                if (isset($this->checks[$migration['configuration_file']])) {
69
                    continue;
70
                }
71
72
                $check = new DoctrineMigration(
73
                    $this->container,
74
                    $this->connectionRegistry,
75
                    $migration[ 'connection' ],
76
                    $migration[ 'configuration_file' ]
77
                );
78
                $check->setLabel(sprintf('Doctrine migrations "%s"', $key));
79
80
                $this->checks[$migration['configuration_file']] = $check;
81
            }
82
        }
83
84
        return $this->checks;
85
    }
86
}
87