TraceIdProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setTraceId() 0 3 1
A __invoke() 0 4 1
A getTraceId() 0 8 2
1
<?php
2
3
namespace Arquivei\LogAdapter\Processors;
4
5
use Arquivei\LogAdapter\OpenCensusHelper;
6
use Monolog\Processor\ProcessorInterface;
7
8
class TraceIdProcessor implements ProcessorInterface
9
{
10
    private ?string $traceId = null;
11
12
    public function __invoke(array $records): array
13
    {
14
        $records['trace_id'] = $this->getTraceId();
15
        return $records;
16
    }
17
18
    private function getTraceId(): string
19
    {
20
        if ($this->traceId !== null) {
21
            return $this->traceId;
22
        }
23
24
        $this->traceId = OpenCensusHelper::traceId();
25
        return $this->traceId;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->traceId returns the type null which is incompatible with the type-hinted return string.
Loading history...
26
    }
27
28
    public function setTraceId(?string $traceId): void
29
    {
30
        $this->traceId = $traceId;
31
    }
32
}
33