| Conditions | 4 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 26 | protected function belongsToTree( |
||
| 27 | string $related, |
||
| 28 | string $throwRelation, |
||
| 29 | ?string $foreignKey = null, |
||
| 30 | $ownerKey = null |
||
| 31 | ) { |
||
| 32 | $instance = $this->newRelatedInstance($related); |
||
| 33 | |||
| 34 | if (!$instance instanceof LTreeModelInterface) { |
||
| 35 | throw new InvalidTraitInjectionClass(sprintf( |
||
| 36 | 'A class using this trait must implement an interface %s', |
||
| 37 | LTreeModelInterface::class |
||
| 38 | )); |
||
| 39 | } |
||
| 40 | |||
| 41 | if ($foreignKey === null) { |
||
| 42 | $foreignKey = $this |
||
| 43 | ->{$throwRelation}() |
||
| 44 | ->getForeignKeyName(); |
||
| 45 | } |
||
| 46 | |||
| 47 | $ownerKey = $ownerKey ?: $instance->getKeyName(); |
||
| 48 | |||
| 49 | return new BelongsToTree($instance->newQuery(), $this, $throwRelation, $foreignKey, $ownerKey); |
||
| 50 | } |
||
| 52 |