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 | View Code Duplication | class AdapterApcu implements iAdapter |
|
|
|
|||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var bool |
||
| 17 | */ |
||
| 18 | public $installed = false; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var bool |
||
| 22 | */ |
||
| 23 | public $debug = false; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * __construct() |
||
| 27 | */ |
||
| 28 | public function __construct() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Check if apcu-cache exists. |
||
| 41 | * |
||
| 42 | * WARNING: use $this->exists($key) instead |
||
| 43 | * |
||
| 44 | * @param string $key |
||
| 45 | * |
||
| 46 | * @return bool |
||
| 47 | * |
||
| 48 | * @internal |
||
| 49 | */ |
||
| 50 | public function apcu_cache_exists($key) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Clears the APCu cache by type. |
||
| 57 | * |
||
| 58 | * @param string $type - If $type is "user", the user cache will be cleared; otherwise, |
||
| 59 | * the system cache (cached files) will be cleared. |
||
| 60 | * |
||
| 61 | * @return boolean |
||
| 62 | * |
||
| 63 | * @internal |
||
| 64 | */ |
||
| 65 | public function cacheClear($type) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Retrieves cached information from APCu's data store |
||
| 72 | * |
||
| 73 | * @param boolean $limited - If $limited is TRUE, the return value will exclude the individual list of cache entries. |
||
| 74 | * This is useful when trying to optimize calls for statistics gathering. |
||
| 75 | * |
||
| 76 | * @return array of cached data (and meta-data) or FALSE on failure. |
||
| 77 | */ |
||
| 78 | public function cacheInfo($limited = false) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @inheritdoc |
||
| 85 | */ |
||
| 86 | public function exists($key) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @inheritdoc |
||
| 97 | */ |
||
| 98 | public function get($key) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @inheritdoc |
||
| 109 | */ |
||
| 110 | public function installed() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @inheritdoc |
||
| 117 | */ |
||
| 118 | public function remove($key) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @inheritdoc |
||
| 125 | */ |
||
| 126 | public function removeAll() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @inheritdoc |
||
| 133 | */ |
||
| 134 | public function set($key, $value) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @inheritdoc |
||
| 141 | */ |
||
| 142 | public function setExpired($key, $data, $ttl) |
||
| 146 | |||
| 147 | } |
||
| 148 |
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.