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 |
||
19 | class Database extends Medoo |
||
20 | { |
||
21 | /** |
||
22 | * @var array|null |
||
23 | */ |
||
24 | protected $config = []; |
||
25 | |||
26 | /** |
||
27 | * @var PDO |
||
28 | */ |
||
29 | public $pdo; |
||
30 | |||
31 | /** |
||
32 | * Database constructor. |
||
33 | * |
||
34 | * @param array $options |
||
35 | */ |
||
36 | 37 | public function __construct(array $options = null) |
|
45 | |||
46 | /** |
||
47 | * reconnect database. |
||
48 | */ |
||
49 | public function reconnect() |
||
53 | |||
54 | /** |
||
55 | * @param $query |
||
56 | * |
||
57 | * @return bool|\PDOStatement |
||
58 | */ |
||
59 | 2 | View Code Duplication | public function query($query) |
72 | |||
73 | /** |
||
74 | * @param $query |
||
75 | * |
||
76 | * @return bool|int |
||
77 | */ |
||
78 | View Code Duplication | public function exec($query) |
|
91 | } |
||
92 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.