| Total Complexity | 9 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 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 |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Get all rate limiting settings |
||
| 58 | */ |
||
| 59 | public static function getRateLimiting(): array |
||
| 63 | } |
||
| 64 | } |
||
| 65 |