Completed
Pull Request — release/3.1 (#301)
by
unknown
04:51 queued 02:19
created

RaCandidate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 81
Duplicated Lines 13.58 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 11
loc 81
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A nominate() 0 18 1
A jsonSerialize() 11 11 1

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\Identity\Entity;
20
21
use Doctrine\ORM\Mapping as ORM;
22
use JsonSerializable;
23
use Surfnet\Stepup\Identity\Value\CommonName;
24
use Surfnet\Stepup\Identity\Value\Email;
25
use Surfnet\Stepup\Identity\Value\IdentityId;
26
use Surfnet\Stepup\Identity\Value\Institution;
27
use Surfnet\Stepup\Identity\Value\NameId;
28
29
/**
30
 * @ORM\Table(name="view_ra_candidate")
31
 * @ORM\Entity(repositoryClass="Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository", readOnly=true)
32
 */
33
///**
34
// * @ORM\Entity(repositoryClass="Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository")
35
// * @ORM\Table(
36
// *      indexes={
37
// *          @ORM\Index(name="idx_ra_candidate_institution", columns={"institution"}),
38
// *          @ORM\Index(name="idx_ra_candidate_name_id", columns={"name_id"}),
39
// *          @ORM\Index(name="idxft_ra_candidate_email", columns={"email"}, flags={"FULLTEXT"}),
40
// *          @ORM\Index(name="idxft_ra_candidate_commonname", columns={"common_name"}, flags={"FULLTEXT"}),
41
// *          @ORM\Index(name="idx_ra_institution", columns={"ra_institution"})
42
// *      },
43
// *     uniqueConstraints={
44
// *          @ORM\UniqueConstraint(name="idx_ra_candidate_unique_identity_institution", columns={"identity_id", "ra_institution"})
45
// *     }
46
// * )
47
// */
48
class RaCandidate implements JsonSerializable
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
49
{
50
    /**
51
     * @ORM\Id
52
     * @ORM\Column(length=36)
53
     *
54
     * @var string
55
     */
56
    public $identityId;
57
58
    /**
59
     * @ORM\Id
60
     * @ORM\Column(type="institution")
61
     *
62
     * @var Institution
63
     */
64
    public $raInstitution;
65
66
    /**
67
     * @ORM\Column(type="institution")
68
     *
69
     * @var \Surfnet\Stepup\Identity\Value\Institution
70
     */
71
    public $institution;
72
73
    /**
74
     * @ORM\Column(type="stepup_name_id")
75
     *
76
     * @var \Surfnet\Stepup\Identity\Value\NameId
77
     */
78
    public $nameId;
79
80
    /**
81
     * @ORM\Column(type="stepup_common_name")
82
     *
83
     * @var \Surfnet\Stepup\Identity\Value\CommonName
84
     */
85
    public $commonName;
86
87
    /**
88
     * @ORM\Column(type="stepup_email")
89
     *
90
     * @var \Surfnet\Stepup\Identity\Value\Email
91
     */
92
    public $email;
93
94
    private function __construct()
95
    {
96
    }
97
98
    public static function nominate(
99
        IdentityId $identityId,
100
        Institution $institution,
101
        NameId $nameId,
102
        CommonName $commonName,
103
        Email $email,
104
        Institution $raInstitution
105
    ) {
106
        $candidate                = new self();
107
        $candidate->identityId    = (string) $identityId;
108
        $candidate->institution   = $institution;
109
        $candidate->nameId        = $nameId;
110
        $candidate->commonName    = $commonName;
111
        $candidate->email         = $email;
112
        $candidate->raInstitution = $raInstitution;
113
114
        return $candidate;
115
    }
116
117 View Code Duplication
    public function jsonSerialize()
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...
118
    {
119
        return [
120
            'identity_id'    => $this->identityId,
121
            'institution'    => $this->institution,
122
            'common_name'    => $this->commonName,
123
            'email'          => $this->email,
124
            'name_id'        => $this->nameId,
125
            'ra_institution' => $this->raInstitution,
126
        ];
127
    }
128
}
129