SendingNotificationFailed::getChannelName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Notifier\Exception;
6
7
use Notifier\Notification\Notification;
8
use Notifier\Recipient\Recipient;
9
use ReflectionClass;
10
use RuntimeException;
11
use Throwable;
12
13
final class SendingNotificationFailed extends RuntimeException implements NotifierException
14
{
15
    /** @var string */
16
    private $channelName;
17
18
    /** @var Notification */
19
    private $notification;
20
21
    /** @var Recipient */
22
    private $recipient;
23
24 2
    public static function for(string $channelName, Notification $notification, Recipient $recipient, Throwable $error): self
25
    {
26 2
        $exception = new self(sprintf(
27 2
            'Failed to send %s via %s channel',
28 2
            (new ReflectionClass($notification))->getShortName(),
29 2
            $channelName
30 2
        ), 0, $error);
31
32 2
        $exception->channelName = $channelName;
33 2
        $exception->notification = $notification;
34 2
        $exception->recipient = $recipient;
35
36 2
        return $exception;
37
    }
38
39 2
    public function getChannelName(): string
40
    {
41 2
        return $this->channelName;
42
    }
43
44 2
    public function getNotification(): Notification
45
    {
46 2
        return $this->notification;
47
    }
48
49 2
    public function getRecipient(): Recipient
50
    {
51 2
        return $this->recipient;
52
    }
53
}
54