Completed
Pull Request — develop (#301)
by
unknown
06:43 queued 04:40
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 nominate() 0 18 1
A jsonSerialize() 11 11 1
A __construct() 0 3 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
 * Be aware that this entity is used for the RA Candidate view. This entity shouldn't be used to store any RA candidates.
31
 * The IgnoreTablesListener is used to prevent schema changes when the Doctrine Schema tool is used.
32
 *
33
 * @ORM\Table(name="view_ra_candidate")
34
 * @ORM\Entity(repositoryClass="Surfnet\StepupMiddleware\ApiBundle\Identity\Repository\RaCandidateRepository", readOnly=true)
35
 */
36
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...
37
{
38
    /**
39
     * @ORM\Id
40
     * @ORM\Column(length=36)
41
     *
42
     * @var string
43
     */
44
    public $identityId;
45
46
    /**
47
     * @ORM\Id
48
     * @ORM\Column(type="institution")
49
     *
50
     * @var Institution
51
     */
52
    public $raInstitution;
53
54
    /**
55
     * @ORM\Column(type="institution")
56
     *
57
     * @var \Surfnet\Stepup\Identity\Value\Institution
58
     */
59
    public $institution;
60
61
    /**
62
     * @ORM\Column(type="stepup_name_id")
63
     *
64
     * @var \Surfnet\Stepup\Identity\Value\NameId
65
     */
66
    public $nameId;
67
68
    /**
69
     * @ORM\Column(type="stepup_common_name")
70
     *
71
     * @var \Surfnet\Stepup\Identity\Value\CommonName
72
     */
73
    public $commonName;
74
75
    /**
76
     * @ORM\Column(type="stepup_email")
77
     *
78
     * @var \Surfnet\Stepup\Identity\Value\Email
79
     */
80
    public $email;
81
82
    private function __construct()
83
    {
84
    }
85
86
    public static function nominate(
87
        IdentityId $identityId,
88
        Institution $institution,
89
        NameId $nameId,
90
        CommonName $commonName,
91
        Email $email,
92
        Institution $raInstitution
93
    ) {
94
        $candidate                = new self();
95
        $candidate->identityId    = (string) $identityId;
96
        $candidate->institution   = $institution;
97
        $candidate->nameId        = $nameId;
98
        $candidate->commonName    = $commonName;
99
        $candidate->email         = $email;
100
        $candidate->raInstitution = $raInstitution;
101
102
        return $candidate;
103
    }
104
105 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...
106
    {
107
        return [
108
            'identity_id'    => $this->identityId,
109
            'institution'    => $this->institution,
110
            'common_name'    => $this->commonName,
111
            'email'          => $this->email,
112
            'name_id'        => $this->nameId,
113
            'ra_institution' => $this->raInstitution,
114
        ];
115
    }
116
}
117