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 SideBar |
||
32 | { |
||
33 | /* |
||
34 | |-------------------------------------------------------------------------- |
||
35 | | Time Class |
||
36 | |-------------------------------------------------------------------------- |
||
37 | | |
||
38 | | For Fetching the sidebar results. |
||
39 | | |
||
40 | */ |
||
41 | |||
42 | protected $obTime; |
||
43 | protected $array; |
||
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 | * Load Sidebar for the user containing all the names of the people |
||
65 | * |
||
66 | * @param int $userId To store session id of the user |
||
67 | * |
||
68 | * @return string |
||
69 | */ |
||
70 | public function loadSideBar($userId) |
||
94 | |||
95 | /** |
||
96 | * Fetch data form the DB for the Sidebar |
||
97 | * |
||
98 | * @param int $userId To store session id of the user |
||
99 | * @param array $row To store data |
||
100 | * |
||
101 | * @return void |
||
102 | */ |
||
103 | public function data($userId, $row) |
||
117 | |||
118 | } |
||
119 |
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.