Event::setAttributes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
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
nc 2
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
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