UInt64   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A checkBitSet() 0 4 1
A __toString() 0 5 1
A toInt() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-profiler package.
5
 *
6
 * (c) sji <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpProfiler\Lib\Integer;
15
16
final class UInt64
17
{
18
    public function __construct(
19
        public int $hi,
20
        public int $lo
21
    ) {
22
    }
23
24
    public function __toString()
25
    {
26
        $hi_hex = str_pad(base_convert((string)$this->hi, 10, 16), 8, '0', STR_PAD_LEFT);
27
        $lo_hex = str_pad(base_convert((string)$this->lo, 10, 16), 8, '0', STR_PAD_LEFT);
28
        return base_convert($hi_hex . $lo_hex, 16, 10);
29
    }
30
31
    /**
32
     * do the wrong thing
33
     */
34
    public function toInt(): int
35
    {
36
        return (int)(string)$this;
37
    }
38
39
    public function checkBitSet(int $bit_pos): bool
40
    {
41
        $binary = str_pad(base_convert((string)$this, 10, 2), 64, '0', STR_PAD_LEFT);
42
        return (bool)strrev($binary)[$bit_pos];
43
    }
44
}
45