@@ -78,38 +78,14 @@ public function parseUrl($url)
78
78
$ argumentType = (is_object ($ url )) ? get_class ($ url ) : gettype ($ url );
79
79
throw new \InvalidArgumentException ('Expected URL as string; got ' . $ argumentType );
80
80
}
81
- $ scheme = parse_url ($ url , PHP_URL_SCHEME );
82
- if (!is_null ($ scheme )) {
83
- $ this ->setScheme ($ scheme );
84
- }
85
- $ hostname = parse_url ($ url , PHP_URL_HOST );
86
- if (!is_null ($ hostname )) {
87
- $ this ->setHostname ($ hostname );
88
- }
89
- $ port = parse_url ($ url , PHP_URL_PORT );
90
- if (!is_null ($ port )) {
91
- $ this ->setPort ($ port );
92
- }
93
- $ username = parse_url ($ url , PHP_URL_USER );
94
- if (!is_null ($ username )) {
95
- $ this ->setUsername ($ username );
96
- }
97
- $ password = parse_url ($ url , PHP_URL_PASS );
98
- if (!is_null ($ password )) {
99
- $ this ->setPassword ($ password );
100
- }
101
- $ path = parse_url ($ url , PHP_URL_PATH );
102
- if (!is_null ($ path )) {
103
- $ this ->setPath ($ path );
104
- }
105
- $ queryString = parse_url ($ url , PHP_URL_QUERY );
106
- if (!is_null ($ queryString )) {
107
- $ this ->parseQueryString ($ queryString );
108
- }
109
- $ fragment = parse_url ($ url , PHP_URL_FRAGMENT );
110
- if (!is_null ($ fragment )) {
111
- $ this ->setFragment ($ fragment );
112
- }
81
+ $ this ->setScheme (parse_url ($ url , PHP_URL_SCHEME ));
82
+ $ this ->setHostname (parse_url ($ url , PHP_URL_HOST ));
83
+ $ this ->setPort (parse_url ($ url , PHP_URL_PORT ));
84
+ $ this ->setUsername (parse_url ($ url , PHP_URL_USER ));
85
+ $ this ->setPassword (parse_url ($ url , PHP_URL_PASS ));
86
+ $ this ->setPath (parse_url ($ url , PHP_URL_PATH ));
87
+ $ this ->parseQueryString (parse_url ($ url , PHP_URL_QUERY ));
88
+ $ this ->setFragment (parse_url ($ url , PHP_URL_FRAGMENT ));
113
89
return $ this ;
114
90
}
115
91
@@ -119,6 +95,10 @@ public function parseUrl($url)
119
95
*/
120
96
public function parseQueryString ($ queryString )
121
97
{
98
+ if (is_null ($ queryString )) {
99
+ $ this ->clearQueryParameters ();
100
+ return $ this ;
101
+ }
122
102
$ queryParameters = array ();
123
103
parse_str ($ queryString , $ queryParameters );
124
104
foreach ($ queryParameters as $ queryParameterKey => $ queryParameterValue ) {
@@ -189,7 +169,7 @@ public function hasScheme()
189
169
*/
190
170
public function setScheme ($ scheme )
191
171
{
192
- if (!is_string ($ scheme )) {
172
+ if (!is_null ( $ scheme ) && ! is_string ($ scheme )) {
193
173
$ argumentType = (is_object ($ scheme )) ? get_class ($ scheme ) : gettype ($ scheme );
194
174
throw new \InvalidArgumentException ('Expected scheme as string; got ' . $ argumentType );
195
175
}
@@ -219,7 +199,7 @@ public function hasHostname()
219
199
*/
220
200
public function setHostname ($ hostname )
221
201
{
222
- if (!is_string ($ hostname )) {
202
+ if (!is_null ( $ hostname ) && ! is_string ($ hostname )) {
223
203
$ argumentType = (is_object ($ hostname )) ? get_class ($ hostname ) : gettype ($ hostname );
224
204
throw new \InvalidArgumentException ('Expected hostname as string; got ' . $ argumentType );
225
205
}
@@ -249,7 +229,7 @@ public function hasPort()
249
229
*/
250
230
public function setPort ($ port )
251
231
{
252
- if (!is_int ($ port )) {
232
+ if (!is_null ( $ port ) && ! is_int ($ port )) {
253
233
$ argumentType = (is_object ($ port )) ? get_class ($ port ) : gettype ($ port );
254
234
throw new \InvalidArgumentException ('Expected port as integer; got ' . $ argumentType );
255
235
}
@@ -279,7 +259,7 @@ public function hasPath()
279
259
*/
280
260
public function setPath ($ path )
281
261
{
282
- if (!is_string ($ path )) {
262
+ if (!is_null ( $ path ) && ! is_string ($ path )) {
283
263
$ argumentType = (is_object ($ path )) ? get_class ($ path ) : gettype ($ path );
284
264
throw new \InvalidArgumentException ('Expected path as string; got ' . $ argumentType );
285
265
}
@@ -317,6 +297,10 @@ public function countQueryParameters()
317
297
*/
318
298
public function setQueryParameters ($ queryParameters )
319
299
{
300
+ if (is_null ($ queryParameters )) {
301
+ $ this ->clearQueryParameters ();
302
+ return $ this ;
303
+ }
320
304
if (!is_array ($ queryParameters )) {
321
305
$ argumentType = (is_object ($ queryParameters )) ? get_class ($ queryParameters ) : gettype ($ queryParameters );
322
306
throw new \InvalidArgumentException ('Expected query parameters as array; got ' . $ argumentType );
@@ -368,6 +352,10 @@ public function removeQueryParameter(QueryParameterInterface $queryParameter)
368
352
*/
369
353
public function removeQueryParameterByKey ($ key )
370
354
{
355
+ if (!is_string ($ key )) {
356
+ $ argumentType = (is_object ($ key )) ? get_class ($ key ) : gettype ($ key );
357
+ throw new \InvalidArgumentException ('Expected query parameter key as string; got ' . $ argumentType );
358
+ }
371
359
for ($ i = 0 ; $ i < count ($ this ->queryParameters ); $ i ++) {
372
360
if ($ this ->queryParameters [$ i ]->getKey () === $ key ) {
373
361
unset($ this ->queryParameters [$ i ]);
@@ -408,7 +396,7 @@ public function hasUsername()
408
396
*/
409
397
public function setUsername ($ username )
410
398
{
411
- if (!is_string ($ username )) {
399
+ if (!is_null ( $ username ) && ! is_string ($ username )) {
412
400
$ argumentType = (is_object ($ username )) ? get_class ($ username ) : gettype ($ username );
413
401
throw new \InvalidArgumentException ('Expected username as string; got ' . $ argumentType );
414
402
}
@@ -438,7 +426,7 @@ public function hasPassword()
438
426
*/
439
427
public function setPassword ($ password )
440
428
{
441
- if (!is_string ($ password )) {
429
+ if (!is_null ( $ password ) && ! is_string ($ password )) {
442
430
$ argumentType = (is_object ($ password )) ? get_class ($ password ) : gettype ($ password );
443
431
throw new \InvalidArgumentException ('Expected password as string; got ' . $ argumentType );
444
432
}
@@ -468,7 +456,7 @@ public function hasFragment()
468
456
*/
469
457
public function setFragment ($ fragment )
470
458
{
471
- if (!is_string ($ fragment )) {
459
+ if (!is_null ( $ fragment ) && ! is_string ($ fragment )) {
472
460
$ argumentType = (is_object ($ fragment )) ? get_class ($ fragment ) : gettype ($ fragment );
473
461
throw new \InvalidArgumentException ('Expected fragment as string; got ' . $ argumentType );
474
462
}
0 commit comments