Completed
Push — master ( fbfcb9...4fd533 )
by Song
02:36
created

AdminController::title()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
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
     * Title for current resource.
14
     *
15
     * @var string
16
     */
17
    protected $title = 'Title';
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
     * Get content title.
33
     *
34
     * @return string
35
     */
36
    protected function title()
37
    {
38
        return $this->title;
39
    }
40
41
    /**
42
     * Index interface.
43
     *
44
     * @param Content $content
45
     *
46
     * @return Content
47
     */
48
    public function index(Content $content)
49
    {
50
        return $content
51
            ->title($this->title())
52
            ->description($this->description['index'] ?? trans('admin.list'))
53
            ->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...
54
    }
55
56
    /**
57
     * Show interface.
58
     *
59
     * @param mixed   $id
60
     * @param Content $content
61
     *
62
     * @return Content
63
     */
64
    public function show($id, Content $content)
65
    {
66
        return $content
67
            ->title($this->title())
68
            ->description($this->description['show'] ?? trans('admin.show'))
69
            ->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...
70
    }
71
72
    /**
73
     * Edit interface.
74
     *
75
     * @param mixed   $id
76
     * @param Content $content
77
     *
78
     * @return Content
79
     */
80
    public function edit($id, Content $content)
81
    {
82
        return $content
83
            ->title($this->title())
84
            ->description($this->description['edit'] ?? trans('admin.edit'))
85
            ->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...
86
    }
87
88
    /**
89
     * Create interface.
90
     *
91
     * @param Content $content
92
     *
93
     * @return Content
94
     */
95
    public function create(Content $content)
96
    {
97
        return $content
98
            ->title($this->title())
99
            ->description($this->description['create'] ?? trans('admin.create'))
100
            ->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...
101
    }
102
}
103