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 |
||
12 | final class SqliteConnection implements Connection |
||
13 | { |
||
14 | use DatabaseTransactionsTrait; |
||
15 | |||
16 | /** |
||
17 | * $_pdo The PDO instance of the connection. |
||
18 | * |
||
19 | * @var PDO |
||
20 | */ |
||
21 | private $_pdo; |
||
22 | |||
23 | /** |
||
24 | * The method called in the constructor. |
||
25 | * |
||
26 | * @return void |
||
|
|||
27 | */ |
||
28 | private function __construct() |
||
37 | |||
38 | /** |
||
39 | * Returns the columns of a table. |
||
40 | * |
||
41 | * @param string $table The table inspected for its columns. |
||
42 | * |
||
43 | * @return array The columns of the table. |
||
44 | */ |
||
45 | View Code Duplication | public function getColumns($table) |
|
55 | |||
56 | /** |
||
57 | * Returns the Connection's PDO. |
||
58 | * |
||
59 | * @return PDO PHP Data Objects |
||
60 | */ |
||
61 | public function getPdo() |
||
65 | |||
66 | /** |
||
67 | * Returns the primary key of a table. |
||
68 | * |
||
69 | * @param string $table The table inspected for its primary key. |
||
70 | * |
||
71 | * @return string The primary key of the table. |
||
72 | */ |
||
73 | public function getPrimaryKey($table) |
||
81 | |||
82 | public static function load() |
||
86 | } |
||
87 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.