Conditions | 10 |
Paths | 7 |
Total Lines | 99 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 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 |
||
182 | static function posts_preview () { |
||
183 | $Config = Config::instance(); |
||
184 | $User = User::instance(); |
||
185 | if (!$User->user()) { |
||
186 | throw new ExitException(403); |
||
187 | } |
||
188 | $L = new Prefix('blogs_'); |
||
189 | $Page = Page::instance(); |
||
190 | if (empty($_POST['title'])) { |
||
191 | $Page->warning($L->post_title_empty); |
||
192 | $Page->json($Page->Top); |
||
193 | return; |
||
194 | } |
||
195 | if (empty($_POST['sections']) && $_POST['sections'] !== '0') { |
||
196 | $Page->warning($L->no_post_sections_specified); |
||
197 | $Page->json($Page->Top); |
||
198 | return; |
||
199 | } |
||
200 | if (empty($_POST['content'])) { |
||
201 | $Page->warning($L->post_content_empty); |
||
202 | $Page->json($Page->Top); |
||
203 | return; |
||
204 | } |
||
205 | if (empty($_POST['tags'])) { |
||
206 | $Page->warning($L->no_post_tags_specified); |
||
207 | $Page->json($Page->Top); |
||
208 | return; |
||
209 | } |
||
210 | $Posts = Posts::instance(); |
||
211 | $Sections = Sections::instance(); |
||
212 | $post = isset($_POST['id']) ? $Posts->get($_POST['id']) : [ |
||
213 | 'date' => TIME, |
||
214 | 'user' => $User->id, |
||
215 | 'comments_count' => 0 |
||
216 | ]; |
||
217 | $module = path($L->Blogs); |
||
218 | $module_data = $Config->module('Blogs'); |
||
219 | $Page->json( |
||
220 | h::{'section.cs-blogs-post article'}( |
||
221 | h::header( |
||
222 | h::h1(xap($_POST['title'])). |
||
223 | ((array)$_POST['sections'] != [0] ? h::p( |
||
224 | h::icon('bookmark'). |
||
225 | implode( |
||
226 | ', ', |
||
227 | array_map( |
||
228 | function ($section) use ($Sections, $L, $module) { |
||
229 | $section = $Sections->get($section); |
||
230 | return h::a( |
||
231 | $section['title'], |
||
232 | [ |
||
233 | 'href' => "$module/".path($L->section)."/$section[full_path]" |
||
234 | ] |
||
235 | ); |
||
236 | }, |
||
237 | (array)$_POST['sections'] |
||
238 | ) |
||
239 | ) |
||
240 | ) : '') |
||
241 | ). |
||
242 | xap($_POST['content'], true, $module_data->allow_iframes_without_content)."\n". |
||
243 | h::footer( |
||
244 | h::p( |
||
245 | h::icon('tags'). |
||
246 | implode( |
||
247 | ', ', |
||
248 | array_map( |
||
249 | function ($tag) use ($L, $module) { |
||
250 | $tag = xap($tag); |
||
251 | return h::a( |
||
252 | $tag, |
||
253 | [ |
||
254 | 'href' => "$module/".path($L->tag)."/$tag", |
||
255 | 'rel' => 'tag' |
||
256 | ] |
||
257 | ); |
||
258 | }, |
||
259 | _trim($_POST['tags']) |
||
260 | ) |
||
261 | ) |
||
262 | ). |
||
263 | h::hr(). |
||
264 | h::p( |
||
265 | h::time( |
||
266 | $L->to_locale(date($L->_datetime_long, $post['date'])), |
||
267 | [ |
||
268 | 'datetime' => date('c', $post['date']) |
||
269 | ] |
||
270 | ). |
||
271 | h::icon('user').$User->username($post['user']). |
||
272 | ( |
||
273 | $module_data->enable_comments ? h::icon('comments').$post['comments_count'] : '' |
||
274 | ) |
||
275 | ) |
||
276 | ) |
||
277 | ). |
||
278 | h::br(2) |
||
279 | ); |
||
280 | } |
||
281 | static function sections_get () { |
||
285 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.