@@ -59,8 +59,7 @@ public static function fromGlobals(): BdkUri
5959 */
6060 public static function fromParsed (array $ parsed ): BdkUri
6161 {
62- $ uri = new BdkUri ();
63- return self ::withParsedValues ($ uri , $ parsed );
62+ return self ::withParsedValues (new BdkUri (), $ parsed );
6463 }
6564
6665 /**
@@ -128,8 +127,7 @@ public static function resolve(UriInterface $base, UriInterface $rel): UriInterf
128127 if ($ rel ->getScheme () !== '' ) {
129128 // rel specified scheme
130129 // return rel (with path cleaned up)
131- return $ rel
132- ->withPath (self ::pathRemoveDots ($ rel ->getPath ()));
130+ return $ rel ->withPath (self ::pathRemoveDots ($ rel ->getPath ()));
133131 }
134132 $ targetValues = array (
135133 'fragment ' => $ rel ->getFragment (),
@@ -158,27 +156,27 @@ public static function resolve(UriInterface $base, UriInterface $rel): UriInterf
158156 * Apply component values to a Uri
159157 *
160158 * @param UriInterface $uri UriInterface instance
161- * @param array $parsed Component values
159+ * @param array $values Component values
162160 *
163161 * @return UriInterface
164162 *
165163 * @since x3.4
166164 */
167165 public static function withParsedValues (UriInterface $ uri , array $ values ): UriInterface
168166 {
169- $ uriKeys = ['fragment ' , 'host ' , 'path ' , 'port ' , 'query ' , 'scheme ' , 'userInfo ' ];
170- $ values = \array_intersect_key (self ::parsedPartsPrep ($ values ), \array_flip ($ uriKeys ));
171- if (\array_key_exists ('path ' , $ values ) && $ values ['path ' ] === null ) {
172- $ values ['path ' ] = '' ;
173- }
174- foreach ($ values as $ key => $ value ) {
167+ $ keys = ['fragment ' , 'host ' , 'path ' , 'port ' , 'query ' , 'scheme ' , 'userInfo ' ];
168+ $ nullToStringKeys = ['fragment ' , 'host ' , 'path ' , 'query ' , 'scheme ' ];
169+ $ values = \array_intersect_key (self ::parsedPartsPrep ($ values ), \array_flip ($ keys ));
170+ \array_walk ($ values , static function ($ value , $ key ) use ($ nullToStringKeys , &$ uri ) {
171+ if ($ value === null && \in_array ($ key , $ nullToStringKeys , true )) {
172+ $ value = '' ;
173+ }
175174 $ method = 'with ' . \ucfirst ($ key );
176175 // using call_user_func_array... some methods (withUserInfo) accept multiple arguments
177- $ args = $ value === null
176+ $ uri = \call_user_func_array ([ $ uri , $ method ], $ value === null
178177 ? array (null )
179- : (array ) $ value ;
180- $ uri = \call_user_func_array ([$ uri , $ method ], $ args );
181- }
178+ : (array ) $ value );
179+ });
182180 return $ uri ;
183181 }
184182
0 commit comments