Total Complexity | 17 |
Total Lines | 76 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
7 | class AssociationStubPolymorphic extends AssociationStubBase |
||
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | private $morphType; |
||
13 | |||
14 | /** |
||
15 | * @return string |
||
16 | */ |
||
17 | public function getMorphType() |
||
18 | { |
||
19 | return $this->morphType; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param string $morphType |
||
24 | */ |
||
25 | public function setMorphType($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) |
||
36 | { |
||
37 | if (!parent::isCompatible($otherStub)) { |
||
38 | return false; |
||
39 | } |
||
40 | $thisTarg = $this->getTargType(); |
||
41 | $thatTarg = $otherStub->getTargType(); |
||
42 | $thisNull = null === $thisTarg; |
||
43 | $thatNull = null === $thatTarg; |
||
44 | if ($thisNull == $thatNull && $thisNull) { |
||
45 | return false; |
||
46 | } |
||
47 | if ((!$thisNull && |
||
48 | !$thatNull) && |
||
49 | ($this->getBaseType() !== $otherStub->getTargType() || |
||
50 | $otherStub->getBaseType() !== $this->getTargType()) |
||
51 | ) { |
||
52 | return false; |
||
53 | } |
||
54 | |||
55 | if ($thisNull && ($thatTarg != $this->getBaseType())) { |
||
56 | return false; |
||
57 | } |
||
58 | if ($thatNull && ($thisTarg != $otherStub->getBaseType())) { |
||
59 | return false; |
||
60 | } |
||
61 | |||
62 | return true; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @throws InvalidOperationException |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function isKnownSide() |
||
70 | { |
||
71 | if (!($this->isOk())) { |
||
72 | throw new InvalidOperationException('Polymorphic stub not OK so known-side determination is meaningless'); |
||
73 | } |
||
74 | return null === $this->targType; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function morphicType() |
||
83 | } |
||
84 | } |
||
85 |