SproutsocialsApiException   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseUUID() 0 3 1
A __construct() 0 9 2
A getResponseApiVersion() 0 3 1
A getResponseServerVersion() 0 3 1
A getResponse() 0 3 1
1
<?php
2
3
4
namespace ThinkOne\LaravelSproutsocialsApi;
5
6
use Illuminate\Http\Client\Response;
7
8
class SproutsocialsApiException extends \Exception
9
{
10
    protected Response $response;
11
12 2
    public function __construct(Response $response)
13
    {
14 2
        $this->response = $response;
15 2
        $error          = $this->response->json('error', '');
16 2
        if (!$error) {
17 2
            $error = $this->response->json('message', '');
18
        }
19
20 2
        parent::__construct("Api returned error: \"{$error}\". Meta: {$this->getResponseApiVersion()}|{$this->getResponseServerVersion()}|{$this->getResponseUUID()}", $response->status());
21
    }
22
23
24
    /**
25
     * @return Response
26
     */
27 1
    public function getResponse(): Response
28
    {
29 1
        return $this->response;
30
    }
31
32
    /**
33
     * @return Response
34
     */
35 2
    public function getResponseUUID(): string
36
    {
37 2
        return (string)$this->response->header('X-Sprout-Request-ID');
38
    }
39
40
    /**
41
     * @return Response
42
     */
43 2
    public function getResponseServerVersion(): string
44
    {
45 2
        return (string)$this->response->header('X-Sprout-Server-Version');
46
    }
47
48
    /**
49
     * @return Response
50
     */
51 2
    public function getResponseApiVersion(): string
52
    {
53 2
        return (string)$this->response->header('X-Sprout-API-Version');
54
    }
55
}
56