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 |
||
19 | class IdpSsoDescriptor extends SSODescriptor |
||
20 | { |
||
21 | /** @var bool|null */ |
||
22 | protected $wantAuthnRequestsSigned; |
||
23 | |||
24 | /** @var SingleSignOnService[]|null */ |
||
25 | protected $singleSignOnServices; |
||
26 | |||
27 | /** @var Attribute[]|null */ |
||
28 | protected $attributes; |
||
29 | |||
30 | /** |
||
31 | * @param bool|null $wantAuthnRequestsSigned |
||
32 | * |
||
33 | * @return IdpSsoDescriptor |
||
34 | */ |
||
35 | 6 | public function setWantAuthnRequestsSigned($wantAuthnRequestsSigned) |
|
41 | |||
42 | /** |
||
43 | * @return bool|null |
||
44 | */ |
||
45 | 3 | public function getWantAuthnRequestsSigned() |
|
49 | |||
50 | /** |
||
51 | * @param SingleSignOnService $singleSignOnService |
||
52 | * |
||
53 | * @return IdpSsoDescriptor |
||
54 | */ |
||
55 | 42 | public function addSingleSignOnService(SingleSignOnService $singleSignOnService) |
|
64 | |||
65 | /** |
||
66 | * @return SingleSignOnService[]|null |
||
67 | */ |
||
68 | 14 | public function getAllSingleSignOnServices() |
|
72 | |||
73 | /** |
||
74 | * @param string $url |
||
75 | * |
||
76 | * @return SingleSignOnService[] |
||
77 | */ |
||
78 | public function getAllSingleSignOnServicesByUrl($url) |
||
89 | |||
90 | /** |
||
91 | * @param string $binding |
||
92 | * |
||
93 | * @return SingleSignOnService[] |
||
94 | */ |
||
95 | 1 | public function getAllSingleSignOnServicesByBinding($binding) |
|
106 | |||
107 | /** |
||
108 | * @param string|null $binding |
||
109 | * |
||
110 | * @return SingleSignOnService|null |
||
111 | */ |
||
112 | 1 | View Code Duplication | public function getFirstSingleSignOnService($binding = null) |
122 | |||
123 | /** |
||
124 | * @param \LightSaml\Model\Assertion\Attribute $attribute |
||
125 | * |
||
126 | * @return IdpSsoDescriptor |
||
127 | */ |
||
128 | 23 | public function addAttribute(Attribute $attribute) |
|
137 | |||
138 | /** |
||
139 | * @return \LightSaml\Model\Assertion\Attribute[]|null |
||
140 | */ |
||
141 | 3 | public function getAllAttributes() |
|
145 | |||
146 | /** |
||
147 | * @param \DOMNode $parent |
||
148 | * @param SerializationContext $context |
||
149 | */ |
||
150 | 2 | public function serialize(\DOMNode $parent, SerializationContext $context) |
|
169 | |||
170 | /** |
||
171 | * @param \DOMNode $node |
||
172 | * @param DeserializationContext $context |
||
173 | */ |
||
174 | 40 | View Code Duplication | public function deserialize(\DOMNode $node, DeserializationContext $context) |
202 | } |
||
203 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.