Skip to content

Commit d740126

Browse files
committed
[Notifier][Discord] Remove length checks
1 parent d46df40 commit d740126

12 files changed

+0
-152
lines changed

src/Symfony/Component/Notifier/Bridge/Discord/DiscordBotTransport.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
1514
use Symfony\Component\Notifier\Exception\LogicException;
1615
use Symfony\Component\Notifier\Exception\TransportException;
1716
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
@@ -31,8 +30,6 @@ final class DiscordBotTransport extends AbstractTransport
3130
{
3231
protected const HOST = 'discord.com';
3332

34-
private const SUBJECT_LIMIT = 2000;
35-
3633
public function __construct(
3734
#[\SensitiveParameter] private string $token,
3835
?HttpClientInterface $client = null,
@@ -65,10 +62,6 @@ protected function doSend(MessageInterface $message): SentMessage
6562
$options = $message->getOptions()?->toArray() ?? [];
6663
$options['content'] = $message->getSubject();
6764

68-
if (mb_strlen($options['content'], 'UTF-8') > self::SUBJECT_LIMIT) {
69-
throw new LengthException(\sprintf('The subject length of a Discord message must not exceed %d characters.', self::SUBJECT_LIMIT));
70-
}
71-
7265
$endpoint = \sprintf('https://%s/api/channels/%s/messages', $this->getEndpoint(), $channelId);
7366
$response = $this->client->request('POST', $endpoint, [
7467
'headers' => [

src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
1514
use Symfony\Component\Notifier\Exception\TransportException;
1615
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1716
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -29,8 +28,6 @@ final class DiscordTransport extends AbstractTransport
2928
{
3029
protected const HOST = 'discord.com';
3130

32-
private const SUBJECT_LIMIT = 2000;
33-
3431
public function __construct(
3532
#[\SensitiveParameter] private string $token,
3633
private string $webhookId,
@@ -62,10 +59,6 @@ protected function doSend(MessageInterface $message): SentMessage
6259
$options = $message->getOptions()?->toArray() ?? [];
6360
$options['content'] = $message->getSubject();
6461

65-
if (mb_strlen($options['content'], 'UTF-8') > self::SUBJECT_LIMIT) {
66-
throw new LengthException(\sprintf('The subject length of a Discord message must not exceed %d characters.', self::SUBJECT_LIMIT));
67-
}
68-
6962
$endpoint = \sprintf('https://%s/api/webhooks/%s/%s', $this->getEndpoint(), $this->webhookId, $this->token);
7063
$response = $this->client->request('POST', $endpoint, [
7164
'json' => array_filter($options),

src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordAuthorEmbedObject.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,16 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Embeds;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
15-
1614
/**
1715
* @author Karoly Gossler <connor@connor.hu>
1816
*/
1917
final class DiscordAuthorEmbedObject extends AbstractDiscordEmbedObject
2018
{
21-
private const NAME_LIMIT = 256;
22-
2319
/**
2420
* @return $this
2521
*/
2622
public function name(string $name): static
2723
{
28-
if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) {
29-
throw new LengthException(\sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
30-
}
31-
3224
$this->options['name'] = $name;
3325

3426
return $this;

src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordEmbed.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,16 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Embeds;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
15-
1614
/**
1715
* @author Karoly Gossler <connor@connor.hu>
1816
*/
1917
final class DiscordEmbed extends AbstractDiscordEmbed
2018
{
21-
private const TITLE_LIMIT = 256;
22-
private const DESCRIPTION_LIMIT = 4096;
23-
private const FIELDS_LIMIT = 25;
24-
2519
/**
2620
* @return $this
2721
*/
2822
public function title(string $title): static
2923
{
30-
if (mb_strlen($title, 'UTF-8') > self::TITLE_LIMIT) {
31-
throw new LengthException(\sprintf('Maximum length for the title is %d characters.', self::TITLE_LIMIT));
32-
}
33-
3424
$this->options['title'] = $title;
3525

3626
return $this;
@@ -41,10 +31,6 @@ public function title(string $title): static
4131
*/
4232
public function description(string $description): static
4333
{
44-
if (mb_strlen($description, 'UTF-8') > self::DESCRIPTION_LIMIT) {
45-
throw new LengthException(\sprintf('Maximum length for the description is %d characters.', self::DESCRIPTION_LIMIT));
46-
}
47-
4834
$this->options['description'] = $description;
4935

5036
return $this;
@@ -125,10 +111,6 @@ public function author(DiscordAuthorEmbedObject $author): static
125111
*/
126112
public function addField(DiscordFieldEmbedObject $field): static
127113
{
128-
if (self::FIELDS_LIMIT === \count($this->options['fields'] ?? [])) {
129-
throw new LengthException(\sprintf('Maximum number of fields should not exceed %d.', self::FIELDS_LIMIT));
130-
}
131-
132114
if (!isset($this->options['fields'])) {
133115
$this->options['fields'] = [];
134116
}

src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFieldEmbedObject.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,16 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Embeds;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
15-
1614
/**
1715
* @author Karoly Gossler <connor@connor.hu>
1816
*/
1917
final class DiscordFieldEmbedObject extends AbstractDiscordEmbedObject
2018
{
21-
private const NAME_LIMIT = 256;
22-
private const VALUE_LIMIT = 1024;
23-
2419
/**
2520
* @return $this
2621
*/
2722
public function name(string $name): static
2823
{
29-
if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) {
30-
throw new LengthException(\sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT));
31-
}
32-
3324
$this->options['name'] = $name;
3425

3526
return $this;
@@ -40,10 +31,6 @@ public function name(string $name): static
4031
*/
4132
public function value(string $value): static
4233
{
43-
if (mb_strlen($value, 'UTF-8') > self::VALUE_LIMIT) {
44-
throw new LengthException(\sprintf('Maximum length for the value is %d characters.', self::VALUE_LIMIT));
45-
}
46-
4734
$this->options['value'] = $value;
4835

4936
return $this;

src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFooterEmbedObject.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,16 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\Discord\Embeds;
1313

14-
use Symfony\Component\Notifier\Exception\LengthException;
15-
1614
/**
1715
* @author Karoly Gossler <connor@connor.hu>
1816
*/
1917
final class DiscordFooterEmbedObject extends AbstractDiscordEmbedObject
2018
{
21-
private const TEXT_LIMIT = 2048;
22-
2319
/**
2420
* @return $this
2521
*/
2622
public function text(string $text): static
2723
{
28-
if (mb_strlen($text, 'UTF-8') > self::TEXT_LIMIT) {
29-
throw new LengthException(\sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
30-
}
31-
3224
$this->options['text'] = $text;
3325

3426
return $this;

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordBotTransportTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ public function testSendThrowsWithoutRecipientId()
5757
$transport->send(new ChatMessage('testMessage'));
5858
}
5959

60-
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
61-
{
62-
$transport = self::createTransport();
63-
64-
$this->expectException(LengthException::class);
65-
$this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.');
66-
67-
$transport->send(new ChatMessage(str_repeat('', 2001), (new DiscordOptions())->recipient('channel_id')));
68-
}
69-
7060
public function testSendWithErrorResponseThrows()
7161
{
7262
$response = new JsonMockResponse(

src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ public static function unsupportedMessagesProvider(): iterable
4545
yield [new DummyMessage()];
4646
}
4747

48-
public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
49-
{
50-
$transport = self::createTransport();
51-
52-
$this->expectException(LengthException::class);
53-
$this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.');
54-
55-
$transport->send(new ChatMessage(str_repeat('', 2001)));
56-
}
57-
5848
public function testSendWithErrorResponseThrows()
5949
{
6050
$response = $this->createMock(ResponseInterface::class);

src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordAuthorEmbedObject;
16-
use Symfony\Component\Notifier\Exception\LengthException;
1716

1817
final class DiscordAuthorEmbedObjectTest extends TestCase
1918
{
@@ -32,12 +31,4 @@ public function testCanBeInstantiated()
3231
'proxy_icon_url' => 'http://proxy-icon-ur.l',
3332
], $author->toArray());
3433
}
35-
36-
public function testThrowsWhenNameExceedsCharacterLimit()
37-
{
38-
$this->expectException(LengthException::class);
39-
$this->expectExceptionMessage('Maximum length for the name is 256 characters.');
40-
41-
(new DiscordAuthorEmbedObject())->name(str_repeat('š', 257));
42-
}
4334
}

src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed;
1616
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject;
17-
use Symfony\Component\Notifier\Exception\LengthException;
1817

1918
final class DiscordEmbedTest extends TestCase
2019
{
@@ -39,39 +38,4 @@ public function testCanBeInstantiated()
3938
],
4039
], $embed->toArray());
4140
}
42-
43-
public function testThrowsWhenTitleExceedsCharacterLimit()
44-
{
45-
$this->expectException(LengthException::class);
46-
$this->expectExceptionMessage('Maximum length for the title is 256 characters.');
47-
48-
(new DiscordEmbed())->title(str_repeat('š', 257));
49-
}
50-
51-
public function testThrowsWhenDescriptionExceedsCharacterLimit()
52-
{
53-
$this->expectException(LengthException::class);
54-
$this->expectExceptionMessage('Maximum length for the description is 4096 characters.');
55-
56-
(new DiscordEmbed())->description(str_repeat('š', 4097));
57-
}
58-
59-
public function testThrowsWhenFieldsLimitReached()
60-
{
61-
$embed = new DiscordEmbed();
62-
for ($i = 0; $i < 25; ++$i) {
63-
$embed->addField((new DiscordFieldEmbedObject())
64-
->name('baz')
65-
->value('qux')
66-
);
67-
}
68-
69-
$this->expectException(\LogicException::class);
70-
$this->expectExceptionMessage('Maximum number of fields should not exceed 25.');
71-
72-
$embed->addField((new DiscordFieldEmbedObject())
73-
->name('fail')
74-
->value('fail')
75-
);
76-
}
7741
}

0 commit comments

Comments
 (0)