Skip to content

Commit 437cad7

Browse files
committed
[Notifier] Introduce LengthException
1 parent 75323bd commit 437cad7

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

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

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

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

14-
use Symfony\Component\Notifier\Exception\LogicException;
14+
use Symfony\Component\Notifier\Exception\LengthException;
1515
use Symfony\Component\Notifier\Exception\TransportException;
1616
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
1717
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -67,7 +67,7 @@ protected function doSend(MessageInterface $message): SentMessage
6767
$content = $message->getSubject();
6868

6969
if (\strlen($content) > 2000) {
70-
throw new LogicException('The subject length of a Discord message must not exceed 2000 characters.');
70+
throw new LengthException('The subject length of a Discord message must not exceed 2000 characters.');
7171
}
7272

7373
$endpoint = sprintf('https://%s/api/webhooks/%s/%s', $this->getEndpoint(), $this->webhookId, $this->token);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\HttpClient\MockHttpClient;
1616
use Symfony\Component\Notifier\Bridge\Discord\DiscordTransport;
17-
use Symfony\Component\Notifier\Exception\LogicException;
17+
use Symfony\Component\Notifier\Exception\LengthException;
1818
use Symfony\Component\Notifier\Exception\TransportException;
1919
use Symfony\Component\Notifier\Exception\UnsupportedMessageTypeException;
2020
use Symfony\Component\Notifier\Message\ChatMessage;
@@ -55,7 +55,7 @@ public function testSendChatMessageWithMoreThan2000CharsThrowsLogicException()
5555
{
5656
$transport = new DiscordTransport('testToken', 'testChannel', $this->createMock(HttpClientInterface::class));
5757

58-
$this->expectException(LogicException::class);
58+
$this->expectException(LengthException::class);
5959
$this->expectExceptionMessage('The subject length of a Discord message must not exceed 2000 characters.');
6060

6161
$transport->send(new ChatMessage(str_repeat('d', 2001)));

src/Symfony/Component/Notifier/Bridge/Slack/Block/SlackHeaderBlock.php

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

1212
namespace Symfony\Component\Notifier\Bridge\Slack\Block;
1313

14-
use Symfony\Component\Notifier\Exception\LogicException;
14+
use Symfony\Component\Notifier\Exception\LengthException;
1515

1616
/**
1717
* @author Tomas Norkūnas <norkunas.tom@gmail.com>
@@ -26,7 +26,7 @@ final class SlackHeaderBlock extends AbstractSlackBlock
2626
public function __construct(string $text)
2727
{
2828
if (\strlen($text) > self::TEXT_LIMIT) {
29-
throw new LogicException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
29+
throw new LengthException(sprintf('Maximum length for the text is %d characters.', self::TEXT_LIMIT));
3030
}
3131

3232
$this->options = [
@@ -41,7 +41,7 @@ public function __construct(string $text)
4141
public function id(string $id): self
4242
{
4343
if (\strlen($id) > self::ID_LIMIT) {
44-
throw new LogicException(sprintf('Maximum length for the block id is %d characters.', self::ID_LIMIT));
44+
throw new LengthException(sprintf('Maximum length for the block id is %d characters.', self::ID_LIMIT));
4545
}
4646

4747
$this->options['block_id'] = $id;

src/Symfony/Component/Notifier/Bridge/Slack/Tests/Block/SlackHeaderBlockTest.php

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

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Notifier\Bridge\Slack\Block\SlackHeaderBlock;
16-
use Symfony\Component\Notifier\Exception\LogicException;
16+
use Symfony\Component\Notifier\Exception\LengthException;
1717

1818
final class SlackHeaderBlockTest extends TestCase
1919
{
@@ -34,15 +34,15 @@ public function testCanBeInstantiated(): void
3434

3535
public function testThrowsWhenTextExceedsCharacterLimit(): void
3636
{
37-
$this->expectException(LogicException::class);
37+
$this->expectException(LengthException::class);
3838
$this->expectExceptionMessage('Maximum length for the text is 150 characters.');
3939

4040
new SlackHeaderBlock(str_repeat('h', 151));
4141
}
4242

4343
public function testThrowsWhenBlockIdExceedsCharacterLimit(): void
4444
{
45-
$this->expectException(LogicException::class);
45+
$this->expectException(LengthException::class);
4646
$this->expectExceptionMessage('Maximum length for the block id is 255 characters.');
4747

4848
$header = new SlackHeaderBlock('header');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
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+
12+
namespace Symfony\Component\Notifier\Exception;
13+
14+
/**
15+
* @author Oskar Stark <oskarstark@googlemail.com>
16+
*
17+
* @experimental in 5.3
18+
*/
19+
class LengthException extends LogicException
20+
{
21+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy