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 |
||
| 11 | class Gateway |
||
| 12 | { |
||
| 13 | const KEY = 'statistics'; |
||
| 14 | |||
| 15 | use RedisTrait; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param int[] $values |
||
| 19 | */ |
||
| 20 | 1 | View Code Duplication | public function increase(array $values) |
| 28 | |||
| 29 | /** |
||
| 30 | * @param string $key |
||
| 31 | * @param int $value |
||
| 32 | */ |
||
| 33 | 2 | View Code Duplication | public function set($key, $value) |
| 44 | |||
| 45 | /** |
||
| 46 | * @return int[] |
||
| 47 | */ |
||
| 48 | 1 | public function getAll() : array |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @param string $key |
||
| 55 | * @return int |
||
| 56 | */ |
||
| 57 | 1 | public function get($key) |
|
| 61 | } |
||
| 62 |