Test Failed
Pull Request — master (#1095)
by Aleksei
10:19
created

AttributedTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
c 0
b 0
f 0
dl 0
loc 39
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withAttribute() 0 5 1
A getAttribute() 0 3 1
A withoutAttribute() 0 5 1
A getAttributes() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Interceptors\Context;
6
7
/**
8
 * Provides a basic implementation of the {@see AttributedInterface}.
9
 */
10
trait AttributedTrait
11
{
12
    /** @var array<non-empty-string, mixed> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<non-empty-string, mixed> at position 2 could not be parsed: Unknown type name 'non-empty-string' at position 2 in array<non-empty-string, mixed>.
Loading history...
13
    private array $attributes = [];
14
15
    /**
16
     * @return array<non-empty-string, mixed> Attributes derived from the context.
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<non-empty-string, mixed> at position 2 could not be parsed: Unknown type name 'non-empty-string' at position 2 in array<non-empty-string, mixed>.
Loading history...
17
     */
18
    public function getAttributes(): array
19
    {
20
        return $this->attributes;
21
    }
22
23
    /**
24
     * @param non-empty-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
25
     */
26
    public function getAttribute(string $name, mixed $default = null): mixed
27
    {
28
        return $this->attributes[$name] ?? $default;
29
    }
30
31
    /**
32
     * @param non-empty-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
33
     */
34
    public function withAttribute(string $name, mixed $value): static
35
    {
36
        $clone = clone $this;
37
        $clone->attributes[$name] = $value;
38
        return $clone;
39
    }
40
41
    /**
42
     * @param non-empty-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
43
     */
44
    public function withoutAttribute(string $name): static
45
    {
46
        $clone = clone $this;
47
        unset($clone->attributes[$name]);
48
        return $clone;
49
    }
50
}
51