Skip to content

Commit a42c68d

Browse files
committed
Refactor method
1 parent 52327d8 commit a42c68d

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

‎src/URITrait.php‎

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,41 +85,25 @@ 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 {
89+
self::$uri = new Url($value);
9090
self::$uri = new Uri($value);
91-
} catch (InvalidUriException $e) {
92-
$failure = true;
91+
return $value;
92+
} catch (InvalidUriException | InvalidUrlException $uri) {
9393
}
9494

95-
if ($failure === true) {
96-
try {
97-
self::$uri = new Url($value);
98-
} catch (InvalidUrlException $e) {
99-
throw new InvalidArgumentException(sprintf(
100-
$message ?: '\'%s\' is not a valid WhatWg compliant URL',
101-
$value,
102-
));
103-
} finally {
104-
$failure = false;
105-
}
106-
107-
if ($failure === true) {
108-
throw new InvalidArgumentException(sprintf(
109-
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
110-
$value,
111-
));
112-
}
113-
}
114-
115-
return $value;
95+
throw new InvalidArgumentException(sprintf(
96+
$message ?: '\'%s\' is not a valid RFC3986 compliant URI',
97+
$value,
98+
));
11699
}
117100

118101

119102
/**
120103
* For convenience and efficiency, to get the Uri-object from the last assertion.
104+
* @return \Uri\Rfc3986\Uri|\Uri\WhatWg\Url
121105
*/
122-
public static function getUri(): Uri
106+
public static function getUri(): Uri|Url
123107
{
124108
return self::$uri;
125109
}

0 commit comments

Comments
 (0)