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

UnrelocatedProcessMemoryByteReader::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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;
15
16
use PhpProfiler\Lib\Process\MemoryMap\ProcessModuleMemoryMapInterface;
17
18
final class UnrelocatedProcessMemoryByteReader implements ByteReaderInterface
19
{
20
    use ByteReaderDisableWriteAccessTrait;
21
22
    private ByteReaderInterface $byte_reader;
23
    private ProcessModuleMemoryMapInterface $module_memory_map;
24
25
    /**
26
     * UnrelocatedProcessMemoryByteReader constructor.
27
     * @param ByteReaderInterface $byte_reader
28
     * @param ProcessModuleMemoryMapInterface $module_memory_map
29
     */
30
    public function __construct(ByteReaderInterface $byte_reader, ProcessModuleMemoryMapInterface $module_memory_map)
31
    {
32
        $this->byte_reader = $byte_reader;
33
        $this->module_memory_map = $module_memory_map;
34
    }
35
36
    public function offsetExists($offset): bool
37
    {
38
        return isset($this->byte_reader[$this->module_memory_map->getMemoryAddressFromOffset($offset)]);
39
    }
40
41
    public function offsetGet($offset): int
42
    {
43
        return $this->byte_reader[$this->module_memory_map->getMemoryAddressFromOffset($offset)];
44
    }
45
46
    public function createSliceAsString(int $offset, int $size): string
47
    {
48
        return $this->byte_reader->createSliceAsString(
49
            $this->module_memory_map->getMemoryAddressFromOffset($offset),
50
            $size
51
        );
52
    }
53
}
54