diff --git a/src/Rhumsaa/Uuid/Uuid.php b/src/Rhumsaa/Uuid/Uuid.php index bb2e6c2..8534d2c 100644 --- a/src/Rhumsaa/Uuid/Uuid.php +++ b/src/Rhumsaa/Uuid/Uuid.php @@ -375,11 +375,20 @@ final class Uuid */ public function toString() { - return ($this->digits($this->getMostSignificantBits() >> 32, 8) . '-' . - $this->digits($this->getMostSignificantBits() >> 16, 4) . '-' . - $this->digits($this->getMostSignificantBits(), 4) . '-' . - $this->digits($this->getLeastSignificantBits() >> 48, 4) . '-' . - $this->digits($this->getLeastSignificantBits(), 12)); + $hex = sprintf( + '%016x%016x', + $this->getMostSignificantBits(), + $this->getLeastSignificantBits() + ); + + return sprintf( + '%s-%s-%s-%s-%s', + substr($hex, 0, 8), + substr($hex, 8, 4), + substr($hex, 12, 4), + substr($hex, 16, 4), + substr($hex, 20) + ); } /** @@ -522,19 +531,6 @@ final class Uuid { } - /** - * Returns $value represented by the specified number of hex $digits. - * - * @param int $value The value to process (in integer form) - * @param int $digits The number of hex digits to return - * @return string - */ - protected function digits($value, $digits) - { - $hi = (1 << ($digits * 4)); - return substr(dechex($hi | ($value & ($hi - 1))), 1); - } - /** * Get the hardware address as a 48-bit positive integer. If all attempts to * obtain the hardware address fail, we choose a random 48-bit number with diff --git a/tests/Rhumsaa/Uuid/UuidTest.php b/tests/Rhumsaa/Uuid/UuidTest.php index 37eb887..5198197 100644 --- a/tests/Rhumsaa/Uuid/UuidTest.php +++ b/tests/Rhumsaa/Uuid/UuidTest.php @@ -321,7 +321,6 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::toString * @covers Rhumsaa\Uuid\Uuid::__toString - * @covers Rhumsaa\Uuid\Uuid::digits */ public function testToString() {