ZendExecutorGlobals::fromCastedCData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
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 2
dl 0
loc 6
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\PhpInternals\Types\Zend;
15
16
use FFI\PhpInternals\zend_executor_globals;
17
use PhpProfiler\Lib\PhpInternals\CastedCData;
18
use PhpProfiler\Lib\Process\Pointer\Dereferencable;
19
use PhpProfiler\Lib\Process\Pointer\Pointer;
20
21
final class ZendExecutorGlobals implements Dereferencable
22
{
23
    /** @var Pointer<ZendExecuteData>|null */
24
    public ?Pointer $current_execute_data;
25
26
    /** @param CastedCData<zend_executor_globals> $casted_cdata */
27
    public function __construct(
28
        private CastedCData $casted_cdata,
29
    ) {
30
        unset($this->current_execute_data);
31
    }
32
33
    public function __get(string $field_name): mixed
34
    {
35
        return match ($field_name) {
36
            'current_execute_data' => $this->casted_cdata->casted->current_execute_data !== null
37
                ? Pointer::fromCData(
38
                    ZendExecuteData::class,
39
                    $this->casted_cdata->casted->current_execute_data,
40
                )
41
                : null
42
            ,
43
        };
44
    }
45
46
    public static function getCTypeName(): string
47
    {
48
        return 'zend_executor_globals';
49
    }
50
51
    public static function fromCastedCData(
52
        CastedCData $casted_cdata,
53
        Pointer $pointer
54
    ): static {
55
        /** @var CastedCData<zend_executor_globals> $casted_cdata */
56
        return new self($casted_cdata);
57
    }
58
}
59