Completed
Push — master ( fac3c6...fac648 )
by Derek Stephen
01:52
created

HasAttributesTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 41
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttributes() 0 3 1
A setAttribute() 0 4 1
A getAttribute() 0 3 2
A setAttributes() 0 4 1
1
<?php
2
3
namespace Bone\Server\Traits;
4
5
trait HasAttributesTrait
6
{
7
    /** @var array $attributes */
8
    private $attributes = [];
9
10
    /**
11
     * @param $key
12
     * @return mixed|null
13
     */
14
    public function getAttribute($key, $default = null)
15
    {
16
        return $this->attributes[$key] ?: $default;
17
    }
18
19
    /**
20
     * @param string $key
21
     * @param $value
22
     * @return $this
23
     */
24
    public function setAttribute(string $key, $value)
25
    {
26
        $this->attributes[$key] = $value;
27
        return $this;
28
    }
29
30
    /**
31
     * @param array $attributes
32
     * @return $this
33
     */
34
    public function setAttributes(array $attributes)
35
    {
36
        $this->attributes = $attributes;
37
        return $this;
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function getAttributes()
44
    {
45
        return $this->attributes;
46
    }
47
}
48