Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
VersionController
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 index
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * The Version Controller for the REST API
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2023-2026 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2023-07-29
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Controller\Api;
21
22use OpenApi\Attributes as OA;
23use phpMyFAQ\Controller\AbstractController;
24use Symfony\Component\HttpFoundation\JsonResponse;
25use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
26use Symfony\Component\Routing\Attribute\Route;
27
28final class VersionController extends AbstractController
29{
30    public function __construct()
31    {
32        parent::__construct();
33
34        if (!$this->isApiEnabled()) {
35            throw new UnauthorizedHttpException(challenge: 'API is not enabled');
36        }
37    }
38
39    #[OA\Get(path: '/api/v4.0/version', operationId: 'getVersion', tags: ['Public Endpoints'])]
40    #[OA\Response(
41        response: 200,
42        description: 'Returns the phpMyFAQ version number as string.',
43        content: new OA\JsonContent(example: '4.0.0'),
44    )]
45    #[Route(path: 'v4.0/version', name: 'api.version', methods: ['GET'])]
46    public function index(): JsonResponse
47    {
48        return $this->json($this->configuration->getVersion());
49    }
50}