Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

Commit bddf1ef

Browse files
committed
refactor: public properties and methods naming
1 parent f446aea commit bddf1ef

4 files changed

+87
-155
lines changed

src/SendinblueEmailMessage.php

+62-94
Original file line numberDiff line numberDiff line change
@@ -6,157 +6,125 @@
66

77
final class SendinblueEmailMessage
88
{
9-
protected array $sender = [];
10-
protected array $to = [];
11-
protected int $templateId;
12-
protected ?string $subject = null;
13-
protected ?array $attachment = null;
14-
protected ?array $bcc = null;
15-
protected ?array $cc = null;
16-
protected ?string $htmlContent = null;
17-
protected ?string $textContent = null;
18-
protected ?array $replyTo = null;
19-
protected ?array $headers = null;
20-
protected ?array $params = null;
21-
22-
public function getSender(): array
23-
{
24-
return $this->sender;
25-
}
26-
27-
public function setSender(array $sender): SendinblueEmailMessage
28-
{
29-
$this->sender = $sender;
9+
public array $from = [];
10+
public array $to = [];
11+
public array $attachment = [];
12+
public array $bcc = [];
13+
public array $cc = [];
14+
public int $templateId;
15+
public ?string $subject = null;
16+
public ?string $htmlContent = null;
17+
public ?string $textContent = null;
18+
public ?array $replyTo = null;
19+
public ?array $headers = null;
20+
public ?array $params = null;
21+
22+
public function from(array $from): SendinblueEmailMessage
23+
{
24+
$this->from = $from;
3025

3126
return $this;
3227
}
3328

34-
public function getTo(): array
35-
{
36-
return $this->to;
37-
}
38-
39-
public function setTo(array $to): SendinblueEmailMessage
29+
public function to($name, $email = null): SendinblueEmailMessage
4030
{
41-
$this->to[] = $to;
31+
if (is_array($name)) {
32+
$this->to = $name;
33+
} else {
34+
$this->to[] = [
35+
'name' => $name,
36+
'email' => $email,
37+
];
38+
}
4239

4340
return $this;
4441
}
4542

46-
public function getBcc(): array
47-
{
48-
return $this->bcc;
49-
}
50-
51-
public function setBcc(array $bcc): SendinblueEmailMessage
43+
public function bcc($name, $email = null): SendinblueEmailMessage
5244
{
53-
$this->bcc = $bcc;
45+
if (is_array($name)) {
46+
$this->bcc = $name;
47+
} else {
48+
$this->bcc[] = [
49+
'name' => $name,
50+
'email' => $email,
51+
];
52+
}
5453

5554
return $this;
5655
}
5756

58-
public function getCc(): array
57+
public function cc($name, $email = null): SendinblueEmailMessage
5958
{
60-
return $this->cc;
61-
}
62-
63-
public function setCc(array $cc): SendinblueEmailMessage
64-
{
65-
$this->cc = $cc;
59+
if (is_array($name)) {
60+
$this->cc = $name;
61+
} else {
62+
$this->cc[] = [
63+
'name' => $name,
64+
'email' => $email,
65+
];
66+
}
6667

6768
return $this;
6869
}
6970

70-
public function getSubject(): string
71+
public function attachment($name, $content = null): SendinblueEmailMessage
7172
{
72-
return $this->subject;
73-
}
74-
75-
public function setSubject(string $subject): SendinblueEmailMessage
76-
{
77-
$this->subject = $subject;
73+
if (is_array($name)) {
74+
$this->attachment = $name;
75+
} else {
76+
$this->attachment[] = [
77+
'name' => $name,
78+
'content' => $content,
79+
];
80+
}
7881

7982
return $this;
8083
}
8184

82-
public function getReplyTo(): array
85+
public function subject(string $subject): SendinblueEmailMessage
8386
{
84-
return $this->replyTo;
85-
}
86-
87-
public function setReplyTo(array $replyTo): SendinblueEmailMessage
88-
{
89-
$this->replyTo = $replyTo;
87+
$this->subject = $subject;
9088

9189
return $this;
9290
}
9391

94-
public function getAttachment(): array
95-
{
96-
return $this->attachment;
97-
}
98-
99-
public function setAttachment(array $attachment): SendinblueEmailMessage
92+
public function replyTo(array $replyTo): SendinblueEmailMessage
10093
{
101-
$this->attachment[] = $attachment;
94+
$this->replyTo = $replyTo;
10295

10396
return $this;
10497
}
10598

106-
public function getHeaders(): array
107-
{
108-
return $this->headers;
109-
}
110-
111-
public function setHeaders(array $headers): SendinblueEmailMessage
99+
public function headers(array $headers): SendinblueEmailMessage
112100
{
113101
$this->headers = $headers;
114102

115103
return $this;
116104
}
117105

118-
public function getTemplateId(): int
119-
{
120-
return $this->templateId;
121-
}
122-
123-
public function setTemplateId(int $templateId): SendinblueEmailMessage
106+
public function templateId(int $templateId): SendinblueEmailMessage
124107
{
125108
$this->templateId = $templateId;
126109

127110
return $this;
128111
}
129112

130-
public function getHtmlContent(): string
131-
{
132-
return $this->htmlContent;
133-
}
134-
135-
public function setHtmlContent(string $htmlContent): SendinblueEmailMessage
113+
public function htmlContent(string $htmlContent): SendinblueEmailMessage
136114
{
137115
$this->htmlContent = $htmlContent;
138116

139117
return $this;
140118
}
141119

142-
public function getTextContent(): string
143-
{
144-
return $this->textContent;
145-
}
146-
147-
public function setTextContent(string $textContent): SendinblueEmailMessage
120+
public function textContent(string $textContent): SendinblueEmailMessage
148121
{
149122
$this->textContent = $textContent;
150123

151124
return $this;
152125
}
153126

154-
public function getParams(): array
155-
{
156-
return $this->params;
157-
}
158-
159-
public function setParams(array $params): SendinblueEmailMessage
127+
public function params(array $params): SendinblueEmailMessage
160128
{
161129
$this->params = $params;
162130

@@ -166,7 +134,7 @@ public function setParams(array $params): SendinblueEmailMessage
166134
public function toArray(): array
167135
{
168136
$data = [
169-
'sender' => $this->sender,
137+
'sender' => $this->from,
170138
'to' => $this->to,
171139
'templateId' => $this->templateId,
172140
'headers' => $this->headers,

src/SendinblueService.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public function __construct(string $identifier, string $key, array $options = []
4040

4141
public function sendEmail(SendinblueEmailMessage $email, array $options = []): ?array
4242
{
43-
if (! $email->getSender()) {
44-
$email->setSender($this->emailFrom);
43+
if (blank($email->from)) {
44+
$email->from($this->emailFrom);
4545
} elseif (array_key_exists('emailFrom', $options)) {
46-
$email->setSender($options['emailFrom']);
46+
$email->from($options['emailFrom']);
4747
}
4848
$response = $this->http->post('/smtp/email', $email->toArray());
4949

@@ -56,10 +56,10 @@ public function sendEmail(SendinblueEmailMessage $email, array $options = []): ?
5656

5757
public function sendSms(SendinblueSmsMessage $sms, array $options = []): ?array
5858
{
59-
if (! $sms->getSender()) {
60-
$sms->setSender($this->smsFrom);
59+
if (blank($sms->from)) {
60+
$sms->from($this->smsFrom);
6161
} elseif (array_key_exists('smsFrom', $options)) {
62-
$sms->setSender($options['smsFrom']);
62+
$sms->from($options['smsFrom']);
6363
}
6464

6565
$response = $this->http->post('/transactionalSMS/sms', $sms->toArray());

src/SendinblueSmsMessage.php

+19-54
Original file line numberDiff line numberDiff line change
@@ -6,92 +6,57 @@
66

77
final class SendinblueSmsMessage
88
{
9-
protected string $sender;
10-
protected string $recipient;
11-
protected string $content;
12-
protected string $type = 'transactional';
13-
protected ?string $tag = null;
14-
protected ?string $webUrl = null;
15-
protected bool $unicodeEnabled = true;
16-
17-
public function getSender(): string
9+
public string $from;
10+
public string $to;
11+
public string $content;
12+
public string $type = 'transactional';
13+
public ?string $tag = null;
14+
public ?string $webUrl = null;
15+
public bool $unicodeEnabled = true;
16+
17+
public function from(string $from): SendinblueSmsMessage
1818
{
19-
return $this->sender;
20-
}
21-
22-
public function setSender(string $sender): SendinblueSmsMessage
23-
{
24-
$this->sender = $sender;
19+
$this->from = $from;
2520

2621
return $this;
2722
}
2823

29-
public function getRecipient(): string
30-
{
31-
return $this->recipient;
32-
}
33-
34-
public function setRecipient(string $recipient): SendinblueSmsMessage
24+
public function to(string $to): SendinblueSmsMessage
3525
{
36-
$this->recipient = $recipient;
26+
$this->to = $to;
3727

3828
return $this;
3929
}
4030

41-
public function getContent(): string
42-
{
43-
return $this->content;
44-
}
45-
46-
public function setContent(string $content): SendinblueSmsMessage
31+
public function content(string $content): SendinblueSmsMessage
4732
{
4833
$this->content = $content;
4934

5035
return $this;
5136
}
5237

53-
public function getType(): string
54-
{
55-
return $this->type;
56-
}
57-
58-
public function setType(string $type): SendinblueSmsMessage
38+
public function type(string $type): SendinblueSmsMessage
5939
{
6040
$this->type = $type;
6141

6242
return $this;
6343
}
6444

65-
public function getTag(): string
66-
{
67-
return $this->tag;
68-
}
69-
70-
public function setTag(string $tag): SendinblueSmsMessage
45+
public function tag(string $tag): SendinblueSmsMessage
7146
{
7247
$this->tag = $tag;
7348

7449
return $this;
7550
}
7651

77-
public function getWebUrl(): string
78-
{
79-
return $this->webUrl;
80-
}
81-
82-
public function setWebUrl(string $webUrl): SendinblueSmsMessage
52+
public function webUrl(string $webUrl): SendinblueSmsMessage
8353
{
8454
$this->webUrl = $webUrl;
8555

8656
return $this;
8757
}
8858

89-
public function getUnicodeEnabled(): bool
90-
{
91-
return $this->unicodeEnabled;
92-
}
93-
94-
public function setUnicodeEnabled(bool $unicodeEnabled): SendinblueSmsMessage
59+
public function unicodeEnabled(bool $unicodeEnabled): SendinblueSmsMessage
9560
{
9661
$this->unicodeEnabled = $unicodeEnabled;
9762

@@ -101,8 +66,8 @@ public function setUnicodeEnabled(bool $unicodeEnabled): SendinblueSmsMessage
10166
public function toArray(): array
10267
{
10368
$data = [
104-
'sender' => $this->sender,
105-
'recipient' => $this->recipient,
69+
'sender' => $this->from,
70+
'recipient' => $this->to,
10671
'content' => $this->content,
10772
'type' => $this->type,
10873
'unicodeEnabled' => $this->unicodeEnabled,

tests/SendinblueSmsChannelTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use Illuminate\Database\Eloquent\Model;
44
use Illuminate\Notifications\Notification;
5-
use SendinBlue\Client\Model\SendTransacSms;
65
use YieldStudio\LaravelSendinblueNotifier\SendinblueService;
76
use YieldStudio\LaravelSendinblueNotifier\SendinblueSmsChannel;
87
use YieldStudio\LaravelSendinblueNotifier\SendinblueSmsMessage;

0 commit comments

Comments
 (0)