Completed
Branch master (f2efac)
by John
02:31
created

DoctrineConnectionHealthIndicator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A doHealthCheck() 0 11 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
 * @package Actuator\Health\Indicator
14
 */
15
class DoctrineConnectionHealthIndicator extends AbstractHealthIndicator
16
{
17
    /**
18
     * @var Connection
19
     */
20
    private $connection;
21
22
    /**
23
     * MemcacheHealthIndicator constructor.
24
     * @param Connection $connection
25
     */
26 6
    public function __construct(Connection $connection)
27
    {
28 6
        assert(!is_null($connection), 'Connection must not be null');
29
30 6
        $this->connection = $connection;
31 6
    }
32
33
    /**
34
     * Actual health check logic.
35
     *
36
     * @param HealthBuilder $builder
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
            return;
47
        }
48
49 3
        $builder->up();
50 3
    }
51
}
52