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.
Passed
Branch php72 (880eb0)
by Joni
05:58
created

BigInt   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 11
dl 0
loc 84
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A base16() 0 3 1
A base10() 0 3 1
A __toString() 0 3 1
A fromBase10() 0 4 1
A fromBase256() 0 4 1
A __construct() 0 3 1
A base256() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\Util;
6
7
/**
8
 * Class for handling big integers.
9
 */
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)
25
    {
26 49
        $this->_num = $num;
27 49
    }
28
29
    /**
30
     * @return string
31
     */
32 2
    public function __toString(): string
33
    {
34 2
        return $this->base10();
35
    }
36
37
    /**
38
     * Initialize from a base10 number.
39
     *
40
     * @param int|string $number
41
     *
42
     * @return self
43
     */
44 18
    public static function fromBase10($number): self
45
    {
46 18
        $num = gmp_init($number, 10);
47 18
        return new self($num);
48
    }
49
50
    /**
51
     * Initialize from a base256 number.
52
     *
53
     * Base64 number is an octet string of big endian, most significant word
54
     * first integer.
55
     *
56
     * @param string $octets
57
     *
58
     * @return self
59
     */
60 33
    public static function fromBase256(string $octets): self
61
    {
62 33
        $num = gmp_import($octets, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
63 33
        return new self($num);
1 ignored issue
show
Bug introduced by
It seems like $num can also be of type false; however, parameter $num of Sop\JWX\Util\BigInt::__construct() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        return new self(/** @scrutinizer ignore-type */ $num);
Loading history...
64
    }
65
66
    /**
67
     * Convert to base10 string.
68
     *
69
     * @return string
70
     */
71 34
    public function base10(): string
72
    {
73 34
        return gmp_strval($this->_num, 10);
74
    }
75
76
    /**
77
     * Convert to base16 string.
78
     *
79
     * @return string
80
     */
81 1
    public function base16(): string
82
    {
83 1
        return gmp_strval($this->_num, 16);
84
    }
85
86
    /**
87
     * Convert to base256 string.
88
     *
89
     * @return string
90
     */
91 19
    public function base256(): string
92
    {
93 19
        return gmp_export($this->_num, 1, GMP_MSW_FIRST | GMP_BIG_ENDIAN);
94
    }
95
}
96