Passed
Push — master ( 473b33...57ebbd )
by Shahrad
01:22
created

HttpResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 12
c 0
b 0
f 0
dl 0
loc 71
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 3 1
A getStatusCode() 0 3 1
A setResponse() 0 6 2
A getHeaderLine() 0 3 1
1
<?php
2
3
namespace EasyHttp\Model;
4
5
/**
6
 * Http Response
7
 *
8
 * @link    https://github.com/shahradelahi/easy-http
9
 * @author  Shahrad Elahi (https://github.com/shahradelahi)
10
 * @license https://github.com/shahradelahi/easy-http/blob/master/LICENSE (MIT License)
11
 */
12
class HttpResponse
13
{
14
15
    /**
16
     * Set response
17
     *
18
     * @param array $input ["status", "headers", "body", "info", "error"]
19
     * @return HttpResponse
20
     */
21
    public function setResponse(array $input): self
22
    {
23
        foreach ($input as $key => $value) {
24
            $this->{$key} = $value;
25
        }
26
        return $this;
27
    }
28
29
    /**
30
     * @var int
31
     */
32
    public int $status;
33
34
    /**
35
     * @var array
36
     */
37
    public array $headers;
38
39
    /**
40
     * @var bool|string
41
     */
42
    public bool|string $body;
43
44
    /**
45
     * @var mixed
46
     */
47
    public mixed $info;
48
49
    /**
50
     * @var string
51
     */
52
    public string $error;
53
54
    /**
55
     * Get status code
56
     *
57
     * @return int
58
     */
59
    public function getStatusCode(): int
60
    {
61
        return $this->status;
62
    }
63
64
    /**
65
     * Get body
66
     *
67
     * @return ?string
68
     */
69
    public function getBody(): ?string
70
    {
71
        return $this->body;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->body could return the type boolean which is incompatible with the type-hinted return null|string. Consider adding an additional type-check to rule them out.
Loading history...
72
    }
73
74
    /**
75
     * Get a key from the response headers
76
     *
77
     * @param string $key
78
     * @return mixed
79
     */
80
    public function getHeaderLine(string $key): mixed
81
    {
82
        return $this->headers[$key] ?? null;
83
    }
84
85
}