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 namespace Comodojo\Cache\Drivers; |
||
21 | class Memory extends AbstractDriver { |
||
22 | |||
23 | const DRIVER_NAME = "memory"; |
||
24 | |||
25 | /** |
||
26 | * Cache repository |
||
27 | * |
||
28 | * @param array |
||
29 | */ |
||
30 | private $data = []; |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | public function __construct(array $configuration = []) {} |
||
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 124 | public function test() { |
|
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | 97 | public function get($key, $namespace) { |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 90 | public function set($key, $namespace, $value, $ttl = null) { |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 12 | public function delete($key, $namespace) { |
|
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | 22 | public function clear($namespace = null) { |
|
110 | |||
111 | /** |
||
112 | * {@inheritdoc} |
||
113 | */ |
||
114 | 3 | View Code Duplication | public function getMultiple(array $keys, $namespace) { |
125 | |||
126 | /** |
||
127 | * {@inheritdoc} |
||
128 | */ |
||
129 | 2 | View Code Duplication | public function setMultiple(array $key_values, $namespace, $ttl = null) { |
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | 4 | View Code Duplication | public function deleteMultiple(array $keys, $namespace) { |
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | 46 | public function has($key, $namespace) { |
|
164 | |||
165 | /** |
||
166 | * {@inheritdoc} |
||
167 | */ |
||
168 | 4 | public function stats() { |
|
173 | |||
174 | 90 | private function checkNamespace($namespace, $create = false) { |
|
186 | |||
187 | 106 | private function checkMemory($key, $namespace) { |
|
203 | |||
204 | } |
||
205 |