1212 use UriManage \Exceptions \UriException ;
1313
1414 class Uri implements UriInterface {
15- protected ?string $ scheme ;
16- protected ?string $ user ;
17- protected ?string $ pass ;
18- protected ?string $ host ;
19- protected ?int $ port ;
15+ protected ?string $ scheme = null ;
16+ protected ?string $ user = null ;
17+ protected ?string $ pass = null ;
18+ protected ?string $ host = null ;
19+ protected ?int $ port = null ;
2020 protected ?Path $ path = null ;
2121 protected ?Query $ query = null ;
22- protected ?string $ fragment ;
23- protected ?string $ originalUri ;
24- protected bool $ hasBaseUrlRemoved = false ;
22+ protected ?string $ fragment = null ;
23+ protected ?string $ originalUri = null ;
2524
2625 /**
2726 * @throws InvalidArgumentException
@@ -62,12 +61,12 @@ function getFragment () : string {
6261 * @return string
6362 */
6463 function getUserInfo () : string {
65- if (! $ this ->hasUserInfo () ) {
64+ if ($ this ->user === null ) {
6665 return '' ;
6766 }
6867
69- if (( $ this ->pass ?? '' ) === '' ) {
70- return $ this ->user ?? '' ;
68+ if ($ this ->pass === null ) {
69+ return $ this ->user ;
7170 }
7271
7372 return sprintf ('%s:%s ' , $ this ->user , $ this ->pass );
@@ -77,19 +76,19 @@ function getUserInfo () : string {
7776 * @return string
7877 */
7978 function getAuthority () : string {
80- if (! $ this ->hasUserInfo () ) {
81- if ($ this ->isDefaultPortForScheme () || $ this ->getPort () === null ) {
79+ if ($ this ->user === null ) {
80+ if ($ this ->isDefaultPortForScheme () || $ this ->port === null ) {
8281 return $ this ->getHost ();
8382 }
8483
85- return sprintf ('%s:%d ' , $ this ->getHost (), $ this ->getPort () );
84+ return sprintf ('%s:%d ' , $ this ->getHost (), $ this ->port );
8685 }
8786
88- if ($ this ->isDefaultPortForScheme () || $ this ->getPort () === null ) {
87+ if ($ this ->isDefaultPortForScheme () || $ this ->port === null ) {
8988 return sprintf ('%s@%s ' , $ this ->getUserInfo (), $ this ->getHost ());
9089 }
9190
92- return sprintf ('%s@%s:%d ' , $ this ->getUserInfo (), $ this ->getHost (), $ this ->getPort () );
91+ return sprintf ('%s@%s:%d ' , $ this ->getUserInfo (), $ this ->getHost (), $ this ->port );
9392 }
9493
9594 /**
@@ -180,7 +179,7 @@ function withHost ($host) : static {
180179 $ instance = clone $ this ;
181180
182181 if ($ host === '' ) {
183- unset( $ instance ->host ) ;
182+ $ instance ->host = null ;
184183 } else {
185184 $ instance ->host = UriParser::parseHost ($ host );
186185 }
@@ -259,13 +258,13 @@ function withUserInfo ($user, $password = null) : static {
259258 }
260259
261260 /**
262- * @param int| null $port
261+ * @param null|int $port
263262 * @return static
264263 */
265264 function withPort ($ port ) : static {
266265 if ($ port === null ) {
267266 $ instance = clone $ this ;
268- unset( $ instance ->port ) ;
267+ $ instance ->port = null ;
269268
270269 return $ instance ;
271270 }
@@ -337,11 +336,4 @@ private function isDefaultPortForScheme () : bool {
337336 return (DefaultSchemePorts::PORT_TO_SCHEME [$ this ->port ] ?? null ) === $ this ->getScheme ();
338337 }
339338
340- /**
341- * @return bool
342- */
343- private function hasUserInfo () : bool {
344- return ($ this ->user ?? null ) !== null ;
345- }
346-
347339 }
0 commit comments