Fuse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 25
c 2
b 0
f 0
dl 0
loc 61
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A main() 0 21 2
A load() 0 6 1
A getInstance() 0 6 2
1
<?php
2
3
/**
4
 * This file is part of the sj-i/php-fuse 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 Fuse;
15
16
use FFI;
17
use FFI\CData;
18
use Fuse\Libc\Fuse\FuseIoctlDataPointer;
19
20
final class Fuse
21
{
22
    private static ?self $instance;
23
    /** @var FuseFFI */
24
    public FFI $ffi;
25
26
    /**
27
     * @param FuseFFI $ffi
28
     */
29
    private function __construct(FFI $ffi)
30
    {
31
        $this->ffi = $ffi;
0 ignored issues
show
Documentation Bug introduced by
$ffi is of type FFI, but the property $ffi was declared to be of type Fuse\FuseFFI. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
32
    }
33
34
    /**
35
     * @return FuseFFI
36
     */
37
    private static function load(): FFI
38
    {
39
        /** @var FuseFFI */
40
        return FFI::cdef(
41
            file_get_contents(__DIR__ . '/Headers/fuse.h'),
42
            'libfuse.so'
43
        );
44
    }
45
46
    public static function getInstance(): self
47
    {
48
        if (!isset(self::$instance)) {
49
            self::$instance = new self(self::load());
50
        }
51
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type null which is incompatible with the type-hinted return Fuse\Fuse. Consider adding an additional type-check to rule them out.
Loading history...
52
    }
53
54
    /**
55
     * @param list<string> $args
0 ignored issues
show
Bug introduced by
The type Fuse\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
     * @param FuseOperations $fuse_operations
57
     * @param CData|null $user_data
58
     * @return int
59
     */
60
    public function main(array $args, FuseOperations $fuse_operations, ?CData $user_data = null): int
61
    {
62
        $argc = count($args);
63
        /** @var \FFI\CDataArray $argv_real */
64
        $argv_real = FFI::new('char *[' . count($args) . ']');
65
        foreach ($args as $key => $item) {
66
            $item_len = strlen($item);
67
            $item_len_nul = $item_len + 1;
68
            /** @var \FFI\CDataArray $argv_item */
69
            $argv_item = FFI::new("char[{$item_len_nul}]", false, true);
70
            FFI::memcpy($argv_item, $item, $item_len);
71
            $argv_item[$item_len] = "\0";
72
            $argv_real[$key] = $argv_item;
73
        }
74
75
        return Fuse::getInstance()->ffi->fuse_main_real(
0 ignored issues
show
introduced by
The method fuse_main_real() does not exist on FFI. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

75
        return Fuse::getInstance()->ffi->/** @scrutinizer ignore-call */ fuse_main_real(
Loading history...
76
            $argc,
77
            $argv_real,
78
            FFI::addr($fuse_operations->getCData()),
79
            $fuse_operations->getSize(),
80
            $user_data
81
        );
82
    }
83
}
84