Skip to content

Commit 58af3e1

Browse files
[Notifier] Bring consistency to bridges
1 parent 7ff95e4 commit 58af3e1

File tree

3 files changed

+82
-162
lines changed

3 files changed

+82
-162
lines changed

MessageBirdOptions.php

Lines changed: 58 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -25,168 +25,125 @@ public function __construct(array $options = [])
2525
$this->options = $options;
2626
}
2727

28-
public function getCreatedDatetime(): ?string
29-
{
30-
return $this->options['created_datetime'] ?? null;
31-
}
32-
33-
public function getDataCoding(): ?string
34-
{
35-
return $this->options['data_coding'] ?? null;
36-
}
37-
38-
public function getFrom(): ?string
39-
{
40-
return $this->options['from'] ?? null;
41-
}
42-
43-
public function getGateway(): ?int
44-
{
45-
return $this->options['gateway'] ?? null;
46-
}
47-
48-
public function getGroupIds(): ?array
49-
{
50-
return $this->options['group_ids'] ?? null;
51-
}
52-
53-
public function getMClass(): ?int
54-
{
55-
return $this->options['m_class'] ?? null;
56-
}
57-
5828
public function getRecipientId(): ?string
5929
{
60-
return $this->options['recipient_id'] ?? null;
61-
}
62-
63-
public function getReference(): ?string
64-
{
65-
return $this->options['reference'] ?? null;
66-
}
67-
68-
public function getReportUrl(): ?string
69-
{
70-
return $this->options['report_url'] ?? null;
71-
}
72-
73-
public function getScheduledDatetime(): ?string
74-
{
75-
return $this->options['scheduled_datetime'] ?? null;
30+
return null;
7631
}
7732

78-
public function getShortenUrls(): ?bool
33+
/**
34+
* @return $this
35+
*/
36+
public function createdDatetime(string $createdDatetime): static
7937
{
80-
return $this->options['shorten_urls'] ?? null;
81-
}
82-
83-
public function getType(): ?string
84-
{
85-
return $this->options['type'] ?? null;
86-
}
87-
88-
public function getTypeDetails(): ?string
89-
{
90-
return $this->options['type_details'] ?? null;
91-
}
92-
93-
public function getValidity(): ?int
94-
{
95-
return $this->options['validity'] ?? null;
96-
}
97-
98-
public function setCreatedDatetime(string $createdDatetime): self
99-
{
100-
$this->options['created_datetime'] = $createdDatetime;
101-
102-
return $this;
103-
}
104-
105-
public function setDataCoding(string $dataCoding): self
106-
{
107-
$this->options['data_coding'] = $dataCoding;
38+
$this->options['createdDatetime'] = $createdDatetime;
10839

10940
return $this;
11041
}
11142

112-
public function setFrom(string $from): self
43+
/**
44+
* @return $this
45+
*/
46+
public function dataCoding(string $dataCoding): static
11347
{
114-
$this->options['from'] = $from;
48+
$this->options['dataCoding'] = $dataCoding;
11549

11650
return $this;
11751
}
11852

119-
public function setGateway(int $gateway): self
53+
/**
54+
* @return $this
55+
*/
56+
public function gateway(int $gateway): static
12057
{
12158
$this->options['gateway'] = $gateway;
12259

12360
return $this;
12461
}
12562

126-
public function setGroupIds(array $groupIds): self
63+
/**
64+
* @return $this
65+
*/
66+
public function groupIds(array $groupIds): static
12767
{
128-
$this->options['group_ids'] = $groupIds;
68+
$this->options['groupIds'] = $groupIds;
12969

13070
return $this;
13171
}
13272

133-
public function setMClass(int $mClass): self
73+
/**
74+
* @return $this
75+
*/
76+
public function mClass(int $mClass): static
13477
{
135-
$this->options['m_class'] = $mClass;
78+
$this->options['mClass'] = $mClass;
13679

13780
return $this;
13881
}
13982

140-
public function setRecipientId(string $id): self
141-
{
142-
$this->options['recipient_id'] = $id;
143-
144-
return $this;
145-
}
146-
147-
public function setReference(string $reference): self
83+
/**
84+
* @return $this
85+
*/
86+
public function reference(string $reference): static
14887
{
14988
$this->options['reference'] = $reference;
15089

15190
return $this;
15291
}
15392

154-
public function setReportUrl(string $reportUrl): self
93+
/**
94+
* @return $this
95+
*/
96+
public function reportUrl(string $reportUrl): static
15597
{
156-
$this->options['report_url'] = $reportUrl;
98+
$this->options['reportUrl'] = $reportUrl;
15799

158100
return $this;
159101
}
160102

161-
public function setScheduledDatetime(string $scheduledDatetime): self
103+
/**
104+
* @return $this
105+
*/
106+
public function scheduledDatetime(string $scheduledDatetime): static
162107
{
163-
$this->options['scheduled_datetime'] = $scheduledDatetime;
108+
$this->options['scheduledDatetime'] = $scheduledDatetime;
164109

165110
return $this;
166111
}
167112

168-
public function setShortenUrls(bool $shortenUrls): self
113+
/**
114+
* @return $this
115+
*/
116+
public function shortenUrls(bool $shortenUrls): static
169117
{
170-
$this->options['shorten_urls'] = $shortenUrls;
118+
$this->options['shortenUrls'] = $shortenUrls;
171119

172120
return $this;
173121
}
174122

175-
public function setType(string $type): self
123+
/**
124+
* @return $this
125+
*/
126+
public function type(string $type): static
176127
{
177128
$this->options['type'] = $type;
178129

179130
return $this;
180131
}
181132

182-
public function setTypeDetails(string $typeDetails): self
133+
/**
134+
* @return $this
135+
*/
136+
public function typeDetails(string $typeDetails): static
183137
{
184-
$this->options['type_details'] = $typeDetails;
138+
$this->options['typeDetails'] = $typeDetails;
185139

186140
return $this;
187141
}
188142

189-
public function setValidity(int $validity): self
143+
/**
144+
* @return $this
145+
*/
146+
public function validity(int $validity): static
190147
{
191148
$this->options['validity'] = $validity;
192149

@@ -195,11 +152,6 @@ public function setValidity(int $validity): self
195152

196153
public function toArray(): array
197154
{
198-
$options = $this->options;
199-
if (isset($options['recipient_id'])) {
200-
unset($options['recipient_id']);
201-
}
202-
203-
return $options;
155+
return $this->options;
204156
}
205157
}

MessageBirdTransport.php

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,57 +55,14 @@ protected function doSend(MessageInterface $message): SentMessage
5555
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
5656
}
5757

58-
$from = $message->getFrom() ?: $this->from;
59-
60-
$opts = $message->getOptions();
61-
$options = $opts ? $opts->toArray() : [];
62-
$options['originator'] = $options['from'] ?? $from;
58+
$options = $message->getOptions()?->toArray() ?? [];
59+
$options['originator'] = $message->getFrom() ?: $this->from;
6360
$options['recipients'] = [$message->getPhone()];
6461
$options['body'] = $message->getSubject();
6562

66-
if (isset($options['group_ids'])) {
67-
$options['groupIds'] = $options['group_ids'];
68-
unset($options['group_ids']);
69-
}
70-
71-
if (isset($options['report_url'])) {
72-
$options['reportUrl'] = $options['report_url'];
73-
unset($options['report_url']);
74-
}
75-
76-
if (isset($options['type_details'])) {
77-
$options['typeDetails'] = $options['type_details'];
78-
unset($options['type_details']);
79-
}
80-
81-
if (isset($options['data_coding'])) {
82-
$options['datacoding'] = $options['data_coding'];
83-
unset($options['data_coding']);
84-
}
85-
86-
if (isset($options['m_class'])) {
87-
$options['mclass'] = $options['m_class'];
88-
unset($options['m_class']);
89-
}
90-
91-
if (isset($options['shorten_urls'])) {
92-
$options['shortenUrls'] = $options['shorten_urls'];
93-
unset($options['shorten_urls']);
94-
}
95-
96-
if (isset($options['scheduled_datetime'])) {
97-
$options['scheduledDatetime'] = $options['scheduled_datetime'];
98-
unset($options['scheduled_datetime']);
99-
}
100-
101-
if (isset($options['created_datetime'])) {
102-
$options['createdDatetime'] = $options['created_datetime'];
103-
unset($options['created_datetime']);
104-
}
105-
10663
$endpoint = sprintf('https://%s/messages', $this->getEndpoint());
10764
$response = $this->client->request('POST', $endpoint, [
108-
'auth_basic' => 'AccessKey:'.$this->token,
65+
'auth_basic' => ['AccessKey', $this->token],
10966
'body' => array_filter($options),
11067
]);
11168

Tests/MessageBirdOptionsTest.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,32 @@ class MessageBirdOptionsTest extends TestCase
1818
{
1919
public function testMessageBirdOptions()
2020
{
21-
$messageBirdOptions = (new MessageBirdOptions())->setFrom('test_from')->setType('test_type')->setScheduledDatetime('test_scheduled_datetime')->setCreatedDatetime('test_created_datetime')->setRecipientId('test_recipient')->setDataCoding('test_data_coding')->setGateway(999)->setGroupIds(['test_group_ids'])->setMClass(888)->setReference('test_reference')->setReportUrl('test_report_url')->setShortenUrls(true)->setTypeDetails('test_type_details')->setValidity(777);
21+
$messageBirdOptions = (new MessageBirdOptions())
22+
->type('test_type')
23+
->scheduledDatetime('test_scheduled_datetime')
24+
->createdDatetime('test_created_datetime')
25+
->dataCoding('test_data_coding')
26+
->gateway(999)
27+
->groupIds(['test_group_ids'])
28+
->mClass(888)
29+
->reference('test_reference')
30+
->reportUrl('test_report_url')
31+
->shortenUrls(true)
32+
->typeDetails('test_type_details')
33+
->validity(777);
2234

2335
self::assertSame([
24-
'from' => 'test_from',
2536
'type' => 'test_type',
26-
'scheduled_datetime' => 'test_scheduled_datetime',
27-
'created_datetime' => 'test_created_datetime',
28-
'data_coding' => 'test_data_coding',
37+
'scheduledDatetime' => 'test_scheduled_datetime',
38+
'createdDatetime' => 'test_created_datetime',
39+
'dataCoding' => 'test_data_coding',
2940
'gateway' => 999,
30-
'group_ids' => ['test_group_ids'],
31-
'm_class' => 888,
41+
'groupIds' => ['test_group_ids'],
42+
'mClass' => 888,
3243
'reference' => 'test_reference',
33-
'report_url' => 'test_report_url',
34-
'shorten_urls' => true,
35-
'type_details' => 'test_type_details',
44+
'reportUrl' => 'test_report_url',
45+
'shortenUrls' => true,
46+
'typeDetails' => 'test_type_details',
3647
'validity' => 777,
3748
], $messageBirdOptions->toArray());
3849
}

0 commit comments

Comments
 (0)