Passed
Push — master ( 9676b0...44a032 )
by Anton
02:07
created

src/Relation/BelongsTo.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Cycle DataMapper ORM
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
declare(strict_types=1);
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);
47
        $relNode = $this->getNode($related);
48
        $this->assertValid($relNode);
0 ignored issues
show
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