Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/private/Snowflake/SnowflakeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// Relative time
[$seconds, $milliseconds] = $this->getCurrentTime();

$serverId = $this->getServerId() & 0x1FF; // Keep 9 bits
$serverId = $this->getServerId(); // Already 9 bits
$isCli = (int)$this->isCli(); // 1 bit
$sequenceId = $this->sequenceGenerator->nextId($seconds, $milliseconds, $serverId); // 12 bits
if ($sequenceId > 0xFFF || $sequenceId === false) {
Expand Down Expand Up @@ -104,12 +104,18 @@

/**
* Return configured serverid or generate one if not set
*
* @return int<0, 511>

Check failure on line 108 in lib/private/Snowflake/SnowflakeGenerator.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificReturnType

lib/private/Snowflake/SnowflakeGenerator.php:108:13: MoreSpecificReturnType: The declared return type 'int<0, 511>' for OC\Snowflake\SnowflakeGenerator::getServerId is more specific than the inferred return type 'int' (see https://psalm.dev/070)
*/
private function getServerId(): int {
$serverid = $this->config->getSystemValueInt('serverid', -1);
return $serverid > 0
? $serverid
: crc32(gethostname() ?: random_bytes(8));
if ($serverid < 1) {
// Fallback: generates a server ID based on hostname
// or random bytes if hostname isn't available
$serverid = hexdec(hash('xxh32', gethostname() ?: random_bytes(8)));
}

return $serverid & 0x1FF;

Check failure on line 118 in lib/private/Snowflake/SnowflakeGenerator.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

LessSpecificReturnStatement

lib/private/Snowflake/SnowflakeGenerator.php:118:10: LessSpecificReturnStatement: The type 'int' is more general than the declared return type 'int<0, 511>' for OC\Snowflake\SnowflakeGenerator::getServerId (see https://psalm.dev/129)
}

private function isCli(): bool {
Expand Down
Loading