ApiHealthCheck::check()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright 2017 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\EngineBlockApiClientBundle\HealthCheck;
20
21
use Exception;
22
use OpenConext\MonitorBundle\HealthCheck\HealthCheckInterface;
23
use OpenConext\MonitorBundle\HealthCheck\HealthReportInterface;
24
use OpenConext\MonitorBundle\Value\HealthReport;
25
use OpenConext\Profile\Repository\ConsentRepositoryInterface;
26
27
class ApiHealthCheck implements HealthCheckInterface
28
{
29
    /**
30
     * @var ConsentRepositoryInterface
31
     */
32
    private $repository;
33
34
    public function __construct(ConsentRepositoryInterface $repository)
35
    {
36
        $this->repository = $repository;
37
    }
38
39
    /**
40
     * @param HealthReportInterface $report
41
     * @return HealthReportInterface
42
     */
43
    public function check(HealthReportInterface $report)
44
    {
45
        try {
46
            $this->repository->findAllFor('a73b204b8d896a55b34e41e71f0138f81e81f4da');
47
        } catch (Exception $e) {
48
            return HealthReport::buildStatusDown(
49
                sprintf(
50
                    'EngineBlock API is not responding as expected. Message "%s" of type "%s".',
51
                    $e->getMessage(),
52
                    get_class($e)
53
                )
54
            );
55
        }
56
        return $report;
57
    }
58
}
59