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 MySqlConnection implements Connection |
||
| 13 | { |
||
| 14 | use LoadEnvVariablesTrait, DatabaseTransactionsTrait; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * The method called in the constructor. |
||
| 18 | * |
||
| 19 | * @return void |
||
|
|
|||
| 20 | */ |
||
| 21 | private function __construct() |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Returns the columns of a table. |
||
| 37 | * |
||
| 38 | * @param string $table The table inspected for its columns. |
||
| 39 | * |
||
| 40 | * @return array The columns of the table. |
||
| 41 | */ |
||
| 42 | View Code Duplication | public function getColumns($table) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Returns the Connection's PDO. |
||
| 56 | * |
||
| 57 | * @return PDO PHP Data Objects |
||
| 58 | */ |
||
| 59 | public function getPdo() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Returns the primary key of a table. |
||
| 66 | * |
||
| 67 | * @param string $table The table inspected for its primary key. |
||
| 68 | * |
||
| 69 | * @return string The primary key of the table. |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function getPrimaryKey($table) |
|
| 79 | |||
| 80 | public static function load() |
||
| 84 | } |
||
| 85 |
Adding a
@returnannotation 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.