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 AdapterApcu 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 apcu-cache exists. |
||
52 | * |
||
53 | * WARNING: we only keep this method for compatibly-reasons |
||
54 | * -> use ->exists($key) |
||
55 | * |
||
56 | * @param string $key |
||
57 | * |
||
58 | * @return bool |
||
59 | * |
||
60 | * @deprecated |
||
61 | */ |
||
62 | public function apcu_cache_exists($key): bool |
||
66 | |||
67 | /** |
||
68 | * Clears the APCu cache by type. |
||
69 | * |
||
70 | * @param string $type <p>WARNING: is not used in APCu only valid for APC</p> |
||
71 | * |
||
72 | * @return bool |
||
73 | * |
||
74 | * @internal |
||
75 | */ |
||
76 | public function cacheClear(string $type): bool |
||
80 | |||
81 | /** |
||
82 | * Retrieves cached information from APCu's data store |
||
83 | * |
||
84 | * @param bool $limited - If $limited is TRUE, the return value will exclude the individual list of cache |
||
85 | * entries. This is useful when trying to optimize calls for statistics gathering |
||
86 | * |
||
87 | * @return array|bool <p>Array of cached data (and meta-data) or FALSE on failure.</p> |
||
88 | */ |
||
89 | public function cacheInfo(bool $limited = false): array |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function exists(string $key): bool |
||
101 | |||
102 | /** |
||
103 | * {@inheritdoc} |
||
104 | */ |
||
105 | public function get(string $key) |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function installed(): bool |
||
121 | |||
122 | /** |
||
123 | * {@inheritdoc} |
||
124 | */ |
||
125 | public function remove(string $key): bool |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function removeAll(): bool |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function set(string $key, $value): bool |
||
145 | |||
146 | /** |
||
147 | * {@inheritdoc} |
||
148 | */ |
||
149 | public function setExpired(string $key, $data, int $ttl = 0): bool |
||
153 | } |
||
154 |
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.