SpansLinker   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 9
c 1
b 0
f 1
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A linkedCTX() 0 8 2
A rootCTX() 0 3 2
1
<?php
2
/**
3
 * Spans linker
4
 * User: moyo
5
 * Date: 01/03/2018
6
 * Time: 3:19 PM
7
 */
8
9
namespace Carno\Tracing\Utils;
10
11
use Carno\Coroutine\Context;
12
use Carno\Tracing\Chips\RootInitializer;
13
use Carno\Tracing\Contracts\Vars\CTX;
14
use OpenTracing\SpanContext;
15
16
trait SpansLinker
17
{
18
    use RootInitializer;
19
20
    /**
21
     * @param Context $context
22
     * @return SpanContext
23
     */
24
    protected function rootCTX(Context $context) : ?SpanContext
25
    {
26
        return $context->get(CTX::G_ROOT) ?: null;
27
    }
28
29
    /**
30
     * @param SpanContext $parent
31
     * @return SpanContext
32
     */
33
    private function linkedCTX(SpanContext $parent = null) : SpanContext
34
    {
35
        return
36
            $parent
37
                ? $parent
38
                    ->withBaggageItem(CTX::PARENT_SPAN_ID, $parent->getBaggageItem(CTX::SPAN_ID))
39
                    ->withBaggageItem(CTX::SPAN_ID, $this->newSpanID())
40
                : $this->newContext()
41
        ;
42
    }
43
}
44