From 8f63d671a71a3399cf528df1be012e41e48e058c Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Sat, 19 Jan 2013 12:48:05 -0600 Subject: [PATCH] Replace BadMethodCallException with UnsatisfiedDependencyException --- .../UnsatisfiedDependencyException.php | 20 ++++++++++++ src/Rhumsaa/Uuid/Uuid.php | 32 +++++++++---------- tests/Rhumsaa/Uuid/UuidTest.php | 16 +++++----- 3 files changed, 44 insertions(+), 24 deletions(-) create mode 100644 src/Rhumsaa/Uuid/Exception/UnsatisfiedDependencyException.php diff --git a/src/Rhumsaa/Uuid/Exception/UnsatisfiedDependencyException.php b/src/Rhumsaa/Uuid/Exception/UnsatisfiedDependencyException.php new file mode 100644 index 0000000..346072d --- /dev/null +++ b/src/Rhumsaa/Uuid/Exception/UnsatisfiedDependencyException.php @@ -0,0 +1,20 @@ + + * @license http://opensource.org/licenses/MIT MIT + */ + +namespace Rhumsaa\Uuid\Exception; + +/** + * Thrown to indicate that the requested operation has depencies that have not + * been satisfied. + */ +class UnsatisfiedDependencyException extends \RuntimeException +{ +} diff --git a/src/Rhumsaa/Uuid/Uuid.php b/src/Rhumsaa/Uuid/Uuid.php index 0ad56fc..0cff229 100644 --- a/src/Rhumsaa/Uuid/Uuid.php +++ b/src/Rhumsaa/Uuid/Uuid.php @@ -297,7 +297,7 @@ class Uuid * * @return \DateTime * @throws Exception\UnsupportedOperationException If this UUID is not a version 1 UUID - * @throws \BadMethodCallException if called on a 32-bit system and Moontoast\Math\BigNumber is not present + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system and Moontoast\Math\BigNumber is not present */ public function getDateTime() { @@ -323,7 +323,7 @@ class Uuid } else { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'When calling ' . __METHOD__ . ' on a 32-bit system, ' . 'Moontoast\Math\BigNumber must be present in order ' . 'to extract DateTime from version 1 UUIDs' @@ -339,12 +339,12 @@ class Uuid * to the RFC 4122 names for the fields. * * @return array - * @throws \BadMethodCallException if called on a 32-bit system + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system */ public function getFields() { if (!self::is64BitSystem()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since some ' . 'values overflow the system max integer value' ); @@ -375,12 +375,12 @@ class Uuid * Returns the least significant 64 bits of this UUID's 128 bit value * * @return \Moontoast\Math\BigNumber - * @throws \BadMethodCallException if Moontoast\Math\BigNumber is not present + * @throws Exception\UnsatisfiedDependencyException if Moontoast\Math\BigNumber is not present */ public function getLeastSignificantBits() { if (!self::hasBigNumber()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' without support for large ' . 'integers, since least significant bits is an unsigned ' . '64-bit integer; Moontoast\Math\BigNumber is required' @@ -415,12 +415,12 @@ class Uuid * Returns the most significant 64 bits of this UUID's 128 bit value * * @return \Moontoast\Math\BigNumber - * @throws \BadMethodCallException if Moontoast\Math\BigNumber is not present + * @throws Exception\UnsatisfiedDependencyException if Moontoast\Math\BigNumber is not present */ public function getMostSignificantBits() { if (!self::hasBigNumber()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' without support for large ' . 'integers, since most significant bits is an unsigned ' . '64-bit integer; Moontoast\Math\BigNumber is required' @@ -474,12 +474,12 @@ class Uuid * * @return int * @see http://tools.ietf.org/html/rfc4122#section-4.1.6 - * @throws \BadMethodCallException if called on a 32-bit system + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system */ public function getNode() { if (!self::is64BitSystem()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since node ' . 'is an unsigned 48-bit integer and can overflow the system ' . 'max integer value' @@ -525,12 +525,12 @@ class Uuid * Returns the low field of the timestamp (the first 32 bits of the UUID). * * @return int - * @throws \BadMethodCallException if called on a 32-bit system + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system */ public function getTimeLow() { if (!self::is64BitSystem()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since time_low ' . 'is an unsigned 32-bit integer and can overflow the system ' . 'max integer value' @@ -584,7 +584,7 @@ class Uuid * * @return int * @throws Exception\UnsupportedOperationException If this UUID is not a version 1 UUID - * @throws \BadMethodCallException if called on a 32-bit system + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system * @see http://tools.ietf.org/html/rfc4122#section-4.1.4 */ public function getTimestamp() @@ -594,7 +594,7 @@ class Uuid } if (!self::is64BitSystem()) { - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'Cannot call ' . __METHOD__ . ' on a 32-bit system, since timestamp ' . 'is an unsigned 60-bit integer and can overflow the system ' . 'max integer value' @@ -858,7 +858,7 @@ class Uuid * since 00:00:00.00, 15 October 1582. * * @return array - * @throws \BadMethodCallException if called on a 32-bit system and Moontoast\Math\BigNumber is not present + * @throws Exception\UnsatisfiedDependencyException if called on a 32-bit system and Moontoast\Math\BigNumber is not present */ protected static function calculateUuidTime($sec, $usec) { @@ -896,7 +896,7 @@ class Uuid ); } - throw new \BadMethodCallException( + throw new Exception\UnsatisfiedDependencyException( 'When calling ' . __METHOD__ . ' on a 32-bit system, ' . 'Moontoast\Math\BigNumber must be present in order ' . 'to generate version 1 UUIDs' diff --git a/tests/Rhumsaa/Uuid/UuidTest.php b/tests/Rhumsaa/Uuid/UuidTest.php index 46f2d8a..ae9efcc 100644 --- a/tests/Rhumsaa/Uuid/UuidTest.php +++ b/tests/Rhumsaa/Uuid/UuidTest.php @@ -186,7 +186,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getDateTime - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetDateTimeThrownException() { @@ -233,7 +233,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getFields - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetFields32Bit() { @@ -273,7 +273,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getLeastSignificantBits - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetLeastSignificantBitsException() { @@ -303,7 +303,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getMostSignificantBits - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetMostSignificantBitsException() { @@ -334,7 +334,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getNode - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetNode32Bit() { @@ -383,7 +383,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getTimeLow - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetTimeLow32Bit() { @@ -464,7 +464,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::getTimestamp - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testGetTimestamp32Bit() { @@ -1164,7 +1164,7 @@ class UuidTest extends \PHPUnit_Framework_TestCase /** * @covers Rhumsaa\Uuid\Uuid::calculateUuidTime - * @expectedException BadMethodCallException + * @expectedException Rhumsaa\Uuid\Exception\UnsatisfiedDependencyException */ public function testCalculateUuidTimeThrownException() {