Passed
Push — master ( 23bbf0...48eab7 )
by Keoghan
05:16
created

setting_missing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
use App\Models\Setting;
4
5
/**
6
 * Get a setting, or all settings.
7
 *
8
 * @param string|null $key
9
 * @param string|null $default
10
 *
11
 * @return mixed|\Illuminate\Support\Collection
12
 */
13
function setting($key = null, $default = null)
14
{
15 48
    if (!$key) {
16 1
        return Setting::all()->pluck('value', 'name');
17
    }
18
19 47
    return Setting::where('name', $key)->value('value') ?? $default;
20
}
21
22
/**
23
 * Check if a setting exists.
24
 *
25
 * @param string $key
26
 *
27
 * @return bool
28
 */
29
function setting_exists($key)
30
{
31 15
    return !is_null(setting($key));
32
}
33
34
/**
35
 * Check if a setting is missing.
36
 *
37
 * @param string $key
38
 *
39
 * @return bool
40
 */
41
function setting_missing($key)
42
{
43 13
    return !setting_exists($key);
44
}
45
46
/**
47
 * Check if we're running tests since environment is limited to production/development.
48
 */
49
function running_tests()
50
{
51 5
    return (bool) config('app.running_tests');
52
}
53