Total Complexity | 10 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class Responding |
||
15 | { |
||
16 | /** |
||
17 | * @var Response |
||
18 | */ |
||
19 | private $response = null; |
||
20 | |||
21 | /** |
||
22 | * Responding constructor. |
||
23 | * @param Response $response |
||
24 | */ |
||
25 | public function __construct(Response $response) |
||
26 | { |
||
27 | $this->response = $response; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return int |
||
32 | */ |
||
33 | public function code() : int |
||
34 | { |
||
35 | return $this->response->getStatusCode(); |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function phrase() : string |
||
42 | { |
||
43 | return $this->response->getReasonPhrase(); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param string $key |
||
48 | * @return string |
||
49 | */ |
||
50 | public function header(string $key) : ?string |
||
51 | { |
||
52 | return $this->response->hasHeader($key) ? $this->response->getHeaderLine($key) : null; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * raw response content |
||
57 | * @return string |
||
58 | */ |
||
59 | public function payload() : string |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * parsed data with status checking |
||
66 | * @return string |
||
67 | * @throws ErrorResponseException |
||
68 | */ |
||
69 | public function data() : string |
||
70 | { |
||
71 | $code = $this->response->getStatusCode(); |
||
72 | |||
73 | if ($code >= 400 && $code < 600) { |
||
74 | throw new ErrorResponseException($this->response->getReasonPhrase(), $code); |
||
75 | } |
||
76 | |||
77 | return $this->payload(); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @deprecated |
||
82 | * @return string |
||
83 | */ |
||
84 | public function __toString() : string |
||
87 | } |
||
88 | } |
||
89 |