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

StringByteReader   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 3 1
A createSliceAsString() 0 3 1
A __construct() 0 3 1
A offsetExists() 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\ByteStream;
15
16
/**
17
 * Class StringByteReader
18
 * @package PhpProfiler\Lib\Binary
19
 */
20
final class StringByteReader implements ByteReaderInterface
21
{
22
    use ByteReaderDisableWriteAccessTrait;
23
24
    private string $source;
25
26
    public function __construct(string $source)
27
    {
28
        $this->source = $source;
29
    }
30
31
    public function offsetExists($offset): bool
32
    {
33
        return isset($this->source[$offset]);
34
    }
35
36
    public function offsetGet($offset): int
37
    {
38
        return ord($this->source[$offset]);
39
    }
40
41
    public function createSliceAsString(int $offset, int $size): string
42
    {
43
        return substr($this->source, $offset, $size);
44
    }
45
}
46