Conditions | 5 |
Paths | 16 |
Total Lines | 75 |
Code Lines | 58 |
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 |
||
80 | public function getLatestNews($limit = 20, $user_id = null, $last_timestamp = null, $words = null) { |
||
81 | $query = $this->getLatestNewsQuery($user_id, $last_timestamp, $words); |
||
82 | $bind_string = ""; |
||
83 | $bind_params = array(); |
||
84 | |||
85 | if ($user_id != null) { |
||
|
|||
86 | $bind_string .= "i"; |
||
87 | $bind_params[] = $user_id; |
||
88 | } |
||
89 | if ($last_timestamp != null) { |
||
90 | $bind_string .= "i"; |
||
91 | $bind_params[] = $last_timestamp; |
||
92 | } |
||
93 | if ($words != null) { |
||
94 | $bind_string .= "s"; |
||
95 | $bind_params[] = $words; |
||
96 | } |
||
97 | |||
98 | $bind_string .= "i"; |
||
99 | $bind_params[] = $limit; |
||
100 | |||
101 | $stmt = \AL\Db\execute_query( |
||
102 | "NewsDAO: getLatestNews", |
||
103 | $this->mysqli, |
||
104 | $query, |
||
105 | $bind_string, ...$bind_params |
||
106 | ); |
||
107 | |||
108 | \AL\Db\bind_result( |
||
109 | "NewsDAO: getLatestNews", |
||
110 | $stmt, |
||
111 | $id, |
||
112 | $headline, |
||
113 | $text, |
||
114 | $date, |
||
115 | $userid, |
||
116 | $image, |
||
117 | $image_id, |
||
118 | $user_id, |
||
119 | $user_userid, |
||
120 | $user_email, |
||
121 | $user_join_date, |
||
122 | $user_karma, |
||
123 | $user_show_email, |
||
124 | $user_avatar_ext, |
||
125 | $user_news_count |
||
126 | ); |
||
127 | |||
128 | $news = []; |
||
129 | while ($stmt->fetch()) { |
||
130 | $user = new \AL\Common\Model\User\User( |
||
131 | $user_id, |
||
132 | $user_userid, |
||
133 | $user_email, |
||
134 | $user_join_date, |
||
135 | $user_karma, |
||
136 | $user_show_email, |
||
137 | $user_avatar_ext, |
||
138 | $user_news_count |
||
139 | ); |
||
140 | |||
141 | $news[] = new \AL\Common\Model\News\News( |
||
142 | $id, |
||
143 | $headline, |
||
144 | $text, |
||
145 | $date, |
||
146 | $image, |
||
147 | $image_id, |
||
148 | $user |
||
149 | ); |
||
150 | } |
||
151 | |||
152 | $stmt->close(); |
||
153 | |||
154 | return $news; |
||
155 | } |
||
266 |