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 |
||
| 8 | trait SortedSetBehavior |
||
| 9 | { |
||
| 10 | private $driver; |
||
| 11 | |||
| 12 | abstract protected function init(); |
||
| 13 | 20 | ||
| 14 | abstract public function actualDriver(); |
||
| 15 | 20 | ||
| 16 | 20 | /** |
|
| 17 | 12 | * Add one or more members to a sorted set, or update its score if it already exists |
|
| 18 | 12 | * @param string $key |
|
| 19 | 12 | * @param array $dictionary (score1, member1[, score2, member2]) or associative array: [member1 => score1, member2 => score2] |
|
| 20 | 12 | * @return int |
|
| 21 | */ |
||
| 22 | 12 | public function zadd($key, ...$dictionary) |
|
| 35 | 4 | ||
| 36 | /** |
||
| 37 | 4 | * Return a range of members in a sorted set, by index |
|
| 38 | 4 | * @param string $key |
|
| 39 | 2 | * @param int $start |
|
| 40 | * @param int $stop |
||
| 41 | 2 | * @param boolean $withscores |
|
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | View Code Duplication | public function zrange($key, $start, $stop, $withscores = false) |
|
| 52 | 4 | ||
| 53 | /** |
||
| 54 | 4 | * Return a range of members in a sorted set, by index, with scores ordered from high to low |
|
| 55 | 4 | * @param string $key |
|
| 56 | 2 | * @param int $start |
|
| 57 | * @param int $stop |
||
| 58 | 2 | * @param boolean $withscores |
|
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | View Code Duplication | public function zrevrange($key, $start, $stop, $withscores = false) |
|
| 69 | } |
||
| 70 |