13
13
use InvalidArgumentException ;
14
14
use function microtime ;
15
15
use function base_convert ;
16
+ use function property_exists ;
16
17
use function random_bytes ;
17
18
use function preg_replace ;
18
19
use function strlen ;
@@ -129,8 +130,8 @@ public static function gen(int $ver = 1, string $node = null, string $ns = null)
129
130
130
131
/**
131
132
* @param int $ver
132
- * @param string $node
133
- * @param string $ns
133
+ * @param string|null $node
134
+ * @param string|null $ns
134
135
* @return UUID
135
136
* @throws InvalidArgumentException
136
137
* @throws Exception
@@ -179,7 +180,7 @@ protected function __construct(string $uuid)
179
180
* Generates a Version 1 UUID.
180
181
* These are derived from the time at which they were generated.
181
182
*
182
- * @param string $node
183
+ * @param string|null $node
183
184
* @return string
184
185
* @throws Exception
185
186
*/
@@ -190,7 +191,7 @@ protected static function mintTime(string $node = null): string
190
191
* integer size limits.
191
192
* Note that this will never be more accurate than to the microsecond.
192
193
*/
193
- $ time = microtime (1 ) * 10000000 + static ::INTERVAL ;
194
+ $ time = microtime (true ) * 10000000 + static ::INTERVAL ;
194
195
195
196
// Convert to a string representation
196
197
$ time = sprintf ('%F ' , $ time );
@@ -237,7 +238,7 @@ protected static function mintTime(string $node = null): string
237
238
* @return string
238
239
* @throws Exception
239
240
*/
240
- public static function randomBytes ($ bytes ): string
241
+ public static function randomBytes (int $ bytes ): string
241
242
{
242
243
return random_bytes ($ bytes );
243
244
}
@@ -250,7 +251,7 @@ public static function randomBytes($bytes): string
250
251
* @param integer $len
251
252
* @return string|null
252
253
*/
253
- protected static function makeBin ($ str , $ len ): ?string
254
+ protected static function makeBin ($ str , int $ len ): ?string
254
255
{
255
256
if ($ str instanceof self) {
256
257
return $ str ->bytes ;
@@ -301,11 +302,11 @@ protected static function mintName($ver, $node, $ns): string
301
302
switch ($ ver ) {
302
303
case static ::MD5 :
303
304
$ version = static ::VERSION_3 ;
304
- $ uuid = md5 ($ ns . $ node , 1 );
305
+ $ uuid = md5 ($ ns . $ node , true );
305
306
break ;
306
307
case static ::SHA1 :
307
308
$ version = static ::VERSION_5 ;
308
- $ uuid = substr (sha1 ($ ns . $ node , 1 ), 0 , 16 );
309
+ $ uuid = substr (sha1 ($ ns . $ node , true ), 0 , 16 );
309
310
break ;
310
311
default :
311
312
// no default really required here
@@ -375,12 +376,17 @@ public static function compare(string $a, string $b): bool
375
376
*/
376
377
public static function validate (string $ uuid ): bool
377
378
{
378
- return (boolean )preg_match ('~ ' . static ::VALID_UUID_REGEX . '~ ' , static ::import ($ uuid )->string );
379
+ return (bool )preg_match ('~ ' . static ::VALID_UUID_REGEX . '~ ' , static ::import ($ uuid )->string );
379
380
}
380
381
381
- public function __isset ($ var ): void
382
+ /**
383
+ * @param string $var
384
+ *
385
+ * @return bool
386
+ */
387
+ public function __isset (string $ var ): bool
382
388
{
383
- //
389
+ return property_exists ( $ this , $ var );
384
390
}
385
391
386
392
public function __set ($ var , $ val ): void
0 commit comments