Passed
Pull Request — master (#7)
by Shinji
12:52
created

LittleEndianReader::read64()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\ByteStream\IntegerByteSequence;
15
16
use PhpProfiler\Lib\ByteStream\ByteReaderInterface;
17
use PhpProfiler\Lib\Integer\UInt64;
18
19
/**
20
 * Class LittleEndianReader
21
 * @package PhpProfiler\Lib\Binary
22
 */
23
final class LittleEndianReader implements IntegerByteSequenceReader
24
{
25
    public function read8(ByteReaderInterface $data, int $offset): int
26
    {
27
        return $data[$offset];
28
    }
29
30
    public function read16(ByteReaderInterface $data, int $offset): int
31
    {
32
        return ($data[$offset + 1] << 8) | $data[$offset];
33
    }
34
35
    public function read32(ByteReaderInterface $data, int $offset): int
36
    {
37
        return ($data[$offset + 3] << 24)
38
            | ($data[$offset + 2] << 16)
39
            | ($data[$offset + 1] << 8)
40
            | $data[$offset];
41
    }
42
43
    public function read64(ByteReaderInterface $data, int $offset): UInt64
44
    {
45
        return new UInt64(
46
            $this->read32($data, $offset + 4),
47
            $this->read32($data, $offset),
48
        );
49
    }
50
}
51