Passed
Branch master (9f13d4)
by Alex
50:02 queued 44:57
created

AssociationStubPolymorphic::isCompatible()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 13
c 7
b 0
f 0
dl 0
loc 22
rs 9.2222
cc 6
nc 5
nop 1
1
<?php declare(strict_types=1);
2
3
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
4
5
use POData\Common\InvalidOperationException;
6
7
class AssociationStubPolymorphic extends AssociationStubBase
8
{
9
    /**
10
     * @var string
11
     */
12
    private $morphType;
13
14
    /**
15
     * @return string
16
     */
17
    public function getMorphType() : ?string
18
    {
19
        return $this->morphType;
20
    }
21
22
    /**
23
     * @param string $morphType
24
     */
25
    public function setMorphType(string $morphType) : void
26
    {
27
        $this->morphType = $morphType;
28
    }
29
30
    /**
31
     * @param \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationStubBase $otherStub
32
     *
33
     * @return bool
34
     */
35
    public function isCompatible(AssociationStubBase $otherStub) : bool
36
    {
37
        if (!parent::isCompatible($otherStub)) {
38
            return false;
39
        }
40
41
        if (null === $this->getTargType() && null === $otherStub->getTargType()) {
42
            return false;
43
        }
44
45
        $thisBase = $this->getBaseType();
46
        $thatBase = $otherStub->getBaseType();
47
        $thatTarg = $otherStub->getTargType() ?? $thisBase;
48
        $thisTarg = $this->getTargType() ?? $thatBase;
49
        if ($thatTarg != $thisBase) {
50
            return false;
51
        }
52
        if ($thisTarg != $thatBase) {
53
            return false;
54
        }
55
56
        return true;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function morphicType() : string
63
    {
64
        return 'polymorphic';
65
    }
66
}
67