IsConcatenable::appendToDeepRelationship()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 21
rs 9.9
c 1
b 0
f 0
cc 4
nc 4
nop 4
1
<?php
2
3
namespace Staudenmeir\EloquentHasManyDeep\Eloquent\Relations\Traits;
4
5
use Illuminate\Database\Eloquent\Relations\Pivot;
6
7
trait IsConcatenable
8
{
9
    /**
10
     * Append the relation's through parents, foreign and local keys to a deep relationship.
11
     *
12
     * @param \Illuminate\Database\Eloquent\Model[] $through
13
     * @param array $foreignKeys
14
     * @param array $localKeys
15
     * @param int $position
16
     * @return array
17
     */
18
    public function appendToDeepRelationship(array $through, array $foreignKeys, array $localKeys, int $position): array
0 ignored issues
show
Unused Code introduced by
The parameter $position is not used and could be removed. ( Ignorable by Annotation )

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

18
    public function appendToDeepRelationship(array $through, array $foreignKeys, array $localKeys, /** @scrutinizer ignore-unused */ int $position): array

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
19
    {
20
        foreach ($this->throughParents as $throughParent) {
21
            $segments = explode(' as ', $throughParent->getTable());
22
23
            $class = get_class($throughParent);
24
25
            if (isset($segments[1])) {
26
                $class .= ' as '.$segments[1];
27
            } elseif ($throughParent instanceof Pivot) {
28
                $class = $throughParent->getTable();
29
            }
30
31
            $through[] = $class;
32
        }
33
34
        $foreignKeys = array_merge($foreignKeys, $this->foreignKeys);
35
36
        $localKeys = array_merge($localKeys, $this->localKeys);
37
38
        return [$through, $foreignKeys, $localKeys];
39
    }
40
}
41