mirror of
https://github.com/ramsey/uuid.git
synced 2026-06-14 15:56:48 +03:00
Remove checks that are no longer necessary
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the ramsey/uuid library
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the ramsey/uuid library
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*
|
||||
* @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user