DefaultMetadataFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 26
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A factoryEventMetadata() 0 10 2
1
<?php
2
/**
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>
4
 */
5
6
namespace Gica\Cqrs\Event\MetadataFactory;
7
8
9
use Gica\Cqrs\Command\CommandDispatcher\AuthenticatedIdentityReaderService;
10
use Gica\Cqrs\Command\CommandWithMetadata;
11
use Gica\Cqrs\Event\MetaData;
12
use Gica\Cqrs\Event\MetadataFactory;
13
14
class DefaultMetadataFactory implements MetadataFactory
15
{
16
17
    /**
18
     * @var AuthenticatedIdentityReaderService
19
     */
20
    private $identityReaderService;
21
22 9
    public function __construct(
23
        ?AuthenticatedIdentityReaderService $identityReaderService = null
24
    )
25
    {
26 9
        $this->identityReaderService = $identityReaderService;
27 9
    }
28
29 9
    public function factoryEventMetadata(CommandWithMetadata $command, $aggregate): MetaData
30
    {
31 9
        return new MetaData(
32 9
            $command->getCommand()->getAggregateId(),
33 9
            get_class($aggregate),
34 9
            new \DateTimeImmutable(),
35 9
            $this->identityReaderService ? $this->identityReaderService->getAuthenticatedIdentityId() : null,
36 9
            $command->getMetadata()
37
        );
38
    }
39
}