ChannelHandleException::createOnException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Yokai\MessengerBundle\Exception;
4
5
use Exception;
6
use RuntimeException;
7
use Yokai\MessengerBundle\Channel\ChannelInterface;
8
use Yokai\MessengerBundle\Delivery;
9
use Yokai\MessengerBundle\Message;
10
11
/**
12
 * @author Yann Eugoné <[email protected]>
13
 */
14
class ChannelHandleException extends RuntimeException implements ExceptionInterface
15
{
16
    /**
17
     * @param ChannelInterface $channel
18
     * @param Delivery         $delivery
19
     * @param Exception       $previous
20
     *
21
     * @return ChannelHandleException
22
     */
23 2
    public static function createOnException(ChannelInterface $channel, Delivery $delivery, Exception $previous)
24
    {
25 2
        return new self(
26 2
            sprintf(
27
                'An error has occurred during the notification process of message "%s" for channel "%s".'
28 2
                .' Exception : %s - %s',
29 2
                $delivery->getMessage(),
30 2
                get_class($channel),
31 2
                get_class($previous),
32 2
                $previous->getMessage()
33
            ),
34 2
            0,
35 2
            $previous
36
        );
37
    }
38
39
    /**
40
     * @param ChannelInterface $channel
41
     * @param Message          $message
42
     * @param mixed            $recipient
43
     *
44
     * @return ChannelHandleException
45
     */
46 1
    public static function unsupportedRecipient(ChannelInterface $channel, Message $message, $recipient)
47
    {
48 1
        return new self(
49 1
            sprintf(
50 1
                'The recipient "%s" is not supported by channel "%s" for message "%s".',
51 1
                is_object($recipient) ? get_class($recipient) : gettype($recipient),
52 1
                get_class($channel),
53 1
                $message->getId()
54
            )
55
        );
56
    }
57
}
58