Completed
Push — master ( 6ddd2c...f7ea80 )
by Anton
01:48
created

src/Parser/SingularNode.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Spiral, Core Components
4
 *
5
 * @author Wolfy-J
6
 */
7
declare(strict_types=1);
8
9
namespace Cycle\ORM\Parser;
10
11
use Cycle\ORM\Exception\ParserException;
12
13
/**
14
 * Node with ability to push it's data into referenced tree location.
15
 */
16
final class SingularNode extends AbstractNode
17
{
18
    /** @var string */
19
    protected $innerKey;
20
21
    /**
22
     * @param array       $columns
23
     * @param string      $primaryKey
24
     * @param string      $innerKey Inner relation key (for example user_id)
25
     * @param string|null $outerKey Outer (parent) relation key (for example id = parent.id)
26
     */
27
    public function __construct(array $columns, string $primaryKey, string $innerKey, string $outerKey)
28
    {
29
        parent::__construct($columns, $outerKey);
30
        $this->setDuplicateCriteria($primaryKey);
31
32
        $this->innerKey = $innerKey;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function push(array &$data)
39
    {
40
        if (empty($this->parent)) {
41
            throw new ParserException("Unable to register data tree, parent is missing");
42
        }
43
44
        if (is_null($data[$this->innerKey])) {
45
            //No data was loaded
46
            return;
47
        }
48
49
        $this->parent->mount(
50
            $this->container,
51
            $this->outerKey,
0 ignored issues
show
It seems like $this->outerKey can also be of type null; however, parameter $key of Cycle\ORM\Parser\AbstractNode::mount() does only seem to accept string, 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

51
            /** @scrutinizer ignore-type */ $this->outerKey,
Loading history...
52
            $data[$this->innerKey],
53
            $data
54
        );
55
    }
56
}