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 |
||
23 | class RoleAttributeValue extends AttributeValue |
||
24 | { |
||
25 | /** |
||
26 | * Issuing authority. |
||
27 | * |
||
28 | * @var GeneralNames $_roleAuthority |
||
29 | */ |
||
30 | protected $_roleAuthority; |
||
31 | |||
32 | /** |
||
33 | * Role name. |
||
34 | * |
||
35 | * @var GeneralName $_roleName |
||
36 | */ |
||
37 | protected $_roleName; |
||
38 | |||
39 | /** |
||
40 | * Constructor. |
||
41 | * |
||
42 | * @param GeneralName $name Role name |
||
43 | * @param GeneralNames|null $authority Issuing authority |
||
44 | */ |
||
45 | 15 | public function __construct(GeneralName $name, |
|
51 | |||
52 | /** |
||
53 | * Initialize from a role string. |
||
54 | * |
||
55 | * @param string $role_name Role name in URI format |
||
56 | * @param GeneralNames|null $authority Issuing authority |
||
57 | * @return self |
||
58 | */ |
||
59 | 2 | public static function fromString($role_name, GeneralNames $authority = null) { |
|
62 | |||
63 | /** |
||
64 | * |
||
65 | * @param UnspecifiedType $el |
||
66 | * @return self |
||
67 | */ |
||
68 | 8 | View Code Duplication | public static function fromASN1(UnspecifiedType $el) { |
83 | |||
84 | /** |
||
85 | * Check whether issuing authority is present. |
||
86 | * |
||
87 | * @return bool |
||
88 | */ |
||
89 | 2 | public function hasRoleAuthority() { |
|
92 | |||
93 | /** |
||
94 | * Get issuing authority. |
||
95 | * |
||
96 | * @throws \LogicException |
||
97 | * @return GeneralNames |
||
98 | */ |
||
99 | 2 | public function roleAuthority() { |
|
105 | |||
106 | /** |
||
107 | * Get role name. |
||
108 | * |
||
109 | * @return GeneralName |
||
110 | */ |
||
111 | 2 | public function roleName() { |
|
114 | |||
115 | /** |
||
116 | * |
||
117 | * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
||
118 | * @return Sequence |
||
119 | */ |
||
120 | 17 | View Code Duplication | public function toASN1() { |
129 | |||
130 | /** |
||
131 | * |
||
132 | * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
||
133 | * @return string |
||
134 | */ |
||
135 | 3 | public function stringValue() { |
|
138 | |||
139 | /** |
||
140 | * |
||
141 | * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
||
142 | * @return BinaryMatch |
||
143 | */ |
||
144 | 1 | public function equalityMatchingRule() { |
|
147 | |||
148 | /** |
||
149 | * |
||
150 | * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
||
151 | * @return string |
||
152 | */ |
||
153 | 1 | public function rfc2253String() { |
|
156 | |||
157 | /** |
||
158 | * |
||
159 | * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
||
160 | * @return string |
||
161 | */ |
||
162 | 1 | protected function _transcodedString() { |
|
165 | } |
||
166 |
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.