Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| HealthCheckController | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| check | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Health\Infrastructure\Controllers; |
| 6 | |
| 7 | use App\Health\Application\Query\HealthCheckHandler; |
| 8 | use App\Health\Application\Query\HealthCheckQuery; |
| 9 | use OpenApi\Attributes as OA; |
| 10 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 11 | use Symfony\Component\HttpFoundation\JsonResponse; |
| 12 | use Symfony\Component\Routing\Attribute\Route; |
| 13 | |
| 14 | #[OA\Tag(name: 'Health')] |
| 15 | class 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 | } |