DoctrineConnectionHealthIndicator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 3
dl 0
loc 40
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doHealthCheck() 0 12 2
1
<?php
2
3
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\HealthBuilder;
6
use Doctrine\DBAL\Connection;
7
use Doctrine\DBAL\DBALException;
8
9
/**
10
 * Simple implementation of a HealthIndicator returning status information for
11
 * a Doctrine Connection.
12
 */
13
class DoctrineConnectionHealthIndicator extends AbstractHealthIndicator
14
{
15
    /**
16
     * @var Connection
17
     */
18
    private $connection;
19
20
    /**
21
     * MemcacheHealthIndicator constructor.
22
     *
23
     * @param Connection $connection
24
     */
25
    public function __construct(Connection $connection)
26 6
    {
27
        assert(!is_null($connection), 'Connection must not be null');
28 6
29
        $this->connection = $connection;
30 6
    }
31 6
32
    /**
33
     * Actual health check logic.
34
     *
35
     * @param HealthBuilder $builder
36
     *
37
     * @throws \Exception any Exception that should create a Status::DOWN
38
     *                    system status.
39
     */
40 6
    protected function doHealthCheck(HealthBuilder $builder)
41
    {
42
        try {
43 6
            $this->connection->query('SELECT 1=1');
44 6
        } catch (DBALException $e) {
45 3
            $builder->down($e);
46 3
47
            return;
48
        }
49 3
50 3
        $builder->up();
51
    }
52
}
53