ScheduledMessage   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Test Coverage

Coverage 25.81%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 85
ccs 8
cts 31
cp 0.2581
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getStates() 0 8 1
A __construct() 0 6 1
A getState() 0 3 1
A getDispatchAt() 0 3 1
A resetErrors() 0 3 1
A setState() 0 5 1
A addError() 0 3 1
A getSerializedMessage() 0 3 1
A getId() 0 3 1
A getBus() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\MessageSchedulerBundle\Entity;
6
7
use DateTimeInterface;
8
use Ramsey\Uuid\Uuid;
9
use Webmozart\Assert\Assert;
10
11
class ScheduledMessage
12
{
13
    public const STATE_PENDING = 'pending';
14
15
    public const STATE_DISPATCHED = 'dispatched';
16
17
    public const STATE_PROCESSING = 'processing';
18
19
    public const STATE_FAILED = 'failed';
20
21
    public const STATE_SUCCESSFUL = 'successful';
22
23
    protected string $id;
24
25
    protected string $serializedMessage;
26
27
    protected DateTimeInterface $dispatchAt;
28
29
    protected ?string $bus;
30
31
    protected string $state = self::STATE_PENDING;
32
33
    protected array $errors = [];
34
35
    protected ?int $version = null;
36
37 1
    public function __construct(string $serializedMessage, DateTimeInterface $dispatchAt, string $bus = null)
38
    {
39 1
        $this->id = (string) Uuid::uuid4();
40 1
        $this->serializedMessage = $serializedMessage;
41 1
        $this->dispatchAt = $dispatchAt;
42 1
        $this->bus = $bus;
43 1
    }
44
45
    public static function getStates(): array
46
    {
47
        return [
48
            self::STATE_PENDING => self::STATE_PENDING,
49
            self::STATE_DISPATCHED => self::STATE_DISPATCHED,
50
            self::STATE_PROCESSING => self::STATE_PROCESSING,
51
            self::STATE_SUCCESSFUL => self::STATE_SUCCESSFUL,
52
            self::STATE_FAILED => self::STATE_FAILED,
53
        ];
54
    }
55
56 1
    public function getId(): string
57
    {
58 1
        return $this->id;
59
    }
60
61
    public function getSerializedMessage(): string
62
    {
63
        return $this->serializedMessage;
64
    }
65
66
    public function getDispatchAt(): DateTimeInterface
67
    {
68
        return $this->dispatchAt;
69
    }
70
71
    public function getBus(): ?string
72
    {
73
        return $this->bus;
74
    }
75
76
    public function getState(): string
77
    {
78
        return $this->state;
79
    }
80
81
    public function setState(string $state): void
82
    {
83
        Assert::oneOf($state, self::getStates());
84
85
        $this->state = $state;
86
    }
87
88
    public function addError(string $error): void
89
    {
90
        $this->errors[] = $error;
91
    }
92
93
    public function resetErrors(): void
94
    {
95
        $this->errors = [];
96
    }
97
}
98