Passed
Pull Request — master (#84)
by Frank
14:06 queued 04:07
created

EventStager   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A stage() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\TestUtilities;
6
7
use EventSauce\EventSourcing\AggregateRoot;
8
use EventSauce\EventSourcing\AggregateRootId;
9
use EventSauce\EventSourcing\AggregateRootRepository;
10
use EventSauce\EventSourcing\InMemoryMessageRepository;
11
12
class EventStager
13
{
14
    /**
15
     * @var AggregateRootId
16
     */
17
    private $id;
18
19
    /**
20
     * @phpstan-var AggregateRootRepository<AggregateRoot>
21
     *
22
     * @var AggregateRootRepository
23
     */
24
    private $repository;
25
26
    /**
27
     * @var AggregateRootTestCase
28
     */
29
    private $testCase;
30
31
    /**
32
     * @var InMemoryMessageRepository
33
     */
34
    private $messageRepository;
35
36
    /**
37
     * @phpstan-param AggregateRootRepository<AggregateRoot> $repository
38
     */
39
    public function __construct(
40
        AggregateRootId $id,
41
        InMemoryMessageRepository $messageRepository,
42
        AggregateRootRepository $repository,
43
        AggregateRootTestCase $testCase
44
    ) {
45
        $this->id = $id;
46
        $this->repository = $repository;
47
        $this->testCase = $testCase;
48
        $this->messageRepository = $messageRepository;
49
    }
50
51
    public function stage(object ...$events): AggregateRootTestCase
52
    {
53
        $this->repository->persistEvents($this->id, count($events), ...$events);
54
        $this->messageRepository->purgeLastCommit();
55
56
        return $this->testCase;
57
    }
58
}
59