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

LocalHashTableRelationInfo::__construct()   A

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