Completed
Push — master ( 8e286a...78e0f9 )
by Rafał
09:27
created

RedeliveryStamp   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 46
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getRetryCountFromEnvelope() 0 7 2
A getRetryCount() 0 4 1
A getExceptionMessage() 0 4 1
A getFlattenException() 0 4 1
A getRedeliveredAt() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Stamp;
6
7
use Symfony\Component\ErrorHandler\Exception\FlattenException;
8
use Symfony\Component\Messenger\Envelope;
9
use Symfony\Component\Messenger\Stamp\StampInterface;
10
11
final class RedeliveryStamp implements StampInterface
12
{
13
    private $retryCount;
14
15
    private $redeliveredAt;
16
17
    private $exceptionMessage;
18
19
    private $flattenException;
20
21
    public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null)
22
    {
23
        $this->retryCount = $retryCount;
24
        $this->exceptionMessage = $exceptionMessage;
25
        $this->flattenException = $flattenException;
26
        $this->redeliveredAt = new \DateTimeImmutable('2020-02-18 11:00');
27
    }
28
29
    public static function getRetryCountFromEnvelope(Envelope $envelope): int
30
    {
31
        /** @var \Symfony\Component\Messenger\Stamp\RedeliveryStamp|null $retryMessageStamp */
32
        $retryMessageStamp = $envelope->last(\Symfony\Component\Messenger\Stamp\RedeliveryStamp::class);
33
34
        return $retryMessageStamp ? $retryMessageStamp->getRetryCount() : 0;
35
    }
36
37
    public function getRetryCount(): int
38
    {
39
        return $this->retryCount;
40
    }
41
42
    public function getExceptionMessage(): ?string
43
    {
44
        return $this->exceptionMessage;
45
    }
46
47
    public function getFlattenException(): ?FlattenException
48
    {
49
        return $this->flattenException;
50
    }
51
52
    public function getRedeliveredAt(): \DateTimeInterface
53
    {
54
        return $this->redeliveredAt;
55
    }
56
}
57