Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
35 / 35
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractHttp
100.00% covered (success)
100.00%
40 / 40
100.00% covered (success)
100.00%
35 / 35
38
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 setRequest
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setResponse
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isComplete
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 isSuccess
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isContinue
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isOk
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isCreated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isAccepted
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNoContent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isRedirect
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isMovedPermanently
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFound
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isClientError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isBadRequest
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isUnauthorized
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isForbidden
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNotFound
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isMethodNotAllowed
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isNotAcceptable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isRequestTimeout
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isConflict
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isLengthRequired
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isUnsupportedMediaType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isUnprocessableEntity
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isTooManyRequests
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isServerError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isInternalServerError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isBadGateway
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isServiceUnavailable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 send
n/a
0 / 0
n/a
0 / 0
0
 render
n/a
0 / 0
n/a
0 / 0
0
 __toString
n/a
0 / 0
n/a
0 / 0
0
1<?php
2declare(strict_types=1);
3/**
4 * Pop PHP Framework (https://www.popphp.org/)
5 *
6 * @link       https://github.com/popphp/popphp-framework
7 * @author     Nick Sagona, III <nick@popphp.org>
8 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
9 * @license    https://www.popphp.org/license     New BSD License
10 */
11
12/**
13 * @namespace
14 */
15namespace Pop\Http;
16
17/**
18 * Abstract HTTP class
19 *
20 * @category   Pop
21 * @package    Pop\Http
22 * @author     Nick Sagona, III <nick@popphp.org>
23 * @copyright  Copyright (c) 2009-2026 Nick Sagona, III
24 * @license    https://www.popphp.org/license     New BSD License
25 * @version    6.0.0
26 */
27abstract class AbstractHttp implements HttpInterface
28{
29
30    /**
31     * Request
32     * @var ?AbstractRequest
33     */
34    protected ?AbstractRequest $request = null;
35
36    /**
37     * Response
38     * @var ?AbstractResponse
39     */
40    protected ?AbstractResponse $response = null;
41
42    /**
43     * Instantiate the HTTP object
44     *
45     * @param  ?AbstractRequest $request
46     * @param  ?AbstractResponse $response
47     */
48    public function __construct(?AbstractRequest $request = null, ?AbstractResponse $response = null)
49    {
50        if ($request !== null) {
51            $this->setRequest($request);
52        }
53        if ($response !== null) {
54            $this->setResponse($response);
55        }
56    }
57
58    /**
59     * Set the request
60     *
61     * @param  AbstractRequest $request
62     * @return AbstractHttp
63     */
64    public function setRequest(AbstractRequest $request): AbstractHttp
65    {
66        $this->request = $request;
67        return $this;
68    }
69
70    /**
71     * Set the response
72     *
73     * @param  AbstractResponse $response
74     * @return AbstractHttp
75     */
76    public function setResponse(AbstractResponse $response): AbstractHttp
77    {
78        $this->response = $response;
79        return $this;
80    }
81
82    /**
83     * Get the request
84     *
85     * @return AbstractRequest
86     */
87    public function getRequest(): AbstractRequest
88    {
89        return $this->request;
90    }
91
92    /**
93     * Get the response
94     *
95     * @return AbstractResponse
96     */
97    public function getResponse(): AbstractResponse
98    {
99        return $this->response;
100    }
101
102    /**
103     * Has request
104     *
105     * @return bool
106     */
107    public function hasRequest(): bool
108    {
109        return ($this->request !== null);
110    }
111
112    /**
113     * Get the response
114     *
115     * @return bool
116     */
117    public function hasResponse(): bool
118    {
119        return ($this->response !== null);
120    }
121
122    /**
123     * Determine if the response is complete
124     *
125     * @return bool
126     */
127    public function isComplete(): bool
128    {
129        return (($this->response !== null) && ($this->response->hasCode()));
130    }
131
132    /**
133     * Determine if the response is a success
134     *
135     * @return bool|null
136     */
137    public function isSuccess(): bool|null
138    {
139        return $this->response?->isSuccess();
140    }
141
142    /**
143     * Determine if the response is an error
144     *
145     * @return bool|null
146     */
147    public function isError(): bool|null
148    {
149        return $this->response?->isError();
150    }
151
152    /**
153     * Determine if the response is a continue
154     *
155     * @return bool|null
156     */
157    public function isContinue(): bool|null
158    {
159        return $this->response?->isContinue();
160    }
161
162    /**
163     * Determine if the response is 200 OK
164     *
165     * @return bool|null
166     */
167    public function isOk(): bool|null
168    {
169        return $this->response?->isOk();
170    }
171
172    /**
173     * Determine if the response is 201 created
174     *
175     * @return bool|null
176     */
177    public function isCreated(): bool|null
178    {
179        return $this->response?->isCreated();
180    }
181
182    /**
183     * Determine if the response is 202 accepted
184     *
185     * @return bool|null
186     */
187    public function isAccepted():bool|null
188    {
189        return $this->response?->isAccepted();
190    }
191
192    /**
193     * Determine if the response is 204 No Content
194     *
195     * @return bool|null
196     */
197    public function isNoContent():bool|null
198    {
199        return $this->response?->isNoContent();
200    }
201
202    /**
203     * Determine if the response is a redirect
204     *
205     * @return bool|null
206     */
207    public function isRedirect(): bool|null
208    {
209        return $this->response?->isRedirect();
210    }
211
212    /**
213     * Determine if the response is a 301 Moved Permanently
214     *
215     * @return bool|null
216     */
217    public function isMovedPermanently(): bool|null
218    {
219        return $this->response?->isMovedPermanently();
220    }
221
222    /**
223     * Determine if the response is a 302 Found
224     *
225     * @return bool|null
226     */
227    public function isFound(): bool|null
228    {
229        return $this->response?->isFound();
230    }
231
232    /**
233     * Determine if the response is a client error
234     *
235     * @return bool|null
236     */
237    public function isClientError(): bool|null
238    {
239        return $this->response?->isClientError();
240    }
241
242    /**
243     * Determine if the response is a 400 Bad Request
244     *
245     * @return bool|null
246     */
247    public function isBadRequest(): bool|null
248    {
249        return $this->response?->isBadRequest();
250    }
251
252    /**
253     * Determine if the response is a 401 Unauthorized
254     *
255     * @return bool|null
256     */
257    public function isUnauthorized(): bool|null
258    {
259        return $this->response?->isUnauthorized();
260    }
261
262    /**
263     * Determine if the response is a 403 Forbidden
264     *
265     * @return bool|null
266     */
267    public function isForbidden(): bool|null
268    {
269        return $this->response?->isForbidden();
270    }
271
272    /**
273     * Determine if the response is a 404 Not Found
274     *
275     * @return bool|null
276     */
277    public function isNotFound(): bool|null
278    {
279        return $this->response?->isNotFound();
280    }
281
282    /**
283     * Determine if the response is a 405 Method Not Allowed
284     *
285     * @return bool|null
286     */
287    public function isMethodNotAllowed(): bool|null
288    {
289        return $this->response?->isMethodNotAllowed();
290    }
291
292    /**
293     * Determine if the response is a 406 Not Acceptable
294     *
295     * @return bool|null
296     */
297    public function isNotAcceptable(): bool|null
298    {
299        return $this->response?->isNotAcceptable();
300    }
301
302    /**
303     * Determine if the response is a 408 Request Timeout
304     *
305     * @return bool|null
306     */
307    public function isRequestTimeout(): bool|null
308    {
309        return $this->response?->isRequestTimeout();
310    }
311
312    /**
313     * Determine if the response is a 409 Conflict
314     *
315     * @return bool|null
316     */
317    public function isConflict(): bool|null
318    {
319        return $this->response?->isConflict();
320    }
321
322    /**
323     * Determine if the response is a 411 Length Required
324     *
325     * @return bool|null
326     */
327    public function isLengthRequired(): bool|null
328    {
329        return $this->response?->isLengthRequired();
330    }
331
332    /**
333     * Determine if the response is a 415 Unsupported Media Type
334     *
335     * @return bool|null
336     */
337    public function isUnsupportedMediaType(): bool|null
338    {
339        return $this->response?->isUnsupportedMediaType();
340    }
341
342    /**
343     * Determine if the response is a 422 Unprocessable Entity
344     *
345     * @return bool|null
346     */
347    public function isUnprocessableEntity(): bool|null
348    {
349        return $this->response?->isUnprocessableEntity();
350    }
351
352    /**
353     * Determine if the response is a 429 Too Many Requests
354     *
355     * @return bool|null
356     */
357    public function isTooManyRequests(): bool|null
358    {
359        return $this->response?->isTooManyRequests();
360    }
361
362    /**
363     * Determine if the response is a server error
364     *
365     * @return bool|null
366     */
367    public function isServerError(): bool|null
368    {
369        return $this->response?->isServerError();
370    }
371
372    /**
373     * Determine if the response is a 500 Internal Server Error
374     *
375     * @return bool|null
376     */
377    public function isInternalServerError(): bool|null
378    {
379        return $this->response?->isInternalServerError();
380    }
381
382    /**
383     * Determine if the response is a 502 Bad Gateway
384     *
385     * @return bool|null
386     */
387    public function isBadGateway(): bool|null
388    {
389        return $this->response?->isBadGateway();
390    }
391
392    /**
393     * Determine if the response is a 503 Service Unavailable
394     *
395     * @return bool|null
396     */
397    public function isServiceUnavailable(): bool|null
398    {
399        return $this->response?->isServiceUnavailable();
400    }
401
402    /**
403     * Send the request/response
404     */
405    abstract public function send();
406
407    /**
408     * Render the request/response to string
409     */
410    abstract public function render(): string;
411
412    /**
413     * Render the request/response to string
414     */
415    abstract public function __toString(): string;
416
417}