Merge pull request #419 from huangzhhui/1.0

Add typehint of Snowflake
This commit is contained in:
李铭昕 2019-08-17 23:50:59 +08:00 committed by GitHub
commit 3649f9391f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View File

@ -72,32 +72,28 @@ class Meta
$this->sequence = $sequence;
}
/**
* @param int $timestamp
* @return Meta
*/
public function setTimestamp(int $timestamp): self
{
$this->timestamp = $timestamp;
return $this;
}
protected function maxMachineId()
protected function maxMachineId(): int
{
return -1 ^ (-1 << self::MACHINE_ID_BITS);
}
protected function maxDataCenterId()
protected function maxDataCenterId(): int
{
return -1 ^ (-1 << self::DATA_CENTER_ID_BITS);
}
protected function maxBusinessId()
protected function maxBusinessId(): int
{
return -1 ^ (-1 << self::BUSINESS_ID_BITS);
}
protected function maxSequence()
protected function maxSequence(): int
{
return -1 ^ (-1 << self::SEQUENCE_BITS);
}

View File

@ -65,22 +65,22 @@ class Snowflake implements IdGeneratorInterface
))->setTimestamp($timestamp + $this->beginSecond);
}
protected function getTimestampShift()
protected function getTimestampShift(): int
{
return Meta::SEQUENCE_BITS + Meta::MACHINE_ID_BITS + Meta::DATA_CENTER_ID_BITS + Meta::BUSINESS_ID_BITS;
}
protected function getBusinessIdShift()
protected function getBusinessIdShift(): int
{
return Meta::SEQUENCE_BITS + Meta::MACHINE_ID_BITS + Meta::DATA_CENTER_ID_BITS;
}
protected function getDataCenterShift()
protected function getDataCenterShift(): int
{
return Meta::SEQUENCE_BITS + Meta::MACHINE_ID_BITS;
}
protected function getMachineIdShift()
protected function getMachineIdShift(): int
{
return Meta::SEQUENCE_BITS;
}