Merge branch 'master' into patch-1

This commit is contained in:
Ben Ramsey
2020-10-29 18:30:23 -05:00
committed by GitHub
30 changed files with 509 additions and 305 deletions
@@ -19,7 +19,7 @@ use Ramsey\Uuid\Math\CalculatorInterface;
use Ramsey\Uuid\Type\Integer as IntegerObject;
/**
* GenericNumberConverter uses the provided calculate to convert decimal
* GenericNumberConverter uses the provided calculator to convert decimal
* numbers to and from hexadecimal values
*
* @psalm-immutable
+2 -2
View File
@@ -137,8 +137,8 @@ class DceSecurityGenerator implements DceSecurityGeneratorInterface
);
}
$domainByte = pack('n', $localDomain)[1];
$identifierBytes = hex2bin(str_pad($identifierHex, 8, '0', STR_PAD_LEFT));
$domainByte = (string) pack('n', $localDomain)[1];
$identifierBytes = (string) hex2bin(str_pad($identifierHex, 8, '0', STR_PAD_LEFT));
if ($node instanceof Hexadecimal) {
$node = $node->toString();
+6 -2
View File
@@ -28,8 +28,12 @@ class DefaultNameGenerator implements NameGeneratorInterface
/** @psalm-pure */
public function generate(UuidInterface $ns, string $name, string $hashAlgorithm): string
{
/** @var string|bool $bytes */
$bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true);
try {
/** @var string|bool $bytes */
$bytes = @hash($hashAlgorithm, $ns->getBytes() . $name, true);
} catch (\ValueError $e) {
$bytes = false; // keep same behavior than PHP 7
}
if ($bytes === false) {
throw new NameException(sprintf(
+4
View File
@@ -94,6 +94,7 @@ final class Fields implements FieldsInterface
public function getTimeLow(): Hexadecimal
{
// Swap the bytes from little endian to network byte order.
/** @var array $hex */
$hex = unpack(
'H*',
pack(
@@ -109,6 +110,7 @@ final class Fields implements FieldsInterface
public function getTimeMid(): Hexadecimal
{
// Swap the bytes from little endian to network byte order.
/** @var array $hex */
$hex = unpack(
'H*',
pack(
@@ -123,6 +125,7 @@ final class Fields implements FieldsInterface
public function getTimeHiAndVersion(): Hexadecimal
{
// Swap the bytes from little endian to network byte order.
/** @var array $hex */
$hex = unpack(
'H*',
pack(
@@ -172,6 +175,7 @@ final class Fields implements FieldsInterface
return null;
}
/** @var array $parts */
$parts = unpack('n*', $this->bytes);
return ((int) $parts[4] >> 4) & 0x00f;
@@ -178,7 +178,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface
}
/** @var string $sid */
$sid = str_getcsv(trim($response))[1] ?? '';
$sid = str_getcsv(trim((string) $response))[1] ?? '';
if (($lastHyphen = strrpos($sid, '-')) === false) {
return '';
@@ -207,7 +207,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface
}
/** @var string[] $userGroups */
$userGroups = preg_split('/\s{2,}/', $response, -1, PREG_SPLIT_NO_EMPTY);
$userGroups = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
$firstGroup = trim($userGroups[1] ?? '', "* \t\n\r\0\x0B");
@@ -222,7 +222,7 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface
}
/** @var string[] $userGroup */
$userGroup = preg_split('/\s{2,}/', $response, -1, PREG_SPLIT_NO_EMPTY);
$userGroup = preg_split('/\s{2,}/', (string) $response, -1, PREG_SPLIT_NO_EMPTY);
$sid = $userGroup[1] ?? '';
+1
View File
@@ -177,6 +177,7 @@ final class Fields implements FieldsInterface
return null;
}
/** @var array $parts */
$parts = unpack('n*', $this->bytes);
return (int) $parts[4] >> 12;
+1
View File
@@ -58,6 +58,7 @@ trait VariantTrait
throw new InvalidBytesException('Invalid number of bytes');
}
/** @var array $parts */
$parts = unpack('n*', $this->getBytes());
// $parts[5] is a 16-bit, unsigned integer containing the variant bits
+8 -2
View File
@@ -36,7 +36,7 @@ use function substr;
final class Integer implements NumberInterface
{
/**
* @var string
* @psalm-var numeric-string
*/
private $value;
@@ -80,7 +80,10 @@ final class Integer implements NumberInterface
$this->isNegative = true;
}
$this->value = $value;
/** @psalm-var numeric-string $numericValue */
$numericValue = $value;
$this->value = $numericValue;
}
public function isNegative(): bool
@@ -88,6 +91,9 @@ final class Integer implements NumberInterface
return $this->isNegative;
}
/**
* @psalm-return numeric-string
*/
public function toString(): string
{
return $this->value;
+6 -2
View File
@@ -471,10 +471,14 @@ class UuidFactory implements UuidFactoryInterface
*/
private function uuidFromBytesAndVersion(string $bytes, int $version): UuidInterface
{
$timeHi = (int) unpack('n*', substr($bytes, 6, 2))[1];
/** @var array $unpackedTime */
$unpackedTime = unpack('n*', substr($bytes, 6, 2));
$timeHi = (int) $unpackedTime[1];
$timeHiAndVersion = pack('n*', BinaryUtils::applyVersion($timeHi, $version));
$clockSeqHi = (int) unpack('n*', substr($bytes, 8, 2))[1];
/** @var array $unpackedClockSeq */
$unpackedClockSeq = unpack('n*', substr($bytes, 8, 2));
$clockSeqHi = (int) $unpackedClockSeq[1];
$clockSeqHiAndReserved = pack('n*', BinaryUtils::applyVariant($clockSeqHi));
$bytes = substr_replace($bytes, $timeHiAndVersion, 6, 2);