ZendExecuteData   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 23 4
A __construct() 0 6 1
A fromCastedCData() 0 6 1
A getCTypeName() 0 3 1
A getFunctionName() 0 7 2
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\PhpInternals\Types\Zend;
15
16
use FFI\PhpInternals\zend_execute_data;
17
use PhpProfiler\Lib\PhpInternals\CastedCData;
18
use PhpProfiler\Lib\Process\Pointer\Dereferencable;
19
use PhpProfiler\Lib\Process\Pointer\Dereferencer;
20
use PhpProfiler\Lib\Process\Pointer\Pointer;
21
22
final class ZendExecuteData implements Dereferencable
23
{
24
    /** @var Pointer<ZendFunction>|null */
25
    public ?Pointer $func;
26
27
    /** @var Pointer<ZendExecuteData>|null */
28
    public ?Pointer $prev_execute_data;
29
30
    /** @var Pointer<ZendOp>|null */
31
    public ?Pointer $opline;
32
33
    /** @param CastedCData<zend_execute_data> $casted_cdata */
34
    public function __construct(
35
        private CastedCData $casted_cdata,
36
    ) {
37
        unset($this->func);
38
        unset($this->prev_execute_data);
39
        unset($this->opline);
40
    }
41
42
    public function __get(string $field_name): mixed
43
    {
44
        return match ($field_name) {
45
            'func' => $this->casted_cdata->casted->func !== null
46
                ? Pointer::fromCData(
47
                    ZendFunction::class,
48
                    $this->casted_cdata->casted->func,
49
                )
50
                : null
51
            ,
52
            'prev_execute_data' => $this->casted_cdata->casted->prev_execute_data !== null
53
                ? Pointer::fromCData(
54
                    ZendExecuteData::class,
55
                    $this->casted_cdata->casted->prev_execute_data,
56
                )
57
                : null
58
            ,
59
            'opline' => $this->casted_cdata->casted->opline !== null
60
                ? Pointer::fromCData(
61
                    ZendOp::class,
62
                    $this->casted_cdata->casted->opline
63
                )
64
                : null
65
            ,
66
        };
67
    }
68
69
    public static function getCTypeName(): string
70
    {
71
        return 'zend_execute_data';
72
    }
73
74
    public static function fromCastedCData(
75
        CastedCData $casted_cdata,
76
        Pointer $pointer
77
    ): static {
78
        /** @var CastedCData<zend_execute_data> $casted_cdata */
79
        return new self($casted_cdata);
80
    }
81
82
    public function getFunctionName(Dereferencer $dereferencer): ?string
83
    {
84
        if (is_null($this->func)) {
85
            return null;
86
        }
87
        $func = $dereferencer->deref($this->func);
88
        return $func->getFullyQualifiedFunctionName($dereferencer);
89
    }
90
}
91