Passed
Pull Request — master (#610)
by John
05:33
created

JudgerController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Admin\Controllers;
4
5
use App\Models\Eloquent\Judger;
6
use App\Models\JudgerModel;
7
use App\Models\Eloquent\OJ;
8
use Encore\Admin\Controllers\AdminController;
9
use Encore\Admin\Controllers\HasResourceActions;
10
use Encore\Admin\Form;
11
use Encore\Admin\Grid;
12
use Encore\Admin\Layout\Content;
13
use Encore\Admin\Show;
14
use Illuminate\Database\Eloquent\Model;
15
16
class JudgerController extends AdminController
17
{
18
    use HasResourceActions;
19
20
    /**
21
     * Index interface.
22
     *
23
     * @param Content $content
24
     * @return Content
25
     */
26
    public function index(Content $content)
27
    {
28
        return $content
29
            ->header(__('admin.judgers.index.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.index.header') can also be of type array and array; however, parameter $header of Encore\Admin\Layout\Content::header() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
            ->header(/** @scrutinizer ignore-type */ __('admin.judgers.index.header'))
Loading history...
30
            ->description(__('admin.judgers.index.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.index.description') can also be of type array and array; however, parameter $description of Encore\Admin\Layout\Content::description() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

30
            ->description(/** @scrutinizer ignore-type */ __('admin.judgers.index.description'))
Loading history...
31
            ->body($this->grid()->render());
32
    }
33
34
    /**
35
     * Show interface.
36
     *
37
     * @param mixed $id
38
     * @param Content $content
39
     * @return Content
40
     */
41
    public function show($id, Content $content)
42
    {
43
        return $content
44
            ->header(__('admin.judgers.show.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.show.header') can also be of type array and array; however, parameter $header of Encore\Admin\Layout\Content::header() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            ->header(/** @scrutinizer ignore-type */ __('admin.judgers.show.header'))
Loading history...
45
            ->description(__('admin.judgers.show.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.show.description') can also be of type array and array; however, parameter $description of Encore\Admin\Layout\Content::description() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
            ->description(/** @scrutinizer ignore-type */ __('admin.judgers.show.description'))
Loading history...
46
            ->body($this->detail($id));
47
    }
48
49
    /**
50
     * Edit interface.
51
     *
52
     * @param mixed $id
53
     * @param Content $content
54
     * @return Content
55
     */
56
    public function edit($id, Content $content)
57
    {
58
        return $content
59
            ->header(__('admin.judgers.edit.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.edit.header') can also be of type array and array; however, parameter $header of Encore\Admin\Layout\Content::header() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

59
            ->header(/** @scrutinizer ignore-type */ __('admin.judgers.edit.header'))
Loading history...
60
            ->description(__('admin.judgers.edit.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.edit.description') can also be of type array and array; however, parameter $description of Encore\Admin\Layout\Content::description() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

60
            ->description(/** @scrutinizer ignore-type */ __('admin.judgers.edit.description'))
Loading history...
61
            ->body($this->form()->edit($id));
62
    }
63
64
    /**
65
     * Create interface.
66
     *
67
     * @param Content $content
68
     * @return Content
69
     */
70
    public function create(Content $content)
71
    {
72
        return $content
73
            ->header(__('admin.judgers.create.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.create.header') can also be of type array and array; however, parameter $header of Encore\Admin\Layout\Content::header() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

73
            ->header(/** @scrutinizer ignore-type */ __('admin.judgers.create.header'))
Loading history...
74
            ->description(__('admin.judgers.create.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.create.description') can also be of type array and array; however, parameter $description of Encore\Admin\Layout\Content::description() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
            ->description(/** @scrutinizer ignore-type */ __('admin.judgers.create.description'))
Loading history...
75
            ->body($this->form());
76
    }
77
78
    /**
79
     * Make a grid builder.
80
     *
81
     * @return Grid
82
     */
83
    protected function grid()
84
    {
85
        $grid=new Grid(new Judger());
86
87
        $grid->column('jid', 'JID');
88
        $grid->column('handle', __('admin.judgers.handle'))->editable();
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.handle') can also be of type array and array; however, parameter $label of Encore\Admin\Grid::column() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
        $grid->column('handle', /** @scrutinizer ignore-type */ __('admin.judgers.handle'))->editable();
Loading history...
89
        $grid->column('password', __('admin.judgers.password'))->editable();
90
        $grid->column('available', __('admin.judgers.availability'))->display(function($available) {
91
            return $available ? '<i class="MDI check-circle wemd-teal-text"></i> '.__('admin.judgers.available') : '<i class="MDI close-circle wemd-pink-text"></i> '.__('admin.judgers.unavailable');
0 ignored issues
show
Bug introduced by
Are you sure __('admin.judgers.available') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
            return $available ? '<i class="MDI check-circle wemd-teal-text"></i> './** @scrutinizer ignore-type */ __('admin.judgers.available') : '<i class="MDI close-circle wemd-pink-text"></i> '.__('admin.judgers.unavailable');
Loading history...
Bug introduced by
Are you sure __('admin.judgers.unavailable') of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
            return $available ? '<i class="MDI check-circle wemd-teal-text"></i> '.__('admin.judgers.available') : '<i class="MDI close-circle wemd-pink-text"></i> './** @scrutinizer ignore-type */ __('admin.judgers.unavailable');
Loading history...
92
        });
93
        $grid->column('oid', __('admin.judgers.oj'))->display(function() {
94
            return $this->oj->name;
0 ignored issues
show
Bug Best Practice introduced by
The property oj does not exist on App\Admin\Controllers\JudgerController. Did you maybe forget to declare it?
Loading history...
95
        });
96
        $grid->column('user_id', __('admin.judgers.user_id'))->editable();
97
        $grid->column('created_at', __('admin.created_at'));
98
        $grid->column('updated_at', __('admin.updated_at'));
99
100
        $grid->filter(function(Grid\Filter $filter) {
101
            $filter->like('handle', __('admin.judgers.handle'));
102
            $filter->like('password', __('admin.judgers.password'));
103
            $filter->like('user_id', __('admin.judgers.user_id'));
104
            $filter->equal('oid', __('admin.judgers.oj'))->select(OJ::all()->pluck('name', 'oid'));
105
        });
106
107
        return $grid;
108
    }
109
110
    /**
111
     * Make a show builder.
112
     *
113
     * @param mixed $id
114
     * @return Show
115
     */
116
    protected function detail($id)
117
    {
118
        $show=new Show(Judger::findOrFail($id));
119
120
        $show->field('jid', 'JID');
121
        $show->field('handle', __('admin.judgers.handle'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.handle') can also be of type array and array; however, parameter $label of Encore\Admin\Show::field() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

121
        $show->field('handle', /** @scrutinizer ignore-type */ __('admin.judgers.handle'));
Loading history...
122
        $show->field('password', __('admin.judgers.password'));
123
        $show->field('available', __('admin.judgers.availability'))->as(function($available) {
124
            return $available ?__('admin.judgers.available') : __('admin.judgers.unavailable');
125
        });
126
        $show->field('oj.name', __('admin.judgers.oj'));
127
        $show->field('user_id', __('admin.judgers.user_id'));
128
        $show->field('created_at', __('admin.created_at'));
129
        $show->field('updated_at', __('admin.updated_at'));
130
131
        return $show;
132
    }
133
134
    /**
135
     * Make a form builder.
136
     *
137
     * @return Form
138
     */
139
    protected function form()
140
    {
141
        $form=new Form(new Judger());
142
        $form->text('handle', __('admin.judgers.handle'))->help(__('admin.judgers.help.handle'))->required();
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgers.help.handle') can also be of type array and array; however, parameter $text of Encore\Admin\Form\Field::help() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

142
        $form->text('handle', __('admin.judgers.handle'))->help(/** @scrutinizer ignore-type */ __('admin.judgers.help.handle'))->required();
Loading history...
143
        $form->text('password', __('admin.judgers.password'))->help(__('admin.judgers.help.password'))->required();
144
        $form->switch('available', __('admin.judgers.availability'))->default(true);
145
        $form->select('oid', __('admin.judgers.oj'))->options(OJ::all()->pluck('name', 'oid'))->required();
146
        $form->text('user_id', __('admin.judgers.user_id'))->help(__('admin.judgers.help.user_id'));
147
        $form->hidden('using')->default(0);
148
        return $form;
149
    }
150
}
151