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