DynamicPropertiesTrait::__unset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Nip\Utility\Traits;
4
5
/**
6
 * Class DynamicPropertiesTrait
7
 * @package Nip\Utility\Traits
8
 */
9
trait DynamicPropertiesTrait
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $properties = [];
15
16
    /**
17
     * @param $name
18
     * @return mixed
19
     */
20
    public function &__get($name)
21
    {
22
        if (!$this->__isset($name)) {
23
            $this->properties[$name] = null;
24
        }
25
        return $this->properties[$name];
26
    }
27
28
    /**
29
     * @param $name
30
     * @param $value
31
     */
32
    public function __set($name, $value)
33
    {
34
        $this->properties[$name] = $value;
35
    }
36
37
    /**
38
     * @param $key
39
     * @return bool
40
     */
41
    public function __isset($key)
42
    {
43
        return array_key_exists($key, $this->properties);
44
    }
45
46
    /**
47
     * Get an attribute from the container.
48
     *
49
     * @param  string $key
50
     * @param  mixed $default
51
     * @return mixed
52
     */
53
    public function get($key, $default = null)
54
    {
55
        if (isset($this->{$key})) {
56
            return $this->{$key};
57
        }
58
59
        return value($default);
60
    }
61
62
    /**
63
     * @param $name
64
     */
65
    public function __unset($name)
66
    {
67
        unset($this->properties[$name]);
68
    }
69
}
70