Completed
Push — master ( a2dd34...253c8c )
by Song
03:46
created

RoleController::detail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Controllers;
4
5
use Encore\Admin\Auth\Database\Permission;
6
use Encore\Admin\Auth\Database\Role;
7
use Encore\Admin\Form;
8
use Encore\Admin\Grid;
9
use Encore\Admin\Layout\Content;
10
use Encore\Admin\Show;
11
use Illuminate\Routing\Controller;
12
13
class RoleController extends Controller
14
{
15
    use HasResourceActions;
16
17
    /**
18
     * Index interface.
19
     *
20
     * @param Content $content
21
     * @return Content
22
     */
23
    public function index(Content $content)
24
    {
25
        return $content
26
            ->header(trans('admin.roles'))
27
            ->description(trans('admin.list'))
28
            ->body($this->grid()->render());
29
    }
30
31
    /**
32
     * Show interface.
33
     *
34
     * @param mixed   $id
35
     * @param Content $content
36
     * @return Content
37
     */
38
    public function show($id, Content $content)
39
    {
40
        return $content
41
            ->header(trans('admin.roles'))
42
            ->description(trans('admin.detail'))
43
            ->body($this->detail($id));
44
    }
45
46
    /**
47
     * Edit interface.
48
     *
49
     * @param mixed $id
50
     * @param Content $content
51
     * @return Content
52
     */
53 View Code Duplication
    public function edit($id, Content $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        return $content
56
            ->header(trans('admin.roles'))
57
            ->description(trans('admin.edit'))
58
            ->body($this->form()->edit($id));
59
    }
60
61
    /**
62
     * Create interface.
63
     *
64
     * @param Content $content
65
     * @return Content
66
     */
67
    public function create(Content $content)
68
    {
69
        return $content
70
            ->header(trans('admin.roles'))
71
            ->description(trans('admin.create'))
72
            ->body($this->form());
73
    }
74
75
    /**
76
     * Make a grid builder.
77
     *
78
     * @return Grid
79
     */
80 View Code Duplication
    protected function grid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $grid = new Grid(new Role());
83
84
        $grid->id('ID')->sortable();
0 ignored issues
show
Documentation Bug introduced by
The method id does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
85
        $grid->slug(trans('admin.slug'));
0 ignored issues
show
Documentation Bug introduced by
The method slug does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
86
        $grid->name(trans('admin.name'));
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
87
88
        $grid->permissions(trans('admin.permission'))->pluck('name')->label();
0 ignored issues
show
Documentation Bug introduced by
The method permissions does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
89
90
        $grid->created_at(trans('admin.created_at'));
0 ignored issues
show
Documentation Bug introduced by
The method created_at does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
91
        $grid->updated_at(trans('admin.updated_at'));
0 ignored issues
show
Documentation Bug introduced by
The method updated_at does not exist on object<Encore\Admin\Grid>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92
93
        $grid->actions(function (Grid\Displayers\Actions $actions) {
94
            if ($actions->row->slug == 'administrator') {
95
                $actions->disableDelete();
96
            }
97
        });
98
99
        $grid->tools(function (Grid\Tools $tools) {
100
            $tools->batch(function (Grid\Tools\BatchActions $actions) {
101
                $actions->disableDelete();
102
            });
103
        });
104
105
        return $grid;
106
    }
107
108
    /**
109
     * Make a show builder.
110
     *
111
     * @param mixed   $id
112
     * @return Show
113
     */
114
    protected function detail($id)
115
    {
116
        $show = new Show(Role::findOrFail($id));
117
118
        $show->id('ID');
0 ignored issues
show
Documentation Bug introduced by
The method id does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
119
        $show->slug(trans('admin.slug'));
0 ignored issues
show
Documentation Bug introduced by
The method slug does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
120
        $show->name(trans('admin.name'));
0 ignored issues
show
Documentation Bug introduced by
The method name does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
121
        $show->permissions(trans('admin.permissions'))->as(function ($permission) {
0 ignored issues
show
Documentation Bug introduced by
The method permissions does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
122
            return $permission->pluck('name');
123
        })->label();
124
        $show->created_at(trans('admin.created_at'));
0 ignored issues
show
Documentation Bug introduced by
The method created_at does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
125
        $show->updated_at(trans('admin.updated_at'));
0 ignored issues
show
Documentation Bug introduced by
The method updated_at does not exist on object<Encore\Admin\Show>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
126
127
        return $show;
128
    }
129
130
    /**
131
     * Make a form builder.
132
     *
133
     * @return Form
134
     */
135
    public function form()
136
    {
137
        $form = new Form(new Role());
138
139
        $form->display('id', 'ID');
140
141
        $form->text('slug', trans('admin.slug'))->rules('required');
142
        $form->text('name', trans('admin.name'))->rules('required');
143
        $form->listbox('permissions', trans('admin.permissions'))->options(Permission::all()->pluck('name', 'id'));
144
145
        $form->display('created_at', trans('admin.created_at'));
146
        $form->display('updated_at', trans('admin.updated_at'));
147
148
        return $form;
149
    }
150
}
151