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 |
||
| 25 | View Code Duplication | class LegacyCouchbaseStore extends TaggableStore implements Store |
|
| 26 | { |
||
| 27 | /** @var string */ |
||
| 28 | protected $prefix; |
||
| 29 | |||
| 30 | /** @var CouchbaseBucket */ |
||
| 31 | protected $bucket; |
||
| 32 | |||
| 33 | /** @var CouchbaseCluster */ |
||
| 34 | protected $cluster; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param CouchbaseCluster $cluster |
||
| 38 | * @param string $bucket |
||
| 39 | * @param string $password |
||
| 40 | * @param null $prefix |
||
| 41 | */ |
||
| 42 | public function __construct(CouchbaseCluster $cluster, $bucket, $password = '', $prefix = null) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * {@inheritdoc} |
||
| 51 | */ |
||
| 52 | public function get($key) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Store an item in the cache if the key doesn't exist. |
||
| 65 | * |
||
| 66 | * @param string|array $key |
||
| 67 | * @param mixed $value |
||
| 68 | * @param int $minutes |
||
| 69 | * |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | public function add($key, $value, $minutes = 0) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritdoc} |
||
| 86 | */ |
||
| 87 | public function put($key, $value, $minutes) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | public function increment($key, $value = 1) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritdoc} |
||
| 103 | */ |
||
| 104 | public function decrement($key, $value = 1) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * {@inheritdoc} |
||
| 112 | */ |
||
| 113 | public function forever($key, $value) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * {@inheritdoc} |
||
| 120 | */ |
||
| 121 | public function forget($key) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * flush bucket. |
||
| 129 | * |
||
| 130 | * @throws FlushException |
||
| 131 | * @codeCoverageIgnore |
||
| 132 | */ |
||
| 133 | public function flush() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * {@inheritdoc} |
||
| 143 | */ |
||
| 144 | public function getPrefix() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Set the cache key prefix. |
||
| 151 | * |
||
| 152 | * @param string $prefix |
||
| 153 | */ |
||
| 154 | public function setPrefix($prefix) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param $bucket |
||
| 161 | * @param string $password |
||
| 162 | * |
||
| 163 | * @return $this |
||
| 164 | */ |
||
| 165 | public function setBucket($bucket, $password = '') |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @param $keys |
||
| 174 | * |
||
| 175 | * @return array|string |
||
| 176 | */ |
||
| 177 | private function resolveKey($keys) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param $meta |
||
| 193 | * |
||
| 194 | * @return array|null |
||
| 195 | */ |
||
| 196 | protected function getMetaDoc($meta) |
||
| 212 | } |
||
| 213 |