Pointer::getCTypeName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\Process\Pointer;
15
16
use FFI\CData;
17
use FFI\CInteger;
18
use FFI\CPointer;
19
use FFI\CType;
20
use PhpProfiler\Lib\PhpInternals\CastedCData;
21
22
/**
23
 * @template T of \PhpProfiler\Lib\Process\Pointer\Dereferencable
24
 */
25
class Pointer
26
{
27
    /** @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...
28
    public function __construct(
29
        public string $type,
30
        public int $address,
31
        public int $size,
32
    ) {
33
    }
34
35
    public function indexedAt(int $n): Pointer
36
    {
37
        return new Pointer(
38
            $this->type,
39
            $this->address + $n * $this->size,
40
            $this->size,
41
        );
42
    }
43
44
    public function getCTypeName(): string
45
    {
46
        return $this->type::getCTypeName();
47
    }
48
49
    /**
50
     * @param CastedCData<CData> $casted_cdata
51
     * @param Pointer<T> $pointer
52
     * @return T
0 ignored issues
show
Bug introduced by
The type PhpProfiler\Lib\Process\Pointer\T 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...
53
     */
54
    public function fromCastedCData(
55
        CastedCData $casted_cdata,
56
        Pointer $pointer
57
    ): mixed {
58
        return $this->type::fromCastedCData($casted_cdata, $pointer);
59
    }
60
61
    /**
62
     * @template TType of \PhpProfiler\Lib\Process\Pointer\Dereferencable
63
     * @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...
64
     * @param CPointer $c_pointer
65
     * @return Pointer<TType>
66
     */
67
    public static function fromCData(
68
        string $type,
69
        CData $c_pointer,
70
    ): self {
71
        /** @var CInteger $addr */
72
        $addr = \FFI::cast('long', $c_pointer);
73
        /**
74
         * @psalm-suppress InaccessibleMethod
75
         * @var CData $element
76
         */
77
        $element = $c_pointer[0];
78
        /** @param CType $ctype */
79
        $ctype = \FFI::typeof($element);
80
        return new self(
81
            $type,
82
            $addr->cdata,
83
            \FFI::sizeof($ctype),
84
        );
85
    }
86
}
87