@@ -111,16 +111,18 @@ class Uri implements UriInterface
111111 */
112112 public function __construct ($ uri = '' )
113113 {
114+ if ('' === $ uri ) {
115+ return ;
116+ }
117+
114118 if (! is_string ($ uri )) {
115119 throw new InvalidArgumentException (sprintf (
116120 '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 )
118122 ));
119123 }
120124
121- if ('' !== $ uri ) {
122- $ this ->parseUri ($ uri );
123- }
125+ $ this ->parseUri ($ uri );
124126 }
125127
126128 /**
@@ -246,7 +248,7 @@ public function withScheme($scheme)
246248 throw new InvalidArgumentException (sprintf (
247249 '%s expects a string argument; received %s ' ,
248250 __METHOD__ ,
249- ( is_object ($ scheme ) ? get_class ($ scheme ) : gettype ($ scheme) )
251+ is_object ($ scheme ) ? get_class ($ scheme ) : gettype ($ scheme )
250252 ));
251253 }
252254
@@ -277,14 +279,14 @@ public function withUserInfo($user, $password = null)
277279 throw new InvalidArgumentException (sprintf (
278280 '%s expects a string user argument; received %s ' ,
279281 __METHOD__ ,
280- ( is_object ($ user ) ? get_class ($ user ) : gettype ($ user) )
282+ is_object ($ user ) ? get_class ($ user ) : gettype ($ user )
281283 ));
282284 }
283285 if (null !== $ password && ! is_string ($ password )) {
284286 throw new InvalidArgumentException (sprintf (
285- '%s expects a string password argument; received %s ' ,
287+ '%s expects a string or null password argument; received %s ' ,
286288 __METHOD__ ,
287- ( is_object ($ password ) ? get_class ($ password ) : gettype ($ password) )
289+ is_object ($ password ) ? get_class ($ password ) : gettype ($ password )
288290 ));
289291 }
290292
@@ -313,7 +315,7 @@ public function withHost($host)
313315 throw new InvalidArgumentException (sprintf (
314316 '%s expects a string argument; received %s ' ,
315317 __METHOD__ ,
316- ( is_object ($ host ) ? get_class ($ host ) : gettype ($ host) )
318+ is_object ($ host ) ? get_class ($ host ) : gettype ($ host )
317319 ));
318320 }
319321
@@ -333,14 +335,14 @@ public function withHost($host)
333335 */
334336 public function withPort ($ port )
335337 {
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-
343338 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+
344346 $ port = (int ) $ port ;
345347 }
346348
@@ -437,7 +439,7 @@ public function withFragment($fragment)
437439 throw new InvalidArgumentException (sprintf (
438440 '%s expects a string argument; received %s ' ,
439441 __METHOD__ ,
440- ( is_object ($ fragment ) ? get_class ($ fragment ) : gettype ($ fragment) )
442+ is_object ($ fragment ) ? get_class ($ fragment ) : gettype ($ fragment )
441443 ));
442444 }
443445
@@ -559,7 +561,7 @@ private function filterScheme($scheme)
559561 return '' ;
560562 }
561563
562- if (! array_key_exists ( $ scheme , $ this ->allowedSchemes )) {
564+ if (! isset ( $ this ->allowedSchemes [ $ scheme ] )) {
563565 throw new InvalidArgumentException (sprintf (
564566 'Unsupported scheme "%s"; must be any empty string or in the set (%s) ' ,
565567 $ scheme ,
@@ -655,7 +657,7 @@ private function filterQuery($query)
655657 private function splitQueryValue ($ value )
656658 {
657659 $ data = explode ('= ' , $ value , 2 );
658- if (1 === count ($ data )) {
660+ if (! isset ($ data[ 1 ] )) {
659661 $ data [] = null ;
660662 }
661663 return $ data ;
0 commit comments