@@ -220,6 +220,14 @@ public function getFragment()
220220 */
221221 public function withScheme ($ scheme )
222222 {
223+ if (! is_string ($ scheme )) {
224+ throw new InvalidArgumentException (sprintf (
225+ '%s expects a string argument; received %s ' ,
226+ __METHOD__ ,
227+ (is_object ($ scheme ) ? get_class ($ scheme ) : gettype ($ scheme ))
228+ ));
229+ }
230+
223231 $ scheme = $ this ->filterScheme ($ scheme );
224232
225233 if ($ scheme === $ this ->scheme ) {
@@ -238,6 +246,21 @@ public function withScheme($scheme)
238246 */
239247 public function withUserInfo ($ user , $ password = null )
240248 {
249+ if (! is_string ($ user )) {
250+ throw new InvalidArgumentException (sprintf (
251+ '%s expects a string user argument; received %s ' ,
252+ __METHOD__ ,
253+ (is_object ($ user ) ? get_class ($ user ) : gettype ($ user ))
254+ ));
255+ }
256+ if (null !== $ password && ! is_string ($ password )) {
257+ throw new InvalidArgumentException (sprintf (
258+ '%s expects a string password argument; received %s ' ,
259+ __METHOD__ ,
260+ (is_object ($ password ) ? get_class ($ password ) : gettype ($ password ))
261+ ));
262+ }
263+
241264 $ info = $ user ;
242265 if ($ password ) {
243266 $ info .= ': ' . $ password ;
@@ -259,6 +282,14 @@ public function withUserInfo($user, $password = null)
259282 */
260283 public function withHost ($ host )
261284 {
285+ if (! is_string ($ host )) {
286+ throw new InvalidArgumentException (sprintf (
287+ '%s expects a string argument; received %s ' ,
288+ __METHOD__ ,
289+ (is_object ($ host ) ? get_class ($ host ) : gettype ($ host ))
290+ ));
291+ }
292+
262293 if ($ host === $ this ->host ) {
263294 // Do nothing if no change was made.
264295 return clone $ this ;
@@ -373,6 +404,14 @@ public function withQuery($query)
373404 */
374405 public function withFragment ($ fragment )
375406 {
407+ if (! is_string ($ fragment )) {
408+ throw new InvalidArgumentException (sprintf (
409+ '%s expects a string argument; received %s ' ,
410+ __METHOD__ ,
411+ (is_object ($ fragment ) ? get_class ($ fragment ) : gettype ($ fragment ))
412+ ));
413+ }
414+
376415 $ fragment = $ this ->filterFragment ($ fragment );
377416
378417 if ($ fragment === $ this ->fragment ) {
@@ -585,10 +624,6 @@ private function splitQueryValue($value)
585624 */
586625 private function filterFragment ($ fragment )
587626 {
588- if (null === $ fragment ) {
589- $ fragment = '' ;
590- }
591-
592627 if (! empty ($ fragment ) && strpos ($ fragment , '# ' ) === 0 ) {
593628 $ fragment = substr ($ fragment , 1 );
594629 }
0 commit comments