Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HealthCheckController
100.00% covered (success)
100.00%
7 / 7
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
 health
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace App\Web\Controller;
6
7use App\Shared\Diagnostics\HealthCheckService;
8use Psr\Http\Message\ResponseInterface;
9use Yiisoft\DataResponse\DataResponseFactoryInterface;
10use Yiisoft\Db\Connection\ConnectionInterface;
11
12 class HealthCheckController
13{
14    public function __construct(
15        private ConnectionInterface $db,
16        private DataResponseFactoryInterface $responseFactory
17    ) {}
18
19    public function health(): ResponseInterface
20    {
21        $projectRoot = dirname(__DIR__, 3);
22        $service = new HealthCheckService($this->db, $projectRoot);
23        $result = $service->performCheck();
24
25        $statusCode = ($result['status'] === 'HEALTHY') ? 200 : 503;
26
27        return $this->responseFactory
28            ->createResponse($result, $statusCode);
29    }
30}