mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-15 16:07:55 +03:00
add typehints and return types
This commit is contained in:
committed by
Ben Ramsey
parent
3a42c259a7
commit
5459113b81
@@ -80,7 +80,7 @@ class DefaultTimeGenerator implements TimeGeneratorInterface
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception if it was not possible to gather sufficient entropy
|
||||
*/
|
||||
public function generate($node = null, $clockSeq = null)
|
||||
public function generate($node = null, int $clockSeq = null): string
|
||||
{
|
||||
$node = $this->getValidNode($node);
|
||||
|
||||
@@ -92,16 +92,19 @@ class DefaultTimeGenerator implements TimeGeneratorInterface
|
||||
// Create a 60-bit time value as a count of 100-nanosecond intervals
|
||||
// since 00:00:00.00, 15 October 1582
|
||||
$timeOfDay = $this->timeProvider->currentTime();
|
||||
$uuidTime = $this->timeConverter->calculateTime((string) $timeOfDay['sec'], (string) $timeOfDay['usec']);
|
||||
$uuidTime = $this->timeConverter->calculateTime(
|
||||
(string) ($timeOfDay['sec'] ?? ''),
|
||||
(string) ($timeOfDay['usec'] ?? '')
|
||||
);
|
||||
|
||||
$timeHi = BinaryUtils::applyVersion($uuidTime['hi'], 1);
|
||||
$timeHi = BinaryUtils::applyVersion((string) ($uuidTime['hi'] ?? 0), 1);
|
||||
$clockSeqHi = BinaryUtils::applyVariant($clockSeq >> 8);
|
||||
|
||||
$hex = vsprintf(
|
||||
'%08s%04s%04s%02s%02s%012s',
|
||||
[
|
||||
$uuidTime['low'],
|
||||
$uuidTime['mid'],
|
||||
$uuidTime['low'] ?? 0,
|
||||
$uuidTime['mid'] ?? 0,
|
||||
sprintf('%04x', $timeHi),
|
||||
sprintf('%02x', $clockSeqHi),
|
||||
sprintf('%02x', $clockSeq & 0xff),
|
||||
@@ -121,7 +124,7 @@ class DefaultTimeGenerator implements TimeGeneratorInterface
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function getValidNode($node)
|
||||
protected function getValidNode($node): string
|
||||
{
|
||||
if ($node === null) {
|
||||
$node = $this->nodeProvider->getNode();
|
||||
@@ -132,7 +135,7 @@ class DefaultTimeGenerator implements TimeGeneratorInterface
|
||||
$node = sprintf('%012x', $node);
|
||||
}
|
||||
|
||||
if (!ctype_xdigit($node) || strlen($node) > 12) {
|
||||
if (!ctype_xdigit((string) $node) || strlen((string) $node) > 12) {
|
||||
throw new InvalidArgumentException('Invalid node value');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user