Completed
Pull Request — master (#11)
by Frank
07:25
created

EventStager::stage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace EventSauce\EventSourcing;
4
5
class EventStager
6
{
7
    /**
8
     * @var AggregateRootId
9
     */
10
    private $id;
11
12
    /**
13
     * @var AggregateRootRepository
14
     */
15
    private $repository;
16
17
    /**
18
     * @var AggregateRootTestCase
19
     */
20
    private $testCase;
21
22
    /**
23
     * @var InMemoryMessageRepository
24
     */
25
    private $messageRepository;
26
27 1
    public function __construct(AggregateRootId $id, InMemoryMessageRepository $messageRepository, AggregateRootRepository $repository, AggregateRootTestCase $testCase)
28
    {
29 1
        $this->id = $id;
30 1
        $this->repository = $repository;
31 1
        $this->testCase = $testCase;
32 1
        $this->messageRepository = $messageRepository;
33 1
    }
34
35
    /**
36
     * @return AggregateRootTestCase
37
     */
38 1
    public function stage(Event ... $events): AggregateRootTestCase
39
    {
40 1
        $this->repository->persistEvents($this->id, ... $events);
41 1
        $this->messageRepository->purgeLastCommit();
42
43 1
        return $this->testCase;
44
    }
45
}