UserFunctionDefinitionContext::isClosureOf()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
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\ReferenceContext;
15
16
use Reli\Lib\PhpProcessReader\PhpMemoryReader\MemoryLocation\ZendOpArrayHeaderMemoryLocation;
17
18
class UserFunctionDefinitionContext extends FunctionDefinitionContext
19
{
20
    public function __construct(
21
        public ZendOpArrayHeaderMemoryLocation $memory_location,
22
    ) {
23
    }
24
25
    public function getFunctionName(): string
26
    {
27
        return $this->memory_location->function_name;
28
    }
29
30
    public function getOpArrayAddress(): int
31
    {
32
        return $this->memory_location->address;
33
    }
34
35
    public function isClosureOf(UserFunctionDefinitionContext $context): bool
36
    {
37
        return $context->isThisContext(
38
            $this->memory_location->file,
39
            $this->memory_location->line_start,
40
        );
41
    }
42
43
    public function isThisContext(
44
        string $file,
45
        int $line,
46
    ): bool {
47
        if ($this->memory_location->file !== $file) {
48
            return false;
49
        }
50
        if ($this->memory_location->line_start > $line) {
51
            return false;
52
        }
53
        if ($this->memory_location->line_end < $line) {
54
            return false;
55
        }
56
        return true;
57
    }
58
59
    public function getContexts(): iterable
60
    {
61
        return ['#is_internal' => false];
62
    }
63
}
64