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 |
||
12 | class AdapterApc implements iAdapter |
||
13 | { |
||
14 | /** |
||
15 | * @var bool |
||
16 | */ |
||
17 | public $installed = false; |
||
18 | |||
19 | /** |
||
20 | * @var bool |
||
21 | */ |
||
22 | public $debug = false; |
||
23 | |||
24 | /** |
||
25 | * __construct() |
||
26 | */ |
||
27 | View Code Duplication | public function __construct() |
|
49 | |||
50 | /** |
||
51 | * Check if apc-cache exists. |
||
52 | * |
||
53 | * WARNING: use $this->exists($key) instead |
||
54 | * |
||
55 | * @param string $key |
||
56 | * |
||
57 | * @return bool |
||
58 | * |
||
59 | * @internal |
||
60 | */ |
||
61 | public function apc_cache_exists($key): bool |
||
65 | |||
66 | /** |
||
67 | * Clears the APC cache by type. |
||
68 | * |
||
69 | * @param string $type - If $type is "user", the user cache will be cleared; otherwise, |
||
70 | * the system cache (cached files) will be cleared |
||
71 | * |
||
72 | * @return bool |
||
73 | * |
||
74 | * @internal |
||
75 | */ |
||
76 | public function cacheClear(string $type): bool |
||
80 | |||
81 | /** |
||
82 | * Retrieves cached information from APC's data store |
||
83 | * |
||
84 | * @param string $type - If $type is "user", information about the user cache will be returned |
||
85 | * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache |
||
86 | * entries. This is useful when trying to optimize calls for statistics gathering |
||
87 | * |
||
88 | * @return array|bool <p>Array of cached data (and meta-data) or FALSE on failure.</p> |
||
89 | */ |
||
90 | public function cacheInfo(string $type = '', bool $limited = false): array |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function exists(string $key): bool |
||
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function get(string $key) |
||
118 | |||
119 | /** |
||
120 | * {@inheritdoc} |
||
121 | */ |
||
122 | public function installed(): bool |
||
126 | |||
127 | /** |
||
128 | * {@inheritdoc} |
||
129 | */ |
||
130 | public function remove(string $key): bool |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function removeAll(): bool |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function set(string $key, $value): bool |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | */ |
||
154 | public function setExpired(string $key, $data, int $ttl = 0): bool |
||
158 | } |
||
159 |
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.