From 37f72746a70492a09c5debbba9fabc032636f684 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Thu, 9 Jan 2020 16:57:12 -0600 Subject: [PATCH] Remove checks that are no longer necessary --- src/Converter/DependencyCheckTrait.php | 81 -------------------------- src/Converter/NumberStringTrait.php | 78 ------------------------- tests/TestCase.php | 55 ----------------- 3 files changed, 214 deletions(-) delete mode 100644 src/Converter/DependencyCheckTrait.php delete mode 100644 src/Converter/NumberStringTrait.php diff --git a/src/Converter/DependencyCheckTrait.php b/src/Converter/DependencyCheckTrait.php deleted file mode 100644 index 2c574d8..0000000 --- a/src/Converter/DependencyCheckTrait.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -declare(strict_types=1); - -namespace Ramsey\Uuid\Converter; - -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; - -/** - * Provides methods to check dependencies for various converters - * - * @psalm-immutable - */ -trait DependencyCheckTrait -{ - /** - * Returns boolean true if the current build of PHP is a 64-bit build, - * throws UnsatisfiedDependencyException otherwise - * - * @throws UnsatisfiedDependencyException if PHP is not 64-bit - */ - private function check64BitPhp(): bool - { - if ($this->getPhpIntSize() < 8) { - throw new UnsatisfiedDependencyException( - 'The PHP build must be 64-bit to use this converter' - ); - } - - return true; - } - - /** - * Returns boolean true if the GMP extension is loaded, throws - * UnsatisfiedDependencyException otherwise - * - * @throws UnsatisfiedDependencyException if GMP is not loaded - */ - private function checkGmpExtension(): bool - { - if (!extension_loaded('gmp')) { - throw new UnsatisfiedDependencyException( - 'ext-gmp must be present to use this converter' - ); - } - - return true; - } - - /** - * Returns boolean true if the moontoast/math library is present, throws - * UnsatisfiedDependencyException otherwise - * - * @throws UnsatisfiedDependencyException if moontoast/math is not loaded - */ - private function checkMoontoastMathLibrary(): bool - { - if (!class_exists('Moontoast\Math\BigNumber')) { - throw new UnsatisfiedDependencyException( - 'moontoast/math must be present to use this converter' - ); - } - - return true; - } - - protected function getPhpIntSize(): int - { - return PHP_INT_SIZE; - } -} diff --git a/src/Converter/NumberStringTrait.php b/src/Converter/NumberStringTrait.php deleted file mode 100644 index fa825d5..0000000 --- a/src/Converter/NumberStringTrait.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @license http://opensource.org/licenses/MIT MIT - */ - -declare(strict_types=1); - -namespace Ramsey\Uuid\Converter; - -use Ramsey\Uuid\Exception\InvalidArgumentException; - -/** - * Provides shared functionality to check the values of string numbers for - * conversion - * - * @psalm-immutable - */ -trait NumberStringTrait -{ - /** - * Returns boolean true if the string $integer contains only digits, throws - * InvalidArgumentException otherwise - * - * @param string $integer The string integer value to check - * @param string $param The name of the parameter being checked - * - * @return bool True if $integer contains only digits, false otherwise - * - * @throws InvalidArgumentException if the string $integer does not contain - * only digits for a positive or negative integer - */ - private function checkIntegerString(string $integer, string $param): bool - { - // If it is a negative integer, remove the sign so that the string - // can be checked properly for only digits with ctype_digit(). - if (strpos($integer, '-') === 0) { - $integer = substr($integer, 1); - } - - if (!ctype_digit($integer)) { - throw new InvalidArgumentException( - "\${$param} must contain only digits" - ); - } - - return true; - } - - /** - * Returns boolean true if the string $hex contains only hexadecimal - * characters, throws InvalidArgumentException otherwise - * - * @param string $hex The hexadecimal string value to check - * @param string $param The name of the parameter being checked - * - * @return bool True if $hex contains only hexadecimal characters, false otherwise - * - * @throws InvalidArgumentException if the string $hex does not contain only - * hexadecimal characters - */ - private function checkHexadecimalString(string $hex, string $param): bool - { - if (!ctype_xdigit($hex)) { - throw new InvalidArgumentException( - "\${$param} must contain only hexadecimal characters" - ); - } - - return true; - } -} diff --git a/tests/TestCase.php b/tests/TestCase.php index 0b4b7c6..87a03b4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -17,61 +17,6 @@ class TestCase extends PhpUnitTestCase Mockery::close(); } - protected function skip64BitTest(): void - { - if (PHP_INT_SIZE === 4) { - $this->markTestSkipped( - 'Skipping test that can run only on a 64-bit build of PHP.' - ); - } - } - - protected function skipIfNoMoontoastMath(): void - { - if (!$this->hasMoontoastMath()) { - $this->markTestSkipped( - 'Skipping test that requires moontoast/math.' - ); - } - } - - protected function skipIfNoGmp(): void - { - if (!$this->hasGmp()) { - $this->markTestSkipped( - 'Skipping test that requires GMP.' - ); - } - } - - protected function hasMoontoastMath(): bool - { - return class_exists('Moontoast\\Math\\BigNumber'); - } - - protected function hasGmp(): bool - { - return extension_loaded('gmp'); - } - - protected function skipIfLittleEndianHost(): void - { - if (self::isLittleEndianSystem()) { - $this->markTestSkipped( - 'Skipping test targeting big-endian architectures.' - ); - } - } - - protected function skipIfBigEndianHost(): void - { - if (!self::isLittleEndianSystem()) { - $this->markTestSkipped( - 'Skipping test targeting little-endian architectures.' - ); - } - } - public static function isLittleEndianSystem(): bool { return current(unpack('v', pack('S', 0x00FF))) === 0x00FF;