Total Complexity | 11 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Changes | 7 | ||
Bugs | 0 | 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 | |||
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 | * @throws InvalidOperationException |
||
61 | * @return bool |
||
62 | */ |
||
63 | public function isKnownSide() |
||
64 | { |
||
65 | if (!($this->isOk())) { |
||
66 | throw new InvalidOperationException('Polymorphic stub not OK so known-side determination is meaningless'); |
||
67 | } |
||
68 | return null === $this->targType; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function morphicType() |
||
77 | } |
||
78 | } |
||
79 |