@@ -111,16 +111,18 @@ class Uri implements UriInterface
111
111
*/
112
112
public function __construct ($ uri = '' )
113
113
{
114
+ if ('' === $ uri ) {
115
+ return ;
116
+ }
117
+
114
118
if (! is_string ($ uri )) {
115
119
throw new InvalidArgumentException (sprintf (
116
120
'URI passed to constructor must be a string; received "%s" ' ,
117
121
(is_object ($ uri ) ? get_class ($ uri ) : gettype ($ uri ))
118
122
));
119
123
}
120
124
121
- if ('' !== $ uri ) {
122
- $ this ->parseUri ($ uri );
123
- }
125
+ $ this ->parseUri ($ uri );
124
126
}
125
127
126
128
/**
@@ -282,7 +284,7 @@ public function withUserInfo($user, $password = null)
282
284
}
283
285
if (null !== $ password && ! is_string ($ password )) {
284
286
throw new InvalidArgumentException (sprintf (
285
- '%s expects a string password argument; received %s ' ,
287
+ '%s expects a string or null password argument; received %s ' ,
286
288
__METHOD__ ,
287
289
(is_object ($ password ) ? get_class ($ password ) : gettype ($ password ))
288
290
));
@@ -333,14 +335,14 @@ public function withHost($host)
333
335
*/
334
336
public function withPort ($ port )
335
337
{
336
- if (! is_numeric ($ port ) && $ port !== null ) {
337
- throw new InvalidArgumentException (sprintf (
338
- 'Invalid port "%s" specified; must be an integer, an integer string, or null ' ,
339
- (is_object ($ port ) ? get_class ($ port ) : gettype ($ port ))
340
- ));
341
- }
342
-
343
338
if ($ port !== null ) {
339
+ if (! is_numeric ($ port ) || is_float ($ port )) {
340
+ throw new InvalidArgumentException (sprintf (
341
+ 'Invalid port "%s" specified; must be an integer, an integer string, or null ' ,
342
+ (is_object ($ port ) ? get_class ($ port ) : gettype ($ port ))
343
+ ));
344
+ }
345
+
344
346
$ port = (int ) $ port ;
345
347
}
346
348
@@ -559,7 +561,7 @@ private function filterScheme($scheme)
559
561
return '' ;
560
562
}
561
563
562
- if (! array_key_exists ( $ scheme , $ this ->allowedSchemes )) {
564
+ if (! isset ( $ this ->allowedSchemes [ $ scheme ] )) {
563
565
throw new InvalidArgumentException (sprintf (
564
566
'Unsupported scheme "%s"; must be any empty string or in the set (%s) ' ,
565
567
$ scheme ,
@@ -655,7 +657,7 @@ private function filterQuery($query)
655
657
private function splitQueryValue ($ value )
656
658
{
657
659
$ data = explode ('= ' , $ value , 2 );
658
- if (1 === count ($ data )) {
660
+ if (! isset ($ data[ 1 ] )) {
659
661
$ data [] = null ;
660
662
}
661
663
return $ data ;
0 commit comments