Conditions | 6 |
Paths | 6 |
Total Lines | 73 |
Code Lines | 19 |
Lines | 73 |
Ratio | 100 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
54 | View Code Duplication | public function getLastViewedPage() { |
|
55 | $locale = MY_Controller::getCurrentLocale(); |
||
56 | |||
57 | $query |
||
58 | = " |
||
59 | SELECT |
||
60 | `users`.`username`, |
||
61 | `type_id`, |
||
62 | `route`.`type`, |
||
63 | `id_entity`, |
||
64 | (CASE `mod_stats_attendance`.`type_id` |
||
65 | WHEN 1 THEN `content`.`title` |
||
66 | WHEN 2 THEN `category`.`name` |
||
67 | WHEN 3 THEN `shop_category_i18n`.`name` |
||
68 | WHEN 4 THEN `shop_products_i18n`.`name` |
||
69 | END) AS `page_name` |
||
70 | FROM |
||
71 | `mod_stats_attendance` |
||
72 | LEFT JOIN |
||
73 | route |
||
74 | ON |
||
75 | route.entity_id = mod_stats_attendance.id_entity |
||
76 | LEFT JOIN |
||
77 | `content` |
||
78 | ON |
||
79 | `content`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 1 |
||
80 | LEFT JOIN |
||
81 | `category` |
||
82 | ON |
||
83 | `category`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 2 |
||
84 | LEFT JOIN |
||
85 | `shop_category` |
||
86 | ON |
||
87 | `shop_category`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 3 |
||
88 | LEFT JOIN |
||
89 | `shop_products` |
||
90 | ON |
||
91 | `shop_products`.`id` = `mod_stats_attendance`.`id_entity` AND `mod_stats_attendance`.`type_id` = 4 |
||
92 | LEFT JOIN |
||
93 | `shop_category_i18n` |
||
94 | ON |
||
95 | `shop_category`.`id` = `shop_category_i18n`.`id` AND `shop_category_i18n`.`locale` = '{$locale}' |
||
96 | LEFT JOIN |
||
97 | `shop_products_i18n` |
||
98 | ON |
||
99 | `shop_products`.`id` = `shop_products_i18n`.`id` AND `shop_products_i18n`.`locale` = '{$locale}' |
||
100 | LEFT JOIN |
||
101 | `users` |
||
102 | ON |
||
103 | `users`.`id` = `mod_stats_attendance`.`id_user` |
||
104 | ORDER BY |
||
105 | `mod_stats_attendance`.`time_add` |
||
106 | DESC |
||
107 | LIMIT 1 |
||
108 | "; |
||
109 | $result = $this->db->query($query); |
||
110 | if ($result) { |
||
111 | $result = $result->row_array(); |
||
112 | if ($result['type_id'] == Attendance::PAGE) { |
||
113 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_PAGE); |
||
114 | } elseif ($result['type_id'] == Attendance::CATEGORY) { |
||
115 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_CATEGORY); |
||
116 | } elseif ($result['type_id'] == Attendance::SHOP_CATEGORY) { |
||
117 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_SHOP_CATEGORY); |
||
118 | } elseif ($result['type_id'] == Attendance::PRODUCT) { |
||
119 | $result['url'] = $this->getUrl($result['id_entity'], Route::TYPE_PRODUCT); |
||
120 | } |
||
121 | |||
122 | return $result; |
||
123 | } |
||
124 | |||
125 | return false; |
||
126 | } |
||
127 | |||
173 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.