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 |
||
| 31 | class Login |
||
| 32 | { |
||
| 33 | /* |
||
| 34 | |-------------------------------------------------------------------------- |
||
| 35 | | Login Class |
||
| 36 | |-------------------------------------------------------------------------- |
||
| 37 | | |
||
| 38 | | To Login the User. |
||
| 39 | | |
||
| 40 | */ |
||
| 41 | |||
| 42 | protected $flag; |
||
| 43 | protected $error; |
||
| 44 | protected $connect; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Create a new class instance. |
||
| 48 | * |
||
| 49 | * @return void |
||
|
|
|||
| 50 | */ |
||
| 51 | View Code Duplication | public function __construct() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * To Authenticate User Credentials |
||
| 65 | * |
||
| 66 | * @param array $data To store User Credentials |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function authLogin($data) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * For Adding Error statements |
||
| 123 | * |
||
| 124 | * @param string $key To store Key |
||
| 125 | * @param string $value To store Key |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function onError($key, $value) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * For Traversing data to check for error |
||
| 140 | * |
||
| 141 | * @param array $data To store Data |
||
| 142 | * |
||
| 143 | * @return array |
||
| 144 | */ |
||
| 145 | public function emptyValue($data) |
||
| 161 | |||
| 162 | } |
||
| 163 | |||
| 164 |
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.