MalformedResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
c 0
b 0
f 0
dl 0
loc 43
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 3 1
A __construct() 0 10 1
A getResponseAsString() 0 3 1
A getRequestAsString() 0 3 1
A __toString() 0 6 1
A getRequest() 0 3 1
1
<?php
2
3
namespace Promopult\TikTokMarketingApi\Exception;
4
5
use GuzzleHttp\Psr7\Message;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
class MalformedResponse extends \RuntimeException
10
{
11
    private RequestInterface $request;
12
    private ResponseInterface $response;
13
14
    public function __construct(
15
        RequestInterface $request,
16
        ResponseInterface $response,
17
        string $message = 'Unexpected Tik-Tok API response.',
18
        int $code = 0,
19
        \Throwable $previous = null
20
    ) {
21
        parent::__construct($message, $code, $previous);
22
        $this->request = $request;
23
        $this->response = $response;
24
    }
25
26
    public function getRequest(): RequestInterface
27
    {
28
        return $this->request;
29
    }
30
31
    public function getResponse(): ResponseInterface
32
    {
33
        return $this->response;
34
    }
35
36
    public function getResponseAsString(): string
37
    {
38
        return Message::toString($this->response);
39
    }
40
41
    public function getRequestAsString(): string
42
    {
43
        return Message::toString($this->request);
44
    }
45
46
    public function __toString(): string
47
    {
48
        return parent::__toString() . PHP_EOL
49
            . 'Http log:' . PHP_EOL
50
            . '>>>' . PHP_EOL . $this->getRequestAsString() . PHP_EOL
51
            . '<<<' . PHP_EOL . $this->getResponseAsString()
52
        ;
53
    }
54
}
55