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 Search |
||
| 32 | { |
||
| 33 | /* |
||
| 34 | |-------------------------------------------------------------------------- |
||
| 35 | | Search Class |
||
| 36 | |-------------------------------------------------------------------------- |
||
| 37 | | |
||
| 38 | | Search for the user. |
||
| 39 | | |
||
| 40 | */ |
||
| 41 | |||
| 42 | protected $connect; |
||
| 43 | protected $array; |
||
| 44 | protected $obTime; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Create a new class instance. |
||
| 48 | * |
||
| 49 | * @return void |
||
|
|
|||
| 50 | */ |
||
| 51 | View Code Duplication | public function __construct() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Fetch Search Item from the DB |
||
| 65 | * |
||
| 66 | * @param object $suggestion To store user id and suggestion value |
||
| 67 | * |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function searchItem($suggestion) |
||
| 116 | } |
||
| 117 |
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.