ServerMessage::withoutAttribute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
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