Completed
Push — master ( ee119a...dae0ea )
by Hamoud
02:12
created

couldNotSendRequestToMobilyWs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
namespace NotificationChannels\MobilyWs\Exceptions;
4
5
use GuzzleHttp\Psr7\Response;
6
use GuzzleHttp\Exception\RequestException;
7
8
class CouldNotSendMobilyWsNotification extends \Exception
9
{
10
    /**
11
     * Thrown when mobily.ws return a response body other than '1'.
12
     *
13
     * @param $code
14
     * @param $message
15
     *
16
     * @return static
17
     */
18 2
    public static function mobilyWsRespondedWithAnError($code, $message)
19
    {
20 2
        return new static(
21 2
            sprintf("Mobily.ws responded with error number %s and message:\n%s",
22 2
                $code,
23
                $message
24 2
            ));
25
    }
26
27
    /**
28
     * Thrown when GuzzleHttp throw a request exception.
29
     *
30
     * @param RequestException $exception
31
     *
32
     * @return static
33
     */
34 1
    public static function couldNotSendRequestToMobilyWs(RequestException $exception)
35
    {
36 1
        return new static(
37 1
            'Request to mobily.ws failed',
38 1
            $exception->getCode(),
39
            $exception
40 1
        );
41
    }
42
43
    /**
44
     * Thrown when any other errors received.
45
     *
46
     * @param Response $response
47
     *
48
     * @return static
49
     */
50
    public static function someErrorWhenSendingSms(Response $response)
51
    {
52
        $code = $response->getStatusCode();
53
        $message = $response->getBody()->getContents();
54
55
        return new static(
56
            sprintf('Could not send sms notification to mobily.ws. Status code %s and message: %s', $code, $message)
57
        );
58
    }
59
60
    /**
61
     * Thrown when any other errors occur.
62
     *
63
     * @param $message
64
     *
65
     * @return static
66
     */
67 8
    public static function withErrorMessage($message)
68
    {
69 8
        return new static($message);
70
    }
71
}
72