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

ArrayContextPool   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 14
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getContextForLocation() 0 9 2
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\ZendArrayMemoryLocation;
17
18
class ArrayContextPool
19
{
20
    /** @var array<int, ArrayHeaderContext> */
21
    private array $contexts = [];
22
23
    public function getContextForLocation(ZendArrayMemoryLocation $memory_location): ArrayHeaderContext
24
    {
25
        if (isset($this->contexts[$memory_location->address])) {
26
            return $this->contexts[$memory_location->address];
27
        }
28
29
        $context = new ArrayHeaderContext($memory_location);
30
        $this->contexts[$memory_location->address] = $context;
31
        return $context;
32
    }
33
}
34