IdentityMap   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A set() 0 3 1
A contains() 0 11 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Behavioral;
6
7
use BasePatterns\LayerSupertype\DomainObject;
8
9
class IdentityMap
10
{
11
    private static array $data = [];
12
13 3
    public static function contains(int $id, string $className): bool
14
    {
15 3
        if (!\array_key_exists($className, self::$data)) {
16 1
            return false;
17
        }
18
19 2
        if (!\array_key_exists($id, self::$data[$className])) {
20 2
            return false;
21
        }
22
23 2
        return true;
24
    }
25
26 3
    public static function get(int $id, string $className): ?DomainObject
27
    {
28 3
        if (self::contains($id, $className)) {
29 2
            return self::$data[$className][$id];
30
        }
31
32 3
        return null;
33
    }
34
35 3
    public static function set(DomainObject $object): void
36
    {
37 3
        self::$data[get_class($object)][$object->getId()] = $object;
38 3
    }
39
}
40