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 ApiConnTrait |
||
| 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 auth($password) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @override |
||
| 31 | * @inheritDoc |
||
| 32 | */ |
||
| 33 | View Code Duplication | public function ping($message = 'PING') |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @override |
||
| 43 | * @inheritDoc |
||
| 44 | */ |
||
| 45 | public function quit() |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @override |
||
| 54 | * @inheritDoc |
||
| 55 | */ |
||
| 56 | public function select($index) |
||
| 63 | } |
||
| 64 |
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.