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 |
||
| 16 | View Code Duplication | class CacheKeys |
|
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | protected static $storeFile = 'repository-cache-keys.json'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | protected static $keys = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param $group |
||
| 30 | * @param $key |
||
| 31 | * |
||
| 32 | * @return void |
||
| 33 | */ |
||
| 34 | public static function putKey($group, $key) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @param $group |
||
| 49 | * |
||
| 50 | * @return array|mixed |
||
| 51 | */ |
||
| 52 | public static function getKeys($group) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @return array|mixed |
||
| 62 | */ |
||
| 63 | public static function loadKeys() |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @return int |
||
| 83 | */ |
||
| 84 | public static function storeKeys() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @return string |
||
| 95 | */ |
||
| 96 | public static function getFileKeys() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param $method |
||
| 105 | * @param $parameters |
||
| 106 | * |
||
| 107 | * @return mixed |
||
| 108 | */ |
||
| 109 | public static function __callStatic($method, $parameters) |
||
| 115 | |||
| 116 | /** |
||
| 117 | * @param $method |
||
| 118 | * @param $parameters |
||
| 119 | * |
||
| 120 | * @return mixed |
||
| 121 | */ |
||
| 122 | public function __call($method, $parameters) |
||
| 128 | } |
||
| 129 |
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.