IdentityMap::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
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