| Conditions | 16 |
| Paths | 5 |
| Total Lines | 53 |
| Code Lines | 29 |
| Lines | 17 |
| Ratio | 32.08 % |
| Changes | 2 | ||
| 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 |
||
| 19 | public function handle($request, Closure $next) |
||
| 20 | { |
||
| 21 | // skip dynamic widgets on administrator pages. |
||
| 22 | if ($request->is('administrator/*') || $request->is('administrator')) { |
||
| 23 | return $next($request); |
||
| 24 | } |
||
| 25 | |||
| 26 | try { |
||
| 27 | $factory = app('arrilot.widget-group-collection'); |
||
| 28 | |||
| 29 | /** @var Collection $widgets */ |
||
| 30 | $widgets = $this->getWidgets(); |
||
| 31 | $widgets->each(function (Collection $group) use ($factory) { |
||
| 32 | $group->each(function (Widget $widget) use ($factory) { |
||
| 33 | $displayWidget = true; |
||
| 34 | |||
| 35 | if ($widget->requiresAuthentication() && ! auth()->check()) { |
||
|
|
|||
| 36 | $displayWidget = false; |
||
| 37 | } |
||
| 38 | |||
| 39 | if ($widget->permissions->count()) { |
||
| 40 | if ($widget->authorization === 'can') { |
||
| 41 | View Code Duplication | foreach ($widget->permissions as $permission) { |
|
| 42 | if (auth()->guest() || |
||
| 43 | (auth()->check() && ! auth()->user()->can($permission->slug)) |
||
| 44 | ) { |
||
| 45 | $displayWidget = false; |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | } |
||
| 49 | View Code Duplication | } else { |
|
| 50 | if (auth()->guest() || |
||
| 51 | (auth()->check() && ! auth() |
||
| 52 | ->user() |
||
| 53 | ->canAtLeast($widget->permissions->pluck('slug')->toArray())) |
||
| 54 | ) { |
||
| 55 | $displayWidget = false; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($displayWidget) { |
||
| 61 | $factory->group($widget->position) |
||
| 62 | ->addWidget($widget->present()->class(), [], $widget); |
||
| 63 | } |
||
| 64 | }); |
||
| 65 | }); |
||
| 66 | } catch (QueryException $e) { |
||
| 67 | // \\_(",)_// |
||
| 68 | } |
||
| 69 | |||
| 70 | return $next($request); |
||
| 71 | } |
||
| 72 | |||
| 85 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.