Conditions | 8 |
Paths | 8 |
Total Lines | 52 |
Code Lines | 32 |
Lines | 0 |
Ratio | 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 |
||
110 | function get_pages_rows () { |
||
111 | $L = new Prefix('static_pages_'); |
||
112 | $Pages = Pages::instance(); |
||
113 | $Categories = Categories::instance(); |
||
114 | $categories = array_slice(Request::instance()->route, 2); |
||
115 | $structure = $Pages->get_structure(); |
||
116 | $path = []; |
||
117 | if (!empty($categories)) { |
||
118 | foreach ($categories as $category) { |
||
119 | $category = $Categories->get($category)['path']; |
||
120 | if (isset($structure['categories'][$category])) { |
||
121 | $structure = $structure['categories'][$category]; |
||
122 | $path[] = $structure['path']; |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | Page::instance()->title($structure['id'] == 0 ? $L->root_category : $structure['title']); |
||
127 | $path = !empty($path) ? implode('/', $path).'/' : ''; |
||
128 | $content = []; |
||
129 | if (!empty($structure['pages'])) { |
||
130 | foreach ($structure['pages'] as &$page) { |
||
131 | $page = $Pages->get($page); |
||
132 | $content[] = [ |
||
133 | [ |
||
134 | h::a( |
||
135 | $page['title'], |
||
136 | [ |
||
137 | 'href' => $path.$page['path'] |
||
138 | ] |
||
139 | ), |
||
140 | [ |
||
141 | 'class' => 'cs-static-pages-padding-left-0' |
||
142 | ] |
||
143 | ], |
||
144 | h::{'a[is=cs-link-button][icon=file-text]'}( |
||
145 | [ |
||
146 | 'href' => "admin/Static_pages/edit_page/$page[id]", |
||
147 | 'tooltip' => $L->edit |
||
148 | ] |
||
149 | ). |
||
150 | h::{'a[is=cs-link-button][icon=trash]'}( |
||
151 | [ |
||
152 | 'href' => "admin/Static_pages/delete_page/$page[id]", |
||
153 | 'tooltip' => $L->delete |
||
154 | ] |
||
155 | ) |
||
156 | ]; |
||
157 | } |
||
158 | unset($page); |
||
159 | } |
||
160 | return $content; |
||
161 | } |
||
162 |