Completed
Push — release/2.9 ( d719bc...ed5cac )
by Michiel
02:40
created

RaCandidateController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 26.92 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 14
loc 52
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A searchAction() 0 15 1
A getAction() 14 14 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\RaCandidateQuery;
23
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaCandidateService;
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
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
29
30
class RaCandidateController extends Controller
31
{
32
    /**
33
     * @var RaCandidateService
34
     */
35
    private $raCandidateService;
36
37
    public function __construct(RaCandidateService $raCandidateService)
38
    {
39
        $this->raCandidateService = $raCandidateService;
40
    }
41
42
    /**
43
     * @param Institution $institution
44
     * @param Request     $request
45
     * @return JsonCollectionResponse
46
     */
47
    public function searchAction(Institution $institution, Request $request)
48
    {
49
        $this->denyAccessUnlessGranted(['ROLE_RA']);
50
51
        $query                    = new RaCandidateQuery();
52
        $query->institution       = $institution;
53
        $query->commonName        = $request->get('commonName');
54
        $query->email             = $request->get('email');
55
        $query->secondFactorTypes = $request->get('secondFactorTypes');
0 ignored issues
show
Documentation Bug introduced by
It seems like $request->get('secondFactorTypes') of type * is incompatible with the declared type array<integer,string> of property $secondFactorTypes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
        $query->pageNumber        = (int) $request->get('p', 1);
57
58
        $paginator = $this->raCandidateService->search($query);
59
60
        return JsonCollectionResponse::fromPaginator($paginator);
61
    }
62
63
    /**
64
     * @param Request $request
65
     * @return JsonResponse
66
     */
67 View Code Duplication
    public function getAction(Request $request)
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...
68
    {
69
        $this->denyAccessUnlessGranted(['ROLE_RA']);
70
71
        $identityId = $request->get('identityId');
72
73
        $raCandidate = $this->raCandidateService->findByIdentityId($identityId);
74
75
        if ($raCandidate === null) {
76
            throw new NotFoundHttpException(sprintf("RaCandidate with IdentityId '%s' does not exist", $identityId));
77
        }
78
79
        return new JsonResponse($raCandidate);
80
    }
81
}
82