DoctrineMongoDbCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 23
loc 23
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 3
A getChecks() 4 4 1

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
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