Skip to content

Commit 10f16fb

Browse files
committed
ISSUE-345: message setters
1 parent fba5aa9 commit 10f16fb

File tree

8 files changed

+155
-55
lines changed

8 files changed

+155
-55
lines changed

Diff for: src/Domain/Model/Messaging/Message.php

+6
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public function getOwner(): ?Administrator
107107
return $this->owner;
108108
}
109109

110+
public function setOwner(?Administrator $owner): self
111+
{
112+
$this->owner = $owner;
113+
return $this;
114+
}
115+
110116
public function getTemplate(): ?Template
111117
{
112118
return $this->template;

Diff for: src/Domain/Model/Messaging/Message/MessageContent.php

+12
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,20 @@ public function getTextMessage(): ?string
6060
return $this->textMessage;
6161
}
6262

63+
public function setTextMessage(?string $textMessage): self
64+
{
65+
$this->textMessage = $textMessage;
66+
return $this;
67+
}
68+
6369
public function getFooter(): ?string
6470
{
6571
return $this->footer;
6672
}
73+
74+
public function setFooter(?string $footer): self
75+
{
76+
$this->footer = $footer;
77+
return $this;
78+
}
6779
}

Diff for: src/Domain/Model/Messaging/Message/MessageFormat.php

+30-38
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,31 @@ public function __construct(
4343
$this->htmlFormatted = $htmlFormatted;
4444
$this->sendFormat = $sendFormat;
4545

46-
foreach ($formatOptions as $option) {
47-
match ($option) {
48-
self::FORMAT_TEXT => $this->asText = true,
49-
self::FORMAT_HTML => $this->asHtml = true,
50-
self::FORMAT_PDF => $this->asPdf = true,
51-
default => throw new InvalidArgumentException('Invalid format option: ' . $option)
52-
};
53-
}
54-
55-
$this->asTextAndHtml = $this->asText && $this->asHtml;
56-
$this->asTextAndPdf = $this->asText && $this->asPdf;
46+
$this->setFormatOptions($formatOptions);
5747
}
5848

5949
public function isHtmlFormatted(): bool
6050
{
6151
return $this->htmlFormatted;
6252
}
6353

54+
public function setHtmlFormatted(bool $htmlFormatted): self
55+
{
56+
$this->htmlFormatted = $htmlFormatted;
57+
return $this;
58+
}
59+
6460
public function getSendFormat(): ?string
6561
{
6662
return $this->sendFormat;
6763
}
6864

65+
public function setSendFormat(?string $sendFormat): self
66+
{
67+
$this->sendFormat = $sendFormat;
68+
return $this;
69+
}
70+
6971
public function isAsText(): bool
7072
{
7173
return $this->asText;
@@ -91,39 +93,29 @@ public function isAsTextAndPdf(): bool
9193
return $this->asTextAndPdf;
9294
}
9395

94-
public function setSendFormat(?string $sendFormat): self
96+
public function getFormatOptions(): array
9597
{
96-
$this->sendFormat = $sendFormat;
97-
return $this;
98+
return array_values(array_filter([
99+
$this->asText ? self::FORMAT_TEXT : null,
100+
$this->asHtml ? self::FORMAT_HTML : null,
101+
$this->asPdf ? self::FORMAT_PDF : null,
102+
]));
98103
}
99104

100-
public function setAsText(bool $asText): self
105+
public function setFormatOptions(array $formatOptions): self
101106
{
102-
$this->asText = $asText;
103-
return $this;
104-
}
105-
106-
public function setAsHtml(bool $asHtml): self
107-
{
108-
$this->asHtml = $asHtml;
109-
return $this;
110-
}
111-
112-
public function setAsPdf(bool $asPdf): self
113-
{
114-
$this->asPdf = $asPdf;
115-
return $this;
116-
}
107+
foreach ($formatOptions as $option) {
108+
match ($option) {
109+
self::FORMAT_TEXT => $this->asText = true,
110+
self::FORMAT_HTML => $this->asHtml = true,
111+
self::FORMAT_PDF => $this->asPdf = true,
112+
default => throw new InvalidArgumentException('Invalid format option: ' . $option)
113+
};
114+
}
117115

118-
public function setAsTextAndHtml(bool $asTextAndHtml): self
119-
{
120-
$this->asTextAndHtml = $asTextAndHtml;
121-
return $this;
122-
}
116+
$this->asTextAndHtml = $this->asText && $this->asHtml;
117+
$this->asTextAndPdf = $this->asText && $this->asPdf;
123118

124-
public function setAsTextAndPdf(bool $asTextAndPdf): self
125-
{
126-
$this->asTextAndPdf = $asTextAndPdf;
127119
return $this;
128120
}
129121
}

Diff for: src/Domain/Model/Messaging/Message/MessageMetadata.php

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public function getStatus(): ?string
4747
return $this->status;
4848
}
4949

50+
public function setStatus(string $status): self
51+
{
52+
$this->status = $status;
53+
return $this;
54+
}
55+
5056
public function isProcessed(): bool
5157
{
5258
return $this->processed;
@@ -83,4 +89,22 @@ public function getSent(): ?DateTime
8389
{
8490
return $this->sent;
8591
}
92+
93+
public function setBounceCount(int $bounceCount): self
94+
{
95+
$this->bounceCount = $bounceCount;
96+
return $this;
97+
}
98+
99+
public function setEntered(?DateTime $entered): self
100+
{
101+
$this->entered = $entered;
102+
return $this;
103+
}
104+
105+
public function setSent(?DateTime $sent): self
106+
{
107+
$this->sent = $sent;
108+
return $this;
109+
}
86110
}

Diff for: src/Domain/Model/Messaging/Message/MessageOptions.php

+36-10
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class MessageOptions
1919
#[ORM\Column(name: 'replyto', type: 'string', length: 255, nullable: false, options: ['default' => ''])]
2020
private string $replyTo;
2121

22-
#[ORM\Column(type: 'datetime', nullable: true)]
23-
private ?DateTime $embargo;
24-
2522
#[ORM\Column(name: 'userselection', type: 'text', nullable: true)]
2623
private ?string $userSelection;
2724

@@ -35,15 +32,13 @@ public function __construct(
3532
string $fromField = '',
3633
string $toField = '',
3734
string $replyTo = '',
38-
?DateTime $embargo = null,
3935
?string $userSelection = null,
4036
?DateTime $sendStart = null,
4137
?string $rssTemplate = null
4238
) {
4339
$this->fromField = $fromField;
4440
$this->toField = $toField;
4541
$this->replyTo = $replyTo;
46-
$this->embargo = $embargo;
4742
$this->userSelection = $userSelection;
4843
$this->sendStart = $sendStart;
4944
$this->rssTemplate = $rssTemplate;
@@ -64,11 +59,6 @@ public function getReplyTo(): string
6459
return $this->replyTo;
6560
}
6661

67-
public function getEmbargo(): ?DateTime
68-
{
69-
return $this->embargo;
70-
}
71-
7262
public function getUserSelection(): ?string
7363
{
7464
return $this->userSelection;
@@ -83,4 +73,40 @@ public function getRssTemplate(): ?string
8373
{
8474
return $this->rssTemplate;
8575
}
76+
77+
public function setFromField(string $fromField): self
78+
{
79+
$this->fromField = $fromField;
80+
return $this;
81+
}
82+
83+
public function setToField(string $toField): self
84+
{
85+
$this->toField = $toField;
86+
return $this;
87+
}
88+
89+
public function setReplyTo(string $replyTo): self
90+
{
91+
$this->replyTo = $replyTo;
92+
return $this;
93+
}
94+
95+
public function setUserSelection(?string $userSelection): self
96+
{
97+
$this->userSelection = $userSelection;
98+
return $this;
99+
}
100+
101+
public function setSendStart(?DateTime $sendStart): self
102+
{
103+
$this->sendStart = $sendStart;
104+
return $this;
105+
}
106+
107+
public function setRssTemplate(?string $rssTemplate): self
108+
{
109+
$this->rssTemplate = $rssTemplate;
110+
return $this;
111+
}
86112
}

Diff for: src/Domain/Model/Messaging/Message/MessageSchedule.php

+41-1
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ class MessageSchedule
2222
#[ORM\Column(name: 'requeueuntil', type: 'datetime', nullable: true)]
2323
private ?DateTime $requeueUntil;
2424

25+
#[ORM\Column(type: 'datetime', nullable: true)]
26+
private ?DateTime $embargo;
27+
2528
public function __construct(
2629
?int $repeatInterval,
2730
?DateTime $repeatUntil,
2831
?int $requeueInterval,
29-
?DateTime $requeueUntil
32+
?DateTime $requeueUntil,
33+
?DateTime $embargo
3034
) {
3135
$this->repeatInterval = $repeatInterval;
3236
$this->repeatUntil = $repeatUntil;
3337
$this->requeueInterval = $requeueInterval;
3438
$this->requeueUntil = $requeueUntil;
39+
$this->embargo = $embargo;
3540
}
3641

3742
public function getRepeatInterval(): ?int
@@ -53,4 +58,39 @@ public function getRequeueUntil(): ?DateTime
5358
{
5459
return $this->requeueUntil;
5560
}
61+
62+
public function getEmbargo(): ?DateTime
63+
{
64+
return $this->embargo;
65+
}
66+
67+
public function setRepeatInterval(?int $repeatInterval): self
68+
{
69+
$this->repeatInterval = $repeatInterval;
70+
return $this;
71+
}
72+
73+
public function setRepeatUntil(?DateTime $repeatUntil): self
74+
{
75+
$this->repeatUntil = $repeatUntil;
76+
return $this;
77+
}
78+
79+
public function setRequeueInterval(?int $requeueInterval): self
80+
{
81+
$this->requeueInterval = $requeueInterval;
82+
return $this;
83+
}
84+
85+
public function setRequeueUntil(?DateTime $requeueUntil): self
86+
{
87+
$this->requeueUntil = $requeueUntil;
88+
return $this;
89+
}
90+
91+
public function setEmbargo(?DateTime $embargo): self
92+
{
93+
$this->embargo = $embargo;
94+
return $this;
95+
}
5696
}

Diff for: tests/Integration/Domain/Repository/Messaging/MessageRepositoryTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testMessageIsPersistedAndFetchedCorrectly(): void
4747

4848
$message = new Message(
4949
new MessageFormat(true, 'text'),
50-
new MessageSchedule(1, null, 3, null),
50+
new MessageSchedule(1, null, 3, null, null),
5151
new MessageMetadata('done'),
5252
new MessageContent('Hello world!'),
5353
new MessageOptions(),
@@ -76,7 +76,7 @@ public function testGetByOwnerIdReturnsOnlyOwnedMessages(): void
7676

7777
$msg1 = new Message(
7878
new MessageFormat(true, MessageFormat::FORMAT_TEXT),
79-
new MessageSchedule(1, null, 3, null),
79+
new MessageSchedule(1, null, 3, null, null),
8080
new MessageMetadata('done'),
8181
new MessageContent('Owned by Admin 1!'),
8282
new MessageOptions(),
@@ -85,7 +85,7 @@ public function testGetByOwnerIdReturnsOnlyOwnedMessages(): void
8585

8686
$msg2 = new Message(
8787
new MessageFormat(true, MessageFormat::FORMAT_TEXT),
88-
new MessageSchedule(1, null, 3, null),
88+
new MessageSchedule(1, null, 3, null, null),
8989
new MessageMetadata(null),
9090
new MessageContent('Owned by Admin 2!'),
9191
new MessageOptions(),
@@ -94,7 +94,7 @@ public function testGetByOwnerIdReturnsOnlyOwnedMessages(): void
9494

9595
$msg3 = new Message(
9696
new MessageFormat(true, MessageFormat::FORMAT_TEXT),
97-
new MessageSchedule(1, null, 3, null),
97+
new MessageSchedule(1, null, 3, null, null),
9898
new MessageMetadata(null),
9999
new MessageContent('Hello world!'),
100100
new MessageOptions(),
@@ -119,7 +119,7 @@ public function testMessageTimestampsAreSetOnPersist(): void
119119

120120
$message = new Message(
121121
new MessageFormat(true, MessageFormat::FORMAT_TEXT),
122-
new MessageSchedule(1, null, 3, null),
122+
new MessageSchedule(1, null, 3, null, null),
123123
new MessageMetadata(null),
124124
new MessageContent('Hello world!'),
125125
new MessageOptions(),

Diff for: tests/Unit/Domain/Model/Messaging/MessageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MessageTest extends TestCase
3030
protected function setUp(): void
3131
{
3232
$this->format = new MessageFormat(true, MessageFormat::FORMAT_TEXT);
33-
$this->schedule = new MessageSchedule(1, new DateTime(), 2, new DateTime());
33+
$this->schedule = new MessageSchedule(1, new DateTime(), 2, new DateTime(), null);
3434
$this->metadata = new MessageMetadata();
3535
$this->content = new MessageContent('This is the body');
3636
$this->options = new MessageOptions();

0 commit comments

Comments
 (0)