SpanContext   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 10
c 2
b 1
f 0
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTraceId() 0 3 1
A restore() 0 3 1
A getSpanId() 0 3 1
A fork() 0 3 1
A __construct() 0 4 1
A generate() 0 3 1
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