DashboardController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 11
c 0
b 0
f 0
rs 9.9666
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Chuckbe\Chuckcms\Controllers;
4
5
use Chuckbe\Chuckcms\Chuck\PageBlockRepository;
6
use Chuckbe\Chuckcms\Models\Page;
7
use Chuckbe\Chuckcms\Models\PageBlock;
8
use Chuckbe\Chuckcms\Models\Repeater;
9
use Chuckbe\Chuckcms\Models\Resource;
10
use Chuckbe\Chuckcms\Models\Site;
11
use Chuckbe\Chuckcms\Models\Template;
12
use Chuckbe\Chuckcms\Models\User;
13
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
14
use Illuminate\Foundation\Bus\DispatchesJobs;
15
use Illuminate\Foundation\Validation\ValidatesRequests;
16
use Illuminate\Routing\Controller as BaseController;
17
18
class DashboardController extends BaseController
19
{
20
    use AuthorizesRequests;
21
    use DispatchesJobs;
22
    use ValidatesRequests;
23
24
    protected $template;
25
    protected $site;
26
    protected $page;
27
    protected $pageblock;
28
    protected $pageBlockRepository;
29
    protected $resource;
30
    protected $repeater;
31
    protected $user;
32
33
    /**
34
     * Create a new controller instance.
35
     *
36
     * @return void
37
     */
38
    public function __construct(Template $template, Site $site, Page $page, PageBlock $pageblock, PageBlockRepository $pageBlockRepository, Resource $resource, Repeater $repeater, User $user)
39
    {
40
        $this->template = $template;
41
        $this->site = $site;
42
        $this->page = $page;
43
        $this->pageblock = $pageblock;
44
        $this->pageBlockRepository = $pageBlockRepository;
45
        $this->resource = $resource;
46
        $this->repeater = $repeater;
47
        $this->user = $user;
48
        $this->middleware('auth');
49
    }
50
51
    /**
52
     * Show the application dashboard.
53
     *
54
     * @return \Illuminate\View\View
55
     */
56
    public function index()
57
    {
58
        return view('chuckcms::backend.dashboard.index');
59
    }
60
61
    /**
62
     * Show the dashboard -> pages.
63
     *
64
     * @return \Illuminate\View\View
65
     */
66
    public function settings()
67
    {
68
        $pages = $this->page->get();
69
        $site = $this->site->first(); //change method to get active site
70
71
        return view('chuckcms::backend.settings.index', compact('pages', 'site'));
72
    }
73
}
74