@@ -22,11 +22,7 @@ class Uuid extends AbstractUid
22
22
23
23
public function __construct (string $ uuid )
24
24
{
25
- try {
26
- $ type = uuid_type ($ uuid );
27
- } catch (\ValueError $ e ) {
28
- throw new \InvalidArgumentException (sprintf ('Invalid UUID%s: "%s". ' , static ::TYPE ? 'v ' .static ::TYPE : '' , $ uuid ), 0 , $ e );
29
- }
25
+ $ type = uuid_is_valid ($ uuid ) ? uuid_type ($ uuid ) : false ;
30
26
31
27
if (false === $ type || \UUID_TYPE_INVALID === $ type || (static ::TYPE ?: $ type ) !== $ type ) {
32
28
throw new \InvalidArgumentException (sprintf ('Invalid UUID%s: "%s". ' , static ::TYPE ? 'v ' .static ::TYPE : '' , $ uuid ));
@@ -59,13 +55,11 @@ public static function fromString(string $uuid): parent
59
55
return new static ($ uuid );
60
56
}
61
57
62
- try {
63
- $ type = uuid_type ($ uuid );
64
- } catch (\ValueError $ e ) {
65
- throw new \InvalidArgumentException (sprintf ('Invalid UUID%s: "%s". ' , static ::TYPE ? 'v ' .static ::TYPE : '' , $ uuid ), 0 , $ e );
58
+ if (!uuid_is_valid ($ uuid )) {
59
+ throw new \InvalidArgumentException (sprintf ('Invalid UUID%s: "%s". ' , static ::TYPE ? 'v ' .static ::TYPE : '' , $ uuid ));
66
60
}
67
61
68
- switch ($ type ) {
62
+ switch (uuid_type ( $ uuid ) ) {
69
63
case UuidV1::TYPE : return new UuidV1 ($ uuid );
70
64
case UuidV3::TYPE : return new UuidV3 ($ uuid );
71
65
case UuidV4::TYPE : return new UuidV4 ($ uuid );
@@ -114,7 +108,7 @@ public static function isValid(string $uuid): bool
114
108
return uuid_is_valid ($ uuid );
115
109
}
116
110
117
- return static ::TYPE === uuid_type ($ uuid );
111
+ return uuid_is_valid ( $ uuid ) && static ::TYPE === uuid_type ($ uuid );
118
112
}
119
113
120
114
public function toBinary (): string
0 commit comments