From 84fe6cf755564a0374740a7ee5d7b28a29eae986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Filipe?= Date: Wed, 17 Oct 2018 09:48:21 +0100 Subject: [PATCH] Removed some `else`/`elseif` and added some early returns to make the code a little easier to read, nothing changes on the big picture --- src/Codec/TimestampLastCombCodec.php | 1 - src/Converter/Time/BigNumberTimeConverter.php | 3 +- src/FeatureSet.php | 4 +- src/Uuid.php | 50 +++++++++++-------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Codec/TimestampLastCombCodec.php b/src/Codec/TimestampLastCombCodec.php index 0cdd009..240f613 100644 --- a/src/Codec/TimestampLastCombCodec.php +++ b/src/Codec/TimestampLastCombCodec.php @@ -19,5 +19,4 @@ namespace Ramsey\Uuid\Codec; */ class TimestampLastCombCodec extends StringCodec { - } diff --git a/src/Converter/Time/BigNumberTimeConverter.php b/src/Converter/Time/BigNumberTimeConverter.php index eb57b1c..112f722 100644 --- a/src/Converter/Time/BigNumberTimeConverter.php +++ b/src/Converter/Time/BigNumberTimeConverter.php @@ -43,7 +43,8 @@ class BigNumberTimeConverter implements TimeConverterInterface $usec = new BigNumber($microSeconds); $usec->multiply('10'); - $uuidTime->add($sec) + $uuidTime + ->add($sec) ->add($usec) ->add('122192928000000000'); diff --git a/src/FeatureSet.php b/src/FeatureSet.php index 56a774e..2027b9e 100644 --- a/src/FeatureSet.php +++ b/src/FeatureSet.php @@ -289,7 +289,9 @@ class FeatureSet { if ($this->is64BitSystem()) { return new PhpTimeConverter(); - } elseif ($this->hasBigNumber()) { + } + + if ($this->hasBigNumber()) { return new BigNumberTimeConverter(); } diff --git a/src/Uuid.php b/src/Uuid.php index cba8c7e..38fbd5e 100644 --- a/src/Uuid.php +++ b/src/Uuid.php @@ -246,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; } - return $comparison; + if ($this->getMostSignificantBitsHex() > $other->getMostSignificantBitsHex()) { + return 1; + } + + if ($this->getLeastSignificantBitsHex() < $other->getLeastSignificantBitsHex()) { + return -1; + } + + if ($this->getLeastSignificantBitsHex() > $other->getLeastSignificantBitsHex()) { + return 1; + } + + 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() @@ -324,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() @@ -573,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; } - return $variant; + if (0 === ($clockSeq & 0x40)) { + return self::RFC_4122; + } + + if (0 === ($clockSeq & 0x20)) { + return self::RESERVED_MICROSOFT; + } + + return self::RESERVED_FUTURE; } public function getVersion()