Skip to content

Commit 604bc8a

Browse files
committed
Use consistent verbiage and formatting.
Cleaned up for consistent verbiage around mutability. All return values that returned the interface name were altered to use `self`, to ensure that they report correctly in documentation and IDEs. `ServerRequest::setAttributes()` was removed, per @Crell, and `ServerRequest::withoutAttribute()` added (to make usage consistent with headers).
1 parent 754d423 commit 604bc8a

File tree

6 files changed

+110
-83
lines changed

6 files changed

+110
-83
lines changed

src/MessageInterface.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
interface MessageInterface
1818
{
1919
/**
20-
* Gets the HTTP protocol version as a string.
20+
* Retrieves the HTTP protocol version as a string.
2121
*
2222
* The string MUST contain only the HTTP version number (e.g., "1.1", "1.0").
2323
*
@@ -36,12 +36,12 @@ public function getProtocolVersion();
3636
* new protocol version.
3737
*
3838
* @param string $version HTTP protocol version
39-
* @return MessageInterface
39+
* @return self
4040
*/
4141
public function withProtocolVersion($version);
4242

4343
/**
44-
* Gets all message headers.
44+
* Retrieves all message headers.
4545
*
4646
* The keys represent the header name as it will be sent over the wire, and
4747
* each value is an array of strings associated with the header.
@@ -81,7 +81,8 @@ public function hasHeader($header);
8181
* a comma.
8282
*
8383
* NOTE: Not all header values may be appropriately represented using
84-
* comma concatenation.
84+
* comma concatenation. For such headers, use getHeaderLines() instead
85+
* and supply your own delimiter when concatenating.
8586
*
8687
* @param string $header Case-insensitive header name.
8788
* @return string
@@ -109,7 +110,7 @@ public function getHeaderLines($header);
109110
*
110111
* @param string $header Header name
111112
* @param string|string[] $value Header value(s).
112-
* @return MessageInterface
113+
* @return self
113114
* @throws \InvalidArgumentException for invalid header names or values.
114115
*/
115116
public function withHeader($header, $value);
@@ -119,30 +120,31 @@ public function withHeader($header, $value);
119120
* given value.
120121
*
121122
* Existing values for the specified header will be maintained. The new
122-
* value(s) will be appended to the existing list.
123+
* value(s) will be appended to the existing list. If the header did not
124+
* exist previously, it will be added.
123125
*
124126
* This method MUST be implemented in such a way as to retain the
125127
* immutability of the message, and MUST return a new instance that has the
126128
* new header and/or value.
127129
*
128130
* @param string $header Header name to add
129131
* @param string|string[] $value Header value(s).
130-
* @return MessageInterface
132+
* @return self
131133
* @throws \InvalidArgumentException for invalid header names or values.
132134
*/
133135
public function withAddedHeader($header, $value);
134136

135137
/**
136138
* Creates a new instance, without the specified header.
137139
*
138-
* Header resolution MUST be done without case-insensitivity.
140+
* Header resolution MUST be done without case-sensitivity.
139141
*
140142
* This method MUST be implemented in such a way as to retain the
141143
* immutability of the message, and MUST return a new instance that removes
142144
* the named header.
143145
*
144146
* @param string $header HTTP header to remove
145-
* @return MessageInterface
147+
* @return self
146148
*/
147149
public function withoutHeader($header);
148150

@@ -163,7 +165,7 @@ public function getBody();
163165
* new body stream.
164166
*
165167
* @param StreamableInterface $body Body.
166-
* @return MessageInterface
168+
* @return self
167169
* @throws \InvalidArgumentException When the body is not valid.
168170
*/
169171
public function withBody(StreamableInterface $body);

src/RequestInterface.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ interface RequestInterface extends MessageInterface
2828
public function getMethod();
2929

3030
/**
31-
* Create a new instance with the provided HTTP method to perform on the
32-
* resource identified by the Request-URI.
31+
* Create a new instance with the provided HTTP method.
3332
*
3433
* While HTTP method names are typically all uppercase characters, HTTP
3534
* method names are case-sensitive and thus implementations SHOULD NOT
@@ -40,13 +39,13 @@ public function getMethod();
4039
* changed request method.
4140
*
4241
* @param string $method Case-insensitive method.
43-
* @return RequestInterface
42+
* @return self
4443
* @throws \InvalidArgumentException for invalid HTTP methods.
4544
*/
4645
public function withMethod($method);
4746

4847
/**
49-
* Retrieves the absolute URI.
48+
* Retrieves the URI instance.
5049
*
5150
* This method MUST return a UriInterface instance.
5251
*
@@ -65,7 +64,7 @@ public function getUri();
6564
*
6665
* @link http://tools.ietf.org/html/rfc3986#section-4.3
6766
* @param UriInterface $uri New request URI to use.
68-
* @return RequestInterface
67+
* @return self
6968
*/
7069
public function withUri(UriInterface $uri);
7170
}

src/ResponseInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getStatusCode();
4747
* @param null|string $reasonPhrase The reason phrase to use with the
4848
* provided status code; if none is provided, implementations MAY
4949
* use the defaults as suggested in the HTTP specification.
50-
* @return ResponseInterface
50+
* @return self
5151
* @throws \InvalidArgumentException For invalid status code arguments.
5252
*/
5353
public function withStatus($code, $reasonPhrase = null);

src/ServerRequestInterface.php

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*
1111
* - Protocol version
1212
* - HTTP method
13-
* - URL
13+
* - URI
1414
* - Headers
1515
* - Message body
1616
*
1717
* Additionally, it encapsulates all data as it has arrived to the
18-
* application from the PHP environment, including:
18+
* application from the CGI and/or PHP environment, including:
1919
*
2020
* - The values represented in $_SERVER.
2121
* - Any cookies provided (generally via $_COOKIE)
@@ -77,7 +77,7 @@ public function getCookieParams();
7777
* updated cookie values.
7878
*
7979
* @param array $cookies Array of key/value pairs representing cookies.
80-
* @return ServerRequestInterface
80+
* @return self
8181
*/
8282
public function withCookieParams(array $cookies);
8383

@@ -102,7 +102,7 @@ public function getQueryParams();
102102
* request. They MAY be injected during instantiation, such as from PHP's
103103
* $_GET superglobal, or MAY be derived from some other value such as the
104104
* URI. In cases where the arguments are parsed from the URI, the data
105-
* MUST be compatible with what PHP's `parse_str()` would return for
105+
* MUST be compatible with what PHP's parse_str() would return for
106106
* purposes of how duplicate query parameters are handled, and how nested
107107
* sets are handled.
108108
*
@@ -115,7 +115,7 @@ public function getQueryParams();
115115
*
116116
* @param array $query Array of query string arguments, typically from
117117
* $_GET.
118-
* @return ServerRequestInterface
118+
* @return self
119119
*/
120120
public function withQueryParams(array $query);
121121

@@ -159,7 +159,7 @@ public function getBodyParams();
159159
* updated body parameters.
160160
*
161161
* @param array $params The deserialized body parameters.
162-
* @return ServerRequestInterface
162+
* @return self
163163
*/
164164
public function withBodyParams(array $params);
165165

@@ -183,6 +183,9 @@ public function getAttributes();
183183
* getAttributes(). If the attribute has not been previously set, returns
184184
* the default value as provided.
185185
*
186+
* This method obviates the need for a hasAttribute() method, as it allows
187+
* specifying a default value to return if the attribute is not found.
188+
*
186189
* @see getAttributes()
187190
* @param string $attribute Attribute name.
188191
* @param mixed $default Default value to return if the attribute does not exist.
@@ -191,36 +194,37 @@ public function getAttributes();
191194
public function getAttribute($attribute, $default = null);
192195

193196
/**
194-
* Create a new instance with the specified attributes as derived from the
195-
* request.
197+
* Create a new instance with the specified derived request attribute.
196198
*
197-
* This method allows setting request attributes, as described in
198-
* getAttributes().
199+
* This method allows setting a single derived request attribute as
200+
* described in getAttributes().
199201
*
200202
* This method MUST be implemented in such a way as to retain the
201203
* immutability of the message, and MUST return a new instance that has the
202-
* updated attributes.
204+
* updated attribute.
203205
*
204206
* @see getAttributes()
205-
* @param array $attributes Attributes derived from the request.
206-
* @return ServerRequestInterface
207+
* @param string $attribute The attribute name.
208+
* @param mixed $value The value of the attribute.
209+
* @return self
207210
*/
208-
public function withAttributes(array $attributes);
211+
public function withAttribute($attribute, $value);
209212

210213
/**
211-
* Create a new instance with the specified derived request attribute.
214+
* Create a new instance that removes the specified derived request
215+
* attribute.
212216
*
213-
* This method allows setting a single derived request attribute as
217+
* This method allows removing a single derived request attribute as
214218
* described in getAttributes().
215219
*
216220
* This method MUST be implemented in such a way as to retain the
217-
* immutability of the message, and MUST return a new instance that has the
218-
* updated attribute.
221+
* immutability of the message, and MUST return a new instance that removes
222+
* the attribute.
219223
*
220224
* @see getAttributes()
221225
* @param string $attribute The attribute name.
222226
* @param mixed $value The value of the attribute.
223-
* @return ServerRequestInterface
227+
* @return self
224228
*/
225-
public function withAttribute($attribute, $value);
229+
public function withoutAttribute($attribute, $value);
226230
}

src/StreamableInterface.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@ public function isSeekable();
7070
/**
7171
* Seek to a position in the stream.
7272
*
73-
* @link http://www.php.net/manual/en/function.fseek.php
73+
* @link http://www.php.net/manual/en/function.fseek.php
7474
* @param int $offset Stream offset
7575
* @param int $whence Specifies how the cursor position will be calculated
76-
* based on the seek offset. Valid values are identical
77-
* to the built-in PHP $whence values for `fseek()`.
78-
* SEEK_SET: Set position equal to offset bytes
79-
* SEEK_CUR: Set position to current location plus offset
80-
* SEEK_END: Set position to end-of-stream plus offset
81-
*
76+
* based on the seek offset. Valid values are identical to the built-in
77+
* PHP $whence values for `fseek()`. SEEK_SET: Set position equal to
78+
* offset bytes SEEK_CUR: Set position to current location plus offset
79+
* SEEK_END: Set position to end-of-stream plus offset.
8280
* @return bool Returns TRUE on success or FALSE on failure.
8381
*/
8482
public function seek($offset, $whence = SEEK_SET);
@@ -90,6 +88,8 @@ public function seek($offset, $whence = SEEK_SET);
9088
* failure; otherwise, it will perform a seek(0), and return the status of
9189
* that operation.
9290
*
91+
* @see seek()
92+
* @link http://www.php.net/manual/en/function.fseek.php
9393
* @return bool Returns TRUE on success or FALSE on failure.
9494
*/
9595
public function rewind();
@@ -105,9 +105,8 @@ public function isWritable();
105105
* Write data to the stream.
106106
*
107107
* @param string $string The string that is to be written.
108-
*
109108
* @return int|bool Returns the number of bytes written to the stream on
110-
* success or FALSE on failure.
109+
* success or FALSE on failure.
111110
*/
112111
public function write($string);
113112

@@ -122,10 +121,10 @@ public function isReadable();
122121
* Read data from the stream.
123122
*
124123
* @param int $length Read up to $length bytes from the object and return
125-
* them. Fewer than $length bytes may be returned if
126-
* underlying stream call returns fewer bytes.
124+
* them. Fewer than $length bytes may be returned if underlying stream
125+
* call returns fewer bytes.
127126
* @return string|false Returns the data read from the stream, false if
128-
* unable to read or if an error occurs.
127+
* unable to read or if an error occurs.
129128
*/
130129
public function read($length);
131130

@@ -145,9 +144,8 @@ public function getContents();
145144
* @link http://php.net/manual/en/function.stream-get-meta-data.php
146145
* @param string $key Specific metadata to retrieve.
147146
* @return array|mixed|null Returns an associative array if no key is
148-
* provided. Returns a specific key value if a key
149-
* is provided and the value is found, or null if
150-
* the key is not found.
147+
* provided. Returns a specific key value if a key is provided and the
148+
* value is found, or null if the key is not found.
151149
*/
152150
public function getMetadata($key = null);
153151
}

0 commit comments

Comments
 (0)