@@ -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
- ( is_object ($ uri ) ? get_class ($ uri ) : gettype ($ uri) )
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
/**
@@ -246,7 +248,7 @@ public function withScheme($scheme)
246
248
throw new InvalidArgumentException (sprintf (
247
249
'%s expects a string argument; received %s ' ,
248
250
__METHOD__ ,
249
- ( is_object ($ scheme ) ? get_class ($ scheme ) : gettype ($ scheme) )
251
+ is_object ($ scheme ) ? get_class ($ scheme ) : gettype ($ scheme )
250
252
));
251
253
}
252
254
@@ -277,14 +279,14 @@ public function withUserInfo($user, $password = null)
277
279
throw new InvalidArgumentException (sprintf (
278
280
'%s expects a string user argument; received %s ' ,
279
281
__METHOD__ ,
280
- ( is_object ($ user ) ? get_class ($ user ) : gettype ($ user) )
282
+ is_object ($ user ) ? get_class ($ user ) : gettype ($ user )
281
283
));
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
- ( is_object ($ password ) ? get_class ($ password ) : gettype ($ password) )
289
+ is_object ($ password ) ? get_class ($ password ) : gettype ($ password )
288
290
));
289
291
}
290
292
@@ -313,7 +315,7 @@ public function withHost($host)
313
315
throw new InvalidArgumentException (sprintf (
314
316
'%s expects a string argument; received %s ' ,
315
317
__METHOD__ ,
316
- ( is_object ($ host ) ? get_class ($ host ) : gettype ($ host) )
318
+ is_object ($ host ) ? get_class ($ host ) : gettype ($ host )
317
319
));
318
320
}
319
321
@@ -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
@@ -437,7 +439,7 @@ public function withFragment($fragment)
437
439
throw new InvalidArgumentException (sprintf (
438
440
'%s expects a string argument; received %s ' ,
439
441
__METHOD__ ,
440
- ( is_object ($ fragment ) ? get_class ($ fragment ) : gettype ($ fragment) )
442
+ is_object ($ fragment ) ? get_class ($ fragment ) : gettype ($ fragment )
441
443
));
442
444
}
443
445
@@ -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