| Conditions | 7 |
| Paths | 12 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | public function __invoke(Request $request) |
||
| 10 | { |
||
| 11 | $page = $request->page; |
||
| 12 | |||
| 13 | $packageController = package_namespace().'\Http\Controllers\Pages\\'.ucfirst($page->slug).'Controller'; |
||
| 14 | $projectController = 'App\Http\Controllers\Pages\\'.ucfirst($page->slug).'Controller'; |
||
| 15 | |||
| 16 | $controller = class_exists($projectController) |
||
| 17 | ? $projectController |
||
| 18 | : $packageController; |
||
| 19 | |||
| 20 | if (! view()->exists(template_namespace().".{$page->slug}") && ! class_exists($controller)) { |
||
|
|
|||
| 21 | return abort(404); |
||
| 22 | } |
||
| 23 | |||
| 24 | if (! class_exists($controller)) { |
||
| 25 | return abort(404); |
||
| 26 | } |
||
| 27 | |||
| 28 | if (view()->exists(template_namespace().".{$page->slug}")) { |
||
| 29 | $response = view(template_namespace().".{$page->slug}")->with('page', $page); |
||
| 30 | } |
||
| 31 | |||
| 32 | $action = new $controller(); |
||
| 33 | |||
| 34 | return method_exists($action, 'index') |
||
| 35 | ? $action->index($page) |
||
| 36 | : $response; |
||
| 37 | } |
||
| 38 | } |
||
| 39 |
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: