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

JudgeServerController::form()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 13
rs 9.9332
c 1
b 0
f 1
1
<?php
2
3
namespace App\Admin\Controllers;
4
5
use App\Models\Eloquent\JudgeServer;
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 JudgeServerController 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.judgeservers.index.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.index.header'))
Loading history...
30
            ->description(__('admin.judgeservers.index.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.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.judgeservers.show.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.show.header'))
Loading history...
45
            ->description(__('admin.judgeservers.show.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.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.judgeservers.edit.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.edit.header'))
Loading history...
60
            ->description(__('admin.judgeservers.edit.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.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.judgeservers.create.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.create.header'))
Loading history...
74
            ->description(__('admin.judgeservers.create.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.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.judgeservers.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 JudgeServer());
86
87
        $grid->column('jsid', 'JSID');
88
        $grid->column('scode', __('admin.judgeservers.scode'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.scode') 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('scode', /** @scrutinizer ignore-type */ __('admin.judgeservers.scode'));
Loading history...
89
        $grid->column('name', __('admin.judgeservers.name'));
90
        $grid->column('host', __('admin.judgeservers.host'));
91
        $grid->column('port', __('admin.judgeservers.port'));
92
        $grid->column('token', __('admin.judgeservers.token'));
93
        $grid->column('available', __('admin.judgeservers.availability'))->display(function($available) {
94
            return $available ?__('admin.judgeservers.available') : __('admin.judgeservers.unavailable');
95
        });
96
        $grid->column('OJ', __('admin.judgeservers.oj'))->display(function() {
97
            return $this->oj->name;
0 ignored issues
show
Bug Best Practice introduced by
The property oj does not exist on App\Admin\Controllers\JudgeServerController. Did you maybe forget to declare it?
Loading history...
98
        });
99
        $grid->column('usage', __('admin.judgeservers.usage'))->display(function($usage) {
100
            return blank($usage) ? "-" : "$usage%";
101
        });
102
        $grid->column('status', __('admin.judgeservers.status'))->display(function($status) {
103
            $status=JudgerModel::$status[$status];
104
            return '<i class="MDI '.$status['icon'].' '.$status['color'].'"></i> '.$status['text'];
105
        });
106
        $grid->column('status_update_at', __('admin.judgeservers.status_update_at'));
107
        $grid->column('created_at', __('admin.created_at'));
108
        $grid->column('updated_at', __('admin.updated_at'));
109
110
        return $grid;
111
    }
112
113
    /**
114
     * Make a show builder.
115
     *
116
     * @param mixed $id
117
     * @return Show
118
     */
119
    protected function detail($id)
120
    {
121
        $show=new Show(JudgeServer::findOrFail($id));
122
123
        $show->field('jsid', 'JSID');
124
        $show->field('scode', __('admin.judgeservers.scode'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.scode') 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

124
        $show->field('scode', /** @scrutinizer ignore-type */ __('admin.judgeservers.scode'));
Loading history...
125
        $show->field('name', __('admin.judgeservers.name'));
126
        $show->field('host', __('admin.judgeservers.host'));
127
        $show->field('port', __('admin.judgeservers.port'));
128
        $show->field('token', __('admin.judgeservers.token'));
129
        $show->field('available', __('admin.judgeservers.availability'))->as(function($available) {
130
            return $available ?__('admin.judgeservers.available') : __('admin.judgeservers.unavailable');
131
        });
132
        $show->field('oj.name', __('admin.judgeservers.oj'));
133
        $show->field('usage', __('admin.judgeservers.usage'))->as(function($usage) {
134
            return blank($usage) ? "-" : "$usage%";
135
        });
136
        $show->field('status', __('admin.judgeservers.status'))->unescape()->as(function($status) {
137
            $status=JudgerModel::$status[$status];
138
            return '<i class="MDI '.$status['icon'].' '.$status['color'].'"></i> '.$status['text'];
139
        });
140
        $show->field('status_update_at', __('admin.judgeservers.status_update_at'));
141
        $show->field('created_at', __('admin.created_at'));
142
        $show->field('updated_at', __('admin.updated_at'));
143
144
        return $show;
145
    }
146
147
    /**
148
     * Make a form builder.
149
     *
150
     * @return Form
151
     */
152
    protected function form()
153
    {
154
        $form=new Form(new JudgeServer());
155
156
        $form->text('scode', __('admin.judgeservers.scode'))->required();
157
        $form->text('name', __('admin.judgeservers.name'))->required();
158
        $form->text('host', __('admin.judgeservers.host'))->required();
159
        $form->text('port', __('admin.judgeservers.port'))->required();
160
        $form->text('token', __('admin.judgeservers.token'))->required();
161
        $form->switch('available', __('admin.judgeservers.availability'));
162
        $form->select('oid', __('admin.judgeservers.oj'))->options(OJ::all()->pluck('name', 'oid'))->help(__('admin.judgeservers.help.onlinejudge'))->required();
0 ignored issues
show
Bug introduced by
It seems like __('admin.judgeservers.help.onlinejudge') 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

162
        $form->select('oid', __('admin.judgeservers.oj'))->options(OJ::all()->pluck('name', 'oid'))->help(/** @scrutinizer ignore-type */ __('admin.judgeservers.help.onlinejudge'))->required();
Loading history...
163
        $form->hidden('status', __('admin.judgeservers.status'))->default(0);
164
        return $form;
165
    }
166
}
167