Passed
Push — master ( a1e60a...ad8bf2 )
by Anton
02:58
created

BelongsTo::queue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 4
nop 5
dl 0
loc 23
rs 9.9
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
namespace Cycle\ORM\Relation;
11
12
use Cycle\ORM\Command\Branch\Nil;
13
use Cycle\ORM\Command\CommandInterface;
14
use Cycle\ORM\Command\ContextCarrierInterface as CC;
15
use Cycle\ORM\Exception\Relation\NullException;
16
use Cycle\ORM\Heap\Node;
17
use Cycle\ORM\Relation\Traits\PromiseOneTrait;
18
19
/**
20
 * Provides ability to link to the parent object. Will claim branch up to the parent object and it's relations. To disable
21
 * branch walk-though use RefersTo relation.
22
 */
23
class BelongsTo extends AbstractRelation implements DependencyInterface
24
{
25
    use PromiseOneTrait;
26
27
    /**
28
     * @inheritdoc
29
     */
30
    public function queue(CC $parentStore, $parentEntity, Node $parentNode, $related, $original): CommandInterface
31
    {
32
        if (is_null($related)) {
33
            if ($this->isRequired()) {
34
                throw new NullException("Relation {$this} can not be null");
35
            }
36
37
            if (!is_null($original)) {
38
                // reset the key
39
                $parentStore->register($this->innerKey, null, true);
40
            }
41
42
            // nothing to do
43
            return new Nil();
44
        }
45
46
        $relStore = $this->orm->queueStore($related);
0 ignored issues
show
Bug introduced by
The method queueStore() does not exist on Cycle\ORM\Select\SourceProviderInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Cycle\ORM\Select\SourceProviderInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        /** @scrutinizer ignore-call */ 
47
        $relStore = $this->orm->queueStore($related);
Loading history...
47
        $relNode = $this->getNode($related);
48
        $this->assertValid($relNode);
0 ignored issues
show
Bug introduced by
It seems like $relNode can also be of type null; however, parameter $relNode of Cycle\ORM\Relation\AbstractRelation::assertValid() does only seem to accept Cycle\ORM\Heap\Node, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        $this->assertValid(/** @scrutinizer ignore-type */ $relNode);
Loading history...
49
50
        $this->forwardContext($relNode, $this->outerKey, $parentStore, $parentNode, $this->innerKey);
51
52
        return $relStore;
53
    }
54
}
55