Completed
Push — master ( 51b9ff...bf1d56 )
by Song
02:39
created

AdminController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Controllers;
4
5
use Encore\Admin\Layout\Content;
6
use Illuminate\Routing\Controller;
7
8
class AdminController extends Controller
9
{
10
    use HasResourceActions;
11
12
    /**
13
     * Set title for current resource.
14
     *
15
     * @var string
16
     */
17
    protected $header = '';
18
19
    /**
20
     * Set description for following 4 action pages.
21
     *
22
     * @var array
23
     */
24
    protected $description = [
25
//        'index'  => 'Index',
26
//        'show'   => 'Show',
27
//        'edit'   => 'Edit',
28
//        'create' => 'Create',
29
    ];
30
31
    /**
32
     * Index interface.
33
     *
34
     * @param Content $content
35
     * @return Content
36
     */
37
    public function index(Content $content)
38
    {
39
        return $content
40
            ->header($this->header)
41
            ->description($this->description['index'] ?? trans('admin.list'))
42
            ->body($this->grid());
0 ignored issues
show
Documentation Bug introduced by
The method grid does not exist on object<Encore\Admin\Controllers\AdminController>? 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...
43
    }
44
45
    /**
46
     * Show interface.
47
     *
48
     * @param mixed $id
49
     * @param Content $content
50
     * @return Content
51
     */
52
    public function show($id, Content $content)
53
    {
54
        return $content
55
            ->header($this->header)
56
            ->description($this->description['show'] ?? trans('admin.show'))
57
            ->body($this->detail($id));
0 ignored issues
show
Documentation Bug introduced by
The method detail does not exist on object<Encore\Admin\Controllers\AdminController>? 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...
58
    }
59
60
    /**
61
     * Edit interface.
62
     *
63
     * @param mixed $id
64
     * @param Content $content
65
     * @return Content
66
     */
67
    public function edit($id, Content $content)
68
    {
69
        return $content
70
            ->header($this->header)
71
            ->description($this->description['edit'] ?? trans('admin.edit'))
72
            ->body($this->form()->edit($id));
0 ignored issues
show
Documentation Bug introduced by
The method form does not exist on object<Encore\Admin\Controllers\AdminController>? 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...
73
    }
74
75
    /**
76
     * Create interface.
77
     *
78
     * @param Content $content
79
     * @return Content
80
     */
81
    public function create(Content $content)
82
    {
83
        return $content
84
            ->header($this->header)
85
            ->description($this->description['create'] ?? trans('admin.create'))
86
            ->body($this->form());
0 ignored issues
show
Documentation Bug introduced by
The method form does not exist on object<Encore\Admin\Controllers\AdminController>? 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...
87
    }
88
}