ServerMessage   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withAttribute() 0 4 1
A withoutAttribute() 0 9 2
A getAttribute() 0 7 2
A getAttributes() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace PTS\Psr7;
5
6
use function array_key_exists;
7
8
trait ServerMessage
9
{
10
    protected array $attributes = [];
11
12
    /**
13
     * @return array
14
     */
15 3
    public function getAttributes(): array
16
    {
17 3
        return $this->attributes;
18
    }
19
20
    /**
21
     * @param string $attribute
22
     * @param mixed $default
23
     *
24
     * @return mixed
25
     */
26 2
    public function getAttribute($attribute, $default = null)
27
    {
28 2
        if (false === array_key_exists($attribute, $this->attributes)) {
29 2
            return $default;
30
        }
31
32 2
        return $this->attributes[$attribute];
33
    }
34
35
    /**
36
     * @param string $attribute
37
     * @param mixed $value
38
     *
39
     * @return $this
40
     */
41 3
    public function withAttribute($attribute, $value)
42
    {
43 3
        $this->attributes[$attribute] = $value;
44 3
        return $this;
45
    }
46
47 2
    public function withoutAttribute($attribute)
48
    {
49 2
        if (false === array_key_exists($attribute, $this->attributes)) {
50 1
            return $this;
51
        }
52
53 2
        unset($this->attributes[$attribute]);
54
55 2
        return $this;
56
    }
57
}
58