1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Linna Http Message. |
||
5 | * |
||
6 | * @author Sebastian Rapetti <[email protected]> |
||
7 | * @copyright (c) 2019, Sebastian Rapetti |
||
8 | * @license http://opensource.org/licenses/MIT MIT License |
||
9 | */ |
||
10 | declare(strict_types=1); |
||
11 | |||
12 | namespace Linna\Http\Message; |
||
13 | |||
14 | use InvalidArgumentException; |
||
15 | use Psr\Http\Message\ResponseInterface; |
||
16 | |||
17 | /** |
||
18 | * PSR-7 Response implementation. |
||
19 | */ |
||
20 | class Response extends Message implements ResponseInterface |
||
21 | { |
||
22 | /** |
||
23 | * Gets the response status code. |
||
24 | * |
||
25 | * The status code is a 3-digit integer result code of the server's attempt |
||
26 | * to understand and satisfy the request. |
||
27 | * |
||
28 | * @return int Status code. |
||
29 | */ |
||
30 | public function getStatusCode(): int |
||
31 | { |
||
32 | } |
||
0 ignored issues
–
show
|
|||
33 | |||
34 | /** |
||
35 | * Return an instance with the specified status code and, optionally, reason phrase. |
||
36 | * |
||
37 | * If no reason phrase is specified, implementations MAY choose to default |
||
38 | * to the RFC 7231 or IANA recommended reason phrase for the response's |
||
39 | * status code. |
||
40 | * |
||
41 | * This method MUST be implemented in such a way as to retain the |
||
42 | * immutability of the message, and MUST return an instance that has the |
||
43 | * updated status and reason phrase. |
||
44 | * |
||
45 | * @link http://tools.ietf.org/html/rfc7231#section-6 |
||
46 | * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
||
47 | * |
||
48 | * @param int $code The 3-digit integer result code to set. |
||
49 | * @param string $reasonPhrase The reason phrase to use with the provided status code; |
||
50 | * if none is provided, implementations MAY use the defaults |
||
51 | * as suggested in the HTTP specification. |
||
52 | * |
||
53 | * @return static |
||
54 | * |
||
55 | * @throws InvalidArgumentException For invalid status code arguments. |
||
56 | */ |
||
57 | public function withStatus(int $code, string $reasonPhrase = ''): ResponseInterface |
||
58 | { |
||
59 | } |
||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return Psr\Http\Message\ResponseInterface . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
60 | |||
61 | /** |
||
62 | * Gets the response reason phrase associated with the status code. |
||
63 | * |
||
64 | * Because a reason phrase is not a required element in a response |
||
65 | * status line, the reason phrase value MAY be null. Implementations MAY |
||
66 | * choose to return the default RFC 7231 recommended reason phrase (or those |
||
67 | * listed in the IANA HTTP Status Code Registry) for the response's |
||
68 | * status code. |
||
69 | * |
||
70 | * @link http://tools.ietf.org/html/rfc7231#section-6 |
||
71 | * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
||
72 | * |
||
73 | * @return string Reason phrase; must return an empty string if none present. |
||
74 | */ |
||
75 | public function getReasonPhrase(): string |
||
76 | { |
||
77 | } |
||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return string . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
78 | } |
||
79 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: