Conditions | 6 |
Paths | 24 |
Total Lines | 109 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
199 | public function getWidgets() |
||
200 | { |
||
201 | $name = $this->getName(); |
||
202 | |||
203 | $userIcon = 'user-times'; |
||
204 | $userText = 'Not logged in'; |
||
205 | if ($member = Security::getCurrentUser()) { |
||
206 | $memberTag = $member->getTitle() . ' (#' . $member->ID . ')'; |
||
207 | |||
208 | $userIcon = 'user'; |
||
209 | $userText = 'Logged in as ' . $memberTag; |
||
210 | |||
211 | // TODO: upgrade to newer version of the module |
||
212 | // Masquerade integration |
||
213 | if (DebugBar::getRequest()->getSession()->get('Masquerade.Old.loggedInAs')) { |
||
214 | $userIcon = 'user-secret'; |
||
215 | $userText = 'Masquerading as member ' . $memberTag; |
||
216 | } |
||
217 | } |
||
218 | |||
219 | $widgets = array( |
||
220 | 'user' => array( |
||
221 | 'icon' => $userIcon, |
||
222 | 'tooltip' => $userText, |
||
223 | "default" => "", |
||
224 | ), |
||
225 | "version" => array( |
||
226 | "icon" => "hashtag", |
||
227 | "tooltip" => class_exists(LeftAndMain::class) ? LeftAndMain::create()->CMSVersion() : 'unknown', |
||
228 | "default" => "" |
||
229 | ), |
||
230 | "locale" => array( |
||
231 | "icon" => "globe", |
||
232 | "tooltip" => i18n::get_locale(), |
||
233 | "default" => "", |
||
234 | ), |
||
235 | "session" => array( |
||
236 | "icon" => "archive", |
||
237 | "widget" => "PhpDebugBar.Widgets.VariableListWidget", |
||
238 | "map" => "$name.session", |
||
239 | "default" => "{}" |
||
240 | ), |
||
241 | "cookies" => array( |
||
242 | "icon" => "asterisk", |
||
243 | "widget" => "PhpDebugBar.Widgets.VariableListWidget", |
||
244 | "map" => "$name.cookies", |
||
245 | "default" => "{}" |
||
246 | ), |
||
247 | "parameters" => array( |
||
248 | "icon" => "arrow-right", |
||
249 | "widget" => "PhpDebugBar.Widgets.VariableListWidget", |
||
250 | "map" => "$name.parameters", |
||
251 | "default" => "{}" |
||
252 | ), |
||
253 | "requirements" => array( |
||
254 | "icon" => "file-text-o", |
||
255 | "widget" => "PhpDebugBar.Widgets.VariableListWidget", |
||
256 | "map" => "$name.requirements.list", |
||
257 | "default" => "{}" |
||
258 | ), |
||
259 | "requirements:badge" => array( |
||
260 | "map" => "$name.requirements.count", |
||
261 | "default" => 0 |
||
262 | ), |
||
263 | "middlewares" => array( |
||
264 | "icon" => "file-text-o", |
||
265 | "widget" => "PhpDebugBar.Widgets.ListWidget", |
||
266 | "map" => "$name.middlewares.list", |
||
267 | "default" => "{}" |
||
268 | ), |
||
269 | "middlewares:badge" => array( |
||
270 | "map" => "$name.middlewares.count", |
||
271 | "default" => 0 |
||
272 | ), |
||
273 | 'templates' => array( |
||
274 | 'icon' => 'file-code-o', |
||
275 | 'widget' => 'PhpDebugBar.Widgets.ListWidget', |
||
276 | 'map' => "$name.templates.templates", |
||
277 | 'default' => '{}' |
||
278 | ), |
||
279 | 'templates:badge' => array( |
||
280 | 'map' => "$name.templates.count", |
||
281 | 'default' => 0 |
||
282 | ) |
||
283 | ); |
||
284 | |||
285 | if (!empty($this->getConfigData())) { |
||
286 | $widgets["SiteConfig"] = array( |
||
287 | "icon" => "sliders", |
||
288 | "widget" => "PhpDebugBar.Widgets.VariableListWidget", |
||
289 | "map" => "$name.config", |
||
290 | "default" => "{}" |
||
291 | ); |
||
292 | } |
||
293 | |||
294 | if (!empty(self::$debug)) { |
||
295 | $widgets["debug"] = array( |
||
296 | "icon" => "list-alt", |
||
297 | "widget" => "PhpDebugBar.Widgets.ListWidget", |
||
298 | "map" => "$name.debug", |
||
299 | "default" => "[]" |
||
300 | ); |
||
301 | $widgets["debug:badge"] = array( |
||
302 | "map" => "$name.debugcount", |
||
303 | "default" => "null" |
||
304 | ); |
||
305 | } |
||
306 | |||
307 | return $widgets; |
||
308 | } |
||
323 |