Event   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 21
c 3
b 1
f 0
dl 0
loc 52
ccs 25
cts 25
cp 1
rs 10
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getAttribute() 0 6 2
A getAttributes() 0 3 1
A setAttribute() 0 4 1
A setAttributes() 0 7 2
A __construct() 0 8 2
A getTimestamp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OpenTelemetry\Tracing;
6
7
class Event
8
{
9
    private $name;
10
    private $timestamp;
11
    private $attributes = [];
12
13 4
    public function __construct(string $name, array $attributes = [], $timestamp = null)
14
    {
15 4
        if ($timestamp === null) {
16 4
            $timestamp = microtime(true);
17
        }
18 4
        $this->name = $name;
19 4
        $this->timestamp = $timestamp;
20 4
        $this->setAttributes($attributes);
21 4
    }
22
23 2
    public function getAttribute(string $key)
24
    {
25 2
        if (!array_key_exists($key, $this->attributes)) {
26 1
            return null;
27
        }
28 2
        return $this->attributes[$key];
29
    }
30
31 4
    public function setAttribute(string $key, $value): self
32
    {
33 4
        $this->attributes[$key] = $value;
34 4
        return $this;
35
    }
36
37 2
    public function getAttributes(): array
38
    {
39 2
        return $this->attributes;
40
    }
41
42 4
    public function setAttributes(array $attributes): self
43
    {
44 4
        $this->attributes = [];
45 4
        foreach ($attributes as $k => $v) {
46 4
            $this->setAttribute($k, $v);
47
        }
48 4
        return $this;
49
    }
50
51 4
    public function getName(): string
52
    {
53 4
        return $this->name;
54
    }
55
56 2
    public function getTimestamp(): float
57
    {
58 2
        return $this->timestamp;
59
    }
60
}
61