Passed
Pull Request — master (#281)
by
unknown
05:45
created

Config::getAdditionalRequiredFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Fenos\Notifynder\Collections;
4
5
use Illuminate\Support\Arr;
6
use InvalidArgumentException;
7
use Fenos\Notifynder\Contracts\ConfigContract;
8
9
/**
10
 * Class Config.
11
 */
12
class Config implements ConfigContract
13
{
14
    /**
15
     * @var array
16
     */
17
    protected $items;
18
19
    /**
20
     * Config constructor.
21
     */
22
    public function __construct()
23
    {
24
        $this->reload();
25
    }
26
27
    /**
28
     * @return bool
29
     */
30
    public function isPolymorphic()
31
    {
32
        return (bool) $this->get('polymorphic');
33
    }
34
35
    /**
36
     * @return bool
37
     */
38
    public function isStrict()
39
    {
40
        return (bool) $this->get('strict_extra');
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isTranslated()
47
    {
48
        return (bool) $this->get('translation.enabled');
49
    }
50
51
    /**
52
     * @return string
53
     * @throws InvalidArgumentException
54
     */
55
    public function getNotifiedModel()
56
    {
57
        $class = $this->get('model');
58
        if (class_exists($class)) {
59
            return $class;
60
        }
61
        throw new InvalidArgumentException("The model class [{$class}] doesn't exist.");
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getAdditionalFields()
68
    {
69
        return Arr::flatten($this->get('additional_fields', []));
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function getAdditionalRequiredFields()
76
    {
77
        return Arr::flatten($this->get('additional_fields.required', []));
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getTranslationDomain()
84
    {
85
        return $this->get('translation.domain', 'notifynder');
86
    }
87
88
    /**
89
     * @param string $key
90
     * @param null|mixed $default
91
     * @return mixed
92
     */
93
    public function get($key, $default = null)
94
    {
95
        return Arr::get($this->items, $key, $default);
96
    }
97
98
    /**
99
     * @param string $key
100
     * @return bool
101
     */
102
    public function has($key)
103
    {
104
        return Arr::has($this->items, $key);
105
    }
106
107
    /**
108
     * @param string $key
109
     * @param null $value
110
     */
111
    public function set($key, $value = null)
112
    {
113
        Arr::set($this->items, $key, $value);
114
        app('config')->set('notifynder.'.$key, $value);
115
    }
116
117
    /**
118
     * @param string $key
119
     * @param null $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
120
     */
121
    public function forget($key)
122
    {
123
        Arr::forget($this->items, $key);
124
        app('config')->offsetUnset('notifynder.'.$key);
125
    }
126
127
    public function reload()
128
    {
129
        $this->items = app('config')->get('notifynder');
130
    }
131
132
    /**
133
     * @param string $key
134
     * @return mixed
135
     */
136
    public function __get($key)
137
    {
138
        return $this->get($key);
139
    }
140
141
    /**
142
     * @param string $key
143
     * @param mixed $value
144
     */
145
    public function __set($key, $value)
146
    {
147
        $this->set($key, $value);
148
    }
149
}
150