AMQPConnectionHealthIndicator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Actuator\Health\Indicator;
4
5
use Actuator\Health\HealthBuilder;
6
use PhpAmqpLib\Connection\AbstractConnection;
7
8
/**
9
 * Simple implementation of a HealthIndicator returning status information for
10
 * an AMQP Connection.
11
 */
12
class AMQPConnectionHealthIndicator extends AbstractHealthIndicator
13
{
14
    /**
15
     * @var AbstractConnection
16
     */
17
    private $connection;
18
19
    /**
20
     * MemcacheHealthIndicator constructor.
21
     *
22
     * @param AbstractConnection $connection
23
     */
24
    public function __construct(AbstractConnection $connection)
25
    {
26
        $this->connection = $connection;
27
    }
28
29
    /**
30
     * Actual health check logic.
31
     *
32
     * @param HealthBuilder $builder
33
     *
34
     * @throws \Exception any Exception that should create a Status::DOWN
35
     *                    system status.
36
     */
37
    protected function doHealthCheck(HealthBuilder $builder)
38
    {
39
        try {
40
            $this->connection->reconnect();
41
            $serverProperties = $this->connection->getServerProperties();
42
            $builder->withDetail('version', $serverProperties['version'][1]);
43
        } catch (\Exception $e) {
44
            $builder->down($e);
45
46
            return;
47
        }
48
49
        $builder->up();
50
    }
51
}
52