| Conditions | 3 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | protected function belongsTo(string $modelClass, string $attribute = null, string $foreignAttribute = 'id') |
||
| 29 | { |
||
| 30 | if (!class_exists($modelClass)) { |
||
| 31 | throw new RuntimeException('Invalid model class in belongs_to definition'); |
||
| 32 | } |
||
| 33 | if (is_null($attribute)) { |
||
| 34 | $reflection = new ReflectionClass($modelClass); |
||
| 35 | $attribute = Str::snake($reflection->getShortName()); |
||
| 36 | $attribute = strtolower($attribute); |
||
| 37 | $attribute = static::prefix($attribute); |
||
| 38 | } |
||
| 39 | $foreignAttribute = $modelClass::prefix($foreignAttribute); |
||
| 40 | $finder = Orm::finder($modelClass); |
||
| 41 | |||
| 42 | return $finder->select() |
||
| 43 | ->where($foreignAttribute, $this->getAttribute($attribute)) |
||
|
|
|||
| 44 | ->one(); |
||
| 45 | } |
||
| 47 |