DoctrineConnectionHealthIndicator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
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