couldNotCommunicateWithWorkplace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Workplace\Exceptions;
4
5
use GuzzleHttp\Exception\ClientException;
6
7
class CouldNotSendNotification extends \Exception
8
{
9
    /**
10
     * Thrown when there's a bad request and an error is responded.
11
     *
12
     * @param ClientException $exception
13
     *
14
     * @return static
15
     */
16
    public static function workplaceRespondedWithAnError(ClientException $exception)
17
    {
18
        $statusCode = $exception->getResponse()->getStatusCode();
19
        $description = 'No description given';
20
        if ($result = json_decode($exception->getResponse()->getBody())) {
21
            $description = $result->description ?? $description;
22
        }
23
24
        return new static("Workplace responded with an error `{$statusCode} - {$description}`");
25
    }
26
27
    /**
28
     * Thrown when there is workplace endpoint defined.
29
     *
30
     * @return static
31
     */
32 1
    public static function endpointNotProvided()
33
    {
34 1
        return new static('Workplace notification endpoint was not provided. Please refer usage docs.');
35
    }
36
37
    /**
38
     * Thrown when we're unable to communicate with Workplace.
39
     *
40
     * @return static
41
     */
42
    public static function couldNotCommunicateWithWorkplace($message)
43
    {
44
        return new static("The communication with Workplace failed. `{$message}`");
45
    }
46
}
47