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 |
||
18 | class DistributionPoint |
||
19 | { |
||
20 | /** |
||
21 | * Distribution point name. |
||
22 | * |
||
23 | * @var DistributionPointName $_distributionPoint |
||
24 | */ |
||
25 | protected $_distributionPoint; |
||
26 | |||
27 | /** |
||
28 | * Revocation reason. |
||
29 | * |
||
30 | * @var ReasonFlags $_reasons |
||
31 | */ |
||
32 | protected $_reasons; |
||
33 | |||
34 | /** |
||
35 | * CRL issuer. |
||
36 | * |
||
37 | * @var GeneralNames $_issuer |
||
38 | */ |
||
39 | protected $_issuer; |
||
40 | |||
41 | /** |
||
42 | * Constructor |
||
43 | * |
||
44 | * @param DistributionPointName $name |
||
45 | * @param ReasonFlags $reasons |
||
46 | * @param GeneralNames $issuer |
||
47 | */ |
||
48 | 13 | public function __construct(DistributionPointName $name = null, |
|
54 | |||
55 | /** |
||
56 | * Initialize from ASN.1. |
||
57 | * |
||
58 | * @param Sequence $seq |
||
59 | * @return self |
||
60 | */ |
||
61 | 8 | public static function fromASN1(Sequence $seq) { |
|
86 | |||
87 | /** |
||
88 | * Check whether distribution point name is set. |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | 9 | public function hasDistributionPointName() { |
|
95 | |||
96 | /** |
||
97 | * Get distribution point name. |
||
98 | * |
||
99 | * @throws \LogicException |
||
100 | * @return DistributionPointName |
||
101 | */ |
||
102 | 9 | public function distributionPointName() { |
|
108 | |||
109 | /** |
||
110 | * Check whether distribution point name is set and it's a full name. |
||
111 | * |
||
112 | * @return bool |
||
113 | */ |
||
114 | 3 | public function hasFullName() { |
|
118 | |||
119 | /** |
||
120 | * Get full distribution point name. |
||
121 | * |
||
122 | * @throws \LogicException |
||
123 | * @return FullName |
||
124 | */ |
||
125 | 3 | public function fullName() { |
|
131 | |||
132 | /** |
||
133 | * Check whether distribution point name is set and it's a relative name. |
||
134 | * |
||
135 | * @return bool |
||
136 | */ |
||
137 | 2 | public function hasRelativeName() { |
|
141 | |||
142 | /** |
||
143 | * Get relative distribution point name. |
||
144 | * |
||
145 | * @throws \LogicException |
||
146 | * @return RelativeName |
||
147 | */ |
||
148 | 2 | public function relativeName() { |
|
154 | |||
155 | /** |
||
156 | * Check whether reasons flags is set. |
||
157 | * |
||
158 | * @return bool |
||
159 | */ |
||
160 | 5 | public function hasReasons() { |
|
163 | |||
164 | /** |
||
165 | * Get revocation reason flags. |
||
166 | * |
||
167 | * @throws \LogicException |
||
168 | * @return ReasonFlags |
||
169 | */ |
||
170 | 5 | public function reasons() { |
|
176 | |||
177 | /** |
||
178 | * Check whether cRLIssuer is set. |
||
179 | * |
||
180 | * @return bool |
||
181 | */ |
||
182 | 5 | public function hasCRLIssuer() { |
|
185 | |||
186 | /** |
||
187 | * Get CRL issuer. |
||
188 | * |
||
189 | * @throws \LogicException |
||
190 | * @return GeneralNames |
||
191 | */ |
||
192 | 5 | public function crlIssuer() { |
|
198 | |||
199 | /** |
||
200 | * Generate ASN.1 structure. |
||
201 | * |
||
202 | * @return Sequence |
||
203 | */ |
||
204 | 5 | View Code Duplication | public function toASN1() { |
218 | } |
||
219 |
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.