Completed
Push — version-4 ( 9f3bb5...94cdcc )
by
unknown
02:54
created

Config::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
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 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
    }
81
82
    public function __get($key)
83
    {
84
        return $this->get($key);
85
    }
86
87
    public function __set($key, $value)
88
    {
89
        $this->set($key, $value);
90
    }
91
}
92