Completed
Push — dev-master ( 61317d...8c136d )
by Derek Stephen
29:12 queued 26:15
created

HasAttributesTrait::setAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Bone\Traits;
4
5
trait HasAttributesTrait
6
{
7
    /** @var array $attributes */
8
    private $attributes = [];
9
10
    /**
11
     * @param $key
12
     * @return mixed|null
13
     */
14 2
    public function getAttribute($key)
15 2
    {
16 2
        return isset($this->attributes[$key]) ? $this->attributes[$key] : null;
17
    }
18
19
    /**
20
     * @param string $key
21
     * @param $value
22
     * @return $this
23
     */
24 1
    public function setAttribute(string $key, $value)
25 1
    {
26 1
        $this->attributes[$key] = $value;
27 1
        return $this;
28
    }
29
30
    /**
31
     * @param array $attributes
32
     * @return $this
33
     */
34 20
    public function setAttributes(array $attributes)
35 20
    {
36 20
        $this->attributes = $attributes;
37 20
        return $this;
38
    }
39
40
    /**
41
     * @return array
42
     */
43 1
    public function getAttributes()
44 1
    {
45 1
        return $this->attributes;
46
    }
47
}
48