DefaultHeadersDecorator::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 0
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
use EventSauce\Clock\Clock;
8
use EventSauce\Clock\SystemClock;
9
10
class DefaultHeadersDecorator implements MessageDecorator
11
{
12
    private ClassNameInflector $inflector;
13
    private Clock $clock;
14
15
    public function __construct(ClassNameInflector $inflector = null, Clock $clock = null)
16
    {
17
        $this->inflector = $inflector ?: new DotSeparatedSnakeCaseInflector();
18
        $this->clock = $clock ?: new SystemClock();
19
    }
20
21
    public function decorate(Message $message): Message
22 22
    {
23
        return $message->withHeader(
24 22
            Header::EVENT_TYPE,
25 22
            $this->inflector->instanceToType($message->event())
26 22
        )->withTimeOfRecording($this->clock->now());
27
    }
28
}
29