Conditions | 5 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
58 | static function browse_posts ($Request) { |
||
59 | $Config = Config::instance(); |
||
60 | $L = Language::prefix('blogs_'); |
||
61 | $page = isset($Request->route[1]) ? (int)$Request->route[1] : 1; |
||
62 | $page = $page > 0 ? $page : 1; |
||
63 | $total = Posts::instance()->get_total_count(); |
||
64 | Page::instance() |
||
65 | ->title($L->browse_posts) |
||
66 | ->content( |
||
67 | h::{'table.cs-table[center][list]'}( |
||
68 | h::{'tr th'}( |
||
69 | [ |
||
70 | $L->post_title, |
||
71 | [ |
||
72 | 'style' => 'width: 30%' |
||
73 | ] |
||
74 | ], |
||
75 | [ |
||
76 | $L->post_sections, |
||
77 | [ |
||
78 | 'style' => 'width: 25%' |
||
79 | ] |
||
80 | ], |
||
81 | [ |
||
82 | $L->post_tags, |
||
83 | [ |
||
84 | 'style' => 'width: 20%' |
||
85 | ] |
||
86 | ], |
||
87 | [ |
||
88 | $L->author_date, |
||
89 | [ |
||
90 | 'style' => 'width: 15%' |
||
91 | ] |
||
92 | ], |
||
93 | $L->action |
||
94 | ). |
||
95 | h::{'tr| td'}( |
||
96 | get_posts_rows($page) |
||
97 | ) |
||
98 | ). |
||
99 | ( |
||
100 | $total ? h::{'.cs-block-margin.cs-text-center.cs-margin nav[is=cs-nav-pagination]'}( |
||
101 | pages( |
||
102 | $page, |
||
103 | ceil($total / $Config->module('Blogs')->posts_per_page), |
||
104 | function ($page) { |
||
105 | return $page == 1 ? 'admin/Blogs/browse_posts' : "admin/Blogs/browse_posts/$page"; |
||
106 | } |
||
107 | ) |
||
108 | ) : '' |
||
109 | ) |
||
110 | ); |
||
111 | } |
||
112 | /** |
||
175 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.