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 /** MicroWincacheDriver */ |
||
19 | class WincacheDriver extends CacheDriver |
||
20 | { |
||
21 | /** |
||
22 | * Constructor |
||
23 | * |
||
24 | * @access public |
||
25 | * |
||
26 | * @param array $config array config |
||
27 | * |
||
28 | * @result void |
||
29 | * @throws Exception |
||
30 | */ |
||
31 | public function __construct(array $config = []) |
||
39 | |||
40 | /** |
||
41 | * @inheritdoc |
||
42 | */ |
||
43 | public function check() |
||
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | public function get($name) |
||
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | public function set($name, $value, $duration = 0) |
||
66 | |||
67 | /** |
||
68 | * @inheritdoc |
||
69 | */ |
||
70 | public function delete($name) |
||
74 | |||
75 | /** |
||
76 | * Clean all data from cache |
||
77 | * |
||
78 | * @access public |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function clean() |
||
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | public function info() |
||
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | public function getMeta($id) |
||
109 | |||
110 | /** |
||
111 | * @inheritdoc |
||
112 | */ |
||
113 | View Code Duplication | public function increment($name, $offset = 1) |
|
120 | |||
121 | /** |
||
122 | * @inheritdoc |
||
123 | */ |
||
124 | View Code Duplication | public function decrement($name, $offset = 1) |
|
131 | } |
||
132 |
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.