Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
Response | |
0.00% |
0 / 19 |
|
0.00% |
0 / 7 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
withProtocolVersion | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
withHeader | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
withAddedHeader | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
withoutHeader | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
withBody | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
withStatus | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\OAuth; |
4 | |
5 | use InvalidArgumentException; |
6 | use MediaWiki\Rest\Response as RestResponse; |
7 | use Psr\Http\Message\ResponseInterface; |
8 | use Psr\Http\Message\StreamInterface; |
9 | |
10 | class Response extends RestResponse implements ResponseInterface { |
11 | |
12 | public function __construct( $bodyContents = '' ) { |
13 | parent::__construct( $bodyContents ); |
14 | } |
15 | |
16 | /** |
17 | * Return an instance with the specified HTTP protocol version. |
18 | * |
19 | * The version string MUST contain only the HTTP version number (e.g., |
20 | * "1.1", "1.0"). |
21 | * |
22 | * This method MUST be implemented in such a way as to retain the |
23 | * immutability of the message, and MUST return an instance that has the |
24 | * new protocol version. |
25 | * |
26 | * @param string $version HTTP protocol version |
27 | * @return static |
28 | */ |
29 | public function withProtocolVersion( $version ) { |
30 | $response = clone $this; |
31 | $response->setProtocolVersion( $version ); |
32 | return $response; |
33 | } |
34 | |
35 | /** |
36 | * Return an instance with the provided value replacing the specified header. |
37 | * |
38 | * While header names are case-insensitive, the casing of the header will |
39 | * be preserved by this function, and returned from getHeaders(). |
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 | * new and/or updated header and value. |
44 | * |
45 | * @param string $name Case-insensitive header field name. |
46 | * @param string|string[] $value Header value(s). |
47 | * @return static |
48 | * @throws InvalidArgumentException for invalid header names or values. |
49 | */ |
50 | public function withHeader( $name, $value ) { |
51 | $response = clone $this; |
52 | $response->setHeader( $name, $value ); |
53 | return $response; |
54 | } |
55 | |
56 | /** |
57 | * Return an instance with the specified header appended with the given value. |
58 | * |
59 | * Existing values for the specified header will be maintained. The new |
60 | * value(s) will be appended to the existing list. If the header did not |
61 | * exist previously, it will be added. |
62 | * |
63 | * This method MUST be implemented in such a way as to retain the |
64 | * immutability of the message, and MUST return an instance that has the |
65 | * new header and/or value. |
66 | * |
67 | * @param string $name Case-insensitive header field name to add. |
68 | * @param string|string[] $value Header value(s). |
69 | * @return static |
70 | * @throws InvalidArgumentException for invalid header names or values. |
71 | */ |
72 | public function withAddedHeader( $name, $value ) { |
73 | $response = clone $this; |
74 | $response->addHeader( $name, $value ); |
75 | return $response; |
76 | } |
77 | |
78 | /** |
79 | * Return an instance without the specified header. |
80 | * |
81 | * Header resolution MUST be done without case-sensitivity. |
82 | * |
83 | * This method MUST be implemented in such a way as to retain the |
84 | * immutability of the message, and MUST return an instance that removes |
85 | * the named header. |
86 | * |
87 | * @param string $name Case-insensitive header field name to remove. |
88 | * @return static |
89 | */ |
90 | public function withoutHeader( $name ) { |
91 | $response = clone $this; |
92 | $response->removeHeader( $name ); |
93 | return $response; |
94 | } |
95 | |
96 | /** |
97 | * Return an instance with the specified message body. |
98 | * |
99 | * The body MUST be a StreamInterface object. |
100 | * |
101 | * This method MUST be implemented in such a way as to retain the |
102 | * immutability of the message, and MUST return a new instance that has the |
103 | * new body stream. |
104 | * |
105 | * @param StreamInterface $body |
106 | * @return static |
107 | * @throws InvalidArgumentException When the body is not valid. |
108 | */ |
109 | public function withBody( StreamInterface $body ) { |
110 | $response = clone $this; |
111 | $response->setBody( $body ); |
112 | return $response; |
113 | } |
114 | |
115 | /** |
116 | * Return an instance with the specified status code and, optionally, reason phrase. |
117 | * |
118 | * If no reason phrase is specified, implementations MAY choose to default |
119 | * to the RFC 7231 or IANA recommended reason phrase for the response's |
120 | * status code. |
121 | * |
122 | * This method MUST be implemented in such a way as to retain the |
123 | * immutability of the message, and MUST return an instance that has the |
124 | * updated status and reason phrase. |
125 | * |
126 | * @link http://tools.ietf.org/html/rfc7231#section-6 |
127 | * @link http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml |
128 | * @param int $code The 3-digit integer result code to set. |
129 | * @param string $reasonPhrase The reason phrase to use with the |
130 | * provided status code; if none is provided, implementations MAY |
131 | * use the defaults as suggested in the HTTP specification. |
132 | * @return static |
133 | * @throws InvalidArgumentException For invalid status code arguments. |
134 | */ |
135 | public function withStatus( $code, $reasonPhrase = '' ) { |
136 | $response = clone $this; |
137 | $response->setStatus( $code, $reasonPhrase ); |
138 | return $response; |
139 | } |
140 | } |