diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ab837b..0eab021 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +* Removed baseConvert() * Made PHP8.1 minimum version * Refactored package file structure diff --git a/README.md b/README.md index defc0b4..dab0e28 100644 --- a/README.md +++ b/README.md @@ -91,10 +91,6 @@ echo Dictum::numericToAlpha(23345452); echo Dictum::alphaToNumeric('aybfra') // 23345452 -echo Dictum::baseConvert(23345452, 10, 36); -// 4J4RS - - echo Dictum::toBoolean('yes') ? 'true' : 'false'; // true ``` diff --git a/composer.json b/composer.json index 3ff6764..c71f95a 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "extra": { "branch-alias": { - "dev-develop": "0.5.x-dev" + "dev-develop": "0.6.x-dev" } } } diff --git a/src/Context.php b/src/Context.php index 9a54ea1..9df49b7 100644 --- a/src/Context.php +++ b/src/Context.php @@ -13,7 +13,6 @@ use DecodeLabs\Dictum\Plugins\Number as NumberPlugin; use DecodeLabs\Dictum\Plugins\Time as TimePlugin; -use DecodeLabs\Exceptional; use DecodeLabs\Veneer; use DecodeLabs\Veneer\LazyLoad; @@ -520,96 +519,6 @@ public function alphaToNumeric( return $text->alphaToNumeric(); } - /** - * Convert between any base from 2 to 62 - * - * @phpstan-return ($input is null ? null : string) - */ - public function baseConvert( - string|Stringable|int|float|null $input, - int $fromBase, - int $toBase, - int $pad = 1 - ): ?string { - if ($input === null) { - return null; - } - - if ( - $fromBase < 2 || - $fromBase > 62 || - $toBase < 2 || - $toBase > 62 - ) { - throw Exceptional::Overflow('Base must be between 2 and 62'); - } - - if (!is_string($input)) { - $input = sprintf('%0.0F', $input); - } - - - if (extension_loaded('gmp')) { - $output = gmp_strval(gmp_init($input, $fromBase), $toBase); - - if ($pad > 1) { - $output = str_pad($output, $pad, '0', STR_PAD_LEFT); - } - - return $output; - } - - - $digitChars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; - $inDigits = []; - $outChars = ''; - - $input = strtolower($input); - $length = strlen($input); - - - for ($i = 0; $i < $length; $i++) { - $digit = ord($input[$i]) - 48; - - if ($digit > 9) { - $digit -= 39; - } - - if ($digit > $fromBase) { - throw Exceptional::Overflow('Digit as exceeded base: ' . $fromBase); - } - - $inDigits[] = $digit; - } - - - while (!empty($inDigits)) { - $work = 0; - $workDigits = []; - - foreach ($inDigits as $digit) { - $work *= $fromBase; - $work += $digit; - - - if ($work < $toBase) { - if (!empty($workDigits)) { - $workDigits[] = 0; - } - } else { - $workDigits[] = (int)($work / $toBase); - $work %= $toBase; - } - } - - $outChars = $digitChars[$work] . $outChars; - $inDigits = $workDigits; - } - - return str_pad($outChars, $pad, '0', STR_PAD_LEFT); - } - - /** diff --git a/src/Text.php b/src/Text.php index 75ca995..fd6b051 100644 --- a/src/Text.php +++ b/src/Text.php @@ -1317,6 +1317,7 @@ public function scanMatches( break; } + /** @phpstan-ignore-next-line */ if (false === ($result = mb_ereg_search_getregs())) { throw Exceptional::InvalidArgument('Unable to complete mb regex with: ' . $pattern); } diff --git a/stubs/DecodeLabs/Dictum.php b/stubs/DecodeLabs/Dictum.php index d663393..27965fc 100644 --- a/stubs/DecodeLabs/Dictum.php +++ b/stubs/DecodeLabs/Dictum.php @@ -81,9 +81,6 @@ public static function numericToAlpha(?int $number, ?string $encoding = NULL): ? public static function alphaToNumeric(Ref0|string|int|float|null $text, ?string $encoding = NULL): ?int { return static::$instance->alphaToNumeric(...func_get_args()); } - public static function baseConvert(Ref0|string|int|float|null $input, int $fromBase, int $toBase, int $pad = 1): ?string { - return static::$instance->baseConvert(...func_get_args()); - } public static function toBoolean(Ref0|string|int|float|null $text, ?string $encoding = NULL): bool { return static::$instance->toBoolean(...func_get_args()); }