| Conditions | 12 |
| Paths | 17 |
| Total Lines | 43 |
| Code Lines | 24 |
| 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 |
||
| 70 | protected function registerMenu($menuBuilder, Menu $menu) |
||
| 71 | { |
||
| 72 | if (! $menuBuilder) { |
||
| 73 | return false; |
||
| 74 | } |
||
| 75 | |||
| 76 | if (! $menu->published) { |
||
| 77 | return false; |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($menu->requiresAuthentication() && ! auth()->check()) { |
||
| 81 | return false; |
||
| 82 | } |
||
| 83 | |||
| 84 | if (count($menu->permissions)) { |
||
| 85 | if ($menu->authorization === 'can') { |
||
| 86 | foreach ($menu->permissions as $permission) { |
||
| 87 | if (! current_user()->can($permission->slug)) { |
||
| 88 | return false; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } else { |
||
| 92 | $permissions = $menu->permissions->pluck('slug')->toArray(); |
||
| 93 | if (! current_user()->canAtLeast($permissions)) { |
||
| 94 | return false; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | $item = $menuBuilder->add($menu->title, url($menu->present()->url)) |
||
| 100 | ->attribute('target', $menu->present()->target) |
||
| 101 | ->attribute('title', $menu->present()->linkTitle); |
||
| 102 | |||
| 103 | if ($menu->present()->linkStyle) { |
||
| 104 | $item->attribute('style', $menu->present()->linkStyle); |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($menu->isActive()) { |
||
| 108 | session()->flash('active_menu', $menu); |
||
| 109 | } |
||
| 110 | |||
| 111 | return $item; |
||
| 112 | } |
||
| 113 | } |
||
| 114 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.