| Total Complexity | 8 |
| Total Lines | 142 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class FakeResponse |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Response body. |
||
| 11 | * |
||
| 12 | * @var mixed |
||
| 13 | */ |
||
| 14 | protected $body; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * HTTP Status. |
||
| 18 | * |
||
| 19 | * @var int |
||
| 20 | */ |
||
| 21 | protected $status = 200; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * HTTP Headers. |
||
| 25 | * |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected $headers = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * HTTP Version. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $httpVersion = '1.1'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Reason phrase. |
||
| 39 | */ |
||
| 40 | protected $reason; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Creates new fake HTTP Response. |
||
| 44 | * |
||
| 45 | * @return $this |
||
| 46 | */ |
||
| 47 | public static function fake() |
||
| 48 | { |
||
| 49 | return new static(); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Sets HTTP response status. |
||
| 54 | * |
||
| 55 | * @param int $status |
||
| 56 | * |
||
| 57 | * @return $this |
||
| 58 | */ |
||
| 59 | public function withStatus(int $status) |
||
| 60 | { |
||
| 61 | $this->status = $status; |
||
| 62 | |||
| 63 | return $this; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Sets HTTP response body. |
||
| 68 | * |
||
| 69 | * @param string|null|resource|\Psr\Http\Message\StreamInterface $body |
||
| 70 | * |
||
| 71 | * @return $this |
||
| 72 | */ |
||
| 73 | public function withBody($body) |
||
| 74 | { |
||
| 75 | $this->body = $body; |
||
| 76 | |||
| 77 | return $this; |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Sets response's JSON content. |
||
| 82 | * |
||
| 83 | * @param array $json |
||
| 84 | * |
||
| 85 | * @return $this |
||
| 86 | */ |
||
| 87 | public function withJson(array $json) |
||
| 88 | { |
||
| 89 | $this->body = json_encode($json); |
||
| 90 | |||
| 91 | return $this; |
||
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Sets response's HTTP headers. |
||
| 96 | * |
||
| 97 | * @param array $headers |
||
| 98 | * |
||
| 99 | * @return $this |
||
| 100 | */ |
||
| 101 | public function withHeaders(array $headers) |
||
| 102 | { |
||
| 103 | $this->headers = $headers; |
||
| 104 | |||
| 105 | return $this; |
||
| 106 | } |
||
| 107 | |||
| 108 | /** |
||
| 109 | * Sets HTTP version. |
||
| 110 | * |
||
| 111 | * @param string $version |
||
| 112 | * |
||
| 113 | * @return $this |
||
| 114 | */ |
||
| 115 | public function withHttpVersion(string $version) |
||
| 116 | { |
||
| 117 | $this->httpVersion = $version; |
||
| 118 | |||
| 119 | return $this; |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Sets Reason Phrase. |
||
| 124 | * |
||
| 125 | * @param string $reason |
||
| 126 | * |
||
| 127 | * @return $this |
||
| 128 | */ |
||
| 129 | public function withReason(string $reason) |
||
| 130 | { |
||
| 131 | $this->reason = $reason; |
||
| 132 | |||
| 133 | return $this; |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Generates HTTP Response. |
||
| 138 | * |
||
| 139 | * @return Response |
||
| 140 | */ |
||
| 141 | public function toResponse(): Response |
||
| 149 | ); |
||
| 150 | } |
||
| 151 | } |
||
| 152 |