Template::map()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 0
cp 0
crap 2
rs 10
1
<?php
2
3
namespace Terranet\Administrator\Services;
4
5
use Terranet\Administrator\Contracts\Module\Navigable;
6
use Terranet\Administrator\Contracts\Services\TemplateProvider;
7
8
class Template implements TemplateProvider
9
{
10
    /**
11
     * Scaffold layout.
12
     *
13
     * @param string $layout
14
     *
15
     * @return string
16
     */
17
    public function layout($layout = 'app')
18
    {
19
        return config('administrator.layouts.'.$layout, 'administrator::layouts.'.$layout);
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

19
        return /** @scrutinizer ignore-call */ config('administrator.layouts.'.$layout, 'administrator::layouts.'.$layout);
Loading history...
20
    }
21
22
    /**
23
     * Scaffold index templates.
24
     *
25
     * @param $partial
26
     *
27
     * @return mixed array|string
28
     */
29
    public function index($partial = 'index')
30
    {
31
        $partials = $this->map(
32
            'index',
33
            ['index', 'create', 'export', 'filters', 'scopes', 'header', 'batch', 'row', 'scripts', 'paginator']
34
        );
35
36
        return null === $partial ? $partials : $partials[$partial];
37
    }
38
39
    /**
40
     * Scaffold media templates.
41
     *
42
     * @param $partial
43
     *
44
     * @return mixed array|string
45
     */
46
    public function media($partial = 'index')
47
    {
48
        $partials = $this->map(
49
            'media',
50
            ['index']
51
        );
52
53
        return null === $partial ? $partials : $partials[$partial];
54
    }
55
56
    /**
57
     * Scaffold translations templates.
58
     *
59
     * @param $partial
60
     *
61
     * @return mixed array|string
62
     */
63
    public function translations($partial = 'index')
64
    {
65
        $partials = $this->map(
66
            'translations',
67
            ['index']
68
        );
69
70
        return null === $partial ? $partials : $partials[$partial];
71
    }
72
73
    /**
74
     * Scaffold view templates.
75
     *
76
     * @param $partial
77
     *
78
     * @return mixed array|string
79
     */
80
    public function view($partial = 'index')
81
    {
82
        $partials = $this->map('view', [
83
            'index',
84
            'model',
85
            'create',
86
        ]);
87
88
        return null === $partial ? $partials : $partials[$partial];
89
    }
90
91
    /**
92
     * Scaffold edit templates.
93
     *
94
     * @param $partial
95
     *
96
     * @return mixed array|string
97
     */
98
    public function edit($partial = 'index')
99
    {
100
        $partials = $this->map('edit', ['index', 'actions', 'row', 'scripts', 'create']);
101
102
        return null === $partial ? $partials : $partials[$partial];
103
    }
104
105
    /**
106
     * @param  string  $partial
107
     * @return array|string
108
     */
109
    public function menu($partial = 'sidebar')
110
    {
111
        $partials = $this->map('menus', [Navigable::MENU_SIDEBAR, Navigable::MENU_TOOLS]);
112
113
        return null === $partial ? $partials : $partials[$partial];
0 ignored issues
show
introduced by
The condition null === $partial is always false.
Loading history...
114
    }
115
116
    /**
117
     * @param  string  $partial
118
     * @return array|string
119
     */
120
    public function partials($partial = 'messages')
121
    {
122
        $partials = $this->map('partials', ['messages', 'breadcrumbs']);
123
124
        return null === $partial ? $partials : $partials[$partial];
0 ignored issues
show
introduced by
The condition null === $partial is always false.
Loading history...
125
    }
126
127
    /**
128
     * @param  string  $partial
129
     * @return array|string
130
     */
131
    public function scripts($partial = null)
132
    {
133
        $partials = $this->map('scripts', ['listeners', 'editors']);
134
135
        return null === $partial ? $partials : $partials[$partial];
136
    }
137
138
    /**
139
     * @param  string  $partial
140
     * @return array|string
141
     */
142
    public function auth($partial = 'login')
143
    {
144
        $partials = $this->map('auth', ['login']);
145
146
        return null === $partial ? $partials : $partials[$partial];
0 ignored issues
show
introduced by
The condition null === $partial is always false.
Loading history...
147
    }
148
149
    /**
150
     * @param  string  $partial
151
     * @return array|string
152
     */
153
    public function dashboard($partial = null)
154
    {
155
        $partials = $this->map('dashboard', ['database', 'members', 'google_analytics']);
156
157
        return null === $partial ? $partials : $partials[$partial];
158
    }
159
160
    /**
161
     * @param $namespace
162
     * @param array $views
163
     *
164
     * @return array
165
     */
166
    protected function map($namespace, array $views = [])
167
    {
168
        return array_merge(
169
            ['index' => "administrator::{$namespace}"],
170
            array_build($views, function ($key, $view) use ($namespace) {
171
                return [$view, "administrator::{$namespace}.{$view}"];
172
            })
173
        );
174
    }
175
}
176