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 hasOne(string $modelClass, string $foreignAttribute = null, string $attribute = 'id') |
||
29 | { |
||
30 | if (!class_exists($modelClass)) { |
||
31 | throw new RuntimeException('Invalid model class in belongs_to definition'); |
||
32 | } |
||
33 | if (is_null($foreignAttribute)) { |
||
34 | $reflection = new ReflectionClass(get_called_class()); |
||
35 | $foreignAttribute = Str::snake($reflection->getShortName()); |
||
36 | $foreignAttribute = strtolower($foreignAttribute); |
||
37 | $foreignAttribute = $modelClass::prefix($foreignAttribute); |
||
38 | } |
||
39 | $attribute = static::prefix($attribute); |
||
40 | $finder = Orm::finder($modelClass); |
||
41 | |||
42 | return $finder->select() |
||
43 | ->where($foreignAttribute, $this->getAttribute($attribute)) |
||
|
|||
44 | ->one(); |
||
45 | } |
||
47 |