Skip to content

Commit 2ac074f

Browse files
committed
fix param type error for util class UUID
1 parent 0455f37 commit 2ac074f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/Util/UUID.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use InvalidArgumentException;
1414
use function microtime;
1515
use function base_convert;
16+
use function property_exists;
1617
use function random_bytes;
1718
use function preg_replace;
1819
use function strlen;
@@ -129,8 +130,8 @@ public static function gen(int $ver = 1, string $node = null, string $ns = null)
129130

130131
/**
131132
* @param int $ver
132-
* @param string $node
133-
* @param string $ns
133+
* @param string|null $node
134+
* @param string|null $ns
134135
* @return UUID
135136
* @throws InvalidArgumentException
136137
* @throws Exception
@@ -179,7 +180,7 @@ protected function __construct(string $uuid)
179180
* Generates a Version 1 UUID.
180181
* These are derived from the time at which they were generated.
181182
*
182-
* @param string $node
183+
* @param string|null $node
183184
* @return string
184185
* @throws Exception
185186
*/
@@ -190,7 +191,7 @@ protected static function mintTime(string $node = null): string
190191
* integer size limits.
191192
* Note that this will never be more accurate than to the microsecond.
192193
*/
193-
$time = microtime(1) * 10000000 + static::INTERVAL;
194+
$time = microtime(true) * 10000000 + static::INTERVAL;
194195

195196
// Convert to a string representation
196197
$time = sprintf('%F', $time);
@@ -237,7 +238,7 @@ protected static function mintTime(string $node = null): string
237238
* @return string
238239
* @throws Exception
239240
*/
240-
public static function randomBytes($bytes): string
241+
public static function randomBytes(int $bytes): string
241242
{
242243
return random_bytes($bytes);
243244
}
@@ -250,7 +251,7 @@ public static function randomBytes($bytes): string
250251
* @param integer $len
251252
* @return string|null
252253
*/
253-
protected static function makeBin($str, $len): ?string
254+
protected static function makeBin($str, int$len): ?string
254255
{
255256
if ($str instanceof self) {
256257
return $str->bytes;
@@ -301,11 +302,11 @@ protected static function mintName($ver, $node, $ns): string
301302
switch ($ver) {
302303
case static::MD5:
303304
$version = static::VERSION_3;
304-
$uuid = md5($ns . $node, 1);
305+
$uuid = md5($ns . $node, true);
305306
break;
306307
case static::SHA1:
307308
$version = static::VERSION_5;
308-
$uuid = substr(sha1($ns . $node, 1), 0, 16);
309+
$uuid = substr(sha1($ns . $node, true), 0, 16);
309310
break;
310311
default:
311312
// no default really required here
@@ -375,12 +376,17 @@ public static function compare(string $a, string $b): bool
375376
*/
376377
public static function validate(string $uuid): bool
377378
{
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);
379380
}
380381

381-
public function __isset($var): void
382+
/**
383+
* @param string $var
384+
*
385+
* @return bool
386+
*/
387+
public function __isset(string $var): bool
382388
{
383-
//
389+
return property_exists($this, $var);
384390
}
385391

386392
public function __set($var, $val): void

0 commit comments

Comments
 (0)