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 |
||
| 17 | class Database extends Medoo |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var array|null |
||
| 21 | */ |
||
| 22 | protected $config = []; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Database constructor. |
||
| 26 | * |
||
| 27 | * @param null $options |
||
| 28 | */ |
||
| 29 | public function __construct($options = null) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * reconnect database. |
||
| 38 | */ |
||
| 39 | public function reconnect() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * check database gone away. |
||
| 46 | */ |
||
| 47 | public function checkGoneAway() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param $query |
||
| 57 | * |
||
| 58 | * @return bool|\PDOStatement |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function query($query) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * @param $query |
||
| 73 | * |
||
| 74 | * @return bool|int |
||
| 75 | */ |
||
| 76 | View Code Duplication | public function exec($query) |
|
| 86 | } |
||
| 87 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.