Passed
Pull Request — master (#84)
by Frank
02:23
created

TestedMessageConsumer::numberOfMessagesProcessed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing\TestUtilities\TestingMessageConsumers;
6
7
use EventSauce\EventSourcing\Message;
8
use EventSauce\EventSourcing\MessageConsumer;
9
use LogicException;
10
11
class TestedMessageConsumer implements MessageConsumer
12
{
13
    /**
14
     * @var int
15
     */
16
    private $failAfterNumberOfMessages;
17
18
    /**
19
     * @var int
20
     */
21
    private $numberOfMessagesProcessed = 0;
22
23 4
    public function __construct(int $failAfterNumberOfMessages)
24
    {
25 4
        $this->failAfterNumberOfMessages = $failAfterNumberOfMessages;
26 4
    }
27
28 4
    public function handle(Message $message): void
29
    {
30 4
        if (++$this->numberOfMessagesProcessed === $this->failAfterNumberOfMessages) {
31 3
            throw new LogicException('Too many messages');
32
        }
33 4
    }
34
35 1
    public function numberOfMessagesProcessed(): int
36
    {
37 1
        return $this->numberOfMessagesProcessed;
38
    }
39
}
40