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 |
||
15 | class Nonces_Runner implements Runner_Interface { |
||
16 | |||
17 | /** |
||
18 | * Generate random nonces. |
||
19 | * |
||
20 | * @param int $number Number of nonces to generate. |
||
21 | * |
||
22 | * @return bool |
||
23 | */ |
||
24 | View Code Duplication | public function run( $number ) { |
|
31 | |||
32 | /** |
||
33 | * Add a batch of mock options. |
||
34 | * |
||
35 | * @param int $limit How many options to add. |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | private function run_batch( $limit ) { |
||
59 | |||
60 | /** |
||
61 | * Generate a random nonce |
||
62 | * |
||
63 | * @return array [ $option_key, $option_value ] |
||
64 | */ |
||
65 | private function get_random_nonce() { |
||
74 | |||
75 | } |
||
76 |