DoctrineMigrationsCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 52
ccs 0
cts 19
cp 0
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\Migrations\Configuration\Configuration;
6
use Laminas\Diagnostics\Check\CheckCollectionInterface;
7
use Laminas\Diagnostics\Check\CheckInterface;
8
use Laminas\Diagnostics\Check\DoctrineMigration as LaminasDoctrineMigration;
9
use Symfony\Component\DependencyInjection\ContainerInterface;
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
    public function getChecks()
52
    {
53
        if (null === $this->checks) {
54
            $this->checks = [];
55
            foreach ($this->migrations as $key => $migration) {
56
                $check = new LaminasDoctrineMigration($this->container->get($migration));
0 ignored issues
show
Documentation introduced by
$this->container->get($migration) is of type object|null, but the function expects a object<Doctrine\Migratio...guration\Configuration>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
57
                $check->setLabel(sprintf('Doctrine migrations "%s"', $key));
58
59
                $this->checks[$key] = $check;
60
            }
61
        }
62
63
        return $this->checks;
64
    }
65
}
66