Passed
Push — 0.9.x ( c89eaa...a1c1c3 )
by Shinji
03:11 queued 01:36
created

Pointer::fromCastedCData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the reliforp/reli-prof 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 Reli\Lib\Process\Pointer;
15
16
use FFI\CData;
17
use FFI\CInteger;
18
use FFI\CPointer;
19
20
/**
21
 * @template T of \Reli\Lib\Process\Pointer\Dereferencable
22
 */
23
class Pointer
24
{
25
    /** @param class-string<T> $type */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<T> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<T>.
Loading history...
26
    public function __construct(
27
        public string $type,
28
        public int $address,
29
        public int $size,
30
    ) {
31
    }
32
33
    public function indexedAt(int $n): Pointer
34
    {
35
        return new Pointer(
36
            $this->type,
37
            $this->address + $n * $this->size,
38
            $this->size,
39
        );
40
    }
41
42
    public function getCTypeNameOfType(): string
43
    {
44
        return $this->type::getCTypeName();
45
    }
46
47
    /**
48
     * @template TType of \Reli\Lib\Process\Pointer\Dereferencable
49
     * @param class-string<TType> $type
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<TType> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<TType>.
Loading history...
50
     * @param CPointer $c_pointer
51
     * @return Pointer<TType>
52
     */
53
    public static function fromCData(
54
        string $type,
55
        CData $c_pointer,
56
    ): self {
57
        /** @var CInteger $addr */
58
        $addr = \FFI::cast('long', $c_pointer);
59
        $ctype = \FFI::typeof($c_pointer)->getPointerType();
0 ignored issues
show
Bug introduced by
The method getPointerType() does not exist on FFI\CType. ( Ignorable by Annotation )

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

59
        $ctype = \FFI::typeof($c_pointer)->/** @scrutinizer ignore-call */ getPointerType();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
60
        return new self(
61
            $type,
62
            $addr->cdata,
63
            \FFI::sizeof($ctype),
64
        );
65
    }
66
}
67