MalformedResponse::getResponseAsString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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