IdentityMap::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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