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

DoctrineConnectionHealthIndicator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
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
 * @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