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 |
||
26 | class Request extends JsCall |
||
27 | { |
||
28 | use \Jaxon\Utils\Traits\Config; |
||
29 | use \Jaxon\Utils\Traits\Manager; |
||
30 | |||
31 | /** |
||
32 | * The type of the request |
||
33 | * |
||
34 | * Can be one of "function" or "class". |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $sType; |
||
39 | |||
40 | /** |
||
41 | * A condition to check before sending this request |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $sCondition = null; |
||
46 | |||
47 | /** |
||
48 | * The arguments of the confirm() call |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $aMessageArgs = null; |
||
53 | |||
54 | /** |
||
55 | * The constructor. |
||
56 | * |
||
57 | * @param string $sName The javascript function or method name |
||
58 | * @param string $sType The type (function or a method) |
||
59 | */ |
||
60 | public function __construct($sName, $sType) |
||
65 | |||
66 | /** |
||
67 | * Check if the request has a parameter of type Jaxon::PAGE_NUMBER |
||
68 | * |
||
69 | * @return boolean |
||
70 | */ |
||
71 | public function hasPageNumber() |
||
82 | |||
83 | /** |
||
84 | * Set a value to the Jaxon::PAGE_NUMBER parameter |
||
85 | * |
||
86 | * @param integer $nPageNumber The current page number |
||
87 | * |
||
88 | * @return Request |
||
89 | */ |
||
90 | public function setPageNumber($nPageNumber) |
||
103 | |||
104 | /** |
||
105 | * Add a confirmation question to the request |
||
106 | * |
||
107 | * @param string $sQuestion The question to ask |
||
108 | * |
||
109 | * @return Request |
||
110 | */ |
||
111 | View Code Duplication | public function confirm($sQuestion) |
|
120 | |||
121 | /** |
||
122 | * Add a condition to the request |
||
123 | * |
||
124 | * The request is sent only if the condition is true. |
||
125 | * |
||
126 | * @param string $sCondition The condition to check |
||
127 | * |
||
128 | * @return Request |
||
129 | */ |
||
130 | public function when($sCondition) |
||
135 | |||
136 | /** |
||
137 | * Add a condition to the request |
||
138 | * |
||
139 | * The request is sent only if the condition is false. |
||
140 | * |
||
141 | * @param string $sCondition The condition to check |
||
142 | * |
||
143 | * @return Request |
||
144 | */ |
||
145 | public function unless($sCondition) |
||
150 | |||
151 | /** |
||
152 | * Check if a value is equal to another before sending the request |
||
153 | * |
||
154 | * @param string $sValue1 The first value to compare |
||
155 | * @param string $sValue2 The second value to compare |
||
156 | * |
||
157 | * @return Request |
||
158 | */ |
||
159 | public function ifeq($sValue1, $sValue2) |
||
164 | |||
165 | /** |
||
166 | * Check if a value is not equal to another before sending the request |
||
167 | * |
||
168 | * @param string $sValue1 The first value to compare |
||
169 | * @param string $sValue2 The second value to compare |
||
170 | * |
||
171 | * @return Request |
||
172 | */ |
||
173 | public function ifne($sValue1, $sValue2) |
||
178 | |||
179 | /** |
||
180 | * Check if a value is greater than another before sending the request |
||
181 | * |
||
182 | * @param string $sValue1 The first value to compare |
||
183 | * @param string $sValue2 The second value to compare |
||
184 | * |
||
185 | * @return Request |
||
186 | */ |
||
187 | public function ifgt($sValue1, $sValue2) |
||
192 | |||
193 | /** |
||
194 | * Check if a value is greater or equal to another before sending the request |
||
195 | * |
||
196 | * @param string $sValue1 The first value to compare |
||
197 | * @param string $sValue2 The second value to compare |
||
198 | * |
||
199 | * @return Request |
||
200 | */ |
||
201 | public function ifge($sValue1, $sValue2) |
||
206 | |||
207 | /** |
||
208 | * Check if a value is lower than another before sending the request |
||
209 | * |
||
210 | * @param string $sValue1 The first value to compare |
||
211 | * @param string $sValue2 The second value to compare |
||
212 | * |
||
213 | * @return Request |
||
214 | */ |
||
215 | public function iflt($sValue1, $sValue2) |
||
220 | |||
221 | /** |
||
222 | * Check if a value is lower or equal to another before sending the request |
||
223 | * |
||
224 | * @param string $sValue1 The first value to compare |
||
225 | * @param string $sValue2 The second value to compare |
||
226 | * |
||
227 | * @return Request |
||
228 | */ |
||
229 | public function ifle($sValue1, $sValue2) |
||
234 | |||
235 | /** |
||
236 | * Set the message to show if the condition to send the request is not met |
||
237 | * |
||
238 | * The first parameter is the message to show. The followin allow to insert data from |
||
239 | * the webpage in the message using positional placeholders. |
||
240 | * |
||
241 | * @param string $sMessage The message to show if the request is not sent |
||
242 | * |
||
243 | * @return Request |
||
244 | */ |
||
245 | View Code Duplication | public function else($sMessage) |
|
253 | |||
254 | /** |
||
255 | * Returns a string representation of the script output (javascript) from this request object |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | public function getScript() |
||
348 | |||
349 | /** |
||
350 | * Prints a string representation of the script output (javascript) from this request object |
||
351 | * |
||
352 | * @return void |
||
353 | */ |
||
354 | public function printScript() |
||
358 | } |
||
359 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.