Passed
Pull Request — master (#1695)
by Tarmo
09:52
created

HealthzController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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;
12
use App\Utils\HealthzService;
13
use OpenApi\Annotations as OA;
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
    public function __construct(
28
        private ResponseHandler $responseHandler,
29
        private HealthzService $healthzService,
30
    ) {
31
    }
32
33
    /**
34
     * Route for application health check. This action will make some simple
35
     * tasks to ensure that application is up and running like expected.
36
     *
37
     * @see https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/
38
     *
39
     * @OA\Response(
40
     *      response=200,
41
     *      description="success",
42
     *      @OA\Schema(
43
     *          type="object",
44
     *          example={"timestamp": "2018-01-01T13:08:05+00:00"},
45
     *          @OA\Property(property="timestamp", type="string"),
46
     *      ),
47
     *  )
48
     *
49
     * @throws Throwable
50
     */
51 3
    #[Route(
52
        path: '/healthz',
53
        methods: [Request::METHOD_GET],
54
    )]
55
    public function __invoke(Request $request): Response
56
    {
57 3
        return $this->responseHandler->createResponse(
58
            $request,
59 3
            $this->healthzService->check(),
60
            format: ResponseHandler::FORMAT_JSON,
61
            context: [
62
                'groups' => [
63 3
                    'Healthz.timestamp',
64
                ],
65
            ],
66
        );
67
    }
68
}
69