Conditions | 8 |
Paths | 19 |
Total Lines | 31 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
28 | protected function getNode($entity, int $claim = 0): ?Node |
||
29 | { |
||
30 | if ($entity === null) { |
||
31 | return null; |
||
32 | } |
||
33 | |||
34 | if ($entity instanceof PromiseInterface && $entity->__loaded()) { |
||
35 | $entity = $entity->__resolve(); |
||
36 | } |
||
37 | |||
38 | if ($entity instanceof ReferenceInterface) { |
||
39 | return new Node(Node::PROMISED, $entity->__scope(), $entity->__role()); |
||
40 | } |
||
41 | |||
42 | $node = $this->orm->getHeap()->get($entity); |
||
43 | |||
44 | if ($node === null) { |
||
45 | // possibly rely on relation target role, it will allow context switch |
||
46 | $node = new Node(Node::NEW, [], $this->orm->getMapper($entity)->getRole()); |
||
47 | $this->orm->getHeap()->attach($entity, $node); |
||
48 | } |
||
49 | |||
50 | if ($claim === 1) { |
||
51 | $node->getState()->addClaim(); |
||
52 | } |
||
53 | |||
54 | if ($claim === -1) { |
||
55 | $node->getState()->decClaim(); |
||
56 | } |
||
57 | |||
58 | return $node; |
||
59 | } |
||
61 |