Passed
Push — master ( 4327b3...ee9427 )
by Derek Stephen
03:49
created

HasAttributesTrait::hasAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 2
    public function getAttribute(string $key, $default = null)
15
    {
16 2
        return $this->attributes[$key] ?: $default;
17
    }
18
19
    /**
20
     * @param string $key
21
     * @param $value
22
     */
23 1
    public function setAttribute(string $key, $value): void
24
    {
25 1
        $this->attributes[$key] = $value;
26 1
    }
27
28
    /**
29
     * @param array $attributes
30
     */
31 8
    public function setAttributes(array $attributes): void
32
    {
33 8
        $this->attributes = $attributes;
34 8
    }
35
36
    /**
37
     * @return array
38
     */
39 2
    public function getAttributes(): array
40
    {
41 2
        return $this->attributes;
42
    }
43
44
    /**
45
     * @param string $key
46
     * @return bool
47
     */
48 1
    public function hasAttribute(string $key): bool
49
    {
50 1
        return array_key_exists($key, $this->attributes);
51
    }
52
}
53