Completed
Push — develop ( b974e0...970378 )
by
unknown
05:31
created

Config::getNotificationModel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A Config::getNotifiedModel() 0 8 2
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
     * @throws InvalidArgumentException
55
     */
56
    public function getNotifiedModel()
57
    {
58
        $class = $this->get('model');
59
        if (class_exists($class)) {
60
            return $class;
61
        }
62
        throw new InvalidArgumentException("The model class [{$class}] doesn't exist.");
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function getAdditionalFields()
69
    {
70
        return Arr::flatten($this->get('additional_fields', []));
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    public function getAdditionalRequiredFields()
77
    {
78
        return Arr::flatten($this->get('additional_fields.required', []));
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getTranslationDomain()
85
    {
86
        return $this->get('translation.domain', 'notifynder');
87
    }
88
89
    /**
90
     * @param string $key
91
     * @param null|mixed $default
92
     * @return mixed
93
     */
94
    public function get($key, $default = null)
95
    {
96
        return Arr::get($this->items, $key, $default);
97
    }
98
99
    /**
100
     * @param string $key
101
     * @return bool
102
     */
103
    public function has($key)
104
    {
105
        return Arr::has($this->items, $key);
106
    }
107
108
    /**
109
     * @param string $key
110
     * @param null $value
111
     */
112
    public function set($key, $value = null)
113
    {
114
        Arr::set($this->items, $key, $value);
115
        app('config')->set('notifynder.'.$key, $value);
116
    }
117
118
    public function reload()
119
    {
120
        $this->items = app('config')->get('notifynder');
121
    }
122
123
    /**
124
     * @param string $key
125
     * @return mixed
126
     */
127
    public function __get($key)
128
    {
129
        return $this->get($key);
130
    }
131
132
    /**
133
     * @param string $key
134
     * @param mixed $value
135
     */
136
    public function __set($key, $value)
137
    {
138
        $this->set($key, $value);
139
    }
140
}
141