Issues (200)

src/Lib/ByteStream/CDataByteReader.php (1 issue)

Labels
Severity
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 FFI\CArray;
17
use FFI\CData;
18
19
use function chr;
20
use function count;
21
use function is_null;
22
23
final class CDataByteReader implements ByteReaderInterface
24
{
25
    use ByteReaderDisableWriteAccessTrait;
26
27
    /** @param CArray<int> $source */
28
    public function __construct(
29
        private CData $source
30
    ) {
31
    }
32
33
    public function offsetExists($offset): bool
34
    {
35
        if (count($this->source) <= $offset) {
0 ignored issues
show
$this->source of type FFI\CData is incompatible with the type Countable|array expected by parameter $value of count(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        if (count(/** @scrutinizer ignore-type */ $this->source) <= $offset) {
Loading history...
36
            return false;
37
        }
38
        return !is_null($this->source[$offset]);
39
    }
40
41
    public function offsetGet($offset): int
42
    {
43
        return $this->source[$offset];
44
    }
45
46
    public function createSliceAsString(int $offset, int $size): string
47
    {
48
        $result = '';
49
        for ($i = $offset, $last_offset = $offset + $size; $i < $last_offset; $i++) {
50
            $result .= chr($this->source[$i]);
51
        }
52
        return $result;
53
    }
54
}
55