diff options
author | Mario <mario@mariovavti.com> | 2020-11-27 08:04:00 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-11-27 08:04:00 +0000 |
commit | f4bb7bcbff3770387c2fecfa91ce4a60b916a474 (patch) | |
tree | ea007e664d435f1f3d63c87bfe1600484d2bd46c /vendor/ramsey/uuid/src/Converter/Number | |
parent | 07e5b8295ea9d342f66d8119d88bd58124b548e6 (diff) | |
download | volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.tar.gz volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.tar.bz2 volse-hubzilla-f4bb7bcbff3770387c2fecfa91ce4a60b916a474.zip |
update composer libs
Diffstat (limited to 'vendor/ramsey/uuid/src/Converter/Number')
3 files changed, 97 insertions, 65 deletions
diff --git a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php index d23512256..fef63fd00 100644 --- a/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Number/BigNumberConverter.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,48 +8,50 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ +declare(strict_types=1); + namespace Ramsey\Uuid\Converter\Number; -use Moontoast\Math\BigNumber; use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Math\BrickMathCalculator; /** - * BigNumberConverter converts UUIDs from hexadecimal characters into - * moontoast/math `BigNumber` representations of integers and vice versa + * Previously used to integrate moontoast/math as a bignum arithmetic library, + * BigNumberConverter is deprecated in favor of GenericNumberConverter + * + * @deprecated Transition to {@see GenericNumberConverter}. + * + * @psalm-immutable */ class BigNumberConverter implements NumberConverterInterface { /** - * Converts a hexadecimal number into a `Moontoast\Math\BigNumber` representation - * - * @param string $hex The hexadecimal string representation to convert - * @return BigNumber + * @var NumberConverterInterface */ - public function fromHex($hex) - { - $number = BigNumber::convertToBase10($hex, 16); + private $converter; - return new BigNumber($number); + public function __construct() + { + $this->converter = new GenericNumberConverter(new BrickMathCalculator()); } /** - * Converts an integer or `Moontoast\Math\BigNumber` integer representation - * into a hexadecimal string representation - * - * @param int|string|BigNumber $integer An integer or `Moontoast\Math\BigNumber` - * @return string Hexadecimal string + * @inheritDoc + * @psalm-pure */ - public function toHex($integer) + public function fromHex(string $hex): string { - if (!$integer instanceof BigNumber) { - $integer = new BigNumber($integer); - } + return $this->converter->fromHex($hex); + } - return BigNumber::convertFromBase10($integer, 16); + /** + * @inheritDoc + * @psalm-pure + */ + public function toHex(string $number): string + { + return $this->converter->toHex($number); } } diff --git a/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php index 96a011c65..c9cfa6864 100644 --- a/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php +++ b/vendor/ramsey/uuid/src/Converter/Number/DegradedNumberConverter.php @@ -1,4 +1,5 @@ <?php + /** * This file is part of the ramsey/uuid library * @@ -7,52 +8,18 @@ * * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com> * @license http://opensource.org/licenses/MIT MIT - * @link https://benramsey.com/projects/ramsey-uuid/ Documentation - * @link https://packagist.org/packages/ramsey/uuid Packagist - * @link https://github.com/ramsey/uuid GitHub */ -namespace Ramsey\Uuid\Converter\Number; +declare(strict_types=1); -use Ramsey\Uuid\Exception\UnsatisfiedDependencyException; -use Ramsey\Uuid\Converter\NumberConverterInterface; +namespace Ramsey\Uuid\Converter\Number; /** - * DegradedNumberConverter throws `UnsatisfiedDependencyException` exceptions - * if attempting to use number conversion functionality in an environment that - * does not support large integers (i.e. when moontoast/math is not available) + * @deprecated DegradedNumberConverter is no longer necessary for converting + * numbers on 32-bit systems. Transition to {@see GenericNumberConverter}. + * + * @psalm-immutable */ -class DegradedNumberConverter implements NumberConverterInterface +class DegradedNumberConverter extends BigNumberConverter { - /** - * Throws an `UnsatisfiedDependencyException` - * - * @param string $hex The hexadecimal string representation to convert - * @return void - * @throws UnsatisfiedDependencyException - */ - public function fromHex($hex) - { - throw new UnsatisfiedDependencyException( - 'Cannot call ' . __METHOD__ . ' without support for large ' - . 'integers, since integer is an unsigned ' - . '128-bit integer; Moontoast\Math\BigNumber is required.' - ); - } - - /** - * Throws an `UnsatisfiedDependencyException` - * - * @param mixed $integer An integer representation to convert - * @return void - * @throws UnsatisfiedDependencyException - */ - public function toHex($integer) - { - throw new UnsatisfiedDependencyException( - 'Cannot call ' . __METHOD__ . ' without support for large ' - . 'integers, since integer is an unsigned ' - . '128-bit integer; Moontoast\Math\BigNumber is required. ' - ); - } } diff --git a/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php new file mode 100644 index 000000000..c85bc3a71 --- /dev/null +++ b/vendor/ramsey/uuid/src/Converter/Number/GenericNumberConverter.php @@ -0,0 +1,62 @@ +<?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\Number; + +use Ramsey\Uuid\Converter\NumberConverterInterface; +use Ramsey\Uuid\Math\CalculatorInterface; +use Ramsey\Uuid\Type\Integer as IntegerObject; + +/** + * GenericNumberConverter uses the provided calculate to convert decimal + * numbers to and from hexadecimal values + * + * @psalm-immutable + */ +class GenericNumberConverter implements NumberConverterInterface +{ + /** + * @var CalculatorInterface + */ + private $calculator; + + public function __construct(CalculatorInterface $calculator) + { + $this->calculator = $calculator; + } + + /** + * @inheritDoc + * @psalm-pure + * @psalm-return numeric-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function fromHex(string $hex): string + { + return $this->calculator->fromBase($hex, 16)->toString(); + } + + /** + * @inheritDoc + * @psalm-pure + * @psalm-return non-empty-string + * @psalm-suppress MoreSpecificReturnType we know that the retrieved `string` is never empty + * @psalm-suppress LessSpecificReturnStatement we know that the retrieved `string` is never empty + */ + public function toHex(string $number): string + { + return $this->calculator->toBase(new IntegerObject($number), 16); + } +} |