| Total Complexity | 7 |
| Total Lines | 69 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class BigInt |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Number. |
||
| 14 | * |
||
| 15 | * @var \GMP |
||
| 16 | */ |
||
| 17 | protected $_num; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Constructor. |
||
| 21 | * |
||
| 22 | * @param \GMP $num GMP number |
||
| 23 | */ |
||
| 24 | 49 | protected function __construct(\GMP $num) |
|
| 27 | 49 | } |
|
| 28 | |||
| 29 | 2 | public function __toString(): string |
|
| 30 | { |
||
| 31 | 2 | return $this->base10(); |
|
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Initialize from a base10 number. |
||
| 36 | * |
||
| 37 | * @param int|string $number |
||
| 38 | */ |
||
| 39 | 18 | public static function fromBase10($number): self |
|
| 40 | { |
||
| 41 | 18 | $num = gmp_init($number, 10); |
|
| 42 | 18 | return new self($num); |
|
|
|
|||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Initialize from a base256 number. |
||
| 47 | * |
||
| 48 | * Base64 number is an octet string of big endian, most significant word |
||
| 49 | * first integer. |
||
| 50 | */ |
||
| 51 | 33 | public static function fromBase256(string $octets): self |
|
| 52 | { |
||
| 53 | 33 | $num = gmp_import($octets, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN); |
|
| 54 | 33 | return new self($num); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Convert to base10 string. |
||
| 59 | */ |
||
| 60 | 34 | public function base10(): string |
|
| 61 | { |
||
| 62 | 34 | return gmp_strval($this->_num, 10); |
|
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Convert to base16 string. |
||
| 67 | */ |
||
| 68 | 1 | public function base16(): string |
|
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Convert to base256 string. |
||
| 75 | */ |
||
| 76 | 19 | public function base256(): string |
|
| 81 |