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
Push — master ( 54c72b...e7e058 )
by Aden
03:11
created

Flare::relativeAdminUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 1
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace LaravelFlare\Flare;
4
5
class Flare
6
{
7
    /**
8
     * The Flare version.
9
     *
10
     * @var string
11
     */
12
    const VERSION = '0.9.x-dev';
13
14
    /**
15
     * Array of expected configuration keys
16
     * with the absolute bare-minimum defaults.
17
     * 
18
     * @var array
19
     */
20
    protected $configurationKeys = [
21
        'admin_title' => 'Laravel Flare',
22
        'admin_url' => 'admin',
23
        'admin_theme' => 'red',
24
        'admin' => [],
25
        'attributes' => [],
26
        'models' => [],
27
        'modules' => [],
28
        'widgets' => [],
29
        'permissions' => \LaravelFlare\Flare\Permissions\Permissions::class,
30
        'policies' => [],
31
        'show' => [
32
            'github' => true,
33
            'login' => true,
34
            'notifications' => true,
35
            'version' => true,
36
        ],
37
    ];
38
39
    /**
40
     * Array of Helper Methods.
41
     *
42
     * @var array
43
     */
44
    protected $helpers = [
45
        'admin' => \LaravelFlare\Flare\Admin\AdminManager::class,
46
        'attributes' => \LaravelFlare\Flare\Admin\Attributes\AttributeManager::class,
47
    ];
48
49
    /**
50
     * Application Instance.
51
     * 
52
     * @var \Illuminate\Foundation\Application
53
     */
54
    protected $app;
55
56
    /**
57
     * Flare Configuration.
58
     * 
59
     * @var array
60
     */
61
    protected $config;
62
63
    /**
64
     * The Title of the Admin Panel.
65
     * 
66
     * @var string
67
     */
68
    protected $adminTitle;
69
70
    /**
71
     * Safe Title of the Admin Panel.
72
     * 
73
     * @var string
74
     */
75
    protected $safeAdminTitle;
76
77
    /**
78
     * Relative Base URL of Admin Panel.
79
     * 
80
     * @var string
81
     */
82
    protected $relativeAdminUrl;
83
84
    /**
85
     * __construct.
86
     *
87
     * @param \Illuminate\Foundation\Application $app
88
     */
89
    public function __construct($app)
90
    {
91
        $this->app = $app;
92
93
        $this->setLoadedConfig();
94
    }
95
96
    /**
97
     * Returns the Application Instance.
98
     * 
99
     * @return mixed
100
     */
101
    public function app()
102
    {
103
        return $this->app;
104
    }
105
106
    /**
107
     * Returns a Flare configuration value(s).
108
     * 
109
     * @param string $key
110
     * 
111
     * @return mixed
112
     */
113
    public function config($key)
114
    {
115
        return $this->getConfig($key);
116
    }
117
118
    /**
119
     * Returns a Flare configuration value(s), falling back 
120
     * to the defined bare-minimum configuration defaults 
121
     * if, for whatever reason the config is undefined.
122
     * 
123
     * @param string $key
124
     * 
125
     * @return mixed
126
     */
127
    public function getConfig($key)
128
    {
129
        if (array_key_exists($key, $this->config)) {
130
            return $this->config[$key];
131
        }
132
133
        return config('flare.'.$key);
134
    }
135
136
    /**
137
     * Allow setting of the Flare config at runtime.
138
     */
139
    public function setConfig()
140
    {
141
    }
142
143
    /**
144
     * Set the loaded config to the protected property.
145
     */
146
    public function setLoadedConfig()
147
    {
148
        $this->config = config('flare.config');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('flare.config') of type * is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
149
    }
150
151
    /**
152
     * @return string
153
     * 
154
     * @deprecated 0.9 Use getAdminTitle() instead.
155
     */
156
    public function adminTitle()
157
    {
158
        return $this->getAdminTitle();
159
    }
160
161
    /**
162
     * Returns the defined Admin Title.
163
     *
164
     * @return string
165
     */
166
    public function getAdminTitle()
167
    {
168
        return $this->adminTitle ? $this->adminTitle : \Flare::config('admin_title');
169
    }
170
171
    /**
172
     * Sets the Admin Title.
173
     * 
174
     * @param mixed $title
175
     */
176
    public function setAdminTitle($title = null)
177
    {
178
        $this->adminTitle = $title;
179
    }
180
181
    /**
182
     * @return string
183
     * 
184
     * @deprecated 0.9 Use getSafeAdminTitle() instead.
185
     */
186
    public function safeAdminTitle()
187
    {
188
        return $this->getSafeAdminTitle();
189
    }
190
191
    /**
192
     * Returns the defined Admin Title, converted
193
     * to a safer format (for <title> tags etc.).
194
     * 
195
     * @return string
196
     */
197
    public function getSafeAdminTitle()
198
    {
199
        return $this->safeAdminTitle ? $this->adminTitle : strip_tags(\Flare::config('admin_title'));
200
    }
201
202
    /**
203
     * Sets the Safe Admin Title which is used 
204
     * in <title> tags etc.
205
     *
206
     * @param mixed $title
207
     */
208
    public function setSafeAdminTitle($title = null)
209
    {
210
        $this->safeAdminTitle = $title;
211
    }
212
213
    /**
214
     * Returns URL to a path in the Admin Panel, using the 
215
     * Admin URL defined in the Flare Config.
216
     * 
217
     * @param string $path
218
     * 
219
     * @return string
220
     */
221
    public function adminUrl($path = '')
222
    {
223
        return url($this->relativeAdminUrl($path));
224
    }
225
226
    /**
227
     * Returns URL to a path in the Admin Panel, using the 
228
     * Admin URL defined in the Flare Config.
229
     * 
230
     * @param string $path
231
     * 
232
     * @return string
233
     */
234
    public function relativeAdminUrl($path = '')
235
    {
236
        return rtrim($this->getRelativeAdminUrl().'/'.$path, '/');
237
    }
238
239
    /**
240
     * Returns URL to a path in the Admin Panel, using the 
241
     * Admin URL defined in the Flare Config.
242
     * 
243
     * @return string
244
     */
245
    public function getRelativeAdminUrl()
246
    {
247
        return $this->relativeAdminUrl ? $this->relativeAdminUrl : \Flare::config('admin_url');
248
    }
249
250
    /**
251
     * Set the Flare Relative Admin URL.
252
     *
253
     * If the provided path is null the relative path provided
254
     * with the getRelativeAdminUrl() method will return the
255
     * configuration file default (or the Flare fallbacks).
256
     * 
257
     * @param mixed $path
258
     */
259
    public function setRelativeAdminUrl($path = null)
260
    {
261
        $this->relativeAdminUrl = $path;
262
    }
263
264
    /**
265
     * Returns URL to a path in the Flare Documentation.
266
     * This is COMING SOON!
267
     * 
268
     * @param string $path
269
     * 
270
     * @return string
271
     */
272
    public function docsUrl($path = '')
273
    {
274
        return url('#'.$path);
275
    }
276
277
    /**
278
     * Takes a named route inside the Flare namespace
279
     * and returns the URL.
280
     * 
281
     * @return string
282
     */
283
    public function route()
284
    {
285
    }
286
287
    /**
288
     * Determines whether part of the Flare Admin Panel
289
     * should be displayed or not and returns true / false.
290
     * 
291
     * @param string $key
292
     * 
293
     * @return bool
294
     */
295
    public function show($key = false)
296
    {
297
        if (!$key) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $key of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
298
            return false;
299
        }
300
301
        return $this->getShow($key);
302
    }
303
304
    /**
305
     * Determines whether part of the Flare Admin Panel
306
     * should be displayed or not and returns true / false.
307
     *
308
     * Accessor for getShow().
309
     * 
310
     * @param string $key
311
     * 
312
     * @return bool
313
     */
314
    public function getShow($key = false)
315
    {
316
        if (array_key_exists($key, $showConfig = $this->getConfig('show'))) {
317
            return $showConfig[$key];
318
        }
319
    }
320
321
    /**
322
     * Returns the current Flare Version.
323
     * 
324
     * @return string
325
     */
326
    public function version()
327
    {
328
        return self::VERSION;
329
    }
330
331
    /**
332
     * Call a Helper Method.
333
     * 
334
     * @param string $method
335
     * @param mixed  $parameters
336
     * 
337
     * @return mixed
338
     */
339
    protected function callHelperMethod($method, $parameters)
340
    {
341
        return $this->app->make($this->helpers[$method], $parameters);
342
    }
343
344
    /**
345
     * Provide access to Helper Methods.
346
     *
347
     * This provides an extensible way of adding helper classes
348
     * which are registerable and available to adccess through
349
     * the Flare Facade.
350
     *
351
     * @param string $method
352
     * @param array  $parameters
353
     * 
354
     * @return mixed
355
     */
356
    public function __call($method, $parameters)
357
    {
358
        if (array_key_exists($method, $this->helpers)) {
359
            return $this->callHelperMethod($method, $parameters);
360
        }
361
362
        return call_user_func_array([$this, $method], $parameters);
363
    }
364
}
365