Issues (188)

src/Parser/ArrayNode.php (2 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Parser;
6
7
use Cycle\ORM\Exception\ParserException;
8
9
/**
10
 * Parses multiple sub children and mount them under parent node.
11
 *
12
 * @internal
13
 */
14
final class ArrayNode extends AbstractNode
15
{
16
    /**
17
     * @param string[] $columns
18
     * @param string[] $primaryKeys
19
     * @param string[] $innerKeys Inner relation key (for example user_id)
20
     * @param string[]|null $outerKeys Outer (parent) relation key (for example id = parent.id)
21
     */
22 2062
    public function __construct(
23
        array $columns,
24
        array $primaryKeys,
25
        protected array $innerKeys,
26
        ?array $outerKeys,
27
    ) {
28 2062
        parent::__construct($columns, $outerKeys);
29 2062
        $this->setDuplicateCriteria($primaryKeys);
30
    }
31
32
    protected function push(array &$data): void
33
    {
34
        if ($this->parent === null) {
35 1918
            throw new ParserException('Unable to register data tree, parent is missing.');
36
        }
37 1918
38 2
        foreach ($this->innerKeys as $key) {
39
            if ($data[$key] === null) {
40
                // no data was parsed
41 1916
                return;
42 1916
            }
43
        }
44 98
45
        $this->parent->mountArray(
46
            $this->container,
0 ignored issues
show
It seems like $this->container can also be of type null; however, parameter $container of Cycle\ORM\Parser\AbstractNode::mountArray() 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

46
            /** @scrutinizer ignore-type */ $this->container,
Loading history...
47
            $this->indexName,
0 ignored issues
show
It seems like $this->indexName can also be of type null; however, parameter $index of Cycle\ORM\Parser\AbstractNode::mountArray() 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

47
            /** @scrutinizer ignore-type */ $this->indexName,
Loading history...
48 1916
            $this->intersectData($this->innerKeys, $data),
49 1916
            $data,
50 1916
        );
51 1916
    }
52
}
53