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 |
||
| 17 | class Memcached extends Suricate\Cache |
||
| 18 | { |
||
| 19 | protected $parametersList = array( |
||
| 20 | 'host', |
||
| 21 | 'port', |
||
| 22 | 'defaultExpiry', |
||
| 23 | ); |
||
| 24 | private $handler; |
||
| 25 | |||
| 26 | public function __construct() |
||
| 32 | |||
| 33 | public function getHost() |
||
| 37 | |||
| 38 | public function setHost($host) |
||
| 44 | |||
| 45 | public function getPort() |
||
| 49 | |||
| 50 | public function setPort($port) |
||
| 56 | |||
| 57 | public function getDefaultExpiry() |
||
| 61 | |||
| 62 | public function setDefaultExpiry($expiry) |
||
| 68 | |||
| 69 | View Code Duplication | private function connect() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Put a value into memcache |
||
| 89 | * @param string $variable Variable name |
||
| 90 | * @param mixed $value Value |
||
| 91 | * @param int $expiry Cache expiry |
||
| 92 | * |
||
| 93 | * @return bool |
||
| 94 | */ |
||
| 95 | public function set(string $variable, $value, $expiry = null) |
||
| 105 | |||
| 106 | public function get(string $variable) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Delete a variable from memcache |
||
| 114 | * |
||
| 115 | * @param string $variable |
||
| 116 | * |
||
| 117 | * @return bool |
||
| 118 | */ |
||
| 119 | public function delete(string $variable) |
||
| 124 | } |
||
| 125 |
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.