NotificationSetting::getAnalytics()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 2
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace Usamamuneerchaudhary\Notifier\Models;
5
6
use Illuminate\Database\Eloquent\Model;
7
8
class NotificationSetting extends Model
9
{
10
    protected $table = 'notifier_settings';
11
    protected $fillable = [
12
        'key',
13
        'value',
14
        'group'
15
    ];
16
17
    protected $casts = [
18
        'value' => 'json'
19
    ];
20
21
    public static function get(string $key, $default = null)
22
    {
23
        $setting = static::where('key', $key)->first();
24
        return $setting ? $setting->value : $default;
25
    }
26
27
    public static function set(string $key, $value, string $group = 'general'): void
28
    {
29
        static::updateOrCreate(
30
            ['key' => $key],
31
            [
32
                'value' => $value,
33
                'group' => $group
34
            ]
35
        );
36
    }
37
38
    /**
39
     * Get all preference settings
40
     */
41
    public static function getPreferences(): array
42
    {
43
        $preferences = static::get('preferences', config('notifier.settings.preferences', []));
44
        return is_array($preferences) ? $preferences : [];
45
    }
46
47
    /**
48
     * Get all analytics settings
49
     */
50
    public static function getAnalytics(): array
51
    {
52
        $analytics = static::get('analytics', config('notifier.settings.analytics', []));
53
        return is_array($analytics) ? $analytics : [];
54
    }
55
56
    /**
57
     * Get all rate limiting settings
58
     */
59
    public static function getRateLimiting(): array
60
    {
61
        $rateLimiting = static::get('rate_limiting', config('notifier.settings.rate_limiting', []));
62
        return is_array($rateLimiting) ? $rateLimiting : [];
63
    }
64
}
65