Passed
Pull Request — master (#84)
by Frank
15:42 queued 05:42
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\AggregateRootId;
8
use EventSauce\EventSourcing\AggregateRootRepository;
9
use EventSauce\EventSourcing\InMemoryMessageRepository;
10
11
class EventStager
12
{
13
    /**
14
     * @var AggregateRootId
15
     */
16
    private $id;
17
18
    /**
19
     * @phpstan-var AggregateRootRepository<AggregateRoot>
20
     *
21
     * @var AggregateRootRepository
22
     */
23
    private $repository;
24
25
    /**
26
     * @var AggregateRootTestCase
27
     */
28
    private $testCase;
29
30
    /**
31
     * @var InMemoryMessageRepository
32
     */
33
    private $messageRepository;
34
35
    /**
36
     * @phpstan-param AggregateRootRepository<AggregateRoot> $repository
37
     */
38
    public function __construct(
39
        AggregateRootId $id,
40
        InMemoryMessageRepository $messageRepository,
41
        AggregateRootRepository $repository,
42
        AggregateRootTestCase $testCase
43
    ) {
44
        $this->id = $id;
45
        $this->repository = $repository;
46
        $this->testCase = $testCase;
47
        $this->messageRepository = $messageRepository;
48
    }
49
50
    public function stage(object ...$events): AggregateRootTestCase
51
    {
52
        $this->repository->persistEvents($this->id, count($events), ...$events);
53
        $this->messageRepository->purgeLastCommit();
54
55
        return $this->testCase;
56
    }
57
}
58