Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HealthCheckController
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 check
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Health\Infrastructure\Controllers;
6
7use App\Health\Application\Query\HealthCheckHandler;
8use App\Health\Application\Query\HealthCheckQuery;
9use OpenApi\Attributes as OA;
10use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11use Symfony\Component\HttpFoundation\JsonResponse;
12use Symfony\Component\Routing\Attribute\Route;
13
14#[OA\Tag(name: 'Health')]
15class HealthCheckController extends AbstractController
16{
17    public function __construct(
18        private readonly HealthCheckHandler $healthHandler,
19    ) {
20    }
21
22    #[Route('/health', name: 'health_check', methods: ['GET'])]
23    public function check(): JsonResponse
24    {
25        $query = new HealthCheckQuery();
26        $result = $this->healthHandler->handle($query);
27
28        $statusCode = $result['status'] === 'ok' ? 200 : 503;
29
30        return new JsonResponse($result, $statusCode);
31    }
32}