Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
12 / 12 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AboutRequirementsApiController | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\About\Presentation\Api; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Modules\About\Application\Service\SystemDiagnosticsServiceInterface; |
| 12 | use App\Shared\Infrastructure\Http\ApiResponseTrait; |
| 13 | use Psr\Http\Message\ResponseFactoryInterface; |
| 14 | use Psr\Http\Message\ResponseInterface; |
| 15 | use Psr\Http\Message\ServerRequestInterface; |
| 16 | |
| 17 | /** |
| 18 | * About System Requirements REST API Controller. |
| 19 | * |
| 20 | * Exposes /api/v1/about/requirements JSON endpoint for live system environment diagnostics. |
| 21 | * |
| 22 | * @package App\Modules\About\Presentation\Api |
| 23 | */ |
| 24 | final readonly class AboutRequirementsApiController |
| 25 | { |
| 26 | use ApiResponseTrait; |
| 27 | |
| 28 | /** |
| 29 | * AboutRequirementsApiController constructor. |
| 30 | * |
| 31 | * @param ResponseFactoryInterface $responseFactory PSR-7 Response factory. |
| 32 | * @param SystemDiagnosticsServiceInterface $diagnosticsService System diagnostics inspection service. |
| 33 | */ |
| 34 | public function __construct( |
| 35 | private ResponseFactoryInterface $responseFactory, |
| 36 | private SystemDiagnosticsServiceInterface $diagnosticsService |
| 37 | ) { |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Handles API request to fetch system requirements and live diagnostic benchmark results. |
| 42 | * |
| 43 | * @param ServerRequestInterface $request PSR-7 Server request. |
| 44 | * @return ResponseInterface PSR-7 JSON response. |
| 45 | */ |
| 46 | public function index(ServerRequestInterface $request): ResponseInterface |
| 47 | { |
| 48 | $queryParams = $request->getQueryParams(); |
| 49 | $category = isset($queryParams['category']) && is_string($queryParams['category']) |
| 50 | ? trim($queryParams['category']) |
| 51 | : null; |
| 52 | |
| 53 | $report = $this->diagnosticsService->runDiagnostics($category); |
| 54 | |
| 55 | return $this->jsonSuccess( |
| 56 | $this->responseFactory, |
| 57 | $report, |
| 58 | 200 |
| 59 | ); |
| 60 | } |
| 61 | } |