Passed
Push — renovate/php-8.x ( bfb893...222c0a )
by
unknown
02:20
created

ZendOpArray   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 9 2
A getFileName() 0 8 2
A __construct() 0 4 1
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\CData;
17
use FFI\PhpInternals\zend_op_array;
18
use PhpProfiler\Lib\Process\Pointer\Dereferencer;
19
use PhpProfiler\Lib\Process\Pointer\Pointer;
20
21
class ZendOpArray
22
{
23
    /**
24
     * @var Pointer<ZendString>|null
25
     * @psalm-suppress PropertyNotSetInConstructor
26
     */
27
    public ?Pointer $filename;
28
29
    /** @param zend_op_array $cdata */
30
    public function __construct(
31
        private CData $cdata,
32
    ) {
33
        unset($this->filename);
34
    }
35
36
    public function __get(string $field_name)
37
    {
38
        return match ($field_name) {
39
            'filename' => $this->filename = $this->cdata->filename !== null
40
                ? Pointer::fromCData(
41
                    ZendString::class,
42
                    $this->cdata->filename,
43
                )
44
                : null
45
            ,
46
        };
47
    }
48
49
    public function getFileName(Dereferencer $dereferencer): ?string
50
    {
51
        if (is_null($this->filename)) {
52
            return null;
53
        }
54
        $filename = $dereferencer->deref($this->filename);
55
        return (string)$dereferencer->deref(
56
            $filename->getValuePointer($this->filename)
57
        );
58
    }
59
}
60