HasAttributesTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAttribute() 0 3 2
A getAttributes() 0 3 1
A setAttribute() 0 3 1
A hasAttribute() 0 3 1
A setAttributes() 0 3 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 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