DoctrineMongoDbCollection::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 11
cp 0
rs 9.8333
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 12
1
<?php
2
3
namespace Liip\MonitorBundle\Check;
4
5
use Doctrine\Persistence\ConnectionRegistry;
6
use Laminas\Diagnostics\Check\CheckCollectionInterface;
7
8
/**
9
 * @author Hugues Gobet <[email protected]>
10
 */
11 View Code Duplication
class DoctrineMongoDbCollection implements CheckCollectionInterface
0 ignored issues
show
Duplication introduced by
This class 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...
12
{
13
    private $checks = [];
14
15
    public function __construct(ConnectionRegistry $manager, $connections)
16
    {
17
        if (!is_array($connections)) {
18
            $connections = [$connections];
19
        }
20
21
        foreach ($connections as $connection) {
22
            $check = new DoctrineMongoDb($manager, $connection);
0 ignored issues
show
Documentation introduced by
$manager is of type object<Doctrine\Persistence\ConnectionRegistry>, but the function expects a object<Doctrine\Bundle\M...Bundle\ManagerRegistry>.

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...
23
            $check->setLabel(sprintf('Doctrine Mongo Db "%s" connection', $connection));
24
25
            $this->checks[sprintf('doctrine_mongodb_%s_connection', $connection)] = $check;
26
        }
27
    }
28
29
    public function getChecks()
30
    {
31
        return $this->checks;
32
    }
33
}
34