Passed
Pull Request — master (#610)
by John
22:48
created

SettingsController::writeSettings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace App\Admin\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Encore\Admin\Layout\Content;
7
use App\Models\Eloquent\OJ;
8
use App\Models\Eloquent\Problem;
9
use App\Models\Eloquent\Compiler;
10
use Encore\Admin\Widgets\Form;
11
use Encore\Admin\Widgets\Box;
12
use Encore\Admin\Widgets\Table;
13
use App\Babel\Babel;
14
use Arr;
15
16
class SettingsController extends Controller
17
{
18
    /**
19
     * Show the Testing Page.
20
     *
21
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Admin\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
22
     */
23
    public function index(Content $content)
24
    {
25
        $content=$content->header(__('admin.settings.index.header'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.settings.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

25
        $content=$content->header(/** @scrutinizer ignore-type */ __('admin.settings.index.header'));
Loading history...
26
        $content=$content->description(__('admin.settings.index.description'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.settings.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

26
        $content=$content->description(/** @scrutinizer ignore-type */ __('admin.settings.index.description'));
Loading history...
27
        if (request()->isMethod('post')) {
28
            $this->writeSettings();
29
            admin_toastr(__('admin.settings.tooltip.success.message'), 'success');
0 ignored issues
show
Bug introduced by
It seems like __('admin.settings.tooltip.success.message') can also be of type array and array; however, parameter $message of admin_toastr() 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
            admin_toastr(/** @scrutinizer ignore-type */ __('admin.settings.tooltip.success.message'), 'success');
Loading history...
30
        }
31
        return $content->body($this->form());
0 ignored issues
show
Bug Best Practice introduced by
The expression return $content->body($this->form()) returns the type Encore\Admin\Layout\Content which is incompatible with the documented return type App\Admin\Controllers\Response.
Loading history...
32
    }
33
34
    /**
35
     * Make a form builder.
36
     *
37
     * @return Form
38
     */
39
    protected function form()
40
    {
41
        $box=new Box(__('admin.settings.form.header'));
0 ignored issues
show
Bug introduced by
It seems like __('admin.settings.form.header') can also be of type array and array; however, parameter $title of Encore\Admin\Widgets\Box::__construct() 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

41
        $box=new Box(/** @scrutinizer ignore-type */ __('admin.settings.form.header'));
Loading history...
42
        $box->style('success');
43
        $form=new Form();
44
        $form->simplemde('terms', __('admin.settings.form.terms'))->default(setting('terms'))->help(__('admin.settings.help.terms'));
45
        $form->method('POST');
46
        $form->action(route('admin.settings.index'));
47
        $form->disableReset();
48
        $box->content($form);
0 ignored issues
show
Bug introduced by
$form of type Encore\Admin\Widgets\Form is incompatible with the type string expected by parameter $content of Encore\Admin\Widgets\Box::content(). ( Ignorable by Annotation )

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

48
        $box->content(/** @scrutinizer ignore-type */ $form);
Loading history...
49
        return $box;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $box returns the type Encore\Admin\Widgets\Box which is incompatible with the documented return type Encore\Admin\Widgets\Form.
Loading history...
50
    }
51
52
    protected function writeSettings()
53
    {
54
        setting(['terms' => request()->terms]);
55
    }
56
}
57