FieldAttributes   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 8
Bugs 2 Features 1
Metric Value
wmc 7
c 8
b 2
f 1
lcom 2
cbo 1
dl 0
loc 56
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A all() 0 4 1
A get() 0 4 2
A has() 0 4 1
A add() 0 12 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
}