GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 9bb5cc...d08348 )
by Joni
02:00
created

BigInt   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 105
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A base10() 0 4 1
A intVal() 0 14 4
A _intMaxGmp() 0 8 2
A _intMinGmp() 0 8 2
A gmpObj() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace ASN1\Util;
6
7
class BigInt
8
{
9
    /**
10
     * Number as a base10 integer string.
11
     *
12
     * @var string
13
     */
14
    private $_num;
15
    
16
    /**
17
     * Number as an integer type.
18
     *
19
     * @internal Lazily initialized
20
     * @var int|null
21
     */
22
    private $_intNum;
23
    
24
    /**
25
     * Constructor.
26
     *
27
     * @param string|int $num
28
     */
29 345
    public function __construct($num)
30
    {
31 345
        $this->_num = strval($num);
32 345
    }
33
    
34
    /**
35
     * Get the number as a base10 integer string.
36
     *
37
     * @return string
38
     */
39 208
    public function base10(): string
40
    {
41 208
        return $this->_num;
42
    }
43
    
44
    /**
45
     * Get the number as an integer.
46
     *
47
     * @throws \RuntimeException If number overflows integer size
48
     * @return int
49
     */
50 210
    public function intVal(): int
51
    {
52 210
        if (!isset($this->_intNum)) {
53 210
            $num = gmp_init($this->_num, 10);
54 210
            if (gmp_cmp($num, $this->_intMaxGmp()) > 0) {
55 4
                throw new \RuntimeException("Integer overflow.");
56
            }
57 206
            if (gmp_cmp($num, $this->_intMinGmp()) < 0) {
58 1
                throw new \RuntimeException("Integer underflow.");
59
            }
60 205
            $this->_intNum = gmp_intval($num);
61
        }
62 205
        return $this->_intNum;
63
    }
64
    
65
    /**
66
     * Get the maximum integer value.
67
     *
68
     * @return \GMP
69
     */
70 210
    private function _intMaxGmp(): \GMP
71
    {
72 210
        static $gmp;
73 210
        if (!isset($gmp)) {
74 1
            $gmp = gmp_init(PHP_INT_MAX, 10);
75
        }
76 210
        return $gmp;
77
    }
78
    
79
    /**
80
     * Get the minimum integer value.
81
     *
82
     * @return \GMP
83
     */
84 206
    private function _intMinGmp(): \GMP
85
    {
86 206
        static $gmp;
87 206
        if (!isset($gmp)) {
88 1
            $gmp = gmp_init(PHP_INT_MIN, 10);
89
        }
90 206
        return $gmp;
91
    }
92
    
93
    /**
94
     * Get the number as a GMP object.
95
     *
96
     * @return \GMP
97
     */
98 124
    public function gmpObj(): \GMP
99
    {
100 124
        return gmp_init($this->_num, 10);
101
    }
102
    
103
    /**
104
     *
105
     * @return string
106
     */
107 1
    public function __toString()
108
    {
109 1
        return $this->base10();
110
    }
111
}
112