Total Complexity | 5 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
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() |
||
46 | } |
||
47 | } |
||
48 |