base_convert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of ocubom/base-convert
5
 *
6
 * © Oscar Cubo Medina <https://ocubom.github.io>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Ocubom\Math;
13
14
/**
15
 * Convert a number between arbitrary bases.
16
 *
17
 * Supports large arbitrary numbers by using a safe php implementation
18
 *
19
 * @see http://php.net/manual/en/function.base-convert.php
20
 * @see http://php.net/manual/en/function.base-convert.php#109660
21
 *
22
 * @param int|string               $number The number to convert
23
 * @param BaseInterface|int|string $source Original base for number
24
 * @param BaseInterface|int|string $target Desired base for number
25
 */
26
function base_convert($number, $source, $target): string
27
{
28 6593
    return Base::convert($number, $source, $target);
29
}
30
31
/**
32
 * Convert a number to crockford base32 encoding.
33
 *
34
 * @param int|string               $number   The number to convert
35
 * @param BaseInterface|int|string $base     The base of $number
36
 * @param bool                     $checksum Include a checksum
37
 */
38
function crockford_encode($number, $base, bool $checksum = false): string
39
{
40 16
    return Crockford::encode($number, $base, $checksum);
41
}
42
43
/**
44
 * Convert a number from crockford base32 encoding.
45
 *
46
 * @param int|string               $number   The crockford number to convert
47
 * @param BaseInterface|int|string $base     The base to convert $number
48
 * @param bool                     $checksum Includes $number a checksum?
49
 */
50
function crockford_decode($number, $base, bool $checksum = false): string
51
{
52 51
    return Crockford::decode($number, $base, $checksum);
53
}
54