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 |
||
| 16 | class Options_Runner implements Runner_Interface { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Generate the random options. |
||
| 20 | * |
||
| 21 | * @param int $number Number of options to generate. |
||
| 22 | * |
||
| 23 | * @return bool |
||
| 24 | */ |
||
| 25 | View Code Duplication | public function run( $number ) { |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Add a batch of mock options. |
||
| 35 | * |
||
| 36 | * @param int $limit How many options to add. |
||
| 37 | * |
||
| 38 | * @return bool |
||
| 39 | */ |
||
| 40 | private function run_batch( $limit ) { |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Generate a random option name. |
||
| 60 | * |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | private function get_random_name() { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Generate a random option value. |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | private function get_random_value() { |
||
| 75 | |||
| 76 | } |
||
| 77 |