1 | <?php |
||
10 | class Response { |
||
11 | use |
||
12 | Singleton; |
||
13 | /** |
||
14 | * Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | public $protocol; |
||
19 | /** |
||
20 | * HTTP status code |
||
21 | * |
||
22 | * @var int |
||
23 | */ |
||
24 | public $code; |
||
25 | /** |
||
26 | * Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, `content-type`, `accept-language` |
||
27 | * |
||
28 | * Values might be strings in case of single value or array of strings in case of multiple values with the same field name |
||
29 | * |
||
30 | * @var string[]|string[][] |
||
31 | */ |
||
32 | public $headers; |
||
33 | /** |
||
34 | * String body (is used instead of `$this->body_stream` in most cases) |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | public $body; |
||
39 | /** |
||
40 | * Body in form of stream (might be used instead of `$this->body` in some cases, if present, `$this->body` is ignored) |
||
41 | * |
||
42 | * Stream is read/write |
||
43 | * |
||
44 | * @var resource |
||
45 | */ |
||
46 | public $body_stream; |
||
47 | /** |
||
48 | * Initialize response object with specified data |
||
49 | * |
||
50 | * @param string $body |
||
51 | * @param null|resource|string $body_stream String, like `php://temp` or resource, like `fopen('php://temp', 'ba+')`, if present, `$body` is ignored |
||
52 | * @param string[]|string[][] $headers Headers are normalized to lowercase keys with hyphen as separator, for instance: `connection`, `referer`, |
||
53 | * `content-type`, `accept-language`; Values might be strings in case of single value or array of strings in case |
||
54 | * of multiple values with the same field name |
||
55 | * @param int $code HTTP status code |
||
56 | * @param string $protocol Protocol, for instance: `HTTP/1.0`, `HTTP/1.1` (default), HTTP/2.0 |
||
57 | */ |
||
58 | function init ($body = '', $body_stream = null, $headers = [], $code = 200, $protocol = 'HTTP/1.1') { |
||
68 | /** |
||
69 | * Set raw HTTP header |
||
70 | * |
||
71 | * @param string $field Field |
||
72 | * @param string $value Value, empty string will cause header removal |
||
73 | * @param bool $replace The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header |
||
74 | * of the same type. By default it will replace |
||
75 | */ |
||
76 | function header ($field, $value, $replace = true) { |
||
86 | /** |
||
87 | * Make redirect to specified location |
||
88 | * |
||
89 | * @param string $location |
||
90 | * @param int|null $code Defaults to 302 if current code is not 201 or 3xx |
||
91 | */ |
||
92 | function redirect ($location, $code = null) { |
||
100 | /** |
||
101 | * Function for setting cookies, taking into account cookies prefix. Parameters like in system `setcookie()` function, but $path, $domain and $secure |
||
102 | * are skipped, they are detected automatically |
||
103 | * |
||
104 | * This function have side effect of setting cookie on `cs\Request` object |
||
105 | * |
||
106 | * @param string $name |
||
107 | * @param string $value |
||
108 | * @param int $expire |
||
109 | * @param bool $httponly |
||
110 | */ |
||
111 | function cookie ($name, $value, $expire = 0, $httponly = false) { |
||
148 | /** |
||
149 | * Provides standard output for all the response data |
||
150 | */ |
||
151 | function standard_output () { |
||
167 | } |
||
168 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.