| Conditions | 4 |
| Paths | 6 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | public function newRelation(Mapper $nativeMapper, $name, $options): Relation |
||
| 22 | { |
||
| 23 | $foreignMapper = $options[RelationConfig::FOREIGN_MAPPER]; |
||
| 24 | if ($this->orm->has($foreignMapper)) { |
||
| 25 | if (! $foreignMapper instanceof Mapper) { |
||
| 26 | $foreignMapper = $this->orm->get($foreignMapper); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | $type = $options[RelationConfig::TYPE]; |
||
| 30 | $relationClass = __NAMESPACE__ . '\\' . Str::className($type); |
||
| 31 | |||
| 32 | if (! class_exists($relationClass)) { |
||
| 33 | throw new \InvalidArgumentException("{$relationClass} does not exist"); |
||
| 34 | } |
||
| 35 | |||
| 36 | return new $relationClass($name, $nativeMapper, $foreignMapper, $options); |
||
| 37 | } |
||
| 38 | } |