FieldAttributes::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php namespace Mascame\Artificer\Fields;
2
3
class FieldAttributes
4
{
5
6
    protected $options;
7
    protected $fieldOptions;
8
9
    public function __construct($options, FieldOptions $fieldOptions)
10
    {
11
        $this->options = $options;
12
        $this->fieldOptions = $fieldOptions;
13
    }
14
15
    /**
16
     * @return array
17
     */
18
    public function all()
19
    {
20
        return $this->fieldOptions->get('attributes', []);
21
    }
22
23
    /**
24
     * @param $key
25
     * @return array
26
     */
27
    public function get($key)
28
    {
29
        return (isset($this->options[$key])) ? $this->options[$key] : [];
30
    }
31
32
    /**
33
     * @param $key
34
     * @return bool
35
     */
36
    public function has($key)
37
    {
38
        return (isset($this->options[$key]));
39
    }
40
41
    /**
42
     * @param array $attributes
43
     * @return array|mixed
44
     */
45
    public function add($attributes = [])
46
    {
47
        $current_attributes = $this->all();
48
49
        if (is_array($current_attributes)) {
50
            $this->fieldOptions->add('attributes', array_merge($current_attributes, $attributes));
51
        } else {
52
            $this->fieldOptions->add('attributes', $attributes);
53
        }
54
55
        return $this->fieldOptions->all();
56
    }
57
58
}