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

Config   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 68
rs 10
wmc 13
lcom 1
cbo 1

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isPolymorphic() 0 4 1
A getNotificationModel() 0 9 2
A getNotifiedModel() 0 8 2
A getAdditionalFields() 0 4 1
A getAdditionalRequiredFields() 0 4 1
A get() 0 4 1
A has() 0 4 1
A set() 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->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