Completed
Push — master ( e5c932...e18320 )
by Alex
02:04
created

AssociationStubPolymorphic::isCompatible()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 7.551
c 0
b 0
f 0
cc 7
eloc 14
nc 5
nop 1
1
<?php
2
3
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
4
5
class AssociationStubPolymorphic extends AssociationStubBase
6
{
7
    /**
8
     * @var string
9
     */
10
    private $morphType;
11
12
    /**
13
     * @return string
14
     */
15
    public function getMorphType()
16
    {
17
        return $this->morphType;
18
    }
19
20
    /**
21
     * @param string $morphType
22
     */
23
    public function setMorphType($morphType)
24
    {
25
        $this->morphType = $morphType;
26
    }
27
28
    /**
29
     * @param \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationStubBase $otherStub
30
     *
31
     * @return bool
32
     */
33
    public function isCompatible(AssociationStubBase $otherStub)
34
    {
35
        if (!parent::isCompatible($otherStub)) {
36
            return false;
37
        }
38
        $thisTarg = $this->getTargType();
39
        $thatTarg = $otherStub->getTargType();
40
        $thisNull = null === $thisTarg;
41
        $thatNull = null === $thatTarg;
42
        if ($thisNull == $thatNull) {
43
            return false;
44
        }
45
        if ($thisNull && ($thatTarg != $this->getBaseType())) {
46
            return false;
47
        }
48
        if ($thatNull && ($thisTarg != $otherStub->getBaseType())) {
49
            return false;
50
        }
51
52
        return true;
53
    }
54
55
    public function isKnownSide()
56
    {
57
        assert($this->isOk(), 'Polymorphic stub not OK so known-side determination is meaningless');
58
        return null === $this->targType;
59
    }
60
}
61