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

Event::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 8
ccs 6
cts 6
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 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
}