| Total Complexity | 10 |
| Total Lines | 109 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | class Response |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var array |
||
| 13 | */ |
||
| 14 | private array $headers; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var int |
||
| 18 | */ |
||
| 19 | private int $statusCode; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Response constructor. |
||
| 23 | */ |
||
| 24 | public function __construct() |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Added several headers. |
||
| 32 | * |
||
| 33 | * @param array $headers |
||
| 34 | * @return $this |
||
| 35 | */ |
||
| 36 | public function addHeaders(array $headers): Response |
||
| 37 | { |
||
| 38 | foreach ($headers as $v) { |
||
| 39 | $this->headers[] = $v; |
||
| 40 | } |
||
| 41 | |||
| 42 | return $this; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Added a header. |
||
| 47 | * |
||
| 48 | * @param string $header |
||
| 49 | * @param mixed $value |
||
| 50 | * @return $this |
||
| 51 | */ |
||
| 52 | public function addHeader(string $header, $value): Response |
||
| 53 | { |
||
| 54 | $this->headers[$header] = $value; |
||
| 55 | |||
| 56 | return $this; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Returns the defined headers. |
||
| 61 | * @return array |
||
| 62 | */ |
||
| 63 | public function getHeaders(): array |
||
| 64 | { |
||
| 65 | return $this->headers; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Set status code. |
||
| 70 | * |
||
| 71 | * @param int $statusCode |
||
| 72 | * @return $this |
||
| 73 | */ |
||
| 74 | public function setStatusCode(int $statusCode): Response |
||
| 75 | { |
||
| 76 | $this->statusCode = $statusCode; |
||
| 77 | |||
| 78 | return $this; |
||
| 79 | } |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Returns the defined status code. |
||
| 83 | * |
||
| 84 | * @return int |
||
| 85 | */ |
||
| 86 | public function getStatusCode(): int |
||
| 87 | { |
||
| 88 | return $this->statusCode; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Set all headers. |
||
| 93 | * |
||
| 94 | * @return $this |
||
| 95 | */ |
||
| 96 | public function response(): Response |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Return a json and set the header to application/json. |
||
| 109 | * |
||
| 110 | * @param array $data |
||
| 111 | * @return false|string |
||
| 112 | */ |
||
| 113 | public function json(array $data) |
||
| 118 | } |
||
| 119 | } |