Passed
Pull Request — master (#1181)
by Tarmo
06:39 queued 03:09
created

LanguageController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 28
ccs 4
cts 4
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 7 1
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Controller/Localization/LanguageController.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Controller\Localization;
10
11
use App\Service\Localization;
12
use OpenApi\Annotations as OA;
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\Routing\Annotation\Route;
16
17
/**
18
 * Class LanguageController
19
 *
20
 * @OA\Tag(name="Localization")
21
 *
22
 * @package App\Controller\Localization
23
 * @author TLe, Tarmo Leppänen <[email protected]>
24
 */
25
class LanguageController
26
{
27 2
    public function __construct(
28
        private Localization $localization,
29
    ) {
30 2
    }
31
32
    /**
33
     * Endpoint action to get supported languages. This is for use to choose
34
     * what language your frontend application can use within its translations.
35
     *
36
     * @OA\Response(
37
     *      response=200,
38
     *      description="List of language strings.",
39
     *      @OA\Schema(
40
     *          type="array",
41
     *          example={"en","fi"},
42
     *          @OA\Items(type="string"),
43
     *      ),
44
     *  )
45
     */
46 2
    #[Route(
47
        path: '/localization/language',
48
        methods: [Request::METHOD_GET],
49
    )]
50
    public function __invoke(): JsonResponse
51
    {
52 2
        return new JsonResponse($this->localization->getLanguages());
53
    }
54
}
55