CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 6
c 1
b 0
f 0
dl 0
loc 39
ccs 2
cts 8
cp 0.25
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A couldNotCommunicateWithSmspoh() 0 3 1
A smspohRespondedWithAnError() 0 7 2
A contentLengthLimitExceeded() 0 3 1
1
<?php
2
3
namespace NotificationChannels\Smspoh\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
8
class CouldNotSendNotification extends Exception
9
{
10
    /**
11
     * Thrown when content length is greater than 918 characters.
12
     *
13
     * @param $count
14
     * @return static
15
     */
16 1
    public static function contentLengthLimitExceeded($count): self
17
    {
18 1
        return new static("Notification was not sent. Content length may not be greater than {$count} characters.", 422);
19
    }
20
21
    /**
22
     * Thrown when we're unable to communicate with smspoh.
23
     *
24
     * @param ClientException $exception
25
     *
26
     * @return static
27
     */
28
    public static function smspohRespondedWithAnError(ClientException $exception): self
29
    {
30
        if (! $exception->hasResponse()) {
31
            return new static('Smspoh responded with an error but no response body found');
32
        }
33
34
        return new static("Smspoh responded with an error '{$exception->getCode()} : {$exception->getMessage()}'", $exception->getCode(), $exception);
35
    }
36
37
    /**
38
     * Thrown when we're unable to communicate with smspoh.
39
     *
40
     * @param Exception $exception
41
     *
42
     * @return static
43
     */
44
    public static function couldNotCommunicateWithSmspoh(Exception $exception): self
45
    {
46
        return new static("The communication with smspoh failed. Reason: {$exception->getMessage()}", $exception->getCode(), $exception);
47
    }
48
}
49