SproutsocialsApiException::getResponseUUID()   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 0
crap 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