Completed
Pull Request — master (#3)
by
unknown
12:23
created

ApiHealthIndicator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Actuator\Health\Indicator;
3
4
use Actuator\Health\HealthBuilder;
5
use Guzzle\Http\Message\Request;
6
use Guzzle\Http\Message\Response;
7
8
class ApiHealthIndicator extends AbstractHealthIndicator
9
{
10
    /**
11
     * @var Request
12
     */
13
    private $request;
14
15
    public function __construct(Request $request)
16
    {
17
        $this->request = $request;
18
    }
19
20
    /**
21
     * Actual health check logic.
22
     *
23
     * @param HealthBuilder $builder
24
     * @throws \Exception any Exception that should create a Status::DOWN
25
     * system status.
26
     */
27
    protected function doHealthCheck(HealthBuilder $builder)
28
    {
29
        /** @var Response $response */
30
        $response = $this->request
31
            ->send();
32
33
        $builder->withDetail('statusCode', $response->getStatusCode());
34
35
        if (!$response->isSuccessful()) {
36
            $builder->down();
37
            return;
38
        }
39
40
        $builder->up();
41
    }
42
}