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 declare(strict_types=1); |
||
25 | class Driver extends AbstractDriver implements DriverInterface { |
||
26 | |||
27 | /** |
||
28 | * Reference to the last executed sql query |
||
29 | * |
||
30 | * @var PDOStatement |
||
31 | */ |
||
32 | protected $statement; |
||
33 | |||
34 | /** |
||
35 | * SQLite has a truncate optimization, |
||
36 | * but no support for the actual keyword |
||
37 | * @var boolean |
||
38 | */ |
||
39 | protected $hasTruncate = FALSE; |
||
40 | |||
41 | /** |
||
42 | * Open SQLite Database |
||
43 | * |
||
44 | * @param string $dsn |
||
45 | * @param string $user |
||
46 | * @param string $pass |
||
47 | * @param array $driverOptions |
||
48 | */ |
||
49 | public function __construct($dsn, $user=NULL, $pass=NULL, array $driverOptions=[]) |
||
58 | |||
59 | /** |
||
60 | * List tables for the current database |
||
61 | * |
||
62 | * @return mixed |
||
63 | */ |
||
64 | public function getTables() |
||
70 | |||
71 | /** |
||
72 | * Retrieve foreign keys for the table |
||
73 | * |
||
74 | * @param string $table |
||
75 | * @return array |
||
76 | */ |
||
77 | public function getFks($table) |
||
94 | |||
95 | /** |
||
96 | * Create sql for batch insert |
||
97 | * |
||
98 | * @codeCoverageIgnore |
||
99 | * @param string $table |
||
100 | * @param array $data |
||
101 | * @return string |
||
102 | */ |
||
103 | public function insertBatch($table, $data=[]) |
||
143 | } |
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.