Passed
Push — master ( a7d12b...46dbe8 )
by Dmitry
03:07
created

Event::getTimestamp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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 3
    public function __construct(string $name, array $attributes = [], $timestamp = null)
14
    {
15 3
        if (is_null($timestamp)) {
16 3
            $timestamp = microtime(true);
17
        }
18 3
        $this->name = $name;
19 3
        $this->timestamp = $timestamp;
20 3
        $this->setAttributes($attributes);
21 3
    }
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 3
    public function setAttribute(string $key, $value) : self
32
    {
33 3
        $this->attributes[$key] = $value;
34 3
        return $this;
35
    }
36
37 1
    public function getAttributes() : array
38
    {
39 1
        return $this->attributes;
40
    }
41
42 3
    public function setAttributes(array $attributes) : self
43
    {
44 3
        $this->attributes = [];
45 3
        foreach ($attributes as $k => $v) {
46 3
            $this->setAttribute($k, $v);
47
        }
48 3
        return $this;
49
    }
50
51 3
    public function getName() : string
52
    {
53 3
        return $this->name;
54
    }
55
56 1
    public function getTimestamp() : float
57
    {
58 1
        return $this->timestamp;
59
    }
60
}