Conditions | 2 |
Paths | 2 |
Total Lines | 14 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 2 |
Changes | 0 |
1 | <?php |
||
16 | 21 | public static function convertEndianness(int $number): int |
|
17 | { |
||
18 | 21 | if ($number > 65535) { |
|
19 | 1 | throw new \OutOfRangeException('This is an INT16 conversion, so the maximum is 65535'); |
|
20 | } |
||
21 | |||
22 | 20 | $finalNumber = hexdec( |
|
23 | // Invert first byte and make it a complete hexadecimal number |
||
24 | 20 | str_pad(dechex($number & 255), 2, '0', STR_PAD_LEFT) . |
|
25 | // Invert second byte and make a complete hexadecimal number |
||
26 | 20 | str_pad(dechex($number >> 8), 2, '0', STR_PAD_LEFT) |
|
27 | ); |
||
28 | |||
29 | 20 | return (int)$finalNumber; |
|
30 | } |
||
60 |