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

HasAttributesTrait::getAttribute()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
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