IdentityMap::contains()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

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