Completed
Push — version-4 ( a7057e...e7ecec )
by
unknown
09:30
created

Config::getAdditionalRequiredFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Fenos\Notifynder\Collections;
4
5
use Fenos\Notifynder\Contracts\ConfigContract;
6
use Fenos\Notifynder\Models\Notification;
7
use Illuminate\Support\Arr;
8
9
class Config implements ConfigContract
10
{
11
    protected $items;
12
13
    public function __construct()
14
    {
15
        $this->items = app('config')->get('notifynder');
16
    }
17
18
    public function isPolymorphic()
19
    {
20
        return (bool) $this->get('polymorphic');
21
    }
22
23
    public function getNotificationModel()
24
    {
25
        $class = $this->get('notification_model');
26
        if (class_exists($class)) {
27
            return $class;
28
        }
29
30
        return Notification::class;
31
    }
32
33
    public function getNotifiedModel()
34
    {
35
        $class = $this->get('model');
36
        if (class_exists($class)) {
37
            return $class;
38
        }
39
        throw new \InvalidArgumentException("The model class [{$class}] doesn't exist.");
40
    }
41
42
    public function getAdditionalFields()
43
    {
44
        return Arr::flatten($this->get('additional_fields', []));
45
    }
46
47
    public function getAdditionalRequiredFields()
48
    {
49
        return Arr::flatten($this->get('additional_fields.required', []));
50
    }
51
52
    public function get($key, $default = null)
53
    {
54
        return Arr::get($this->items, $key, $default);
55
    }
56
57
    public function has($key)
58
    {
59
        return Arr::has($this->items, $key);
60
    }
61
62
    public function set($key, $value = null)
63
    {
64
        Arr::set($this->items, $key, $value);
65
    }
66
67
    public function __get($key)
68
    {
69
        return $this->get($key);
70
    }
71
72
    public function __set($key, $value)
73
    {
74
        $this->set($key, $value);
75
    }
76
}
77