Passed
Pull Request — 0.9.x (#308)
by Shinji
02:11
created

ZendArgInfosMemoryLocation::fromZendOpArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 12
rs 9.9666
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\PhpProcessReader\PhpMemoryReader\MemoryLocation;
15
16
use Reli\Lib\PhpInternals\Types\Zend\ZendOpArray;
17
use Reli\Lib\PhpInternals\ZendTypeReader;
18
use Reli\Lib\Process\MemoryLocation;
19
20
class ZendArgInfosMemoryLocation extends MemoryLocation
21
{
22
    public static function fromZendOpArray(ZendOpArray $zend_op_array, ZendTypeReader $zend_type_reader): self
23
    {
24
        assert(!is_null($zend_op_array->arg_info));
25
        $begin = $zend_op_array->arg_info;
26
        $num = $zend_op_array->num_args;
27
        if ($zend_op_array->hasReturnType($zend_type_reader)) {
28
            $begin = $zend_op_array->arg_info->indexedAt(-1);
29
            $num++;
30
        }
31
        return new self(
32
            $begin->address,
33
            $num * $zend_type_reader->sizeOf('zend_arg_info'),
34
        );
35
    }
36
}
37