SpansLinker::rootCTX()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 2
nc 1
nop 1
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