diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordBotTransport.php b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordBotTransport.php index d99cbebd5309f..740e381b47101 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordBotTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordBotTransport.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Notifier\Bridge\Discord; -use Symfony\Component\Notifier\Exception\LengthException; use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException; @@ -31,8 +30,6 @@ final class DiscordBotTransport extends AbstractTransport { protected const HOST = 'discord.com'; - private const SUBJECT_LIMIT = 2000; - public function __construct( #[\SensitiveParameter] private string $token, ?HttpClientInterface $client = null, @@ -65,10 +62,6 @@ protected function doSend(MessageInterface $message): SentMessage $options = $message->getOptions()?->toArray() ?? []; $options['content'] = $message->getSubject(); - if (mb_strlen($options['content'], 'UTF-8') > self::SUBJECT_LIMIT) { - throw new LengthException(\sprintf('The subject length of a Discord message must not exceed %d characters.', self::SUBJECT_LIMIT)); - } - $endpoint = \sprintf('https://%s/api/channels/%s/messages', $this->getEndpoint(), $channelId); $response = $this->client->request('POST', $endpoint, [ 'headers' => [ diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php index cad26db49a342..895877be0289a 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/DiscordTransport.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Notifier\Bridge\Discord; -use Symfony\Component\Notifier\Exception\LengthException; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException; use Symfony\Component\Notifier\Message\ChatMessage; @@ -29,8 +28,6 @@ final class DiscordTransport extends AbstractTransport { protected const HOST = 'discord.com'; - private const SUBJECT_LIMIT = 2000; - public function __construct( #[\SensitiveParameter] private string $token, private string $webhookId, @@ -62,10 +59,6 @@ protected function doSend(MessageInterface $message): SentMessage $options = $message->getOptions()?->toArray() ?? []; $options['content'] = $message->getSubject(); - if (mb_strlen($options['content'], 'UTF-8') > self::SUBJECT_LIMIT) { - throw new LengthException(\sprintf('The subject length of a Discord message must not exceed %d characters.', self::SUBJECT_LIMIT)); - } - $endpoint = \sprintf('https://%s/api/webhooks/%s/%s', $this->getEndpoint(), $this->webhookId, $this->token); $response = $this->client->request('POST', $endpoint, [ 'json' => array_filter($options), diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordAuthorEmbedObject.php b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordAuthorEmbedObject.php index 4a8356baceec5..7dfb1cc1befc5 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordAuthorEmbedObject.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordAuthorEmbedObject.php @@ -11,24 +11,16 @@ namespace Symfony\Component\Notifier\Bridge\Discord\Embeds; -use Symfony\Component\Notifier\Exception\LengthException; - /** * @author Karoly Gossler */ final class DiscordAuthorEmbedObject extends AbstractDiscordEmbedObject { - private const NAME_LIMIT = 256; - /** * @return $this */ public function name(string $name): static { - if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT)); - } - $this->options['name'] = $name; return $this; diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordEmbed.php b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordEmbed.php index 29f6750ebd3fb..286e5ebc242e8 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordEmbed.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordEmbed.php @@ -11,26 +11,16 @@ namespace Symfony\Component\Notifier\Bridge\Discord\Embeds; -use Symfony\Component\Notifier\Exception\LengthException; - /** * @author Karoly Gossler */ final class DiscordEmbed extends AbstractDiscordEmbed { - private const TITLE_LIMIT = 256; - private const DESCRIPTION_LIMIT = 4096; - private const FIELDS_LIMIT = 25; - /** * @return $this */ public function title(string $title): static { - if (mb_strlen($title, 'UTF-8') > self::TITLE_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the title is %d characters.', self::TITLE_LIMIT)); - } - $this->options['title'] = $title; return $this; @@ -41,10 +31,6 @@ public function title(string $title): static */ public function description(string $description): static { - if (mb_strlen($description, 'UTF-8') > self::DESCRIPTION_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the description is %d characters.', self::DESCRIPTION_LIMIT)); - } - $this->options['description'] = $description; return $this; @@ -125,10 +111,6 @@ public function author(DiscordAuthorEmbedObject $author): static */ public function addField(DiscordFieldEmbedObject $field): static { - if (self::FIELDS_LIMIT === \count($this->options['fields'] ?? [])) { - throw new LengthException(\sprintf('Maximum number of fields should not exceed %d.', self::FIELDS_LIMIT)); - } - if (!isset($this->options['fields'])) { $this->options['fields'] = []; } diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFieldEmbedObject.php b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFieldEmbedObject.php index b529f55d602ee..79f8bca808f98 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFieldEmbedObject.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFieldEmbedObject.php @@ -11,25 +11,16 @@ namespace Symfony\Component\Notifier\Bridge\Discord\Embeds; -use Symfony\Component\Notifier\Exception\LengthException; - /** * @author Karoly Gossler */ final class DiscordFieldEmbedObject extends AbstractDiscordEmbedObject { - private const NAME_LIMIT = 256; - private const VALUE_LIMIT = 1024; - /** * @return $this */ public function name(string $name): static { - if (mb_strlen($name, 'UTF-8') > self::NAME_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the name is %d characters.', self::NAME_LIMIT)); - } - $this->options['name'] = $name; return $this; @@ -40,10 +31,6 @@ public function name(string $name): static */ public function value(string $value): static { - if (mb_strlen($value, 'UTF-8') > self::VALUE_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the value is %d characters.', self::VALUE_LIMIT)); - } - $this->options['value'] = $value; return $this; diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFooterEmbedObject.php b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFooterEmbedObject.php index 8d606ee6c4e68..62d2579a0ecaf 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFooterEmbedObject.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Embeds/DiscordFooterEmbedObject.php @@ -11,24 +11,16 @@ namespace Symfony\Component\Notifier\Bridge\Discord\Embeds; -use Symfony\Component\Notifier\Exception\LengthException; - /** * @author Karoly Gossler */ final class DiscordFooterEmbedObject extends AbstractDiscordEmbedObject { - private const TEXT_LIMIT = 2048; - /** * @return $this */ public function text(string $text): static { - if (mb_strlen($text, 'UTF-8') > self::TEXT_LIMIT) { - throw new LengthException(\sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT)); - } - $this->options['text'] = $text; return $this; diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordBotTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordBotTransportTest.php index 7ca7043eca90d..2534ca5af9260 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordBotTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordBotTransportTest.php @@ -15,7 +15,6 @@ use Symfony\Component\HttpClient\Response\JsonMockResponse; use Symfony\Component\Notifier\Bridge\Discord\DiscordBotTransport; use Symfony\Component\Notifier\Bridge\Discord\DiscordOptions; -use Symfony\Component\Notifier\Exception\LengthException; use Symfony\Component\Notifier\Exception\LogicException; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Message\ChatMessage; @@ -57,16 +56,6 @@ public function testSendThrowsWithoutRecipientId() $transport->send(new ChatMessage('testMessage')); } - public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException() - { - $transport = self::createTransport(); - - $this->expectException(LengthException::class); - $this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.'); - - $transport->send(new ChatMessage(str_repeat('囍', 2001), (new DiscordOptions())->recipient('channel_id'))); - } - public function testSendWithErrorResponseThrows() { $response = new JsonMockResponse( diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php index 6d4a830c1e702..7ee3040148718 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/DiscordTransportTest.php @@ -13,7 +13,6 @@ use Symfony\Component\HttpClient\MockHttpClient; use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport; -use Symfony\Component\Notifier\Exception\LengthException; use Symfony\Component\Notifier\Exception\TransportException; use Symfony\Component\Notifier\Message\ChatMessage; use Symfony\Component\Notifier\Message\SmsMessage; @@ -45,16 +44,6 @@ public static function unsupportedMessagesProvider(): iterable yield [new DummyMessage()]; } - public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException() - { - $transport = self::createTransport(); - - $this->expectException(LengthException::class); - $this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.'); - - $transport->send(new ChatMessage(str_repeat('囍', 2001))); - } - public function testSendWithErrorResponseThrows() { $response = $this->createMock(ResponseInterface::class); diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php index dcc6d2198b527..57024ca5fbd2e 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordAuthorEmbedObject; -use Symfony\Component\Notifier\Exception\LengthException; final class DiscordAuthorEmbedObjectTest extends TestCase { @@ -32,12 +31,4 @@ public function testCanBeInstantiated() 'proxy_icon_url' => 'http://proxy-icon-ur.l', ], $author->toArray()); } - - public function testThrowsWhenNameExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the name is 256 characters.'); - - (new DiscordAuthorEmbedObject())->name(str_repeat('š', 257)); - } } diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php index f79786f6ae7e2..038be54bb8ed6 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php @@ -14,7 +14,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed; use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject; -use Symfony\Component\Notifier\Exception\LengthException; final class DiscordEmbedTest extends TestCase { @@ -39,39 +38,4 @@ public function testCanBeInstantiated() ], ], $embed->toArray()); } - - public function testThrowsWhenTitleExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the title is 256 characters.'); - - (new DiscordEmbed())->title(str_repeat('š', 257)); - } - - public function testThrowsWhenDescriptionExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the description is 4096 characters.'); - - (new DiscordEmbed())->description(str_repeat('š', 4097)); - } - - public function testThrowsWhenFieldsLimitReached() - { - $embed = new DiscordEmbed(); - for ($i = 0; $i < 25; ++$i) { - $embed->addField((new DiscordFieldEmbedObject()) - ->name('baz') - ->value('qux') - ); - } - - $this->expectException(\LogicException::class); - $this->expectExceptionMessage('Maximum number of fields should not exceed 25.'); - - $embed->addField((new DiscordFieldEmbedObject()) - ->name('fail') - ->value('fail') - ); - } } diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFieldEmbedObjectTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFieldEmbedObjectTest.php index 77594c458793e..ab7b75b65cff8 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFieldEmbedObjectTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFieldEmbedObjectTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject; -use Symfony\Component\Notifier\Exception\LengthException; final class DiscordFieldEmbedObjectTest extends TestCase { @@ -30,20 +29,4 @@ public function testCanBeInstantiated() 'inline' => true, ], $field->toArray()); } - - public function testThrowsWhenNameExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the name is 256 characters.'); - - (new DiscordFieldEmbedObject())->name(str_repeat('š', 257)); - } - - public function testThrowsWhenValueExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the value is 1024 characters.'); - - (new DiscordFieldEmbedObject())->value(str_repeat('š', 1025)); - } } diff --git a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFooterEmbedObjectTest.php b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFooterEmbedObjectTest.php index b1c60d6f74d91..a2f9176808a49 100644 --- a/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFooterEmbedObjectTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFooterEmbedObjectTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFooterEmbedObject; -use Symfony\Component\Notifier\Exception\LengthException; final class DiscordFooterEmbedObjectTest extends TestCase { @@ -30,12 +29,4 @@ public function testCanBeInstantiated() 'proxy_icon_url' => 'http://proxy-icon-ur.l', ], $author->toArray()); } - - public function testThrowsWhenTextExceedsCharacterLimit() - { - $this->expectException(LengthException::class); - $this->expectExceptionMessage('Maximum length for the text is 2048 characters.'); - - (new DiscordFooterEmbedObject())->text(str_repeat('š', 2049)); - } }