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 |
||
17 | class V2Form extends AttCertIssuer |
||
18 | { |
||
19 | /** |
||
20 | * Issuer name. |
||
21 | * |
||
22 | * @var GeneralNames $_issuerName |
||
23 | */ |
||
24 | protected $_issuerName; |
||
25 | |||
26 | /** |
||
27 | * Issuer PKC's issuer and serial. |
||
28 | * |
||
29 | * @var IssuerSerial $_baseCertificateID |
||
30 | */ |
||
31 | protected $_baseCertificateID; |
||
32 | |||
33 | /** |
||
34 | * Linked object. |
||
35 | * |
||
36 | * @var ObjectDigestInfo $_objectDigestInfo |
||
37 | */ |
||
38 | protected $_objectDigestInfo; |
||
39 | |||
40 | /** |
||
41 | * Constructor |
||
42 | * |
||
43 | * @param GeneralNames|null $names |
||
44 | */ |
||
45 | 9 | public function __construct(GeneralNames $names = null) { |
|
50 | |||
51 | /** |
||
52 | * Initialize from ASN.1. |
||
53 | * |
||
54 | * @param Sequence $seq |
||
55 | * @return self |
||
56 | */ |
||
57 | 6 | View Code Duplication | protected static function _fromASN1(Sequence $seq) { |
81 | |||
82 | /** |
||
83 | * Check whether issuer name is set. |
||
84 | * |
||
85 | * @return bool |
||
86 | */ |
||
87 | 3 | public function hasIssuerName() { |
|
90 | |||
91 | /** |
||
92 | * Get issuer name. |
||
93 | * |
||
94 | * @throws \LogicException |
||
95 | * @return GeneralNames |
||
96 | */ |
||
97 | 3 | public function issuerName() { |
|
103 | |||
104 | /** |
||
105 | * Get DN of the issuer. |
||
106 | * |
||
107 | * This is a convenience method conforming to RFC 5755, which states |
||
108 | * that Issuer must contain only one non-empty distinguished name. |
||
109 | * |
||
110 | * @return Name |
||
111 | */ |
||
112 | 1 | public function name() { |
|
115 | |||
116 | /** |
||
117 | * |
||
118 | * @see \X509\AttributeCertificate\AttCertIssuer::ASN1() |
||
119 | * @return ImplicitlyTaggedType Tagged Sequence |
||
120 | */ |
||
121 | 11 | View Code Duplication | public function toASN1() { |
136 | } |
||
137 |
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.