UnverifiedSecondFactorController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 32
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A collection() 0 12 1
A __construct() 0 3 1
A get() 0 11 2
1
<?php
2
3
/**
4
 * Copyright 2014 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 Surfnet\Stepup\Identity\Value\IdentityId;
22
use Surfnet\Stepup\Identity\Value\SecondFactorId;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Entity\UnverifiedSecondFactor;
24
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\UnverifiedSecondFactorQuery;
25
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\SecondFactorService;
26
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse;
27
use Surfnet\StepupMiddleware\ApiBundle\Controller\AbstractController;
28
use Symfony\Component\HttpFoundation\JsonResponse;
29
use Symfony\Component\HttpFoundation\Request;
30
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
31
32
class UnverifiedSecondFactorController extends AbstractController
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UnverifiedSecondFactorController
Loading history...
33
{
34
    public function __construct(
35
        private readonly SecondFactorService $secondFactorService,
36
    ) {
37
    }
38
39
    public function get(string $id): JsonResponse
40
    {
41
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
42
43
        $secondFactor = $this->secondFactorService->findUnverified(new SecondFactorId($id));
44
45
        if (!$secondFactor instanceof UnverifiedSecondFactor) {
46
            throw new NotFoundHttpException(sprintf("Unverified second factor '%s' does not exist", $id));
47
        }
48
49
        return new JsonResponse($secondFactor);
50
    }
51
52
    public function collection(Request $request): JsonCollectionResponse
53
    {
54
        $this->denyAccessUnlessGrantedOneOff(['ROLE_RA', 'ROLE_SS', 'ROLE_READ']);
55
56
        $query = new UnverifiedSecondFactorQuery();
57
        $query->identityId = new IdentityId($request->get('identityId'));
58
        $query->verificationNonce = $request->get('verificationNonce');
59
        $query->pageNumber = (int)$request->get('p', 1);
60
61
        $paginator = $this->secondFactorService->searchUnverifiedSecondFactors($query);
62
63
        return JsonCollectionResponse::fromPaginator($paginator);
64
    }
65
}
66