AnnouncementController::edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Admin\Controllers;
4
5
use App\Models\Eloquent\Announcement;
6
use App\Models\Eloquent\User;
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
15
class AnnouncementController extends AdminController
16
{
17
    use HasResourceActions;
18
19
    /**
20
     * Index interface.
21
     *
22
     * @param Content $content
23
     * @return Content
24
     */
25
    public function index(Content $content)
26
    {
27
        return $content
28
            ->header(__('admin.announcements.index.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

28
            ->header(/** @scrutinizer ignore-type */ __('admin.announcements.index.header'))
Loading history...
29
            ->description(__('admin.announcements.index.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

29
            ->description(/** @scrutinizer ignore-type */ __('admin.announcements.index.description'))
Loading history...
30
            ->body($this->grid()->render());
31
    }
32
33
    /**
34
     * Show interface.
35
     *
36
     * @param mixed $id
37
     * @param Content $content
38
     * @return Content
39
     */
40
    public function show($id, Content $content)
41
    {
42
        return $content
43
            ->header(__('admin.announcements.show.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

43
            ->header(/** @scrutinizer ignore-type */ __('admin.announcements.show.header'))
Loading history...
44
            ->description(__('admin.announcements.show.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

44
            ->description(/** @scrutinizer ignore-type */ __('admin.announcements.show.description'))
Loading history...
45
            ->body($this->detail($id));
46
    }
47
48
    /**
49
     * Edit interface.
50
     *
51
     * @param mixed $id
52
     * @param Content $content
53
     * @return Content
54
     */
55
    public function edit($id, Content $content)
56
    {
57
        return $content
58
            ->header(__('admin.announcements.edit.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

58
            ->header(/** @scrutinizer ignore-type */ __('admin.announcements.edit.header'))
Loading history...
59
            ->description(__('admin.announcements.edit.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

59
            ->description(/** @scrutinizer ignore-type */ __('admin.announcements.edit.description'))
Loading history...
60
            ->body($this->form()->edit($id));
61
    }
62
63
    /**
64
     * Create interface.
65
     *
66
     * @param Content $content
67
     * @return Content
68
     */
69
    public function create(Content $content)
70
    {
71
        return $content
72
            ->header(__('admin.announcements.create.header'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

72
            ->header(/** @scrutinizer ignore-type */ __('admin.announcements.create.header'))
Loading history...
73
            ->description(__('admin.announcements.create.description'))
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.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

73
            ->description(/** @scrutinizer ignore-type */ __('admin.announcements.create.description'))
Loading history...
74
            ->body($this->form());
75
    }
76
77
    /**
78
     * Make a grid builder.
79
     *
80
     * @return Grid
81
     */
82
    protected function grid()
83
    {
84
        $grid=new Grid(new Announcement());
85
86
        $grid->column('anid', 'ANID');
87
        $grid->column('user', __('admin.announcements.user'))->display(function() {
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.user') 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

87
        $grid->column('user', /** @scrutinizer ignore-type */ __('admin.announcements.user'))->display(function() {
Loading history...
88
            return $this->user->readable_name;
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist on App\Admin\Controllers\AnnouncementController. Did you maybe forget to declare it?
Loading history...
89
        }); ;
90
        $grid->column('title', __('admin.announcements.title'))->editable();
91
        $grid->column('created_at', __('admin.created_at'));
92
        $grid->column('updated_at', __('admin.updated_at'));
93
94
        $grid->filter(function(Grid\Filter $filter) {
95
            $filter->like('title', __('admin.announcements.title'));
96
            $filter->equal('uid', __('admin.announcements.user'))->select(function($id) {
0 ignored issues
show
Bug introduced by
function(...) { /* ... */ } of type callable is incompatible with the type Illuminate\Support\Collection|array expected by parameter $options of Encore\Admin\Grid\Filter\AbstractFilter::select(). ( Ignorable by Annotation )

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

96
            $filter->equal('uid', __('admin.announcements.user'))->select(/** @scrutinizer ignore-type */ function($id) {
Loading history...
97
                $user=User::find($id);
98
                if ($user) {
99
                    return [$user->id => $user->readable_name];
100
                }
101
            })->config('minimumInputLength', 4)->ajax(route('admin.api.users'));
102
        });
103
104
        return $grid;
105
    }
106
107
    /**
108
     * Make a show builder.
109
     *
110
     * @param mixed $id
111
     * @return Show
112
     */
113
    protected function detail($id)
114
    {
115
        $show=new Show(Announcement::findOrFail($id));
116
117
        $show->field('anid', 'ANID');
118
        $show->field('user.name', __('admin.announcements.user'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.user') 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

118
        $show->field('user.name', /** @scrutinizer ignore-type */ __('admin.announcements.user'));
Loading history...
119
        $show->field('title', __('admin.announcements.title'));
120
        $show->field('content', __('admin.announcements.content'));
121
        $show->field('created_at', __('admin.created_at'));
122
        $show->field('updated_at', __('admin.updated_at'));
123
124
        return $show;
125
    }
126
127
    /**
128
     * Make a form builder.
129
     *
130
     * @return Form
131
     */
132
    protected function form()
133
    {
134
        $form=new Form(new Announcement());
135
        $form->text('title', __('admin.announcements.title'))->required();
136
        $form->simplemde('content', __('admin.announcements.content'))->help(__('admin.announcements.help.markdown'))->required();
0 ignored issues
show
Bug introduced by
It seems like __('admin.announcements.help.markdown') 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

136
        $form->simplemde('content', __('admin.announcements.content'))->help(/** @scrutinizer ignore-type */ __('admin.announcements.help.markdown'))->required();
Loading history...
137
        $form->select('uid', __('admin.announcements.user'))->options(function($id) {
138
            $user=User::find($id);
139
            if ($user) {
140
                return [$user->id => $user->readable_name];
141
            }
142
        })->config('minimumInputLength', 4)->ajax(route('admin.api.users'))->required();
143
        return $form;
144
    }
145
}
146