Completed
Push — master ( bb12ea...352126 )
by Dmitry
02:13
created

MalformedResponse::getResponseAsString()   A

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
class MalformedResponse extends \RuntimeException
6
{
7
    /**
8
     * @var \Psr\Http\Message\RequestInterface
9
     */
10
    private $request;
11
12
    /**
13
     * @var \Psr\Http\Message\ResponseInterface
14
     */
15
    private $response;
16
17
    public function __construct(
18
        \Psr\Http\Message\RequestInterface $request,
19
        \Psr\Http\Message\ResponseInterface $response,
20
        $message = 'Unexpected Tik-Tok API response.',
21
        $code = 0,
22
        \Throwable $previous = null
23
    ) {
24
        parent::__construct($message, $code, $previous);
25
        $this->request = $request;
26
        $this->response = $response;
27
    }
28
29
    public function getRequest(): \Psr\Http\Message\RequestInterface
30
    {
31
        return $this->request;
32
    }
33
34
    public function getResponse(): \Psr\Http\Message\ResponseInterface
35
    {
36
        return $this->response;
37
    }
38
39
    public function getResponseAsString(): string
40
    {
41
        return \GuzzleHttp\Psr7\Message::toString($this->response);
42
    }
43
44
    public function getRequestAsString(): string
45
    {
46
        return \GuzzleHttp\Psr7\Message::toString($this->request);
47
    }
48
49
    public function __toString(): string
50
    {
51
        return parent::__toString() . PHP_EOL
52
            . 'Http log:' . PHP_EOL
53
            . '>>>' . $this->getRequestAsString() . PHP_EOL
54
            . '<<<' . $this->getResponseAsString()
55
        ;
56
    }
57
}
58