Skip to content

Commit 24da22e

Browse files
committed
🚿 docblock updates/cleanup
1 parent dd2205f commit 24da22e

File tree

4 files changed

+31
-53
lines changed

4 files changed

+31
-53
lines changed

src/Header.php

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ class Header{
2222
* Normalizes an array of header lines to format ["Name" => "Value (, Value2, Value3, ...)", ...]
2323
* An exception is being made for Set-Cookie, which holds an array of values for each cookie.
2424
* For multiple cookies with the same name, only the last value will be kept.
25-
*
26-
* @param array $headers
27-
*
28-
* @return array
2925
*/
3026
public static function normalize(array $headers):array{
3127
$normalized = [];

src/Query.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
namespace chillerlan\HTTP\Utils;
1212

13-
use function array_merge, explode, implode, is_array, is_bool, is_string, rawurldecode, sort, str_replace, uksort;
13+
use function array_merge, call_user_func_array, explode, implode, is_array, is_bool, is_iterable,
14+
is_numeric, is_string, rawurldecode, sort, str_replace, trim, uksort;
1415
use const PHP_QUERY_RFC1738, PHP_QUERY_RFC3986, SORT_STRING;
1516

1617
/**
@@ -26,6 +27,10 @@ final class Query{
2627
public const NO_ENCODING = -1;
2728

2829
/**
30+
* Cleans/normalizes an array of query parameters, booleans will be converted according to the given $bool_cast constant.
31+
* By default, booleans will be left as-is (BOOLEANS_AS_BOOL) and may result in empty values.
32+
* If $remove_empty is set to true, empty and null values will be removed from the array.
33+
*
2934
* @param iterable $params
3035
* @param int|null $bool_cast converts booleans to a type determined like following:
3136
* BOOLEANS_AS_BOOL : unchanged boolean value (default)
@@ -76,7 +81,7 @@ public static function cleanParams(iterable $params, int $bool_cast = null, bool
7681
}
7782
else{
7883

79-
if($remove_empty && ($value === null || (!is_numeric($value) && empty($value)))){
84+
if($remove_empty && (!is_numeric($value) && empty($value))){
8085
continue;
8186
}
8287

@@ -88,7 +93,7 @@ public static function cleanParams(iterable $params, int $bool_cast = null, bool
8893
}
8994

9095
/**
91-
* Build a query string from an array of key value pairs.
96+
* Builds a query string from an array of key value pairs.
9297
*
9398
* Valid values for $encoding are PHP_QUERY_RFC3986 (default) and PHP_QUERY_RFC1738,
9499
* any other integer value will be interpreted as "no encoding".
@@ -158,27 +163,22 @@ public static function build(array $params, int $encoding = null, string $delimi
158163
}
159164

160165
/**
161-
* merges additional query parameters into an existing query string
162-
*
163-
* @param string $uri
164-
* @param array $query
165-
*
166-
* @return string
166+
* Merges additional query parameters into an existing query string
167167
*/
168168
public static function merge(string $uri, array $query):string{
169169
$parsedquery = self::parse(parseUrl($uri)['query'] ?? '');
170170
$requestURI = explode('?', $uri)[0];
171171
$params = array_merge($parsedquery, $query);
172172

173173
if(!empty($params)){
174-
$requestURI .= '?'.Query::build($params);
174+
$requestURI .= '?'.self::build($params);
175175
}
176176

177177
return $requestURI;
178178
}
179179

180180
/**
181-
* Parse a query string into an associative array.
181+
* Parses a query string into an associative array.
182182
*
183183
* @link https://github.com/guzzle/psr7/blob/c0dcda9f54d145bd4d062a6d15f54931a67732f9/src/Query.php#L9-L57
184184
*/

src/Server.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(
4141
}
4242

4343
/**
44-
* Return a ServerRequest populated with superglobals:
44+
* Returns a ServerRequest populated with superglobals:
4545
* - $_GET
4646
* - $_POST
4747
* - $_COOKIE
@@ -74,7 +74,7 @@ public function createServerRequestFromGlobals():ServerRequestInterface{
7474
}
7575

7676
/**
77-
* Create a Uri populated with values from $_SERVER.
77+
* Creates an Uri populated with values from $_SERVER.
7878
*/
7979
public function createUriFromGlobals():UriInterface{
8080
$hasPort = false;
@@ -124,11 +124,11 @@ public function createUriFromGlobals():UriInterface{
124124

125125

126126
/**
127-
* Return an UploadedFile instance array.
127+
* Returns an UploadedFile instance array.
128128
*
129-
* @param array $files A array which respect $_FILES structure
129+
* @param array $files An array which respect $_FILES structure
130130
*
131-
* @return array
131+
* @return \Psr\Http\Message\UploadedFileInterface[]
132132
* @throws \InvalidArgumentException for unrecognized values
133133
*/
134134
public function normalizeFiles(array $files):array{
@@ -156,7 +156,7 @@ public function normalizeFiles(array $files):array{
156156
}
157157

158158
/**
159-
* Create and return an UploadedFile instance from a $_FILES specification.
159+
* Creates an UploadedFile instance from a $_FILES specification.
160160
*
161161
* If the specification represents an array of values, this method will
162162
* delegate to normalizeNestedFileSpec() and return that return value.
@@ -181,7 +181,7 @@ public function createUploadedFileFromSpec(array $value){
181181
}
182182

183183
/**
184-
* Normalize an array of file specifications.
184+
* Normalizes an array of file specifications.
185185
*
186186
* Loops through all nested files and returns a normalized array of
187187
* UploadedFileInterface instances.

src/message_helpers.php

+13-31
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ function getMimetypeFromFilename(string $filename):?string{
140140
}
141141

142142
/**
143+
* Recursive rawurlencode
144+
*
143145
* @param string|string[] $data
144146
*
145147
* @return string|string[]
@@ -159,9 +161,6 @@ function r_rawurlencode($data){
159161
}
160162

161163
/**
162-
* @param \Psr\Http\Message\MessageInterface $message
163-
* @param bool|null $assoc
164-
*
165164
* @return \stdClass|array|bool
166165
*/
167166
function get_json(MessageInterface $message, bool $assoc = null){
@@ -173,9 +172,6 @@ function get_json(MessageInterface $message, bool $assoc = null){
173172
}
174173

175174
/**
176-
* @param \Psr\Http\Message\MessageInterface $message
177-
* @param bool|null $assoc
178-
*
179175
* @return \SimpleXMLElement|array|bool
180176
*/
181177
function get_xml(MessageInterface $message, bool $assoc = null){
@@ -190,10 +186,6 @@ function get_xml(MessageInterface $message, bool $assoc = null){
190186

191187
/**
192188
* Returns the string representation of an HTTP message. (from Guzzle)
193-
*
194-
* @param \Psr\Http\Message\MessageInterface $message Message to convert to a string.
195-
*
196-
* @return string
197189
*/
198190
function message_to_string(MessageInterface $message):string{
199191
$msg = '';
@@ -223,9 +215,6 @@ function message_to_string(MessageInterface $message):string{
223215
/**
224216
* Decompresses the message content according to the Content-Encoding header and returns the decompressed data
225217
*
226-
* @param \Psr\Http\Message\MessageInterface $message
227-
*
228-
* @return string
229218
* @throws \RuntimeException
230219
*/
231220
function decompress_content(MessageInterface $message):string{
@@ -270,7 +259,7 @@ function decompress_content(MessageInterface $message):string{
270259
];
271260

272261
/**
273-
* Checks whether the URI has a port set and if that port is one of the default ports for the given scheme
262+
* Checks whether the UriInterface has a port set and if that port is one of the default ports for the given scheme
274263
*/
275264
function uriIsDefaultPort(UriInterface $uri):bool{
276265
$port = $uri->getPort();
@@ -280,7 +269,7 @@ function uriIsDefaultPort(UriInterface $uri):bool{
280269
}
281270

282271
/**
283-
* Whether the URI is absolute, i.e. it has a scheme.
272+
* Checks Whether the URI is absolute, i.e. it has a scheme.
284273
*
285274
* An instance of UriInterface can either be an absolute URI or a relative reference. This method returns true
286275
* if it is the former. An absolute URI has a scheme. A relative reference is used to express a URI relative
@@ -299,7 +288,7 @@ function uriIsAbsolute(UriInterface $uri):bool{
299288
}
300289

301290
/**
302-
* Whether the URI is a network-path reference.
291+
* Checks Whether the URI is a network-path reference.
303292
*
304293
* A relative reference that begins with two slash characters is termed an network-path reference.
305294
*
@@ -310,7 +299,7 @@ function uriIsNetworkPathReference(UriInterface $uri):bool{
310299
}
311300

312301
/**
313-
* Whether the URI is a absolute-path reference.
302+
* Checks Whether the URI is a absolute-path reference.
314303
*
315304
* A relative reference that begins with a single slash character is termed an absolute-path reference.
316305
*
@@ -321,7 +310,7 @@ function uriIsAbsolutePathReference(UriInterface $uri):bool{
321310
}
322311

323312
/**
324-
* Whether the URI is a relative-path reference.
313+
* Checks Whether the URI is a relative-path reference.
325314
*
326315
* A relative reference that does not begin with a slash character is termed a relative-path reference.
327316
*
@@ -332,12 +321,9 @@ function uriIsRelativePathReference(UriInterface $uri):bool{
332321
}
333322

334323
/**
335-
* removes a specific query string value.
324+
* Removes a specific query string value.
336325
*
337-
* Any existing query string values that exactly match the provided key are
338-
* removed.
339-
*
340-
* @param string $key Query string key to remove.
326+
* Any existing query string values that exactly match the provided $key are removed.
341327
*/
342328
function uriWithoutQueryValue(UriInterface $uri, string $key):UriInterface{
343329
$current = $uri->getQuery();
@@ -356,16 +342,12 @@ function uriWithoutQueryValue(UriInterface $uri, string $key):UriInterface{
356342
}
357343

358344
/**
359-
* adds a specific query string value.
360-
*
361-
* Any existing query string values that exactly match the provided key are
362-
* removed and replaced with the given key value pair.
345+
* Adds a specific query string value.
363346
*
364-
* A value of null will set the query string key without a value, e.g. "key"
365-
* instead of "key=value".
347+
* Any existing query string values that exactly match the provided $key are
348+
* removed and replaced with the given $key $value pair.
366349
*
367-
* @param string $key Key to set.
368-
* @param string|null $value Value to set
350+
* A value of null will set the query string key without a value, e.g. "key" instead of "key=value".
369351
*/
370352
function uriWithQueryValue(UriInterface $uri, string $key, string $value = null):UriInterface{
371353
$current = $uri->getQuery();

0 commit comments

Comments
 (0)