SpanContext::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OpenTelemetry\Tracing;
6
7
class SpanContext
8
{
9
    private $traceId;
10
    private $spanId;
11
12 13
    public static function generate()
13
    {
14 13
        return self::fork(bin2hex(random_bytes(16)));
15
    }
16
17 13
    public static function fork(string $traceId)
18
    {
19 13
        return self::restore($traceId, bin2hex(random_bytes(8)));
20
    }
21
22 13
    public static function restore(string $traceId, string $spanId)
23
    {
24 13
        return new self($traceId, $spanId);
25
    }
26
27 13
    public function __construct(string $traceId, string $spanId)
28
    {
29 13
        $this->traceId = $traceId;
30 13
        $this->spanId = $spanId;
31 13
    }
32
33 11
    public function getTraceId(): string
34
    {
35 11
        return $this->traceId;
36
    }
37
38 5
    public function getSpanId(): string
39
    {
40 5
        return $this->spanId;
41
    }
42
}
43