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 |
||
13 | final class PgSqlConnection implements Connection |
||
14 | { |
||
15 | use LoadEnvVariablesTrait, DatabaseTransactionsTrait; |
||
16 | |||
17 | /** |
||
18 | * The method called in the constructor. |
||
19 | * |
||
20 | * @return void |
||
|
|||
21 | */ |
||
22 | private function __construct() |
||
33 | |||
34 | /** |
||
35 | * Returns the columns of a table. |
||
36 | * |
||
37 | * @param string $table The table inspected for its columns. |
||
38 | * |
||
39 | * @return array The columns of the table. |
||
40 | */ |
||
41 | View Code Duplication | public function getColumns($table) |
|
51 | |||
52 | /** |
||
53 | * Returns the Connection's PDO. |
||
54 | * |
||
55 | * @return PDO PHP Data Objects |
||
56 | */ |
||
57 | public function getPdo() |
||
61 | |||
62 | /** |
||
63 | * Returns the primary key of a table. |
||
64 | * |
||
65 | * @param string $table The table inspected for its primary key. |
||
66 | * |
||
67 | * @return string The primary key of the table. |
||
68 | */ |
||
69 | public function getPrimaryKey($table) |
||
89 | |||
90 | public static function load() |
||
94 | } |
||
95 |
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.