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 | abstract class AbstractMap implements MapInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Adds all the mappings from specified map to this map |
||
| 20 | * |
||
| 21 | * @param MapInterface $map |
||
| 22 | * @return void |
||
| 23 | */ |
||
| 24 | 1 | public function putAll(MapInterface $map) |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Adds all the mappings from specified array to this map |
||
| 34 | * |
||
| 35 | * @param array $map |
||
| 36 | * @return void |
||
| 37 | */ |
||
| 38 | 1 | public function putAllArray(array $map) |
|
| 45 | |||
| 46 | /** |
||
| 47 | * Find the first [@see MapEntry] in map |
||
| 48 | * |
||
| 49 | * The closure will get passed a MapEntry. Returning true will end the |
||
| 50 | * loop and return that MapEntry |
||
| 51 | * |
||
| 52 | * @param callable $find |
||
| 53 | * @return MapEntry|null |
||
| 54 | */ |
||
| 55 | 2 | View Code Duplication | public function find(callable $find) |
| 66 | |||
| 67 | /** |
||
| 68 | * Use a closure to determine existence in the map |
||
| 69 | * |
||
| 70 | * The closure will get passed a [@see MapEntry]. Returning true from the |
||
| 71 | * closure will return true from this method. |
||
| 72 | * |
||
| 73 | * @param callable $exists |
||
| 74 | * @return bool |
||
| 75 | */ |
||
| 76 | 1 | View Code Duplication | public function exists(callable $exists): bool |
| 87 | } |
||
| 88 |