JobInjectionMaker   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A injectParentSpanToCommand() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Jaravel\Services\Job;
6
7
use OpenTelemetry\API\Trace\Propagation\TraceContextPropagator;
8
use Umbrellio\Jaravel\Middleware\JobTracingMiddleware;
9
10
class JobInjectionMaker
11
{
12
    private TraceContextPropagator $contextPropagator;
13
14
    public function __construct(TraceContextPropagator $contextPropagator)
15
    {
16
        $this->contextPropagator = $contextPropagator;
17
    }
18
19
    public function injectParentSpanToCommand(object $command): object
20
    {
21
        $tracingContextField = JobTracingMiddleware::JOB_TRACING_CONTEXT_FIELD;
22
23
        if (isset($command->{$tracingContextField})) {
24
            return $command;
25
        }
26
27
        $command->{$tracingContextField} = [];
28
        $this->contextPropagator->inject($command->{$tracingContextField});
29
30
        return $command;
31
    }
32
}
33