Skip to content

Commit f07cb27

Browse files
Apply code style updates
1 parent 5ac238d commit f07cb27

File tree

8 files changed

+106
-39
lines changed

8 files changed

+106
-39
lines changed

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2023-present Fabien Potencier
1+
Copyright (c) 2025-present Fabien Potencier
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Tests/TokenManagerMock.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Tests;
413

514
use Symfony\Component\HttpClient\MockHttpClient;
615
use Symfony\Component\Mailer\Bridge\MicrosoftGraph\TokenManager;
716

817
class TokenManagerMock extends TokenManager
918
{
10-
public function __construct() {
19+
public function __construct()
20+
{
1121
parent::__construct('', '', '', '', '', new MockHttpClient());
1222
}
1323

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Tests/TokenManagerTest.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Tests;
413

514
use PHPUnit\Framework\TestCase;
@@ -14,7 +23,7 @@
1423

1524
class TokenManagerTest extends TestCase
1625
{
17-
public function testTokenRetrieved(): void
26+
public function testTokenRetrieved()
1827
{
1928
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
2029
$this->assertSame('POST', $method);
@@ -34,12 +43,13 @@ public function testTokenRetrieved(): void
3443
$manager->getToken();
3544
}
3645

37-
public function testTokenCached(): void {
46+
public function testTokenCached()
47+
{
3848
$counter = 0;
3949
$client = new MockHttpClient(function () use (&$counter): ResponseInterface {
40-
$counter++;
50+
++$counter;
4151

42-
return new JsonMockResponse(['access_token' => 't' . $counter, 'expires_in' => 3599]);
52+
return new JsonMockResponse(['access_token' => 't'.$counter, 'expires_in' => 3599]);
4353
});
4454

4555
$manager = new TokenManager('graph', 'auth', 'tenant', 'client', 'key', $client);
@@ -49,12 +59,13 @@ public function testTokenCached(): void {
4959
$this->assertSame(1, $counter);
5060
}
5161

52-
public function testTokenExpired(): void {
62+
public function testTokenExpired()
63+
{
5364
$counter = 0;
5465
$client = new MockHttpClient(function () use (&$counter): ResponseInterface {
55-
$counter++;
66+
++$counter;
5667

57-
return new JsonMockResponse(['access_token' => 't' . $counter, 'expires_in' => 3599]);
68+
return new JsonMockResponse(['access_token' => 't'.$counter, 'expires_in' => 3599]);
5869
});
5970

6071
Clock::set(new MockClock('2025-07-31 11:00'));
@@ -68,7 +79,8 @@ public function testTokenExpired(): void {
6879
$this->assertSame(2, $counter);
6980
}
7081

71-
public function testNonSuccessCodeThrown(): void {
82+
public function testNonSuccessCodeThrown()
83+
{
7284
$client = new MockHttpClient(fn (): ResponseInterface => new MockResponse('', ['http_code' => 503]));
7385

7486
$manager = new TokenManager('graph', 'auth', 'tenant', 'client', 'key', $client);

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Tests/Transport/MicrosoftGraphApiTransportTest.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Tests\Transport;
413

514
use PHPUnit\Framework\TestCase;
@@ -19,7 +28,7 @@ class MicrosoftGraphApiTransportTest extends TestCase
1928
*/
2029
public function testToString(MicrosoftGraphApiTransport $transport, string $expected)
2130
{
22-
$this->assertSame($expected, (string)$transport);
31+
$this->assertSame($expected, (string) $transport);
2332
}
2433

2534
public static function getTransportData(): array
@@ -32,7 +41,7 @@ public static function getTransportData(): array
3241
];
3342
}
3443

35-
public function testSend(): void
44+
public function testSend()
3645
{
3746
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
3847
$this->assertSame('POST', $method);
@@ -85,7 +94,7 @@ public function testSend(): void
8594
$transport->send($mail);
8695
}
8796

88-
public function testCcBcc(): void
97+
public function testCcBcc()
8998
{
9099
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
91100
$this->assertSame('POST', $method);
@@ -117,7 +126,7 @@ public function testCcBcc(): void
117126
$transport->send($mail);
118127
}
119128

120-
public function testHtmlBody(): void
129+
public function testHtmlBody()
121130
{
122131
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
123132
$this->assertSame('POST', $method);
@@ -143,7 +152,7 @@ public function testHtmlBody(): void
143152
$transport->send($mail);
144153
}
145154

146-
public function testEmbeddedAttachment(): void
155+
public function testEmbeddedAttachment()
147156
{
148157
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
149158
$this->assertSame('POST', $method);
@@ -169,7 +178,7 @@ public function testEmbeddedAttachment(): void
169178
$transport->send($mail);
170179
}
171180

172-
public function testRespectsNoSaveParameter(): void
181+
public function testRespectsNoSaveParameter()
173182
{
174183
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
175184
$this->assertSame('POST', $method);
@@ -193,7 +202,7 @@ public function testRespectsNoSaveParameter(): void
193202
$transport->send($mail);
194203
}
195204

196-
public function testCustomHeader(): void
205+
public function testCustomHeader()
197206
{
198207
$client = new MockHttpClient(function (string $method, string $url, array $options): ResponseInterface {
199208
$this->assertSame('POST', $method);
@@ -222,7 +231,7 @@ public function testCustomHeader(): void
222231
}
223232

224233
/** @dataProvider importanceProvider */
225-
public function testImportance(string $expected, int $priority): void
234+
public function testImportance(string $expected, int $priority)
226235
{
227236
$client = new MockHttpClient(function (string $method, string $url, array $options) use ($expected): ResponseInterface {
228237
$this->assertSame('POST', $method);
@@ -256,9 +265,9 @@ public static function importanceProvider(): iterable
256265
yield ['low', Email::PRIORITY_LOWEST];
257266
}
258267

259-
public function testNonSuccessCodeThrown(): void
268+
public function testNonSuccessCodeThrown()
260269
{
261-
$client = new MockHttpClient(fn(): ResponseInterface => new MockResponse('', ['http_code' => 503]));
270+
$client = new MockHttpClient(fn (): ResponseInterface => new MockResponse('', ['http_code' => 503]));
262271

263272
$transport = new MicrosoftGraphApiTransport('graph', new TokenManagerMock(), true, $client);
264273

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Tests/Transport/MicrosoftGraphTransportFactoryTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Tests\Transport;
413

514
use Psr\Log\NullLogger;

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/TokenManager.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph;
413

14+
use Symfony\Component\Clock\DatePoint;
515
use Symfony\Component\Mailer\Exception\HttpTransportException;
616
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
717
use Symfony\Contracts\HttpClient\HttpClientInterface;
8-
use Symfony\Component\Clock\DatePoint;
918

1019
class TokenManager
1120
{
@@ -14,10 +23,10 @@ class TokenManager
1423

1524
/**
1625
* @param string $graphEndpoint Graph API URL to which to POST emails
17-
* @param string $authEndpoint Authentication URL
18-
* @param string $tenantId Microsoft Azure tenant identifier
19-
* @param string $appId Microsoft Azure app registration ID
20-
* @param string $appSecret Microsoft Azure app registration secret
26+
* @param string $authEndpoint Authentication URL
27+
* @param string $tenantId Microsoft Azure tenant identifier
28+
* @param string $appId Microsoft Azure app registration ID
29+
* @param string $appSecret Microsoft Azure app registration secret
2130
*/
2231
public function __construct(
2332
private readonly string $graphEndpoint,
@@ -26,11 +35,11 @@ public function __construct(
2635
private readonly string $appId,
2736
#[\SensitiveParameter] private readonly string $appSecret,
2837
private readonly HttpClientInterface $client,
29-
)
30-
{
38+
) {
3139
}
3240

33-
public function getToken(): string {
41+
public function getToken(): string
42+
{
3443
if (null !== $this->token && null !== $this->tokenExpires && $this->tokenExpires > new DatePoint()) {
3544
// Token still valid
3645
return $this->token;
@@ -53,7 +62,7 @@ public function getToken(): string {
5362
}
5463

5564
if (200 !== $statusCode) {
56-
throw new HttpTransportException('Unable to authenticate: ' . $response->getContent(false) . \sprintf(' (code %d).', $statusCode), $response);
65+
throw new HttpTransportException('Unable to authenticate: '.$response->getContent(false).\sprintf(' (code %d).', $statusCode), $response);
5766
}
5867

5968
$tokenData = $response->toArray();

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Transport/MicrosoftGraphApiTransport.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Transport;
413

514
use Psr\EventDispatcher\EventDispatcherInterface;
@@ -21,13 +30,13 @@ class MicrosoftGraphApiTransport extends AbstractApiTransport
2130

2231
/**
2332
* @param string $graphEndpoint Graph API URL to which to POST emails
24-
* @param bool $noSave Whether the skip saving the send message in the Sent Items box
33+
* @param bool $noSave Whether the skip saving the send message in the Sent Items box
2534
*/
2635
public function __construct(
2736
private readonly string $graphEndpoint,
2837
private readonly TokenManager $tokenManager,
2938
private readonly bool $noSave,
30-
HttpClientInterface $client = null,
39+
?HttpClientInterface $client = null,
3140
?EventDispatcherInterface $dispatcher = null,
3241
?LoggerInterface $logger = null,
3342
) {
@@ -41,7 +50,7 @@ public function __toString(): string
4150

4251
protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $envelope): ResponseInterface
4352
{
44-
$endpoint = "https://$this->graphEndpoint" . \sprintf(self::userEndpoint, $envelope->getSender()->getAddress());
53+
$endpoint = "https://$this->graphEndpoint".\sprintf(self::userEndpoint, $envelope->getSender()->getAddress());
4554
$payload = $this->getPayload($email, $envelope);
4655

4756
$response = $this->client->request('POST', $endpoint, [
@@ -56,7 +65,7 @@ protected function doSendApi(SentMessage $sentMessage, Email $email, Envelope $e
5665
}
5766

5867
if (202 !== $statusCode) {
59-
throw new HttpTransportException('Unable to send an email: ' . $response->getContent(false) . \sprintf(' (code %d).', $statusCode), $response);
68+
throw new HttpTransportException('Unable to send an email: '.$response->getContent(false).\sprintf(' (code %d).', $statusCode), $response);
6069
}
6170

6271
return $response;
@@ -69,7 +78,7 @@ private function getPayload(Email $email, Envelope $envelope): array
6978
'subject' => $email->getSubject(),
7079
'body' => $this->getBodyPayload($email),
7180
'importance' => $this->getImportanceLevel($email),
72-
'toRecipients' => \array_map($this->getEmailAddress(...), $email->getTo()),
81+
'toRecipients' => array_map($this->getEmailAddress(...), $email->getTo()),
7382
];
7483

7584
if ($email->getFrom()) {
@@ -81,19 +90,19 @@ private function getPayload(Email $email, Envelope $envelope): array
8190
$message['attachments'] = $attachments;
8291
}
8392

84-
if ($bcc = \array_map($this->getEmailAddress(...), $email->getBcc())) {
93+
if ($bcc = array_map($this->getEmailAddress(...), $email->getBcc())) {
8594
$message['bccRecipients'] = $bcc;
8695
}
8796

88-
if ($cc = \array_map($this->getEmailAddress(...), $email->getCc())) {
97+
if ($cc = array_map($this->getEmailAddress(...), $email->getCc())) {
8998
$message['ccRecipients'] = $cc;
9099
}
91100

92101
if ($headers = $this->getMessageCustomHeaders($email)) {
93102
$message['internetMessageHeaders'] = $headers;
94103
}
95104

96-
if ($replyTo = \array_map($this->getEmailAddress(...), $email->getReplyTo())) {
105+
if ($replyTo = array_map($this->getEmailAddress(...), $email->getReplyTo())) {
97106
$message['replyTo'] = $replyTo;
98107
}
99108

@@ -143,7 +152,7 @@ private function getMessageAttachments(Email $email): array
143152
$attr = [
144153
'@odata.type' => '#microsoft.graph.fileAttachment',
145154
'name' => $filename,
146-
'contentBytes' => \base64_encode($attachment->getBody()),
155+
'contentBytes' => base64_encode($attachment->getBody()),
147156
'contentType' => $headers->get('Content-Type')->getBody(),
148157
];
149158

src/Symfony/Component/Mailer/Bridge/MicrosoftGraph/Transport/MicrosoftGraphTransportFactory.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Mailer\Bridge\MicrosoftGraph\Transport;
413

514
use Symfony\Component\Mailer\Bridge\MicrosoftGraph\TokenManager;
@@ -23,7 +32,7 @@ public function create(Dsn $dsn): TransportInterface
2332
}
2433

2534
$graphEndpoint = $dsn->getHost();
26-
$authEndpoint = $dsn->getOption('authEndpoint');
35+
$authEndpoint = $dsn->getOption('authEndpoint');
2736
if ('default' === $graphEndpoint) {
2837
$graphEndpoint = 'graph.microsoft.com';
2938
if (null === $authEndpoint) {

0 commit comments

Comments
 (0)