1 | <?php |
||
13 | class Number extends Serializable |
||
14 | { |
||
15 | const MAX_NUM_SIZE = 4; |
||
16 | const MAX = 2**31-1; |
||
17 | const MIN = -2**31+1; |
||
18 | |||
19 | /** |
||
20 | * @var Math |
||
21 | */ |
||
22 | private $math; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | private $number; |
||
28 | |||
29 | /** |
||
30 | * Number constructor. |
||
31 | * @param int $number |
||
32 | * @param Math $math |
||
33 | */ |
||
34 | 3501 | public function __construct($number, Math $math) |
|
39 | |||
40 | /** |
||
41 | * @param int $number |
||
42 | * @param Math|null $math |
||
43 | * @return self |
||
44 | */ |
||
45 | 3230 | public static function int($number, Math $math = null) |
|
52 | |||
53 | /** |
||
54 | * @param \GMP $number |
||
55 | * @param Math|null $math |
||
56 | * @return self |
||
57 | */ |
||
58 | public static function gmp(\GMP $number, Math $math = null) |
||
65 | |||
66 | /** |
||
67 | * @param BufferInterface $vch |
||
68 | * @param bool $fRequireMinimal |
||
69 | * @param int $maxNumSize |
||
70 | * @param Math|null $math |
||
71 | * @return self |
||
72 | */ |
||
73 | 2694 | public static function buffer(BufferInterface $vch, $fRequireMinimal, $maxNumSize = self::MAX_NUM_SIZE, Math $math = null) |
|
95 | |||
96 | /** |
||
97 | * @param BufferInterface $buffer |
||
98 | * @return int |
||
99 | */ |
||
100 | 2510 | private function parseBuffer(BufferInterface $buffer) |
|
123 | |||
124 | /** |
||
125 | * @return BufferInterface |
||
126 | */ |
||
127 | 3378 | private function serialize() |
|
152 | |||
153 | /** |
||
154 | * @return BufferInterface |
||
155 | */ |
||
156 | 3378 | public function getBuffer(): BufferInterface |
|
160 | |||
161 | /** |
||
162 | * @return int |
||
163 | */ |
||
164 | 462 | public function getInt() |
|
174 | |||
175 | /** |
||
176 | * @return \GMP |
||
177 | */ |
||
178 | 948 | public function getGmp() |
|
182 | } |
||
183 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.