DefaultHeadersDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 17
ccs 4
cts 4
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 3
A decorate() 0 6 1
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