Test Failed
Push — master ( 6f7a22...abd8b8 )
by Hirofumi
31:24
created

SlackGateway::destinationType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Infrastructure\Domain\Model;
5
6
use Maknz\Slack\Client;
7
use Maknz\Slack\Message;
8
use Shippinno\Notification\Domain\Model\Gateway;
9
use Shippinno\Notification\Domain\Model\Notification;
10
use Shippinno\Notification\Domain\Model\NotificationNotSentException;
11
use Shippinno\Notification\Domain\Model\SlackChannelDestination;
12
use Throwable;
13
14
class SlackGateway extends Gateway
15
{
16
    /**
17
     * @var Client
18
     */
19
    private $client;
20
21
    /**
22
     * @param Client $client
23
     */
24
    public function __construct(Client $client)
25
    {
26
        $this->client = $client;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    protected function doSend(Notification $notification): void
33
    {
34
        /** @var SlackChannelDestination $destination */
35
        $destination = $notification->destination();
36
        $text = $notification->subject()->subject()."\n\n";
37
        $text .= $notification->body()->body();
38
        $message = new Message($this->client);
39
        $message->setAllowMarkdown(true);
40
        $message->setText($text);
41
        $message->setChannel($destination->channel());
42
        try {
43
            $message->send();
44
        } catch (Throwable $e) {
1 ignored issue
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
45
            throw new NotificationNotSentException($notification, $e);
46
        }
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function destinationType(): string
53
    {
54
        return SlackChannelDestination::class;
55
    }
56
}
57