AMQPConnectionHealthIndicator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
c 2
b 1
f 0
lcom 1
cbo 3
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A doHealthCheck() 0 14 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
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