Total Complexity | 4 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
5 | class RawResponse { |
||
6 | |||
7 | /** @var string */ |
||
8 | public $request; |
||
9 | |||
10 | /** @var array */ |
||
11 | public $header; |
||
12 | |||
13 | /** @var array|string */ |
||
14 | public $body; |
||
15 | |||
16 | public static function createFrom(string $method, string $url, string $response, int $headerSize) : self { |
||
17 | |||
18 | $result = new self(); |
||
19 | |||
20 | $header = substr($response, 0, $headerSize); |
||
21 | $body = substr($response, $headerSize); |
||
22 | |||
23 | $body_json = json_decode($body, true); |
||
24 | |||
25 | $result->request = $method . ' ' . $url; |
||
26 | |||
27 | $result->header = array_map(function($line) { |
||
28 | return trim($line); |
||
29 | }, explode("\n", $header)); |
||
30 | |||
31 | $result->body = $body_json === null ? $body : $body_json; |
||
32 | |||
33 | return $result; |
||
34 | } |
||
35 | |||
36 | public function toString() : string { |
||
42 | ]); |
||
43 | } |
||
44 | |||
45 | public static function getFromString(string $string) : self { |
||
56 | } |
||
57 | } |