Completed
Pull Request — master (#141)
by Evgenij
02:04
created

DoctrineMigrationsCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getChecks() 0 14 3
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use Doctrine\DBAL\Migrations\Configuration\Configuration;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use ZendDiagnostics\Check\CheckCollectionInterface;
8
use ZendDiagnostics\Check\CheckInterface;
9
use ZendDiagnostics\Check\DoctrineMigration as ZendDoctrineMigration;
10
11
/**
12
 * Class DoctrineMigrationsCollection
13
 */
14
class DoctrineMigrationsCollection implements CheckCollectionInterface
15
{
16
    /**
17
     * DI Container
18
     *
19
     * @var ContainerInterface
20
     */
21
    private $container;
22
23
    /**
24
     * Available checks
25
     *
26
     * @var CheckInterface[]
27
     */
28
    private $checks;
29
30
    /**
31
     * Migrations configuration service ids
32
     *
33
     * @var string[]
34
     */
35
    private $migrations;
36
37
    /**
38
     * DoctrineMigrationsCollection constructor.
39
     *
40
     * @param ContainerInterface $container  DI container
41
     * @param Configuration[]    $migrations Migrations configuration service ids
42
     */
43
    public function __construct(
44
        ContainerInterface $container,
45
        array $migrations
46
    ) {
47
        $this->container  = $container;
48
        $this->migrations = $migrations;
0 ignored issues
show
Documentation Bug introduced by
It seems like $migrations of type array<integer,object<Doc...uration\Configuration>> is incompatible with the declared type array<integer,string> of property $migrations.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getChecks()
55
    {
56
        if ($this->checks === null) {
57
            $this->checks = [];
58
            foreach ($this->migrations as $key => $migration) {
59
                $check = new ZendDoctrineMigration($this->container->get($migration));
60
                $check->setLabel(sprintf('Doctrine migrations "%s"', $key));
61
62
                $this->checks[$key] = $check;
63
            }
64
        }
65
66
        return $this->checks;
67
    }
68
}
69