Completed
Pull Request — master (#4037)
by Muhlis
02:52
created

ImageController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Encore\Admin\Controllers\ModelForm;
7
use Encore\Admin\Facades\Admin;
8
use Encore\Admin\Form;
9
use Encore\Admin\Grid;
10
use Encore\Admin\Layout\Content;
11
use Tests\Models\Image;
12
13
class ImageController extends Controller
14
{
15
    use ModelForm;
0 ignored issues
show
Deprecated Code introduced by
The trait Encore\Admin\Controllers\ModelForm has been deprecated with message: Use `HasResourceActions` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
16
17
    /**
18
     * Index interface.
19
     *
20
     * @return Content
21
     */
22
    public function index()
23
    {
24
        return Admin::content(function (Content $content) {
25
            $content->header('header');
26
            $content->description('description');
27
28
            $content->body($this->grid());
29
        });
30
    }
31
32
    /**
33
     * Edit interface.
34
     *
35
     * @param $id
36
     *
37
     * @return Content
38
     */
39 View Code Duplication
    public function edit($id)
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...
40
    {
41
        return Admin::content(function (Content $content) use ($id) {
42
            $content->header('header');
43
            $content->description('description');
44
45
            $content->body($this->form()->edit($id));
46
        });
47
    }
48
49
    /**
50
     * Create interface.
51
     *
52
     * @return Content
53
     */
54
    public function create()
55
    {
56
        return Admin::content(function (Content $content) {
57
            $content->header('Upload image');
58
59
            $content->body($this->form());
60
        });
61
    }
62
63
    /**
64
     * Make a grid builder.
65
     *
66
     * @return Grid
67
     */
68 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...
69
    {
70
        return Admin::grid(Image::class, function (Grid $grid) {
71
            $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...
72
73
            $grid->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...
74
            $grid->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...
75
76
            $grid->disableFilter();
77
        });
78
    }
79
80
    /**
81
     * Make a form builder.
82
     *
83
     * @return Form
84
     */
85
    protected function form()
86
    {
87
        return Admin::form(Image::class, function (Form $form) {
88
            $form->display('id', 'ID');
89
90
            $form->image('image1');
91
            $form->image('image2')->rotate(90);
0 ignored issues
show
Documentation Bug introduced by
The method rotate does not exist on object<Encore\Admin\Form\Field\Image>? 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
            $form->image('image3')->flip('v');
0 ignored issues
show
Documentation Bug introduced by
The method flip does not exist on object<Encore\Admin\Form\Field\Image>? 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...
93
            $form->image('image4')->move(null, 'renamed.jpeg');
94
            $form->image('image5')->name(function ($file) {
95
                return 'asdasdasdasdasd.'.$file->guessExtension();
96
            });
97
            $form->image('image6')->uniqueName();
98
99
            $form->display('created_at', 'Created At');
100
            $form->display('updated_at', 'Updated At');
101
        });
102
    }
103
}
104