Completed
Push — master ( 9f13d4...a886ae )
by Alex
38:38 queued 38:36
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
2
3
declare(strict_types=1);
4
5
namespace AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations;
6
7
use POData\Common\InvalidOperationException;
8
9
class AssociationStubPolymorphic extends AssociationStubBase
10
{
11
    /**
12
     * @var string
13
     */
14
    private $morphType;
15
16
    /**
17
     * @return string
18
     */
19
    public function getMorphType(): ?string
20
    {
21
        return $this->morphType;
22
    }
23
24
    /**
25
     * @param string $morphType
26
     */
27
    public function setMorphType(string $morphType): void
28
    {
29
        $this->morphType = $morphType;
30
    }
31
32
    /**
33
     * @param \AlgoWeb\PODataLaravel\Models\ObjectMap\Entities\Associations\AssociationStubBase $otherStub
34
     *
35
     * @return bool
36
     */
37
    public function isCompatible(AssociationStubBase $otherStub): bool
38
    {
39
        if (!parent::isCompatible($otherStub)) {
40
            return false;
41
        }
42
43
        if (null === $this->getTargType() && null === $otherStub->getTargType()) {
44
            return false;
45
        }
46
47
        $thisBase = $this->getBaseType();
48
        $thatBase = $otherStub->getBaseType();
49
        $thatTarg = $otherStub->getTargType() ?? $thisBase;
50
        $thisTarg = $this->getTargType() ?? $thatBase;
51
        if ($thatTarg != $thisBase) {
52
            return false;
53
        }
54
        if ($thisTarg != $thatBase) {
55
            return false;
56
        }
57
58
        return true;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function morphicType(): string
65
    {
66
        return 'polymorphic';
67
    }
68
}
69