CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 27
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serviceRespondedWithAnError() 0 14 3
A curlError() 0 4 1
A exceededOfMessages() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Line\Exceptions;
4
5
use LINE\LINEBot\Response;
6
use LINE\LINEBot\Exception\CurlExecutionException;
7
8
class CouldNotSendNotification extends \Exception
9
{
10
    public static function serviceRespondedWithAnError(Response $response)
11
    {
12
        $responseBody = $response->getJSONDecodedBody();
13
        $errorMsg = $response->getHeader('X-Line-Request-Id').': '.$responseBody['message'];
14
15
        if (preg_match('/The request body has [\d]+ errors?/', $responseBody['message'], $matches)) {
16
            foreach ($responseBody['details'] as $detail) {
17
                $errorMsg .= PHP_EOL.$detail['message'];
18
                $errorMsg .= PHP_EOL.$detail['property'];
19
            }
20
        }
21
22
        return new static($errorMsg);
23
    }
24
25
    public static function curlError(CurlExecutionException $exeption)
26
    {
27
        return new static('LINEBot Curl error: '.$exeption->getMessage());
28
    }
29
30
    public static function exceededOfMessages(int $count)
31
    {
32
        return new static('It exceeds the maximum of messages that can be sent. max:5, attempted:'.$count);
33
    }
34
}
35