Passed
Push — master ( a1fc90...f8dfb5 )
by Tarmo
09:37
created

HealthzController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 11 1
A __construct() 0 4 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Controller/HealthzController.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Controller;
10
11
use App\Rest\ResponseHandler;
0 ignored issues
show
Bug introduced by
The type App\Rest\ResponseHandler was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use App\Utils\HealthzService;
13
use Swagger\Annotations as SWG;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use Symfony\Component\Routing\Annotation\Route;
17
use Throwable;
18
19
/**
20
 * Class HealthzController
21
 *
22
 * @package App\Controller
23
 * @author  TLe, Tarmo Leppänen <[email protected]>
24
 */
25
class HealthzController
26
{
27
    private ResponseHandler $responseHandler;
28
    private HealthzService $healthzService;
29
30
    /**
31
     * HealthzController constructor.
32
     */
33 2
    public function __construct(ResponseHandler $responseHandler, HealthzService $healthzService)
34
    {
35 2
        $this->responseHandler = $responseHandler;
36 2
        $this->healthzService = $healthzService;
37 2
    }
38
39
    /**
40
     * Route for application health check. This action will make some simple
41
     * tasks to ensure that application is up and running like expected.
42
     *
43
     * @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
44
     *
45
     * @Route(
46
     *     path="/healthz",
47
     *     methods={"GET"}
48
     *  )
49
     *
50
     * @SWG\Response(
51
     *      response=200,
52
     *      description="success",
53
     *      @SWG\Schema(
54
     *          type="object",
55
     *          example={"timestamp": "2018-01-01T13:08:05+00:00"},
56
     *          @SWG\Property(property="timestamp", type="string"),
57
     *      ),
58
     *  )
59
     *
60
     * @throws Throwable
61
     */
62 2
    public function __invoke(Request $request): Response
63
    {
64 2
        return $this->responseHandler->createResponse(
65 2
            $request,
66 2
            $this->healthzService->check(),
67 2
            null,
68 2
            200,
69 2
            ResponseHandler::FORMAT_JSON,
70
            [
71
                'groups' => [
72 2
                    'Healthz.timestamp',
73
                ],
74
            ]
75
        );
76
    }
77
}
78