Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 21c4768

Browse files
OskarStarkfabpot
authored andcommitted
[Notifier][Discord] Make webhookId argument required
1 parent 9052b2b commit 21c4768

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class DiscordTransport extends AbstractTransport
3232
private $token;
3333
private $webhookId;
3434

35-
public function __construct(string $token, string $webhookId = null, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
35+
public function __construct(string $token, string $webhookId, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
3636
{
3737
$this->token = $token;
3838
$this->webhookId = $webhookId;

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

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

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

14+
use Symfony\Component\Notifier\Exception\IncompleteDsnException;
1415
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
1516
use Symfony\Component\Notifier\Transport\AbstractTransportFactory;
1617
use Symfony\Component\Notifier\Transport\Dsn;
@@ -31,6 +32,11 @@ public function create(Dsn $dsn): TransportInterface
3132
$scheme = $dsn->getScheme();
3233
$token = $this->getUser($dsn);
3334
$webhookId = $dsn->getOption('webhook_id');
35+
36+
if (!$webhookId) {
37+
throw new IncompleteDsnException('Missing webhook_id.', $dsn->getOriginalDsn());
38+
}
39+
3440
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3541
$port = $dsn->getPort();
3642

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ public function testCreateWithDsn()
3131
$this->assertSame(sprintf('discord://%s?webhook_id=%s', $host, $webhookId), (string) $transport);
3232
}
3333

34+
public function testCreateWithNoWebhookIdThrowsMalformed(): void
35+
{
36+
$factory = new DiscordTransportFactory();
37+
38+
$this->expectException(IncompleteDsnException::class);
39+
40+
$factory->create(Dsn::fromString('discord://token@host'));
41+
}
42+
3443
public function testCreateWithNoTokenThrowsMalformed()
3544
{
3645
$factory = new DiscordTransportFactory();

0 commit comments

Comments
 (0)