aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/ramsey/uuid/src/Uuid.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/ramsey/uuid/src/Uuid.php')
-rw-r--r--vendor/ramsey/uuid/src/Uuid.php103
1 files changed, 57 insertions, 46 deletions
diff --git a/vendor/ramsey/uuid/src/Uuid.php b/vendor/ramsey/uuid/src/Uuid.php
index 45f9fa448..38fbd5ed6 100644
--- a/vendor/ramsey/uuid/src/Uuid.php
+++ b/vendor/ramsey/uuid/src/Uuid.php
@@ -14,8 +14,13 @@
namespace Ramsey\Uuid;
+use DateTime;
+use Exception;
+use InvalidArgumentException;
use Ramsey\Uuid\Converter\NumberConverterInterface;
use Ramsey\Uuid\Codec\CodecInterface;
+use Ramsey\Uuid\Exception\InvalidUuidStringException;
+use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
use Ramsey\Uuid\Exception\UnsupportedOperationException;
/**
@@ -140,14 +145,14 @@ class Uuid implements UuidInterface
* @var array
* @see UuidInterface::getFieldsHex()
*/
- protected $fields = array(
+ protected $fields = [
'time_low' => '00000000',
'time_mid' => '0000',
'time_hi_and_version' => '0000',
'clock_seq_hi_and_reserved' => '00',
'clock_seq_low' => '00',
'node' => '000000000000',
- );
+ ];
/**
* The number converter to use for converting hex values to/from integers.
@@ -229,7 +234,7 @@ class Uuid implements UuidInterface
*
* @param string $serialized
* @link http://php.net/manual/en/class.serializable.php
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
+ * @throws InvalidUuidStringException
*/
public function unserialize($serialized)
{
@@ -241,28 +246,32 @@ class Uuid implements UuidInterface
public function compareTo(UuidInterface $other)
{
- $comparison = 0;
-
if ($this->getMostSignificantBitsHex() < $other->getMostSignificantBitsHex()) {
- $comparison = -1;
- } elseif ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) {
- $comparison = 1;
- } elseif ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) {
- $comparison = -1;
- } elseif ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) {
- $comparison = 1;
+ return -1;
+ }
+
+ if ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) {
+ return 1;
+ }
+
+ if ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) {
+ return -1;
+ }
+
+ if ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) {
+ return 1;
}
- return $comparison;
+ return 0;
}
public function equals($other)
{
- if (!($other instanceof UuidInterface)) {
+ if (!$other instanceof UuidInterface) {
return false;
}
- return ($this->compareTo($other) == 0);
+ return $this->compareTo($other) == 0;
}
public function getBytes()
@@ -319,8 +328,7 @@ class Uuid implements UuidInterface
*/
public function getClockSequence()
{
- return (($this->getClockSeqHiAndReserved() & 0x3f) << 8)
- | $this->getClockSeqLow();
+ return ($this->getClockSeqHiAndReserved() & 0x3f) << 8 | $this->getClockSeqLow();
}
public function getClockSequenceHex()
@@ -345,7 +353,7 @@ class Uuid implements UuidInterface
$unixTime = ($this->getTimestamp() - 0x01b21dd213814000) / 1e7;
$unixTime = number_format($unixTime, 0, '', '');
- return new \DateTime("@{$unixTime}");
+ return new DateTime("@{$unixTime}");
}
/**
@@ -368,14 +376,14 @@ class Uuid implements UuidInterface
*/
public function getFields()
{
- return array(
+ return [
'time_low' => $this->getTimeLow(),
'time_mid' => $this->getTimeMid(),
'time_hi_and_version' => $this->getTimeHiAndVersion(),
'clock_seq_hi_and_reserved' => $this->getClockSeqHiAndReserved(),
'clock_seq_low' => $this->getClockSeqLow(),
'node' => $this->getNode(),
- );
+ ];
}
public function getFieldsHex()
@@ -400,7 +408,7 @@ class Uuid implements UuidInterface
* Returns the least significant 64 bits of this UUID's 128 bit value.
*
* @return mixed Converted representation of the unsigned 64-bit integer value
- * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
+ * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
*/
public function getLeastSignificantBits()
{
@@ -421,7 +429,7 @@ class Uuid implements UuidInterface
* Returns the most significant 64 bits of this UUID's 128 bit value.
*
* @return mixed Converted representation of the unsigned 64-bit integer value
- * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
+ * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
*/
public function getMostSignificantBits()
{
@@ -568,17 +576,20 @@ class Uuid implements UuidInterface
public function getVariant()
{
$clockSeq = $this->getClockSeqHiAndReserved();
+
if (0 === ($clockSeq & 0x80)) {
- $variant = self::RESERVED_NCS;
- } elseif (0 === ($clockSeq & 0x40)) {
- $variant = self::RFC_4122;
- } elseif (0 === ($clockSeq & 0x20)) {
- $variant = self::RESERVED_MICROSOFT;
- } else {
- $variant = self::RESERVED_FUTURE;
+ return self::RESERVED_NCS;
+ }
+
+ if (0 === ($clockSeq & 0x40)) {
+ return self::RFC_4122;
+ }
+
+ if (0 === ($clockSeq & 0x20)) {
+ return self::RESERVED_MICROSOFT;
}
- return $variant;
+ return self::RESERVED_FUTURE;
}
public function getVersion()
@@ -624,8 +635,8 @@ class Uuid implements UuidInterface
*
* @param string $bytes
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
- * @throws \InvalidArgumentException
+ * @throws InvalidUuidStringException
+ * @throws InvalidArgumentException
*/
public static function fromBytes($bytes)
{
@@ -637,7 +648,7 @@ class Uuid implements UuidInterface
*
* @param string $name A string that specifies a UUID
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
+ * @throws InvalidUuidStringException
*/
public static function fromString($name)
{
@@ -649,8 +660,8 @@ class Uuid implements UuidInterface
*
* @param string $integer String representation of 128-bit integer
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
+ * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
+ * @throws InvalidUuidStringException
*/
public static function fromInteger($integer)
{
@@ -665,7 +676,7 @@ class Uuid implements UuidInterface
*/
public static function isValid($uuid)
{
- $uuid = str_replace(array('urn:', 'uuid:', '{', '}'), '', $uuid);
+ $uuid = str_replace(['urn:', 'uuid:', '{', '}'], '', $uuid);
if ($uuid == self::NIL) {
return true;
@@ -687,10 +698,10 @@ class Uuid implements UuidInterface
* could arise when the clock is set backwards in time or if the node ID
* changes.
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if called on a 32-bit system and
+ * @throws UnsatisfiedDependencyException if called on a 32-bit system and
* `Moontoast\Math\BigNumber` is not present
- * @throws \InvalidArgumentException
- * @throws \Exception if it was not possible to gather sufficient entropy
+ * @throws InvalidArgumentException
+ * @throws Exception if it was not possible to gather sufficient entropy
*/
public static function uuid1($node = null, $clockSeq = null)
{
@@ -701,10 +712,10 @@ class Uuid implements UuidInterface
* Generate a version 3 UUID based on the MD5 hash of a namespace identifier
* (which is a UUID) and a name (which is a string).
*
- * @param string $ns The UUID namespace in which to create the named UUID
+ * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
+ * @throws InvalidUuidStringException
*/
public static function uuid3($ns, $name)
{
@@ -715,9 +726,9 @@ class Uuid implements UuidInterface
* Generate a version 4 (random) UUID.
*
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
- * @throws \InvalidArgumentException
- * @throws \Exception
+ * @throws UnsatisfiedDependencyException if `Moontoast\Math\BigNumber` is not present
+ * @throws InvalidArgumentException
+ * @throws Exception
*/
public static function uuid4()
{
@@ -728,10 +739,10 @@ class Uuid implements UuidInterface
* Generate a version 5 UUID based on the SHA-1 hash of a namespace
* identifier (which is a UUID) and a name (which is a string).
*
- * @param string $ns The UUID namespace in which to create the named UUID
+ * @param string|UuidInterface $ns The UUID namespace in which to create the named UUID
* @param string $name The name to create a UUID for
* @return UuidInterface
- * @throws \Ramsey\Uuid\Exception\InvalidUuidStringException
+ * @throws InvalidUuidStringException
*/
public static function uuid5($ns, $name)
{