GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#688)
by
unknown
18:52
created

Template::getViewPath()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 1
crap 3.0416
1
<?php
2
3
namespace SleepingOwl\Admin\Templates;
4
5
use Illuminate\View\View;
6
use SleepingOwl\Admin\Contracts\AdminInterface;
7
use Illuminate\Contracts\Foundation\Application;
8
use SleepingOwl\Admin\Contracts\Template\MetaInterface;
9
use SleepingOwl\Admin\Contracts\Template\TemplateInterface;
10
use SleepingOwl\Admin\Contracts\Navigation\NavigationInterface;
11
12
abstract class Template implements TemplateInterface
13
{
14
    /**
15
     * @var Application
16
     */
17
    protected $app;
18
19
    /**
20
     * @var MetaInterface
21
     */
22
    protected $meta;
23
24
    /**
25
     * @var NavigationInterface
26
     */
27
    protected $navigation;
28
29
    /**
30
     * @var Breadcrumbs
31
     */
32
    protected $breadcrumbs;
33
34
    /**
35
     * @var AdminInterface
36
     */
37
    protected $admin;
38
39
    /**
40
     * TemplateDefault constructor.
41
     *
42
     * @param Application $application
43
     * @param AdminInterface $admin
44
     * @param MetaInterface $meta
45
     * @param NavigationInterface $navigation
46
     * @param Breadcrumbs $breadcrumbs
47
     */
48 285
    public function __construct(
49
        Application $application,
50
        AdminInterface $admin,
51
        MetaInterface $meta,
52
        NavigationInterface $navigation,
53
        Breadcrumbs $breadcrumbs
54
    ) {
55 285
        $this->app = $application;
56 285
        $this->meta = $meta;
57 285
        $this->navigation = $navigation;
58 285
        $this->breadcrumbs = $breadcrumbs;
59 285
        $this->admin = $admin;
60 285
    }
61
62
    /**
63
     * Название с указанием версии.
64
     *
65
     * @return string
66
     */
67
    public function longName()
68
    {
69
        return $this->name().' v.'.$this->version();
70
    }
71
72
    /**
73
     * @return Breadcrumbs
74
     */
75
    public function breadcrumbs()
76
    {
77
        return $this->breadcrumbs;
78
    }
79
80
    /**
81
     * @return MetaInterface
82
     */
83 285
    public function meta()
84
    {
85 285
        return $this->meta;
86
    }
87
88
    /**
89
     * @return NavigationInterface
90
     */
91
    public function navigation()
92
    {
93
        return $this->navigation;
94
    }
95
96
    /**
97
     * Генерация относительно пути до asset файлов для текущей темы.
98
     *
99
     * @param string $path относительный путь до файла, например `js/app.js`
100
     *
101
     * @return string
102
     */
103 285
    public function assetPath($path = null)
104
    {
105 285
        return ! is_null($path) ? $this->assetDir().'/'.ltrim($path, '/') : $this->assetDir();
106
    }
107
108
    /**
109
     * @return string
110
     */
111 2
    public function getTitle()
112
    {
113 2
        return config('sleeping_owl.title');
114
    }
115
116
    /**
117
     * @param string $title
118
     * @param string $separator
119
     *
120
     * @return string
121
     */
122 1
    public function makeTitle($title, $separator = ' | ')
123
    {
124 1
        if (empty($title)) {
125 1
            return $this->getTitle();
126
        }
127
128 1
        return $title."{$separator}".$this->getTitle();
129
    }
130
131
    /**
132
     * @param string $view
133
     *
134
     * @return string
135
     */
136 285
    public function getViewPath($view)
137
    {
138 285
        if ($view instanceof View) {
139 1
            return $view->getPath();
140
        }
141
142 285
        if (strpos($view, '::') !== false) {
143
            return $view;
144
        }
145
146 285
        return $this->getViewNamespace().'.'.$view;
147
    }
148
149
    /**
150
     * @param string|View $view
151
     * @param array  $data
152
     * @param array  $mergeData
153
     *
154
     * @return \Illuminate\Contracts\View\Factory|View
155
     */
156 1
    public function view($view, array $data = [], $mergeData = [])
157
    {
158 1
        $data['template'] = $this;
159
160 1
        if ($view instanceof View) {
161 1
            return $view->with($data);
162
        }
163
164 1
        return view($this->getViewPath($view), $data, $mergeData);
165
    }
166
167
    /**
168
     * @param string $key
169
     *
170
     * @return string
171
     */
172
    public function renderBreadcrumbs($key)
173
    {
174
        if (config('sleeping_owl.breadcrumbs')) {
175
            $this->breadcrumbs()->setView(
176
                $this->getViewPath('_partials.breadcrumbs')
177
            );
178
179
            return $this->breadcrumbs()->renderIfExists($key);
180
        }
181
    }
182
183
    /**
184
     * @return string
185
     */
186
    public function renderNavigation()
187
    {
188
        return $this->navigation()->render(
189
            $this->getViewPath('_partials.navigation.navigation')
0 ignored issues
show
Unused Code introduced by
The call to NavigationInterface::render() has too many arguments starting with $this->getViewPath('_par...navigation.navigation').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
190
        );
191
    }
192
193
    /**
194
     * Регистрация стандартных глобальных Javascript перменных.
195
     */
196
    protected function setGlobalVariables()
197
    {
198
        $globalVars = $this->admin->scriptVariables();
199
200
        foreach ($globalVars as $var => $value) {
201
            $this->meta->putGlobalVar($var, $value);
0 ignored issues
show
Bug introduced by
The method putGlobalVar() does not seem to exist on object<SleepingOwl\Admin...Template\MetaInterface>.

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...
202
        }
203
    }
204
205
    /**
206
     * @param string $title
207
     *
208
     * @return string
209
     */
210
    public function renderMeta($title)
211
    {
212
        $this->setGlobalVariables();
213
214
        return $this->meta()
215
            ->setTitle($this->makeTitle($title))
216
            ->addMeta(['charset' => 'utf-8'], 'meta::charset')
217
            ->addMeta(['content' => csrf_token(), 'name' => 'csrf-token'])
218
            ->addMeta(['content' => 'width=device-width, initial-scale=1', 'name' => 'viewport'])
219
            ->addMeta(['content' => 'IE=edge', 'http-equiv' => 'X-UA-Compatible'])
220
            ->render();
221
    }
222
223
    /**
224
     * Render func.
225
     * @return array
226
     */
227
    public function toArray()
228
    {
229
        return [
230
            'asset_dir' => $this->assetDir(),
231
            'view_namespace' => $this->getViewNamespace(),
232
            'name' => $this->name(),
233
            'version' => $this->version(),
234
            'homepage' => $this->homepage(),
235
        ];
236
    }
237
}
238