add typehints and return types

This commit is contained in:
Massimiliano Arione
2019-09-12 15:47:49 +02:00
committed by Ben Ramsey
parent 3a42c259a7
commit 5459113b81
34 changed files with 185 additions and 175 deletions
+10 -7
View File
@@ -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');
}