Issues (372)

example/dummy_file.php (14 issues)

1
<?php
2
3
include __DIR__ . "/../vendor/autoload.php";
4
5
use FFI\CData;
6
use Fuse\Fuse;
7
use Fuse\FuseOperations;
8
use Fuse\Libc\Errno\Errno;
9
use Fuse\Libc\Sys\Stat\Stat;
10
use Fuse\Mounter;
11
12
const FILE_PATH = '/example';
13
const FILE_NAME = 'example';
14
const FILE_CONTENT = 'hello FUSE from PHP' . PHP_EOL;
15
16
function getattr_cb(string $path, \FFI\CData $stbuf): int
17
{
18
    $typename = 'struct stat';
19
    $type = Fuse::getInstance()->ffi->type(
20
        $typename
21
    );
22
    $size = FFI::sizeof(
23
        $type
24
    );
25
    echo "attr read {$path}" . PHP_EOL;
26
27
    FFI::memset($stbuf, 0, $size);
28
    if ($path === '/') {
29
        $stbuf->st_mode = Stat::S_IFDIR | 0755;
0 ignored issues
show
The property st_mode does not seem to exist on FFI\CData.
Loading history...
30
        $stbuf->st_nlink = 2;
0 ignored issues
show
The property st_nlink does not seem to exist on FFI\CData.
Loading history...
31
        $stbuf->st_uid = getmyuid();
0 ignored issues
show
The property st_uid does not seem to exist on FFI\CData.
Loading history...
32
        $stbuf->st_gid = getmygid();
0 ignored issues
show
The property st_gid does not seem to exist on FFI\CData.
Loading history...
33
        return 0;
34
    }
35
36
    if ($path === FILE_PATH) {
37
        $stbuf->st_mode = Stat::S_IFREG | 0777;
38
        $stbuf->st_nlink = 1;
39
        $stbuf->st_size = strlen(FILE_CONTENT);
0 ignored issues
show
The property st_size does not seem to exist on FFI\CData.
Loading history...
40
        $stbuf->st_uid = getmyuid();
41
        $stbuf->st_gid = getmygid();
42
        return 0;
43
    }
44
45
    return -Errno::ENOENT;
46
}
47
48
function readdir_cb(string $path, CData $buf, CData $filler, int $offset, CData $fi): int
0 ignored issues
show
The parameter $fi is not used and could be removed. ( Ignorable by Annotation )

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

48
function readdir_cb(string $path, CData $buf, CData $filler, int $offset, /** @scrutinizer ignore-unused */ CData $fi): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $path is not used and could be removed. ( Ignorable by Annotation )

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

48
function readdir_cb(/** @scrutinizer ignore-unused */ string $path, CData $buf, CData $filler, int $offset, CData $fi): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $offset is not used and could be removed. ( Ignorable by Annotation )

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

48
function readdir_cb(string $path, CData $buf, CData $filler, /** @scrutinizer ignore-unused */ int $offset, CData $fi): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
{
50
    $filler($buf, '.', null, 0);
51
    $filler($buf, '..', null, 0);
52
    $filler($buf, FILE_NAME, null, 0);
53
54
    return 0;
55
}
56
57
function open_cb(string $path, CData $fi): int
0 ignored issues
show
The parameter $fi is not used and could be removed. ( Ignorable by Annotation )

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

57
function open_cb(string $path, /** @scrutinizer ignore-unused */ CData $fi): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
{
59
    if ($path !== FILE_PATH) {
60
        return -Errno::ENOENT;
61
    }
62
63
    echo "open {$path}" . PHP_EOL;
64
    return 0;
65
}
66
67
function read_cb(string $path, CData $buf, int $size, int $offset, CData $fi): int
0 ignored issues
show
The parameter $fi is not used and could be removed. ( Ignorable by Annotation )

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

67
function read_cb(string $path, CData $buf, int $size, int $offset, /** @scrutinizer ignore-unused */ CData $fi): int

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
{
69
    echo "read {$path}" . PHP_EOL;
70
71
    $len = strlen(FILE_CONTENT);
72
73
    if ($offset + $size > $len) {
74
        $size = ($len - $offset);
75
    }
76
77
    $content = substr(FILE_CONTENT, $offset, $size);
78
    FFI::memcpy($buf, $content, $size);
79
80
    return $size;
81
}
82
83
$fuse_operations = new FuseOperations();
84
$fuse_operations->getattr = 'getattr_cb';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'getattr_cb' of type string is incompatible with the declared type Fuse\getattr_op|Fuse\getattr_typed_op|null of property $getattr.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
85
$fuse_operations->open = 'open_cb';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'open_cb' of type string is incompatible with the declared type Fuse\open_op|Fuse\open_typed_op|null of property $open.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
86
$fuse_operations->read = 'read_cb';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'read_cb' of type string is incompatible with the declared type Fuse\read_op|Fuse\read_typed_op|null of property $read.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
87
$fuse_operations->readdir = 'readdir_cb';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'readdir_cb' of type string is incompatible with the declared type Fuse\readdir_op|Fuse\readdir_typed_op|null of property $readdir.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
88
89
$mounter = new Mounter();
90
return $mounter->mount('/tmp/example/', $fuse_operations);
91