| Conditions | 15 | 
| Paths | 4 | 
| Total Lines | 50 | 
| Code Lines | 28 | 
| 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  | 
            ||
| 19 | public function handle($request, Closure $next)  | 
            ||
| 20 |     { | 
            ||
| 21 | // skip dynamic widgets on administrator pages.  | 
            ||
| 22 |         if ($request->is(admin_prefix() . '*')) { | 
            ||
| 23 | return $next($request);  | 
            ||
| 24 | }  | 
            ||
| 25 | |||
| 26 |         try { | 
            ||
| 27 |             $factory = app('arrilot.widget-group-collection'); | 
            ||
| 28 |             $this->getWidgetsToDisplay()->each(function (Collection $group) use ($factory) { | 
            ||
| 29 |                 $group->each(function (Widget $widget) use ($factory) { | 
            ||
| 30 | $displayWidget = true;  | 
            ||
| 31 | |||
| 32 |                     if ($widget->requiresAuthentication() && ! auth()->check()) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 33 | $displayWidget = false;  | 
            ||
| 34 | }  | 
            ||
| 35 | |||
| 36 |                     if (count($widget->permissions)) { | 
            ||
| 37 |                         if ($widget->authorization === 'can') { | 
            ||
| 38 |                             foreach ($widget->permissions as $permission) { | 
            ||
| 39 | if (auth()->guest() ||  | 
            ||
| 40 | (auth()->check() && ! auth()->user()->can($permission->slug))  | 
            ||
| 41 |                                 ) { | 
            ||
| 42 | $displayWidget = false;  | 
            ||
| 43 | continue;  | 
            ||
| 44 | }  | 
            ||
| 45 | }  | 
            ||
| 46 |                         } else { | 
            ||
| 47 | if (auth()->guest() ||  | 
            ||
| 48 | (auth()->check() && ! auth()  | 
            ||
| 49 | ->user()  | 
            ||
| 50 |                                         ->canAtLeast($widget->permissions->pluck('slug')->toArray())) | 
            ||
| 51 |                             ) { | 
            ||
| 52 | $displayWidget = false;  | 
            ||
| 53 | }  | 
            ||
| 54 | }  | 
            ||
| 55 | }  | 
            ||
| 56 | |||
| 57 |                     if ($displayWidget) { | 
            ||
| 58 | $factory->group($widget->position)  | 
            ||
| 59 | ->addWidget($widget->present()->class, [], $widget);  | 
            ||
| 60 | }  | 
            ||
| 61 | });  | 
            ||
| 62 | });  | 
            ||
| 63 |         } catch (QueryException $e) { | 
            ||
| 64 |             // \\_(",)_// | 
            ||
| 65 | }  | 
            ||
| 66 | |||
| 67 | return $next($request);  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 84 | 
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: