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\File; |
||||||
15 | |||||||
16 | use FFI; |
||||||
17 | use PhpProfiler\Lib\FFI\CannotAllocateBufferException; |
||||||
18 | |||||||
19 | class NativeFileReader implements FileReaderInterface |
||||||
20 | { |
||||||
21 | /** @var FFI\Libc\libc_file_ffi */ |
||||||
22 | private FFI $ffi; |
||||||
23 | |||||||
24 | public function __construct() |
||||||
25 | { |
||||||
26 | /** @var FFI\Libc\libc_file_ffi */ |
||||||
27 | $this->ffi = FFI::cdef(' |
||||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
28 | int open(const char *pathname, int flags); |
||||||
29 | ssize_t read(int fd, void *buf, size_t count); |
||||||
30 | int close(int fd); |
||||||
31 | '); |
||||||
32 | } |
||||||
33 | |||||||
34 | public function readAll(string $path): string |
||||||
35 | { |
||||||
36 | $buffer = $this->ffi->new("unsigned char[4096]") |
||||||
37 | ?? throw new CannotAllocateBufferException('cannot allocate buffer'); |
||||||
38 | |||||||
39 | $fd = $this->ffi->open($path, 0); |
||||||
0 ignored issues
–
show
The method
open() does not exist on FFI . It seems like you code against a sub-type of FFI such as FFI\Libc\libc_file_ffi .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
40 | $result = ""; |
||||||
41 | $done = false; |
||||||
42 | do { |
||||||
43 | $read_len = $this->ffi->read($fd, $buffer, 4096); |
||||||
0 ignored issues
–
show
The method
read() does not exist on FFI . It seems like you code against a sub-type of FFI such as FFI\Libc\libc_file_ffi .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
44 | if ($read_len > 0) { |
||||||
45 | $result .= FFI::string($buffer, min($read_len, 4096)); |
||||||
46 | } else { |
||||||
47 | $done = true; |
||||||
48 | } |
||||||
49 | } while (!$done); |
||||||
50 | $this->ffi->close($fd); |
||||||
0 ignored issues
–
show
The method
close() does not exist on FFI . It seems like you code against a sub-type of FFI such as FFI\Libc\libc_file_ffi .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
51 | |||||||
52 | return $result; |
||||||
53 | } |
||||||
54 | } |
||||||
55 |