| Total Complexity | 17 |
| Total Lines | 77 |
| 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 && null === $thatNull) { |
||
|
|
|||
| 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 | |||
| 56 | if ($thisNull && ($thatTarg != $this->getBaseType())) { |
||
| 57 | return false; |
||
| 58 | } |
||
| 59 | if ($thatNull && ($thisTarg != $otherStub->getBaseType())) { |
||
| 60 | return false; |
||
| 61 | } |
||
| 62 | |||
| 63 | return true; |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @throws InvalidOperationException |
||
| 68 | * @return bool |
||
| 69 | */ |
||
| 70 | public function isKnownSide() |
||
| 71 | { |
||
| 72 | if (!($this->isOk())) { |
||
| 73 | throw new InvalidOperationException('Polymorphic stub not OK so known-side determination is meaningless'); |
||
| 74 | } |
||
| 75 | return null === $this->targType; |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | public function morphicType() |
||
| 84 | } |
||
| 85 | } |
||
| 86 |