Passed
Push — 2.0 ( 6dfe09...fea9f0 )
by Sébastien
05:30
created

LocalHashTableRelationInfo   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
c 0
b 0
f 0
dl 0
loc 37
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A clear() 0 3 1
A __construct() 0 3 1
A markAsLoaded() 0 3 1
A isLoaded() 0 3 1
1
<?php
2
3
namespace Bdf\Prime\Relations\Info;
4
5
/**
6
 * Store loading information into an array, using WeakMap for identify entities
7
 */
8
final class LocalHashTableRelationInfo implements RelationInfoInterface
9
{
10
    /**
11
     * Store loaded state of entities relations
12
     * Use the entity object as key, and boolean as value
13
     *
14
     * @var \WeakMap<object, bool>
15
     */
16
    private $loaded;
17
18 265
    public function __construct()
19
    {
20 265
        $this->loaded = new \WeakMap();
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 176
    public function isLoaded($entity): bool
27
    {
28 176
        return !empty($this->loaded[$entity]);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 10
    public function clear($entity): void
35
    {
36 10
        unset($this->loaded[$entity]);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 232
    public function markAsLoaded($entity): void
43
    {
44 232
        $this->loaded[$entity] = true;
45
    }
46
}
47