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 |
||
| 13 | class Cache extends Service implements Interfaces\ICache |
||
| 14 | { |
||
| 15 | protected $parametersList = array('type'); |
||
| 16 | public static $container; |
||
| 17 | |||
| 18 | View Code Duplication | protected function init() |
|
| 37 | |||
| 38 | public function getInstance() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Setter |
||
| 46 | * Put a variable in cache |
||
| 47 | * @param string $variable The key that will be associated with the item. |
||
| 48 | * @param mixed $value The variable to store. |
||
| 49 | * @param int $expiry Expiration time of the item. If it's equal to zero, the item will never expire. |
||
| 50 | * You can also use Unix timestamp or a number of seconds starting from current time, |
||
| 51 | * but in the latter case the number of seconds may not exceed 2592000 (30 days). |
||
| 52 | */ |
||
| 53 | public function set($variable, $value, $expiry = null) |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Get a variable from cache |
||
| 61 | * @param string $variable The key to fetch |
||
| 62 | * @return mixed Data fetched from cache, false if not found |
||
| 63 | */ |
||
| 64 | public function get($variable) |
||
| 69 | } |
||
| 70 |
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.