VettingTypeHintController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 22
rs 10
c 2
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 14 2
1
<?php
2
3
/**
4
 * Copyright 2022 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Controller;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\Stepup\Identity\Value\Institution;
23
use Surfnet\StepupMiddleware\ApiBundle\Exception\NotFoundException;
24
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\VettingTypeHintService;
25
use Surfnet\StepupMiddleware\ApiBundle\Controller\AbstractController;
26
use Symfony\Component\HttpFoundation\JsonResponse;
27
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
28
29
class VettingTypeHintController extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class VettingTypeHintController
Loading history...
30
{
31
    public function __construct(
32
        private readonly VettingTypeHintService $service,
33
        private readonly LoggerInterface $logger,
34
    ) {
35
    }
36
37
    public function get(string $institution): JsonResponse
38
    {
39
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
40
        $this->logger->info(sprintf('Received request to get a vetting type hint for institution: %s', $institution));
41
42
        try {
43
            $recoveryToken = $this->service->findBy(new Institution($institution));
44
        } catch (NotFoundException $e) {
45
            throw new NotFoundHttpException(
46
                sprintf("Vetting type hint for institution '%s' was not found", $institution),
47
                $e,
48
            );
49
        }
50
        return new JsonResponse($recoveryToken);
51
    }
52
}
53