Completed
Push — develop ( 606257...546cb3 )
by
unknown
15s
created

buildRaSecondFactorQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
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\Response\JsonCollectionResponse;
24
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
25
use Symfony\Component\HttpFoundation\JsonResponse;
26
use Symfony\Component\HttpFoundation\Request;
27
28
final class RaSecondFactorController extends Controller
29
{
30 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...
31
    {
32
        $this->denyAccessUnlessGranted(['ROLE_RA']);
33
34
        $query = $this->buildRaSecondFactorQuery($request, $institution);
35
36
        $paginator = $this->getService()->search($query);
37
38
        return JsonCollectionResponse::fromPaginator($paginator);
39
    }
40
41 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...
42
    {
43
        $this->denyAccessUnlessGranted(['ROLE_RA']);
44
45
        $query = $this->buildRaSecondFactorQuery($request, $institution);
46
47
        $results = $this->getService()->searchUnpaginated($query);
48
49
        return new JsonResponse($results);
50
    }
51
52
    /**
53
     * @param Request $request
54
     * @param Institution $institution
55
     * @return RaSecondFactorQuery
56
     */
57
    private function buildRaSecondFactorQuery(Request $request, Institution $institution)
58
    {
59
        $query                 = new RaSecondFactorQuery();
60
        $query->institution    = $institution;
61
        $query->pageNumber     = (int) $request->get('p', 1);
62
        $query->name           = $request->get('name');
63
        $query->type           = $request->get('type');
64
        $query->secondFactorId = $request->get('secondFactorId');
65
        $query->email          = $request->get('email');
66
        $query->status         = $request->get('status');
67
        $query->orderBy        = $request->get('orderBy');
68
        $query->orderDirection = $request->get('orderDirection');
69
        return $query;
70
    }
71
72
    /**
73
     * @return \Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaSecondFactorService
74
     */
75
    private function getService()
76
    {
77
        return $this->get('surfnet_stepup_middleware_api.service.ra_second_factor');
78
    }
79
}
80