Completed
Push — master ( 2f25c9...4c0020 )
by
unknown
06:10
created

Config   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 141
rs 10
c 0
b 0
f 0
wmc 17
lcom 1
cbo 1

15 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isPolymorphic() 0 4 1
A isStrict() 0 4 1
A isTranslated() 0 4 1
A getNotificationModel() 0 9 2
A getNotifiedModel() 0 8 2
A getAdditionalFields() 0 4 1
A getAdditionalRequiredFields() 0 4 1
A getTranslationDomain() 0 4 1
A get() 0 4 1
A has() 0 4 1
A set() 0 5 1
A reload() 0 4 1
A __get() 0 4 1
A __set() 0 4 1
1
<?php
2
3
namespace Fenos\Notifynder\Collections;
4
5
use Illuminate\Support\Arr;
6
use InvalidArgumentException;
7
use Fenos\Notifynder\Models\Notification;
8
use Fenos\Notifynder\Contracts\ConfigContract;
9
10
/**
11
 * Class Config.
12
 */
13
class Config implements ConfigContract
14
{
15
    /**
16
     * @var array
17
     */
18
    protected $items;
19
20
    /**
21
     * Config constructor.
22
     */
23
    public function __construct()
24
    {
25
        $this->reload();
26
    }
27
28
    /**
29
     * @return bool
30
     */
31
    public function isPolymorphic()
32
    {
33
        return (bool) $this->get('polymorphic');
34
    }
35
36
    /**
37
     * @return bool
38
     */
39
    public function isStrict()
40
    {
41
        return (bool) $this->get('strict_extra');
42
    }
43
44
    /**
45
     * @return bool
46
     */
47
    public function isTranslated()
48
    {
49
        return (bool) $this->get('translation.enabled');
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getNotificationModel()
56
    {
57
        $class = $this->get('notification_model');
58
        if (class_exists($class)) {
59
            return $class;
60
        }
61
62
        return Notification::class;
63
    }
64
65
    /**
66
     * @return string
67
     * @throws InvalidArgumentException
68
     */
69
    public function getNotifiedModel()
70
    {
71
        $class = $this->get('model');
72
        if (class_exists($class)) {
73
            return $class;
74
        }
75
        throw new InvalidArgumentException("The model class [{$class}] doesn't exist.");
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function getAdditionalFields()
82
    {
83
        return Arr::flatten($this->get('additional_fields', []));
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function getAdditionalRequiredFields()
90
    {
91
        return Arr::flatten($this->get('additional_fields.required', []));
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getTranslationDomain()
98
    {
99
        return $this->get('translation.domain', 'notifynder');
100
    }
101
102
    /**
103
     * @param string $key
104
     * @param null|mixed $default
105
     * @return mixed
106
     */
107
    public function get($key, $default = null)
108
    {
109
        return Arr::get($this->items, $key, $default);
110
    }
111
112
    /**
113
     * @param string $key
114
     * @return bool
115
     */
116
    public function has($key)
117
    {
118
        return Arr::has($this->items, $key);
119
    }
120
121
    /**
122
     * @param string $key
123
     * @param null $value
124
     */
125
    public function set($key, $value = null)
126
    {
127
        Arr::set($this->items, $key, $value);
128
        app('config')->set('notifynder.'.$key, $value);
129
    }
130
131
    public function reload()
132
    {
133
        $this->items = app('config')->get('notifynder');
134
    }
135
136
    /**
137
     * @param string $key
138
     * @return mixed
139
     */
140
    public function __get($key)
141
    {
142
        return $this->get($key);
143
    }
144
145
    /**
146
     * @param string $key
147
     * @param mixed $value
148
     */
149
    public function __set($key, $value)
150
    {
151
        $this->set($key, $value);
152
    }
153
}
154