@@ -63,8 +63,8 @@ public function __construct(string $uri, ?string $baseUri = null)
6363 throw new InvalidUriException ($ exception ->getMessage (), previous: $ exception );
6464 }
6565
66- Encoder::isUserEncoded ($ components ['user ' ]) || throw new InvalidUriException ('The encoded userInfo string component contains invalid characters. ' );
67- Encoder::isPasswordEncoded ($ components ['pass ' ]) || throw new InvalidUriException ('The encoded userInfo string component contains invalid characters. ' );
66+ Encoder::isUserEncoded ($ components ['user ' ]) || throw new InvalidUriException ('The encoded userInfo string component ` ' . $ components [ ' userInfo ' ]. ' ` contains invalid characters. ' );
67+ Encoder::isPasswordEncoded ($ components ['pass ' ]) || throw new InvalidUriException ('The encoded userInfo component ` ' . $ components [ ' userInfo ' ]. ' ` contains invalid characters. ' );
6868 Encoder::isPathEncoded ($ components ['path ' ]) || throw new InvalidUriException ('The encoded path component ` ' .$ components ['path ' ].'` contains invalid characters. ' );
6969 Encoder::isQueryEncoded ($ components ['query ' ]) || throw new InvalidUriException ('The encoded query string component ` ' .$ components ['query ' ].'` contains invalid characters. ' );
7070 Encoder::isFragmentEncoded ($ components ['fragment ' ]) || throw new InvalidUriException ('The encoded fragment string component ` ' .$ components ['fragment ' ].'` contains invalid characters. ' );
@@ -204,7 +204,7 @@ public function getRawUserInfo(): ?string
204204 */
205205 public function withUserInfo (#[SensitiveParameter] ?string $ userInfo ): self
206206 {
207- if ($ userInfo === $ this ->getRawUserInfo ()) {
207+ if ($ this ->getRawUserInfo () === $ userInfo ) {
208208 return $ this ;
209209 }
210210
@@ -213,9 +213,8 @@ public function withUserInfo(#[SensitiveParameter] ?string $userInfo): self
213213 }
214214
215215 [$ user , $ password ] = explode (': ' , $ userInfo , 2 ) + [1 => null ];
216- if (!Encoder::isUserEncoded ($ user ) || !Encoder::isPasswordEncoded ($ password )) {
217- throw new InvalidUriException ('The encoded userInfo string component contains invalid characters. ' );
218- }
216+ Encoder::isUserEncoded ($ user ) || throw new InvalidUriException ('The encoded userInfo string component ` ' .$ userInfo .'` contains invalid characters. ' );
217+ Encoder::isPasswordEncoded ($ password ) || throw new InvalidUriException ('The encoded userInfo string component ` ' .$ userInfo .'` contains invalid characters. ' );
219218
220219 return $ this ->withComponent (['user ' => $ user , 'pass ' => $ password ]);
221220 }
@@ -350,11 +349,11 @@ public function withFragment(?string $fragment): self
350349 */
351350 public function equals (self $ uri , bool $ excludeFragment = true ): bool
352351 {
353- if ( $ excludeFragment && ( $ this -> getFragment () !== $ uri -> getFragment ()) ) {
354- return [... $ this ->normalizedComponents , ...[ ' fragment ' => null ]] === [... $ uri ->normalizedComponents , ...[ ' fragment ' => null ]];
355- }
356-
357- return $ this -> normalizedComponents === $ uri -> normalizedComponents ;
352+ return match ( true ) {
353+ $ this ->getFragment () === $ uri ->getFragment (),
354+ ! $ excludeFragment => $ this -> normalizedComponents === $ uri -> normalizedComponents ,
355+ default => [... $ this -> normalizedComponents , ...[ ' fragment ' => null ]] === [... $ uri -> normalizedComponents , ...[ ' fragment ' => null ]],
356+ } ;
358357 }
359358
360359 public function toRawString (): string
0 commit comments