| Conditions | 2 |
| Paths | 2 |
| Total Lines | 77 |
| Code Lines | 65 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 162 | public function getNews($news_id) { |
||
| 163 | $stmt = \AL\Db\execute_query( |
||
| 164 | "NewsDAO: getNews", |
||
| 165 | $this->mysqli, |
||
| 166 | "SELECT |
||
| 167 | news.news_id, |
||
| 168 | news.news_headline, |
||
| 169 | news.news_text, |
||
| 170 | news.news_date, |
||
| 171 | news.user_id, |
||
| 172 | CONCAT(news_image.news_image_id, '.', news_image.news_image_ext) as news_image, |
||
| 173 | news_image.news_image_id, |
||
| 174 | users.user_id, |
||
| 175 | users.userid, |
||
| 176 | users.email, |
||
| 177 | users.join_date, |
||
| 178 | users.karma, |
||
| 179 | users.show_email, |
||
| 180 | users.avatar_ext, |
||
| 181 | (SELECT COUNT(*) |
||
| 182 | FROM news |
||
| 183 | WHERE news.user_id = users.user_id) AS user_news_count |
||
| 184 | FROM news |
||
| 185 | LEFT JOIN news_image ON news.news_image_id = news_image.news_image_id |
||
| 186 | LEFT JOIN users ON news.user_id = users.user_id |
||
| 187 | WHERE news.news_id = ?", |
||
| 188 | "i", $news_id |
||
| 189 | ); |
||
| 190 | |||
| 191 | \AL\Db\bind_result( |
||
| 192 | "NewsDAO: getNews", |
||
| 193 | $stmt, |
||
| 194 | $id, |
||
| 195 | $headline, |
||
| 196 | $text, |
||
| 197 | $date, |
||
| 198 | $userid, |
||
| 199 | $image, |
||
| 200 | $image_id, |
||
| 201 | $user_id, |
||
| 202 | $user_userid, |
||
| 203 | $user_email, |
||
| 204 | $user_join_date, |
||
| 205 | $user_karma, |
||
| 206 | $user_show_email, |
||
| 207 | $user_avatar_ext, |
||
| 208 | $user_news_count |
||
| 209 | ); |
||
| 210 | |||
| 211 | $news = null; |
||
| 212 | |||
| 213 | if ($stmt->fetch()) { |
||
| 214 | $user = new \AL\Common\Model\User\User( |
||
| 215 | $user_id, |
||
| 216 | $user_userid, |
||
| 217 | $user_email, |
||
| 218 | $user_join_date, |
||
| 219 | $user_karma, |
||
| 220 | $user_show_email, |
||
| 221 | $user_avatar_ext, |
||
| 222 | $user_news_count |
||
| 223 | ); |
||
| 224 | |||
| 225 | $news = new \AL\Common\Model\News\News( |
||
| 226 | $id, |
||
| 227 | $headline, |
||
| 228 | $text, |
||
| 229 | $date, |
||
| 230 | $image, |
||
| 231 | $image_id, |
||
| 232 | $user |
||
| 233 | ); |
||
| 234 | } |
||
| 235 | |||
| 236 | $stmt->close(); |
||
| 237 | |||
| 238 | return $news; |
||
| 239 | } |
||
| 266 |