Conditions | 17 |
Paths | 9600 |
Total Lines | 306 |
Code Lines | 235 |
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 |
||
213 | private function _define_profile_menu() |
||
214 | { |
||
215 | global $txt, $context, $modSettings; |
||
216 | |||
217 | $profile_areas = [ |
||
218 | 'info' => [ |
||
219 | 'title' => $txt['profileInfo'], |
||
220 | 'areas' => [ |
||
221 | 'summary' => [ |
||
222 | 'label' => $txt['summary'], |
||
223 | 'controller' => ProfileInfo::class, |
||
224 | 'function' => 'action_summary', |
||
225 | // From the summary it's possible to activate an account, so we need the token |
||
226 | 'token' => 'profile-aa%u', |
||
227 | 'token_type' => 'get', |
||
228 | 'permission' => [ |
||
229 | 'own' => 'profile_view_own', |
||
230 | 'any' => 'profile_view_any', |
||
231 | ], |
||
232 | ], |
||
233 | 'statistics' => [ |
||
234 | 'label' => $txt['statPanel'], |
||
235 | 'controller' => ProfileInfo::class, |
||
236 | 'function' => 'action_statPanel', |
||
237 | 'permission' => [ |
||
238 | 'own' => 'profile_view_own', |
||
239 | 'any' => 'profile_view_any', |
||
240 | ], |
||
241 | ], |
||
242 | 'showposts' => [ |
||
243 | 'label' => $txt['showPosts'], |
||
244 | 'controller' => ProfileInfo::class, |
||
245 | 'function' => 'action_showPosts', |
||
246 | 'subsections' => [ |
||
247 | 'messages' => [$txt['showMessages'], ['profile_view_own', 'profile_view_any']], |
||
248 | 'topics' => [$txt['showTopics'], ['profile_view_own', 'profile_view_any']], |
||
249 | 'unwatchedtopics' => [$txt['showUnwatched'], ['profile_view_own', 'profile_view_any'], 'enabled' => $modSettings['enable_unwatch'] && $context['user']['is_owner']], |
||
250 | 'attach' => [$txt['showAttachments'], ['profile_view_own', 'profile_view_any']], |
||
251 | ], |
||
252 | 'permission' => [ |
||
253 | 'own' => 'profile_view_own', |
||
254 | 'any' => 'profile_view_any', |
||
255 | ], |
||
256 | ], |
||
257 | 'showlikes' => [ |
||
258 | 'label' => $txt['likes_show'], |
||
259 | 'controller' => Likes::class, |
||
260 | 'function' => 'action_showProfileLikes', |
||
261 | 'enabled' => !empty($modSettings['likes_enabled']) && $context['user']['is_owner'], |
||
262 | 'subsections' => [ |
||
263 | 'given' => [$txt['likes_given'], ['profile_view_own']], |
||
264 | 'received' => [$txt['likes_received'], ['profile_view_own']], |
||
265 | ], |
||
266 | 'permission' => [ |
||
267 | 'own' => 'profile_view_own', |
||
268 | 'any' => [], |
||
269 | ], |
||
270 | ], |
||
271 | 'permissions' => [ |
||
272 | 'label' => $txt['showPermissions'], |
||
273 | 'controller' => ProfileInfo::class, |
||
274 | 'function' => 'action_showPermissions', |
||
275 | 'permission' => [ |
||
276 | 'own' => 'manage_permissions', |
||
277 | 'any' => 'manage_permissions', |
||
278 | ], |
||
279 | ], |
||
280 | 'history' => [ |
||
281 | 'label' => $txt['history'], |
||
282 | 'controller' => ProfileHistory::class, |
||
283 | 'function' => 'action_index', |
||
284 | 'subsections' => [ |
||
285 | 'activity' => [$txt['trackActivity'], 'moderate_forum'], |
||
286 | 'ip' => [$txt['trackIP'], 'moderate_forum'], |
||
287 | 'edits' => [$txt['trackEdits'], 'moderate_forum', 'enabled' => featureEnabled('ml') && !empty($modSettings['userlog_enabled'])], |
||
288 | 'logins' => [$txt['trackLogins'], ['profile_view_own', 'moderate_forum']], |
||
289 | ], |
||
290 | 'permission' => [ |
||
291 | 'own' => 'moderate_forum', |
||
292 | 'any' => 'moderate_forum', |
||
293 | ], |
||
294 | ], |
||
295 | 'viewwarning' => [ |
||
296 | 'label' => $txt['profile_view_warnings'], |
||
297 | 'enabled' => featureEnabled('w') && !empty($modSettings['warning_enable']) && $this->_profile['warning'] && (!empty($modSettings['warning_show']) && ($context['user']['is_owner'] || $modSettings['warning_show'] == 2)), |
||
298 | 'controller' => ProfileInfo::class, |
||
299 | 'function' => 'action_viewWarning', |
||
300 | 'permission' => [ |
||
301 | 'own' => 'profile_view_own', |
||
302 | 'any' => 'issue_warning', |
||
303 | ], |
||
304 | ], |
||
305 | ], |
||
306 | ], |
||
307 | 'edit_profile' => [ |
||
308 | 'title' => $txt['profileEdit'], |
||
309 | 'areas' => [ |
||
310 | 'account' => [ |
||
311 | 'label' => $txt['account'], |
||
312 | 'controller' => ProfileOptions::class, |
||
313 | 'function' => 'action_account', |
||
314 | 'enabled' => $context['user']['is_admin'] || ((int) $this->_profile['id_group'] !== 1 && !in_array(1, array_map('intval', explode(',', $this->_profile['additional_groups'])), true)), 'sc' => 'post', |
||
315 | 'token' => 'profile-ac%u', |
||
316 | 'password' => true, |
||
317 | 'permission' => [ |
||
318 | 'own' => ['profile_identity_any', 'profile_identity_own', 'manage_membergroups'], |
||
319 | 'any' => ['profile_identity_any', 'manage_membergroups'], |
||
320 | ], |
||
321 | ], |
||
322 | 'forumprofile' => [ |
||
323 | 'label' => $txt['forumprofile'], |
||
324 | 'controller' => ProfileOptions::class, |
||
325 | 'function' => 'action_forumProfile', |
||
326 | 'sc' => 'post', |
||
327 | 'token' => 'profile-fp%u', |
||
328 | 'permission' => [ |
||
329 | 'own' => ['profile_extra_any', 'profile_extra_own', 'profile_title_own', 'profile_title_any'], |
||
330 | 'any' => ['profile_extra_any', 'profile_title_any'], |
||
331 | ], |
||
332 | ], |
||
333 | 'theme' => [ |
||
334 | 'label' => $txt['theme'], |
||
335 | 'controller' => ProfileOptions::class, |
||
336 | 'function' => 'action_themepick', |
||
337 | 'sc' => 'post', |
||
338 | 'token' => 'profile-th%u', |
||
339 | 'permission' => [ |
||
340 | 'own' => ['profile_extra_any', 'profile_extra_own'], |
||
341 | 'any' => ['profile_extra_any'], |
||
342 | ], |
||
343 | ], |
||
344 | 'pick' => [ |
||
345 | 'label' => $txt['theme'], |
||
346 | 'controller' => ProfileOptions::class, |
||
347 | 'function' => 'action_pick', |
||
348 | 'hidden' => true, |
||
349 | 'sc' => 'post', |
||
350 | 'token' => 'profile-th%u', |
||
351 | 'permission' => [ |
||
352 | 'own' => ['profile_extra_any', 'profile_extra_own'], |
||
353 | 'any' => ['profile_extra_any'], |
||
354 | ], |
||
355 | ], |
||
356 | 'notification' => [ |
||
357 | 'label' => $txt['notifications'], |
||
358 | 'controller' => ProfileOptions::class, |
||
359 | 'function' => 'action_notification', |
||
360 | 'sc' => 'post', |
||
361 | 'token' => 'profile-nt%u', |
||
362 | 'subsections' => [ |
||
363 | 'settings' => [$txt['notify_settings']], |
||
364 | 'boards' => [$txt['notify_boards']], |
||
365 | 'topics' => [$txt['notify_topics']], |
||
366 | ], |
||
367 | 'permission' => [ |
||
368 | 'own' => ['profile_extra_any', 'profile_extra_own'], |
||
369 | 'any' => ['profile_extra_any'], |
||
370 | ], |
||
371 | ], |
||
372 | // Without profile_extra_own, settings are accessible from the PM section. |
||
373 | // @todo at some point decouple it from PMs |
||
374 | 'contactprefs' => [ |
||
375 | 'label' => $txt['contactprefs'], |
||
376 | 'controller' => ProfileOptions::class, |
||
377 | 'function' => 'action_pmprefs', |
||
378 | 'enabled' => allowedTo(['profile_extra_own', 'profile_extra_any']), |
||
379 | 'sc' => 'post', |
||
380 | 'token' => 'profile-pm%u', |
||
381 | 'permission' => [ |
||
382 | 'own' => ['pm_read'], |
||
383 | 'any' => ['profile_extra_any'], |
||
384 | ], |
||
385 | ], |
||
386 | 'ignoreboards' => [ |
||
387 | 'label' => $txt['ignoreboards'], |
||
388 | 'controller' => ProfileOptions::class, |
||
389 | 'function' => 'action_ignoreboards', |
||
390 | 'enabled' => !empty($modSettings['allow_ignore_boards']), |
||
391 | 'sc' => 'post', |
||
392 | 'token' => 'profile-ib%u', |
||
393 | 'permission' => [ |
||
394 | 'own' => ['profile_extra_any', 'profile_extra_own'], |
||
395 | 'any' => ['profile_extra_any'], |
||
396 | ], |
||
397 | ], |
||
398 | 'lists' => [ |
||
399 | 'label' => $txt['editBuddyIgnoreLists'], |
||
400 | 'controller' => ProfileOptions::class, |
||
401 | 'function' => 'action_editBuddyIgnoreLists', |
||
402 | 'enabled' => !empty($modSettings['enable_buddylist']) && $context['user']['is_owner'], |
||
403 | 'sc' => 'post', |
||
404 | 'token' => 'profile-bl%u', |
||
405 | 'subsections' => [ |
||
406 | 'buddies' => [$txt['editBuddies']], |
||
407 | 'ignore' => [$txt['editIgnoreList']], |
||
408 | ], |
||
409 | 'permission' => [ |
||
410 | 'own' => ['profile_extra_any', 'profile_extra_own'], |
||
411 | 'any' => [], |
||
412 | ], |
||
413 | ], |
||
414 | 'groupmembership' => [ |
||
415 | 'label' => $txt['groupmembership'], |
||
416 | 'controller' => ProfileOptions::class, |
||
417 | 'function' => 'action_groupMembership', |
||
418 | 'enabled' => !empty($modSettings['show_group_membership']) && $context['user']['is_owner'], |
||
419 | 'sc' => 'request', |
||
420 | 'token' => 'profile-gm%u', |
||
421 | 'token_type' => 'request', |
||
422 | 'permission' => [ |
||
423 | 'own' => ['profile_view_own'], |
||
424 | 'any' => ['manage_membergroups'], |
||
425 | ], |
||
426 | ], |
||
427 | ], |
||
428 | ], |
||
429 | 'profile_action' => [ |
||
430 | 'title' => $txt['profileAction'], |
||
431 | 'areas' => [ |
||
432 | 'sendpm' => [ |
||
433 | 'label' => $txt['profileSendIm'], |
||
434 | 'custom_url' => getUrl('action', ['action' => 'pm', 'sa' => 'send']), |
||
435 | 'permission' => [ |
||
436 | 'own' => [], |
||
437 | 'any' => ['pm_send'], |
||
438 | ], |
||
439 | ], |
||
440 | 'issuewarning' => [ |
||
441 | 'label' => $txt['profile_issue_warning'], |
||
442 | 'enabled' => featureEnabled('w') && !empty($modSettings['warning_enable']) && (!$context['user']['is_owner'] || $context['user']['is_admin']), |
||
443 | 'controller' => ProfileAccount::class, |
||
444 | 'function' => 'action_issuewarning', |
||
445 | 'token' => 'profile-iw%u', |
||
446 | 'permission' => [ |
||
447 | 'own' => [], |
||
448 | 'any' => ['issue_warning'], |
||
449 | ], |
||
450 | ], |
||
451 | 'banuser' => [ |
||
452 | 'label' => $txt['profileBanUser'], |
||
453 | 'custom_url' => getUrl('admin', ['action' => 'admin', 'area' => 'ban', 'sa' => 'add']), |
||
454 | 'enabled' => (int) $this->_profile['id_group'] !== 1 && !in_array(1, array_map('intval', explode(',', $this->_profile['additional_groups'])), true), |
||
455 | 'permission' => [ |
||
456 | 'own' => [], |
||
457 | 'any' => ['manage_bans'], |
||
458 | ], |
||
459 | ], |
||
460 | 'subscriptions' => [ |
||
461 | 'label' => $txt['subscriptions'], |
||
462 | 'controller' => ProfileSubscriptions::class, |
||
463 | 'function' => 'action_subscriptions', |
||
464 | 'enabled' => !empty($modSettings['paid_enabled']), |
||
465 | 'permission' => [ |
||
466 | 'own' => ['profile_view_own'], |
||
467 | 'any' => ['moderate_forum'], |
||
468 | ], |
||
469 | ], |
||
470 | 'deleteaccount' => [ |
||
471 | 'label' => $txt['deleteAccount'], |
||
472 | 'controller' => ProfileAccount::class, |
||
473 | 'function' => 'action_deleteaccount', |
||
474 | 'sc' => 'post', |
||
475 | 'token' => 'profile-da%u', |
||
476 | 'password' => true, |
||
477 | 'permission' => [ |
||
478 | 'own' => ['profile_remove_any', 'profile_remove_own'], |
||
479 | 'any' => ['profile_remove_any'], |
||
480 | ], |
||
481 | ], |
||
482 | 'activateaccount' => [ |
||
483 | 'controller' => ProfileAccount::class, |
||
484 | 'function' => 'action_activateaccount', |
||
485 | 'sc' => 'get', |
||
486 | 'token' => 'profile-aa%u', |
||
487 | 'token_type' => 'get', |
||
488 | 'permission' => [ |
||
489 | 'own' => [], |
||
490 | 'any' => ['moderate_forum'], |
||
491 | ], |
||
492 | ], |
||
493 | ], |
||
494 | ], |
||
495 | ]; |
||
496 | |||
497 | // Set a few options for the menu. |
||
498 | $menuOptions = [ |
||
499 | 'disable_url_session_check' => true, |
||
500 | 'hook' => 'profile', |
||
501 | 'extra_url_parameters' => [ |
||
502 | 'u' => $context['id_member'], |
||
503 | ], |
||
504 | ]; |
||
505 | |||
506 | // Actually create the menu! |
||
507 | $this->_profile_include_data = (new Menu()) |
||
508 | ->addMenuData($profile_areas) |
||
509 | ->addOptions($menuOptions) |
||
510 | ->prepareMenu() |
||
511 | ->setContext() |
||
512 | ->getIncludeData(); |
||
513 | |||
514 | unset($profile_areas); |
||
515 | |||
516 | // Make a note of the Unique ID for this menu. |
||
517 | $context['profile_menu_id'] = $context['max_menu_id']; |
||
518 | $context['profile_menu_name'] = 'menu_data_' . $context['profile_menu_id']; |
||
519 | } |
||
816 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.