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 |
||
| 10 | class Intraface_Auth_User |
||
| 11 | { |
||
| 12 | private $db; |
||
| 13 | private $email; |
||
| 14 | private $password; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Constructor |
||
| 18 | * |
||
| 19 | * @param object $db Databaseobject |
||
| 20 | * @param string $email Username |
||
| 21 | * @param string $password Password |
||
| 22 | * |
||
| 23 | * @return void |
||
|
|
|||
| 24 | */ |
||
| 25 | 3 | function __construct(MDB2_Driver_Common $db, $session_id, $email = null, $password = null) |
|
| 32 | |||
| 33 | /** |
||
| 34 | * Auth |
||
| 35 | * |
||
| 36 | * @return object |
||
| 37 | */ |
||
| 38 | 1 | public function auth() |
|
| 65 | |||
| 66 | 1 | function isLoggedIn() |
|
| 80 | |||
| 81 | /** |
||
| 82 | * logout() |
||
| 83 | * |
||
| 84 | * @return boolean |
||
| 85 | */ |
||
| 86 | 2 | View Code Duplication | public function logout() |
| 95 | |||
| 96 | /** |
||
| 97 | * Returns an identification string on the user |
||
| 98 | * |
||
| 99 | * @return string identification (email) |
||
| 100 | */ |
||
| 101 | public function getIdentification() |
||
| 105 | } |
||
| 106 |
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.