SendingNotificationFailed   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 41
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A for() 0 14 1
A getChannelName() 0 4 1
A getNotification() 0 4 1
A getRecipient() 0 4 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