Test Failed
Pull Request — master (#816)
by butschster
06:47
created

Span   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 15
c 1
b 0
f 0
dl 0
loc 64
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAttributes() 0 3 1
A getAttribute() 0 3 1
A getName() 0 3 1
A setAttribute() 0 5 1
A setStatus() 0 5 1
A getStatus() 0 3 1
A hasAttribute() 0 3 1
A updateName() 0 5 1
A setAttributes() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Telemetry;
6
7
use Ramsey\Uuid\Uuid;
8
use Spiral\Telemetry\Span\Status;
9
10
/**
11
 * @internal
12
 */
13
final class Span implements SpanInterface
14
{
15
    private ?Status $status = null;
16
17
    /**
18
     * @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...
19
     */
20
    public function __construct(
21
        private string $name,
22
        private array $attributes = []
23
    ) {
24
    }
25
26
    public function getName(): string
27
    {
28
        return $this->name;
29
    }
30
31
    public function updateName(string $name): self
32
    {
33
        $this->name = $name;
34
35
        return $this;
36
    }
37
38
    public function getAttributes(): array
39
    {
40
        return $this->attributes;
41
    }
42
43
    public function setAttributes(array $attributes): self
44
    {
45
        $this->attributes = $attributes;
46
47
        return $this;
48
    }
49
50
    public function setAttribute(string $name, mixed $value): self
51
    {
52
        $this->attributes[$name] = $value;
53
54
        return $this;
55
    }
56
57
    public function hasAttribute(string $name): bool
58
    {
59
        return isset($this->attributes[$name]);
60
    }
61
62
    public function getAttribute(string $name): mixed
63
    {
64
        return $this->attributes[$name] ?? null;
65
    }
66
67
    public function setStatus(string|int $code, string $description = null): self
68
    {
69
        $this->status = new Status($code, $description);
70
71
        return $this;
72
    }
73
74
    public function getStatus(): ?Status
75
    {
76
        return $this->status;
77
    }
78
}
79