Completed
Push — feature/caas ( c7df64...f05503 )
by Michiel
03:29
created

RaSecondFactorController::collectionAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 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
 */
18
19
namespace Surfnet\StepupMiddleware\ApiBundle\Controller;
20
21
use Surfnet\Stepup\Identity\Value\Institution;
22
use Surfnet\StepupMiddleware\ApiBundle\Identity\Query\RaSecondFactorQuery;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaSecondFactorService;
24
use Surfnet\StepupMiddleware\ApiBundle\Response\JsonCollectionResponse;
25
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
26
use Symfony\Component\HttpFoundation\JsonResponse;
27
use Symfony\Component\HttpFoundation\Request;
28
29
final class RaSecondFactorController extends Controller
30
{
31
    /**
32
     * @var RaSecondFactorService
33
     */
34
    private $raSecondFactorService;
35
36
    public function __construct(RaSecondFactorService $raSecondFactorService)
37
    {
38
        $this->raSecondFactorService = $raSecondFactorService;
39
    }
40
41 View Code Duplication
    public function collectionAction(Request $request, Institution $institution)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $this->denyAccessUnlessGranted(['ROLE_RA']);
44
45
        $query = $this->buildRaSecondFactorQuery($request, $institution);
46
47
        $paginator = $this->raSecondFactorService->search($query);
48
49
        return JsonCollectionResponse::fromPaginator($paginator);
50
    }
51
52 View Code Duplication
    public function exportAction(Request $request, Institution $institution)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
    {
54
        $this->denyAccessUnlessGranted(['ROLE_RA']);
55
56
        $query = $this->buildRaSecondFactorQuery($request, $institution);
57
58
        $results = $this->raSecondFactorService->searchUnpaginated($query);
59
60
        return new JsonResponse($results);
61
    }
62
63
    /**
64
     * @param Request $request
65
     * @param Institution $institution
66
     * @return RaSecondFactorQuery
67
     */
68
    private function buildRaSecondFactorQuery(Request $request, Institution $institution)
69
    {
70
        $query = new RaSecondFactorQuery();
71
        $query->institution = $institution;
72
        $query->pageNumber = (int)$request->get('p', 1);
73
        $query->name = $request->get('name');
74
        $query->type = $request->get('type');
75
        $query->secondFactorId = $request->get('secondFactorId');
76
        $query->email = $request->get('email');
77
        $query->status = $request->get('status');
78
        $query->orderBy = $request->get('orderBy');
79
        $query->orderDirection = $request->get('orderDirection');
80
81
        return $query;
82
    }
83
}