Skip to content

Commit 2b7c191

Browse files
authored
Merge pull request #13 from inlinestudio/dependabot/github_actions/ramsey/composer-install-3
Bump ramsey/composer-install from 2 to 3
2 parents 35a8faf + f65e282 commit 2b7c191

File tree

4 files changed

+45
-44
lines changed

4 files changed

+45
-44
lines changed

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
coverage: none
2121

2222
- name: Install composer dependencies
23-
uses: ramsey/composer-install@v2
23+
uses: ramsey/composer-install@v3
2424

2525
- name: Run PHPStan
2626
run: ./vendor/bin/phpstan --error-format=github

config/inlinestudio-mailconnectors.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
'O365' => [
66
'tenant' => env('OFFICE365MAIL_TENANT', null),
77
'client_id' => env('OFFICE365MAIL_CLIENT_ID', null),
8-
'client_secret' => env('OFFICE365MAIL_CLIENT_SECRET', null)
9-
]
10-
]
8+
'client_secret' => env('OFFICE365MAIL_CLIENT_SECRET', null),
9+
],
10+
],
1111
];

src/Mailers/O365/Office365Connector.php

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace InlineStudio\MailConnectors\Mailers\O365;
44

5+
use GuzzleHttp\Client as GuzzleClient;
6+
use Illuminate\Support\Str;
57
use Microsoft\Graph\Graph;
68
use Microsoft\Graph\Model\Message;
79
use Microsoft\Graph\Model\UploadSession;
8-
use Symfony\Component\Mime\Email;
910
use Symfony\Component\Mime\Address;
10-
use Illuminate\Support\Str;
11-
use GuzzleHttp\Client as GuzzleClient;
11+
use Symfony\Component\Mime\Email;
1212

1313
class Office365Connector
1414
{
@@ -18,7 +18,9 @@ class Office365Connector
1818
protected Graph $client;
1919

2020
protected string $clientId;
21+
2122
protected string $clientSecret;
23+
2224
protected string $tenant;
2325

2426
protected const BYTE_TO_MB = 1048576;
@@ -38,8 +40,8 @@ public function __construct(string $clientId, string $clientSecret, string $tena
3840

3941
protected function getAccessToken(): string
4042
{
41-
$guzzle = new GuzzleClient();
42-
$url = 'https://login.microsoftonline.com/' . $this->tenant . '/oauth2/v2.0/token';
43+
$guzzle = new GuzzleClient;
44+
$url = 'https://login.microsoftonline.com/'.$this->tenant.'/oauth2/v2.0/token';
4345
$response = $guzzle->post(
4446
$url,
4547
[
@@ -75,20 +77,20 @@ public function sendMessageRequest(Email $message): Message
7577
$this->uploadLargeAttachments($message, $draft->getId());
7678

7779
// Send the message
78-
return $this->client->createRequest("POST", "/users/" . (current($message->getFrom())->getAddress()) . "/messages/" . $draft->getId() . "/send")
80+
return $this->client->createRequest('POST', '/users/'.(current($message->getFrom())->getAddress()).'/messages/'.$draft->getId().'/send')
7981
->setReturnType(Message::class)
8082
->execute();
8183
}
8284

83-
return $this->client->createRequest("POST", "/users/" . (current($message->getFrom())->getAddress()) . "/sendmail")
85+
return $this->client->createRequest('POST', '/users/'.(current($message->getFrom())->getAddress()).'/sendmail')
8486
->attachBody($this->getBody($message, true))
8587
->setReturnType(Message::class)
8688
->execute();
8789
}
8890

8991
protected function createDraftMessage(Email $message): Message
9092
{
91-
return $this->client->createRequest("POST", "/users/" . (current($message->getFrom())->getAddress()) . "/messages")
93+
return $this->client->createRequest('POST', '/users/'.(current($message->getFrom())->getAddress()).'/messages')
9294
->attachBody($this->getBody($message, false, true))
9395
->setReturnType(Message::class)
9496
->execute();
@@ -100,7 +102,7 @@ protected function uploadLargeAttachments(Email $message, string $draftId): void
100102
$fileName = $attachment->getPreparedHeaders()->getHeaderParameter('Content-Disposition', 'filename');
101103
$content = $attachment->getBody();
102104
$fileSize = strlen($content);
103-
$size = $fileSize / self::BYTE_TO_MB; //byte -> mb
105+
$size = $fileSize / self::BYTE_TO_MB; // byte -> mb
104106
$id = Str::random(10);
105107

106108
if ($size <= 3) {
@@ -109,10 +111,10 @@ protected function uploadLargeAttachments(Email $message, string $draftId): void
109111
'name' => $fileName,
110112
'contentType' => $attachment->getPreparedHeaders()->get('Content-Type')->getBody(),
111113
'contentBytes' => base64_encode($attachment->getBody()),
112-
'contentId' => $id
114+
'contentId' => $id,
113115
];
114116

115-
$this->client->createRequest("POST", "/users/" . (current($message->getFrom())->getAddress()) . "/messages/" . $draftId . "/attachments")
117+
$this->client->createRequest('POST', '/users/'.(current($message->getFrom())->getAddress()).'/messages/'.$draftId.'/attachments')
116118
->attachBody($attachmentBody)
117119
->setReturnType(UploadSession::class)
118120
->execute();
@@ -129,19 +131,19 @@ protected function chunkUpload(Email $message, string $draftId, string $fileName
129131
'attachmentType' => 'file',
130132
'name' => $fileName,
131133
'size' => $fileSize,
132-
]
134+
],
133135
];
134136

135-
$uploadSession = $this->client->createRequest("POST", "/users/" . (current($message->getFrom())->getAddress()) . "/messages/" . $draftId . "/attachments/createUploadSession")
137+
$uploadSession = $this->client->createRequest('POST', '/users/'.(current($message->getFrom())->getAddress()).'/messages/'.$draftId.'/attachments/createUploadSession')
136138
->attachBody($attachmentMessage)
137139
->setReturnType(UploadSession::class)
138140
->execute();
139141

140-
$fragSize = 1024 * 1024 * 4; //4mb at once...
142+
$fragSize = 1024 * 1024 * 4; // 4mb at once...
141143
$numFragments = ceil($fileSize / $fragSize);
142144
$contentChunked = str_split($content, $fragSize);
143145
$bytesRemaining = $fileSize;
144-
$guzzle = new GuzzleClient();
146+
$guzzle = new GuzzleClient;
145147

146148
$i = 0;
147149
while ($i < $numFragments) {
@@ -157,14 +159,14 @@ protected function chunkUpload(Email $message, string $draftId, string $fileName
157159
$contentRange = "bytes {$start}-{$end}/{$fileSize}";
158160
$headers = [
159161
'Content-Length' => $numBytes,
160-
'Content-Range' => $contentRange
162+
'Content-Range' => $contentRange,
161163
];
162164

163165
$guzzle->put($uploadSession->getUploadUrl(), [
164-
'headers' => $headers,
165-
'body' => $data,
166+
'headers' => $headers,
167+
'body' => $data,
166168
'allow_redirects' => false,
167-
'timeout' => 1000
169+
'timeout' => 1000,
168170
]);
169171

170172
$bytesRemaining = $bytesRemaining - $chunkSize;
@@ -177,7 +179,7 @@ protected function getBodySize(Email $message): float
177179
$messageBody = $this->getBody($message, true);
178180
$messageBodyLength = mb_strlen(json_encode($messageBody, JSON_NUMERIC_CHECK), '8bit');
179181

180-
return $messageBodyLength / self::BYTE_TO_MB; //byte -> mb
182+
return $messageBodyLength / self::BYTE_TO_MB; // byte -> mb
181183
}
182184

183185
/**
@@ -190,7 +192,7 @@ protected function getBody(Email $message, bool $withAttachments = false, bool $
190192
'emailAddress' => [
191193
'address' => current($message->getFrom())->getAddress(),
192194
'name' => current($message->getFrom())->getName(),
193-
]
195+
],
194196
],
195197
'toRecipients' => $this->getTo($message),
196198
'ccRecipients' => $this->getCc($message),
@@ -199,23 +201,23 @@ protected function getBody(Email $message, bool $withAttachments = false, bool $
199201
'subject' => $message->getSubject(),
200202
'body' => [
201203
'contentType' => $message->getHtmlBody() ? 'html' : 'text',
202-
'content' => $message->getHtmlBody() ?: $message->getTextBody()
203-
]
204+
'content' => $message->getHtmlBody() ?: $message->getTextBody(),
205+
],
204206
];
205207

206-
if (!$isDraft) {
208+
if (! $isDraft) {
207209
$messageData = ['message' => $messageData];
208210
}
209211

210212
if (count($message->getAttachments()) > 0 && $withAttachments) {
211213
$attachments = [];
212214
foreach ($message->getAttachments() as $attachment) {
213215
$attachments[] = [
214-
"@odata.type" => "#microsoft.graph.fileAttachment",
215-
"name" => $attachment->getFilename(),
216-
"contentType" => $attachment->getContentType(),
217-
"contentBytes" => base64_encode($attachment->getBody()),
218-
'contentId' => $attachment->getContentId()
216+
'@odata.type' => '#microsoft.graph.fileAttachment',
217+
'name' => $attachment->getFilename(),
218+
'contentType' => $attachment->getContentType(),
219+
'contentBytes' => base64_encode($attachment->getBody()),
220+
'contentId' => $attachment->getContentId(),
219221
];
220222
}
221223
$messageData['message']['attachments'] = $attachments;
@@ -234,7 +236,7 @@ protected function getTo(Email $message): array
234236
'emailAddress' => [
235237
'address' => $recipient->getAddress(),
236238
'name' => $recipient->getName(),
237-
]
239+
],
238240
]
239241
)->values()->toArray();
240242
}
@@ -245,11 +247,11 @@ protected function getTo(Email $message): array
245247
protected function getCc(Email $message): array
246248
{
247249
return collect($message->getCc())->map(
248-
fn (Address $cc) => [
250+
fn (Address $cc) => [
249251
'emailAddress' => [
250252
'address' => $cc->getAddress(),
251253
'name' => $cc->getName(),
252-
]
254+
],
253255
]
254256
)->values()->toArray();
255257
}
@@ -260,12 +262,11 @@ protected function getCc(Email $message): array
260262
protected function getReplyTo(Email $message): array
261263
{
262264
return collect($message->getReplyTo())->map(
263-
fn (Address $replyTo) =>
264-
[
265+
fn (Address $replyTo) => [
265266
'emailAddress' => [
266267
'address' => $replyTo->getAddress(),
267268
'name' => $replyTo->getName(),
268-
]
269+
],
269270
]
270271
)->values()->toArray();
271272
}
@@ -280,7 +281,7 @@ protected function getBcc(Email $message): array
280281
'emailAddress' => [
281282
'address' => $bcc->getAddress(),
282283
'name' => $bcc->getName(),
283-
]
284+
],
284285
]
285286
)->values()->toArray();
286287
}

src/Mailers/O365/Transport/Office365MailTransport.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace InlineStudio\MailConnectors\Mailers\O365\Transport;
44

5+
use InlineStudio\MailConnectors\Mailers\O365\Office365Connector;
56
use Psr\EventDispatcher\EventDispatcherInterface;
67
use Psr\Log\LoggerInterface;
7-
use InlineStudio\MailConnectors\Mailers\O365\Office365Connector;
88
use Symfony\Component\Mailer\SentMessage;
99
use Symfony\Component\Mailer\Transport\AbstractTransport;
1010
use Symfony\Component\Mime\MessageConverter;
@@ -15,11 +15,11 @@ class Office365MailTransport extends AbstractTransport
1515
* The O365 API client.
1616
*/
1717
protected Office365Connector $client;
18-
18+
1919
/**
2020
* Create a new O365 transport instance.
2121
*/
22-
public function __construct(Office365Connector $client, EventDispatcherInterface $dispatcher = null, LoggerInterface $logger = null)
22+
public function __construct(Office365Connector $client, ?EventDispatcherInterface $dispatcher = null, ?LoggerInterface $logger = null)
2323
{
2424
$this->client = $client;
2525
parent::__construct($dispatcher, $logger);
@@ -41,4 +41,4 @@ public function __toString(): string
4141
{
4242
return 'O365';
4343
}
44-
}
44+
}

0 commit comments

Comments
 (0)