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 |
||
| 9 | trait ApiCoreTrait |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @param Request $request |
||
| 13 | * @return mixed |
||
| 14 | */ |
||
| 15 | abstract function dispatch(Request $request); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @override |
||
| 19 | * @inheritDoc |
||
| 20 | */ |
||
| 21 | public function bgRewriteAoF() |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @override |
||
| 30 | * @inheritDoc |
||
| 31 | */ |
||
| 32 | public function bgSave() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @override |
||
| 41 | * @inheritDoc |
||
| 42 | */ |
||
| 43 | public function sync() |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @override |
||
| 53 | * @inheritDoc |
||
| 54 | */ |
||
| 55 | public function time() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @override |
||
| 65 | * @inheritDoc |
||
| 66 | */ |
||
| 67 | public function monitor() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @override |
||
| 77 | * @inheritDoc |
||
| 78 | */ |
||
| 79 | public function flushAll() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @override |
||
| 88 | * @inheritDoc |
||
| 89 | */ |
||
| 90 | 1 | public function flushDb() |
|
| 97 | |||
| 98 | /** |
||
| 99 | * @override |
||
| 100 | * @inheritDoc |
||
| 101 | */ |
||
| 102 | public function info($section = []) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @override |
||
| 133 | * @inheritDoc |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function slaveOf($host, $port) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * @override |
||
| 146 | * @inheritDoc |
||
| 147 | */ |
||
| 148 | public function save() |
||
| 155 | } |
||
| 156 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.