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 |
||
24 | final class RaSecondFactorExportQuery implements HttpQuery |
||
25 | { |
||
26 | const STATUS_UNVERIFIED = 'unverified'; |
||
27 | const STATUS_VERIFIED = 'verified'; |
||
28 | const STATUS_VETTED = 'vetted'; |
||
29 | const STATUS_REVOKED = 'revoked'; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $institution; |
||
35 | |||
36 | /** |
||
37 | * @var string|null |
||
38 | */ |
||
39 | private $name; |
||
40 | |||
41 | /** |
||
42 | * @var string|null |
||
43 | */ |
||
44 | private $type; |
||
45 | |||
46 | /** |
||
47 | * @var string|null The second factor type's ID (eg. Yubikey public ID) |
||
48 | */ |
||
49 | private $secondFactorId; |
||
50 | |||
51 | /** |
||
52 | * @var string|null |
||
53 | */ |
||
54 | private $email; |
||
55 | |||
56 | /** |
||
57 | * @var string|null One of the STATUS_* constants. |
||
58 | */ |
||
59 | private $status; |
||
60 | |||
61 | /** |
||
62 | * @var string|null |
||
63 | */ |
||
64 | private $orderBy; |
||
65 | |||
66 | /** |
||
67 | * @var string|null |
||
68 | */ |
||
69 | private $orderDirection; |
||
70 | |||
71 | /** |
||
72 | * @param string $institution |
||
73 | */ |
||
74 | public function __construct($institution) |
||
79 | |||
80 | /** |
||
81 | * @return null|string |
||
82 | */ |
||
83 | public function getName() |
||
87 | |||
88 | /** |
||
89 | * @param null|string $name |
||
90 | */ |
||
91 | public function setName($name) |
||
97 | |||
98 | /** |
||
99 | * @return null|string |
||
100 | */ |
||
101 | public function getType() |
||
105 | |||
106 | /** |
||
107 | * @param null|string $type |
||
108 | */ |
||
109 | public function setType($type) |
||
115 | |||
116 | /** |
||
117 | * @return null|string |
||
118 | */ |
||
119 | public function getSecondFactorId() |
||
123 | |||
124 | /** |
||
125 | * @param null|string $secondFactorId |
||
126 | */ |
||
127 | public function setSecondFactorId($secondFactorId) |
||
133 | |||
134 | /** |
||
135 | * @return null|string |
||
136 | */ |
||
137 | public function getEmail() |
||
141 | |||
142 | /** |
||
143 | * @param null|string $email |
||
144 | */ |
||
145 | public function setEmail($email) |
||
151 | |||
152 | /** |
||
153 | * @return null|string |
||
154 | */ |
||
155 | public function getStatus() |
||
159 | |||
160 | /** |
||
161 | * @param string $status |
||
162 | */ |
||
163 | View Code Duplication | public function setStatus($status) |
|
172 | |||
173 | /** |
||
174 | * @param string $orderBy |
||
175 | */ |
||
176 | public function setOrderBy($orderBy) |
||
182 | |||
183 | /** |
||
184 | * @param string|null $orderDirection |
||
185 | */ |
||
186 | View Code Duplication | public function setOrderDirection($orderDirection) |
|
195 | |||
196 | View Code Duplication | private function assertNonEmptyString($value, $name) |
|
206 | |||
207 | /** |
||
208 | * Return the Http Query string as should be used, MUST include the '?' prefix. |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | View Code Duplication | public function toHttpQuery() |
|
232 | } |
||
233 |
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.