Completed
Push — master ( 0ba58c...dd341e )
by Gabriel
07:12
created

MorphMany::saveResult()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Nip\Records\Relations;
4
5
use Nip\Database\Query\AbstractQuery;
6
use Nip\Records\AbstractModels\Record;
7
8
/**
9
 * Class MorphMany
10
 * @package Nip\Records\Relations
11
 */
12
class MorphMany extends MorphOneOrMany
13
{
14
15
    /**
16
     * @param AbstractQuery $query
17
     */
18 1
    public function populateQuerySpecific(AbstractQuery $query)
19
    {
20 1
        $query->where($this->getMorphTypeField() . ' = ?', $this->getMorphValue());
0 ignored issues
show
Documentation introduced by
$this->getMorphValue() is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
21
22 1
        $pk = $this->getManager()->getPrimaryKey();
23 1
        $query->where('`' . $this->getFK() . '` = ?', $this->getItem()->{$pk});
24 1
    }
25
26
    /** @noinspection PhpMissingParentCallCommonInspection
27
     * @inheritdoc
28
     */
29 1
    public function populateEagerQueryFromFkList($query, $fkList)
30
    {
31 1
        $value = $this->hasManager() ? $this->getMorphValue() : '';
32 1
        $query->where($this->getMorphTypeField() . ' = ?', $value);
33 1
        return parent::populateEagerQueryFromFkList($query, $fkList);
34
    }
35
36
    /**
37
     * @param Record $item
38
     */
39 1
    public function saveResult(Record $item)
40
    {
41 1
        $value = $this->hasManager() ? $this->getMorphValue() : '';
42 1
        $item->{$this->getMorphTypeField()} = $value;
43 1
        return parent::saveResult($item);
44
    }
45
}
46