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