Completed
Push — master ( 1eee65...06f8ee )
by John
14:50
created

AMQPConnectionHealthIndicator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

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
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doHealthCheck() 0 13 2
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
 * @package Actuator\Health\Indicator
13
 */
14
class AMQPConnectionHealthIndicator extends AbstractHealthIndicator
15
{
16
    /**
17
     * @var AbstractConnection
18
     */
19
    private $connection;
20
21
    /**
22
     * MemcacheHealthIndicator constructor.
23
     * @param AbstractConnection $connection
24
     */
25
    public function __construct(AbstractConnection $connection)
26
    {
27
        $this->connection = $connection;
28
    }
29
30
    /**
31
     * Actual health check logic.
32
     *
33
     * @param HealthBuilder $builder
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
            return;
46
        }
47
48
        $builder->up();
49
    }
50
}
51