for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of the sj-i/php-profiler package.
*
* (c) sji <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace PhpProfiler\Lib\File;
use FFI;
class NativeFileReader implements FileReaderInterface
{
/** @var FFI\Libc\libc_file_ffi */
private FFI $ffi;
public function __construct()
$this->ffi = FFI::cdef('
ffi
FFI\Libc\libc_file_ffi
int open(const char *pathname, int flags);
ssize_t read(int fd, void *buf, size_t count);
int close(int fd);
');
}
public function readAll(string $path): string
$buffer = $this->ffi->new("unsigned char[4096]");
$fd = $this->ffi->open($path, 0);
open()
FFI
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
/** @scrutinizer ignore-call */
$result = "";
$done = false;
do {
$read_len = $this->ffi->read($fd, $buffer, 4096);
read()
if ($read_len > 0) {
$result .= FFI::string($buffer, min($read_len, 4096));
} else {
$done = true;
} while (!$done);
$this->ffi->close($fd);
close()
$this->ffi->/** @scrutinizer ignore-call */
close($fd);
return $result;