Skip to content

Commit 3b29a94

Browse files
committed
Refactor method
1 parent 52327d8 commit 3b29a94

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/URITrait.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,33 @@ protected static function validURL(string $value, string $message = ''): string
8585
*/
8686
protected static function validURI(string $value, string $message = ''): string
8787
{
88-
$failure = false;
8988
try {
9089
self::$uri = new Uri($value);
90+
return $value;
9191
} catch (InvalidUriException $e) {
92-
$failure = true;
93-
}
94-
95-
if ($failure === true) {
9692
try {
9793
self::$uri = new Url($value);
94+
return $value;
9895
} catch (InvalidUrlException $e) {
9996
throw new InvalidArgumentException(sprintf(
10097
$message ?: '\'%s\' is not a valid WhatWg compliant URL',
10198
$value,
10299
));
103100
} finally {
104-
$failure = false;
105-
}
106-
107-
if ($failure === true) {
108101
throw new InvalidArgumentException(sprintf(
109102
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
110103
$value,
111104
));
112105
}
113106
}
114-
115-
return $value;
116107
}
117108

118109

119110
/**
120111
* For convenience and efficiency, to get the Uri-object from the last assertion.
112+
* @return \Uri\Rfc3986\Uri|\Uri\WhatWg\Url
121113
*/
122-
public static function getUri(): Uri
114+
public static function getUri(): Uri|Url
123115
{
124116
return self::$uri;
125117
}

0 commit comments

Comments
 (0)