8000 Apply review changes · symfony/symfony@e9ef87f · GitHub
[go: up one dir, main page]

Skip to content

Commit e9ef87f

Browse files
committed
Apply review changes
1 parent 625d273 commit e9ef87f

File tree

7 files changed

+32
-60
lines changed

7 files changed

+32
-60
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/Tests export-ignore
22
/phpunit.xml.dist export-ignore
33
/.gitattributes export-ignore
4-
/.gitignore export-ignore
4+
/.gitignore export-ignore
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
vendor/
22
composer.lock
3-
phpunit.xml
3+
phpunit.xml

src/Symfony/Component/Notifier/Bridge/Plivo/PlivoOptions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,48 +79,56 @@ public function setLog(bool $log): self
7979
public function setMediaUrls(string $mediaUrls): self
8080
{
8181
$this->options['media_urls'] = $mediaUrls;
82+
8283
return $this;
8384
}
8485

8586
public function setMethod(string $method): self
8687
{
8788
$this->options['method'] = $method;
89+
8890
return $this;
8991
}
9092

9193
public function setPowerpackUuid(string $powerpackUuid): self
9294
{
9395
$this->options['powerpack_uuid'] = $powerpackUuid;
96+
9497
return $this;
9598
}
9699

97100
public function setRecipientId(string $id): self
98101
{
99102
$this->options['recipient_id'] = $id;
103+
100104
return $this;
101105
}
102106

103107
public function setSrc(string $src): self
104108
{
105109
$this->options['src'] = $src;
110+
106111
return $this;
107112
}
108113

109114
public function setTrackable(bool $trackable): self
110115
{
111116
$this->options['trackable'] = $trackable;
117+
112118
return $this;
113119
}
114120

115121
public function setType(string $type): self
116122
{
117123
$this->options['type'] = $type;
124+
118125
return $this;
119126
}
120127

121128
public function setUrl(string $url): self
122129
{
123130
$this->options['url'] = $url;
131+
124132
return $this;
125133
}
126134

src/Symfony/Component/Notifier/Bridge/Plivo/PlivoTransport.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,26 @@ protected function doSend(MessageInterface $message): SentMessage
5454
if (!$message instanceof SmsMessage) {
5555
throw new UnsupportedMessageTypeException(__CLASS__, SmsMessage::class, $message);
5656
}
57+
5758
$opts = $message->getOptions();
5859
$options = $opts ? $opts->toArray() : [];
5960
$options['text'] = $message->getSubject();
6061
$options['src'] = $options['src'] ?? $this->from;
6162
$options['dst'] = $options['dst'] ?? $message->getPhone();
63+
6264
if (!preg_match('/^[a-zA-Z0-9\s]{2,11}$/', $options['src']) && !preg_match('/^\+?[1-9]\d{1,14}$/', $options['src'])) {
6365
throw new InvalidArgumentException(sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID. Phone number must contain only numbers and optional + character.', $this->from));
6466
}
67+
6568
$endpoint = sprintf('https://%s/v1/Account/%s/Message/', $this->getEndpoint(), $this->authId);
66-
$response = $this->client->request(
67-
'POST',
68-
$endpoint,
69-
[
70-
'auth_basic' => $this->authId.':'.$this->authToken,
71-
'json' => array_filter($options),
72-
]
73-
);
69+
$response = $this->client->request('POST', $endpoint,['auth_basic' => $this->authId.':'.$this->authToken, 'json' => array_filter($options)]);
70+
7471
try {
7572
$statusCode = $response->getStatusCode();
7673
} catch (TransportExceptionInterface $e) {
7774
throw new TransportException('Could not reach the remote Plivo server.', $response, 0, $e);
7875
}
76+
7977
if (202 !== $statusCode) {
8078
try {
8179
$error = $response->toArray(false);
@@ -84,6 +82,7 @@ protected function doSend(MessageInterface $message): SentMessage
8482
}
8583
throw new TransportException(sprintf('Unable to send the SMS - status code: %s: %s', $statusCode, $error['error'] ?? 'unknown error'), $response);
8684
}
85+
8786
$success = $response->toArray(false);
8887
$sentMessage = new SentMessage($message, (string) $this);
8988
$sentMessage->setMessageId($success['message_uuid'][0]);

src/Symfony/Component/Notifier/Bridge/Plivo/PlivoTransportFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,14 @@ public function create(Dsn $dsn): PlivoTransport
2828
if (self::TRANSPORT_SCHEME !== $scheme) {
2929
throw new UnsupportedSchemeException($dsn, self::TRANSPORT_SCHEME, $this->getSupportedSchemes());
3030
}
31-
31+
3232
$authId = $this->getUser($dsn);
3333
$authToken = $this->getPassword($dsn);
3434
$from = $dsn->getRequiredOption('from');
3535
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3636
$port = $dsn->getPort();
3737

38-
return (new PlivoTransport($authId, $authToken, $from, $this->client, $this->dispatcher))
39-
->setHost($host)
40-
->setPort($port)
41-
;
38+
return (new PlivoTransport($authId, $authToken, $from, $this->client, $this->dispatcher))->setHost($host)->setPort($port);
4239
}
4340

4441
protected function getSupportedSchemes(): array

src/Symfony/Component/Notifier/Bridge/Plivo/Tests/PlivoTransportFactoryTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ public function createFactory(): PlivoTransportFactory
2222

2323
public function createProvider(): iterable
2424
{
25-
yield [
26-
'plivo://host.test?from=0611223344',
27-
'plivo://authId:authToken@host.test?from=0611223344',
28-
];
25+
yield ['plivo://host.test?from=0611223344', 'plivo://authId:authToken@host.test?from=0611223344'];
2926
}
3027

3128
public function incompleteDsnProvider(): iterable
@@ -40,14 +37,8 @@ public function missingRequiredOptionProvider(): iterable
4037

4138
public function supportsProvider(): iterable
4239
{
43-
yield [
44-
true,
45-
'plivo://authId:authToken@default?from=0611223344',
46-
];
47-
yield [
48-
false,
49-
'somethingElse://authId:authToken@default?from=0611223344',
50-
];
40+
yield [true, 'plivo://authId:authToken@default?from=0611223344'];
41+
yield [false, 'somethingElse://authId:authToken@default?from=0611223344'];
5142
}
5243

5344
public function unsupportedSchemeProvider(): iterable

src/Symfony/Component/Notifier/Bridge/Plivo/Tests/PlivoTransportTest.php

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,33 @@
2222

2323
final class PlivoTransportTest extends TransportTestCase
2424
{
25-
public function createTransport(
26-
HttpClientInterface $client = null,
27-
string $from = 'from'
28-
): PlivoTransport {
29-
return new PlivoTransport('authId', 'authToken', $from, $client ?? $this->createMock(HttpClientInterface::class)
30-
);
25+
public function createTransport(HttpClientInterface $client = null, string $from = 'from'): PlivoTransport {
26+
return new PlivoTransport('authId', 'authToken', $from, $client ?? $this->createMock(HttpClientInterface::class));
3127
}
3228

3329
public function invalidFromProvider(): iterable
3430
{
35-
// alphanumeric sender ids
3631
yield 'too short' => ['a'];
3732
yield 'too long' => ['abcdefghijkl'];
38-
// phone numbers
3933
yield 'no zero at start if phone number' => ['+0'];
4034
yield 'phone number too short' => ['+1'];
4135
}
4236

4337
public function supportedMessagesProvider(): iterable
4438
{
45-
yield [
46-
new SmsMessage('0611223344', 'Hello!'),
47-
];
39+
yield [new SmsMessage('0611223344', 'Hello!')];
4840
}
4941

5042
/**
5143
* @dataProvider invalidFromProvider
5244
*/
5345
public function testInvalidArgumentExceptionIsThrownIfFromIsInvalid(string $from): void
5446
{
55-
$transport = $this->createTransport(
56-
null,
57-
$from
58-
);
47+
$transport = $this->createTransport(null, $from);
48+
5949
$this->expectException(InvalidArgumentException::class);
6050
$this->expectExceptionMessage(sprintf('The "From" number "%s" is not a valid phone number, shortcode, or alphanumeric sender ID.', $from));
51+
6152
$transport->send(new SmsMessage('+33612345678', 'Hello!'));
6253
}
6354

@@ -68,20 +59,8 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
6859
{
6960
$message = new SmsMessage('+33612345678', 'Hello!');
7061
$response = $this->createMock(ResponseInterface::class);
71-
$response->expects(self::exactly(2))
72-
->method('getStatusCode')
73-
->willReturn(202)
74-
;
75-
$response->expects(self::once())
76-
->method('getContent')
77-
->willReturn(
78-
json_encode([
79-
'message' => 'message(s) queued',
80-
'message_uuid' => ['foo'],
81-
'api_id' => 'bar',
82-
])
83-
)
84-
;
62+
$response->expects(self::exactly(2))->method('getStatusCode')->willReturn(202);
63+
$response->expects(self::once())->method('getContent')->willReturn(json_encode(['message' => 'message(s) queued', 'message_uuid' => ['foo'], 'api_id' => 'bar',]));
8564
$client = new MockHttpClient(function (string $method, string $url) use ($response): ResponseInterface {
8665
self::assertSame('POST', $method);
8766
self::assertSame('https://api.plivo.com/v1/Account/authId/Message/', $url);
@@ -91,15 +70,13 @@ public function testNoInvalidArgumentExceptionIsThrownIfFromIsValid(string $from
9170
);
9271
$transport = $this->createTransport($client, $from);
9372
$sentMessage = $transport->send($message);
73+
9474
self::assertSame('foo', $sentMessage->getMessageId());
9575
}
9676

9777
public function toStringProvider(): iterable
9878
{
99-
yield [
100-
'plivo://api.plivo.com?from=from',
101-
$this->createTransport(),
102-
];
79+
yield ['plivo://api.plivo.com?from=from', $this->createTransport()];
10380
}
10481

10582
public function unsupportedMessagesProvider(): iterable

0 commit comments

Comments
 (0)
0