Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
5 / 10 |
|
37.50% |
3 / 8 |
CRAP | |
0.00% |
0 / 1 |
| Setting | |
50.00% |
5 / 10 |
|
37.50% |
3 / 8 |
22.50 | |
0.00% |
0 / 1 |
| get | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| set | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getBool | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setBool | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| isArticleProcessingEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setArticleProcessingEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isPublishingApprovalsEnabled | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPublishingApprovalsEnabled | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Model; |
| 6 | |
| 7 | class Setting extends Model |
| 8 | { |
| 9 | protected $fillable = ['key', 'value']; |
| 10 | |
| 11 | public static function get(string $key, mixed $default = null): mixed |
| 12 | { |
| 13 | $setting = static::where('key', $key)->first(); |
| 14 | |
| 15 | return $setting ? $setting->value : $default; |
| 16 | } |
| 17 | |
| 18 | public static function set(string $key, mixed $value): void |
| 19 | { |
| 20 | static::updateOrCreate(['key' => $key], ['value' => $value]); |
| 21 | } |
| 22 | |
| 23 | public static function getBool(string $key, bool $default = false): bool |
| 24 | { |
| 25 | $value = static::get($key, $default); |
| 26 | |
| 27 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
| 28 | } |
| 29 | |
| 30 | public static function setBool(string $key, bool $value): void |
| 31 | { |
| 32 | static::set($key, $value ? '1' : '0'); |
| 33 | } |
| 34 | |
| 35 | public static function isArticleProcessingEnabled(): bool |
| 36 | { |
| 37 | return static::getBool('article_processing_enabled', true); |
| 38 | } |
| 39 | |
| 40 | public static function setArticleProcessingEnabled(bool $enabled): void |
| 41 | { |
| 42 | static::setBool('article_processing_enabled', $enabled); |
| 43 | } |
| 44 | |
| 45 | public static function isPublishingApprovalsEnabled(): bool |
| 46 | { |
| 47 | return static::getBool('enable_publishing_approvals', false); |
| 48 | } |
| 49 | |
| 50 | public static function setPublishingApprovalsEnabled(bool $enabled): void |
| 51 | { |
| 52 | static::setBool('enable_publishing_approvals', $enabled); |
| 53 | } |
| 54 | } |