Completed
Push — version-4 ( 100839...4b96e4 )
by
unknown
02:31
created

Config   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 1 Features 3
Metric Value
c 5
b 1
f 3
dl 0
loc 89
rs 10
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 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->reload();
16
    }
17
18
    public function isPolymorphic()
19
    {
20
        return (bool)$this->get('polymorphic');
21
    }
22
23
    public function isStrict()
24
    {
25
        return (bool)$this->get('strict_extra');
26
    }
27
28
    public function isTranslated()
29
    {
30
        return (bool)$this->get('translation.enabled');
31
    }
32
33
    public function getNotificationModel()
34
    {
35
        $class = $this->get('notification_model');
36
        if (class_exists($class)) {
37
            return $class;
38
        }
39
40
        return Notification::class;
41
    }
42
43
    public function getNotifiedModel()
44
    {
45
        $class = $this->get('model');
46
        if (class_exists($class)) {
47
            return $class;
48
        }
49
        throw new \InvalidArgumentException("The model class [{$class}] doesn't exist.");
50
    }
51
52
    public function getAdditionalFields()
53
    {
54
        return Arr::flatten($this->get('additional_fields', []));
55
    }
56
57
    public function getAdditionalRequiredFields()
58
    {
59
        return Arr::flatten($this->get('additional_fields.required', []));
60
    }
61
62
    public function getTranslationDomain()
63
    {
64
        return $this->get('translation.domain', 'notifynder');
65
    }
66
67
    public function get($key, $default = null)
68
    {
69
        return Arr::get($this->items, $key, $default);
70
    }
71
72
    public function has($key)
73
    {
74
        return Arr::has($this->items, $key);
75
    }
76
77
    public function set($key, $value = null)
78
    {
79
        Arr::set($this->items, $key, $value);
80
        app('config')->set('notifynder.'.$key, $value);
81
    }
82
83
    public function reload()
84
    {
85
        $this->items = app('config')->get('notifynder');
86
    }
87
88
    public function __get($key)
89
    {
90
        return $this->get($key);
91
    }
92
93
    public function __set($key, $value)
94
    {
95
        $this->set($key, $value);
96
    }
97
}
98