contentLengthLimitExceeded()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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