Passed
Branch master (e714e6)
by Gabriel
13:58 queued 11:36
created

HasDataTrait   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 85
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 5 1
A append() 0 6 2
A __isset() 0 3 1
A __unset() 0 3 1
A get() 0 6 2
A __get() 0 3 1
A __set() 0 3 1
A has() 0 3 1
1
<?php
2
3
namespace Nip\View\Traits;
4
5
/**
6
 * Trait HasDataTrait
7
 * @package Nip\View\Traits
8
 */
9
trait HasDataTrait
10
{
11
    protected $data = [];
12
13
    /**
14
     * @param $name
15
     * @return mixed|null
16
     */
17
    public function __get($name)
18
    {
19
        return $this->get($name);
20
    }
21
22
    /**
23
     * @param $name
24
     * @param $value
25
     * @return $this
26
     */
27
    public function __set($name, $value)
28
    {
29
        return $this->set($name, $value);
30
    }
31
32
    /**
33
     * @param  string $name
34
     * @return mixed|null
35
     */
36
    public function get($name)
37
    {
38
        if ($this->has($name)) {
39
            return $this->data[$name];
40
        } else {
41
            return null;
42
        }
43
    }
44
45
    /**
46
     * @param string $name
47
     * @return bool
48
     */
49
    public function has($name)
50
    {
51
        return isset($this->data[$name]);
52
    }
53
54
    /**
55
     * @param string $name
56
     * @param mixed $value
57
     * @return $this
58
     */
59
    public function set($name, $value)
60
    {
61
        $this->data[$name] = $value;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @param $name
68
     * @return bool
69
     */
70
    public function __isset($name)
71
    {
72
        return isset($this->data[$name]);
73
    }
74
75
    /**
76
     * @param $name
77
     */
78
    public function __unset($name)
79
    {
80
        unset($this->data[$name]);
81
    }
82
83
    /**
84
     * @param string $name
85
     * @param string $appended
86
     * @return $this
87
     */
88
    public function append($name, $appended)
89
    {
90
        $value = $this->has($name) ? $this->get($name) : '';
91
        $value .= $appended;
92
93
        return $this->set($name, $value);
94
    }
95
}
96