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 ( cd59f8...9e7309 )
by Aden
25:22
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
    ];
47
48
    /**
49
     * Application Instance.
50
     * 
51
     * @var \Illuminate\Foundation\Application
52
     */
53
    protected $app;
54
55
    /**
56
     * Flare Configuration.
57
     * 
58
     * @var array
59
     */
60
    protected $config;
61
62
    /**
63
     * The Title of the Admin Panel.
64
     * 
65
     * @var string
66
     */
67
    protected $adminTitle;
68
69
    /**
70
     * Safe Title of the Admin Panel.
71
     * 
72
     * @var string
73
     */
74
    protected $safeAdminTitle;
75
76
    /**
77
     * Relative Base URL of Admin Panel.
78
     * 
79
     * @var string
80
     */
81
    protected $relativeAdminUrl;
82
83
    /**
84
     * __construct.
85
     *
86
     * @param \Illuminate\Foundation\Application $app
87
     */
88
    public function __construct($app)
89
    {
90
        $this->app = $app;
91
92
        $this->setLoadedConfig();
93
    }
94
95
    /**
96
     * Returns the Application Instance.
97
     * 
98
     * @return mixed
99
     */
100
    public function app()
101
    {
102
        return $this->app;
103
    }
104
105
    /**
106
     * Returns a Flare configuration value(s).
107
     * 
108
     * @param string $key
109
     * 
110
     * @return mixed
111
     */
112
    public function config($key)
113
    {
114
        return $this->getConfig($key);
115
    }
116
117
    /**
118
     * Returns a Flare configuration value(s), falling back 
119
     * to the defined bare-minimum configuration defaults 
120
     * if, for whatever reason the config is undefined.
121
     * 
122
     * @param string $key
123
     * 
124
     * @return mixed
125
     */
126
    public function getConfig($key)
127
    {
128
        if (array_key_exists($key, $this->config)) {
129
            return $this->config[$key];
130
        }
131
132
        return config('flare.'.$key);
133
    }
134
135
    /**
136
     * Allow setting of the Flare config at runtime.
137
     */
138
    public function setConfig()
139
    {
140
    }
141
142
    /**
143
     * Set the loaded config to the protected property.
144
     *
145
     * Defaults to the configuration provided in this file 
146
     * (the bare minimum) if no config is found available.
147
     *
148
     * @return void
149
     */
150
    public function setLoadedConfig()
151
    {
152
        if (!config('flare.config')) {
153
            $this->config = $this->configurationKeys;
154
            return;
155
        }
156
157
        $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...
158
    }
159
160
    /**
161
     * @return string
162
     * 
163
     * @deprecated 0.9 Use getAdminTitle() instead.
164
     */
165
    public function adminTitle()
166
    {
167
        return $this->getAdminTitle();
168
    }
169
170
    /**
171
     * Returns the defined Admin Title.
172
     *
173
     * @return string
174
     */
175
    public function getAdminTitle()
176
    {
177
        return $this->adminTitle ? $this->adminTitle : \Flare::config('admin_title');
178
    }
179
180
    /**
181
     * Sets the Admin Title.
182
     * 
183
     * @param mixed $title
184
     */
185
    public function setAdminTitle($title = null)
186
    {
187
        $this->adminTitle = $title;
188
    }
189
190
    /**
191
     * @return string
192
     * 
193
     * @deprecated 0.9 Use getSafeAdminTitle() instead.
194
     */
195
    public function safeAdminTitle()
196
    {
197
        return $this->getSafeAdminTitle();
198
    }
199
200
    /**
201
     * Returns the defined Admin Title, converted
202
     * to a safer format (for <title> tags etc.).
203
     * 
204
     * @return string
205
     */
206
    public function getSafeAdminTitle()
207
    {
208
        return $this->safeAdminTitle ? $this->adminTitle : strip_tags(\Flare::config('admin_title'));
209
    }
210
211
    /**
212
     * Sets the Safe Admin Title which is used 
213
     * in <title> tags etc.
214
     *
215
     * @param mixed $title
216
     */
217
    public function setSafeAdminTitle($title = null)
218
    {
219
        $this->safeAdminTitle = $title;
220
    }
221
222
    /**
223
     * Returns URL to a path in the Admin Panel, using the 
224
     * Admin URL defined in the Flare Config.
225
     * 
226
     * @param string $path
227
     * 
228
     * @return string
229
     */
230
    public function adminUrl($path = '')
231
    {
232
        return url($this->relativeAdminUrl($path));
233
    }
234
235
    /**
236
     * Returns URL to a path in the Admin Panel, using the 
237
     * Admin URL defined in the Flare Config.
238
     * 
239
     * @param string $path
240
     * 
241
     * @return string
242
     */
243
    public function relativeAdminUrl($path = '')
244
    {
245
        return rtrim($this->getRelativeAdminUrl().'/'.$path, '/');
246
    }
247
248
    /**
249
     * Returns URL to a path in the Admin Panel, using the 
250
     * Admin URL defined in the Flare Config.
251
     * 
252
     * @return string
253
     */
254
    public function getRelativeAdminUrl()
255
    {
256
        return $this->relativeAdminUrl ? $this->relativeAdminUrl : \Flare::config('admin_url');
257
    }
258
259
    /**
260
     * Set the Flare Relative Admin URL.
261
     *
262
     * If the provided path is null the relative path provided
263
     * with the getRelativeAdminUrl() method will return the
264
     * configuration file default (or the Flare fallbacks).
265
     * 
266
     * @param mixed $path
267
     */
268
    public function setRelativeAdminUrl($path = null)
269
    {
270
        $this->relativeAdminUrl = $path;
271
    }
272
273
    /**
274
     * Returns URL to a path in the Flare Documentation.
275
     * This is COMING SOON!
276
     * 
277
     * @param string $path
278
     * 
279
     * @return string
280
     */
281
    public function docsUrl($path = '')
282
    {
283
        return url('#'.$path);
284
    }
285
286
    /**
287
     * Takes a named route inside the Flare namespace
288
     * and returns the URL.
289
     * 
290
     * @return string
291
     */
292
    public function route()
293
    {
294
    }
295
296
    /**
297
     * Determines whether part of the Flare Admin Panel
298
     * should be displayed or not and returns true / false.
299
     * 
300
     * @param string $key
301
     * 
302
     * @return bool
303
     */
304
    public function show($key = false)
305
    {
306
        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...
307
            return false;
308
        }
309
310
        return $this->getShow($key);
311
    }
312
313
    /**
314
     * Determines whether part of the Flare Admin Panel
315
     * should be displayed or not and returns true / false.
316
     *
317
     * Accessor for getShow().
318
     * 
319
     * @param string $key
320
     * 
321
     * @return bool
322
     */
323
    public function getShow($key = false)
324
    {
325
        if (array_key_exists($key, $showConfig = $this->getConfig('show'))) {
326
            return $showConfig[$key];
327
        }
328
    }
329
330
    /**
331
     * Returns the current Flare Version.
332
     * 
333
     * @return string
334
     */
335
    public function version()
336
    {
337
        return self::VERSION;
338
    }
339
340
    /**
341
     * Returns the compatibility version of Flare to use.
342
     *
343
     * This will either return 'LTS' for Laravel installs of
344
     * the Long Term Support branch (5.1.x) or 'Edge' for all
345
     * other versions (including dev-master).
346
     * 
347
     * @return string
348
     */
349
    public function compatibility()
350
    {
351
        if (strpos($this->app->version(), '5.1.') !== false && strpos($this->app->version(), '(LTS)') !== false) {
352
            return 'LTS';
353
        }
354
355
        return 'Edge';
356
    }
357
358
    /**
359
     * Register a helper method.
360
     */
361
    public function registerHelper($helper, $class)
362
    {
363
        if (array_key_exists($helper, $this->helpers)) {
364
            throw new Exception("Helper method `$helper` has already been defined");
365
        }
366
367
        $this->helpers[$helper] = $class;
368
    }
369
370
    /**
371
     * Unregister a helper method.
372
     *
373
     * @param string $helper
374
     */
375
    public function unregisterHelper($helper)
376
    {
377
        unset($this->helpers[$helper]);
378
    }
379
380
    /**
381
     * Call a Helper Method.
382
     * 
383
     * @param string $method
384
     * @param mixed  $parameters
385
     * 
386
     * @return mixed
387
     */
388
    protected function callHelperMethod($method, $parameters)
389
    {
390
        return $this->app->make($this->helpers[$method], $parameters);
391
    }
392
393
    /**
394
     * Provide access to Helper Methods.
395
     *
396
     * This provides an extensible way of adding helper classes
397
     * which are registerable and available to adccess through
398
     * the Flare Facade.
399
     *
400
     * @param string $method
401
     * @param array  $parameters
402
     * 
403
     * @return mixed
404
     */
405
    public function __call($method, $parameters)
406
    {
407
        if (array_key_exists($method, $this->helpers)) {
408
            return $this->callHelperMethod($method, $parameters);
409
        }
410
411
        return call_user_func_array([$this, $method], $parameters);
412
    }
413
}
414