Completed
Push — master ( e12ed1...1e692e )
by wen
03:09
created

AdminController::getCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\Http\Controllers;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Illuminate\Routing\Controller;
7
use Sco\Admin\Contracts\ComponentInterface;
8
use Sco\Admin\Contracts\ModelFactoryInterface;
9
10
class AdminController extends Controller
11
{
12
    public function index()
13
    {
14
        return view('admin::app');
15
    }
16
17
    public function getList(ComponentInterface $component)
18
    {
19
        if (!$component->isView()) {
20
            throw new AuthorizationException();
21
        }
22
23
        return $component->get();
24
    }
25
26
27
    public function config(ComponentInterface $component)
28
    {
29
        if (!$component->isView()) {
30
            throw new AuthorizationException();
31
        }
32
33
        return $component->getConfigs();
34
    }
35
36
    public function getCreate(ComponentInterface $component)
0 ignored issues
show
Unused Code introduced by
The parameter $component is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
39
    }
40
41
    public function create()
42
    {
43
        return view('admin::app');
44
    }
45
46
    public function store(ComponentInterface $component)
47
    {
48
        $component->store();
0 ignored issues
show
Bug introduced by
The method store() does not seem to exist on object<Sco\Admin\Contracts\ComponentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
    }
50
51
    public function getEdit(ComponentInterface $component, $id)
52
    {
53
        if ((!$id && !$component->isCreate()) || ($id && !$component->isEdit())) {
54
            throw new AuthorizationException();
55
        }
56
57
    }
58
59
    public function edit(ComponentInterface $component, $id)
60
    {
61
        dd($component->find($id));
0 ignored issues
show
Bug introduced by
The method find() does not seem to exist on object<Sco\Admin\Contracts\ComponentInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
    }
63
64
    public function update()
65
    {
66
    }
67
68
    public function delete(ModelFactoryInterface $modelFactory, $id)
69
    {
70
        $modelFactory->delete($id);
71
        return response()->json(['message' => 'ok']);
72
    }
73
74
    public function batchDelete(ModelFactoryInterface $modelFactory)
0 ignored issues
show
Unused Code introduced by
The parameter $modelFactory is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
75
    {
76
    }
77
78
    public function forceDelete(ModelFactoryInterface $modelFactory, $id)
79
    {
80
        $modelFactory->forceDelete($id);
81
        return response()->json(['message' => 'ok']);
82
    }
83
84
    public function restore(ModelFactoryInterface $modelFactory, $id)
85
    {
86
        $modelFactory->restore($id);
87
        return response()->json(['message' => 'ok']);
88
    }
89
}
90