| Conditions | 9 |
| Paths | 9 |
| Total Lines | 48 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 32 |
| CRAP Score | 9.0022 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 19 | 2 | public function run(ModelsCommand $command, Model $model): void |
|
| 20 | { |
||
| 21 | 2 | $traits = class_uses_recursive($model); |
|
| 22 | |||
| 23 | 2 | if (!in_array(HasRelationships::class, $traits)) { |
|
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | 2 | $methods = (new ReflectionClass($model))->getMethods(ReflectionMethod::IS_PUBLIC); |
|
| 28 | |||
| 29 | 2 | foreach ($methods as $method) { |
|
| 30 | 2 | if ($method->isStatic() || $method->getNumberOfParameters() > 0) { |
|
| 31 | 2 | continue; |
|
| 32 | } |
||
| 33 | |||
| 34 | try { |
||
| 35 | 2 | $relation = $method->invoke($model); |
|
| 36 | 2 | } catch (Exception) { |
|
| 37 | 2 | continue; |
|
| 38 | } |
||
| 39 | |||
| 40 | 2 | if (!$relation instanceof HasManyDeep) { |
|
| 41 | 2 | continue; |
|
| 42 | } |
||
| 43 | |||
| 44 | 2 | $isHasOneDeep = $relation instanceof HasOneDeep; |
|
| 45 | |||
| 46 | 2 | $type = $isHasOneDeep |
|
| 47 | 2 | ? '\\' . $relation->getRelated()::class |
|
| 48 | 2 | : '\\' . Collection::class . '|\\' . $relation->getRelated()::class . '[]'; |
|
| 49 | |||
| 50 | 2 | $command->setProperty( |
|
| 51 | 2 | $method->getName(), |
|
| 52 | 2 | $type, |
|
| 53 | 2 | true, |
|
| 54 | 2 | false, |
|
| 55 | 2 | '', |
|
| 56 | 2 | $isHasOneDeep |
|
| 57 | 2 | ); |
|
| 58 | |||
| 59 | 2 | if (!$isHasOneDeep) { |
|
| 60 | 2 | $command->setProperty( |
|
| 61 | 2 | Str::snake($method->getName()) . '_count', |
|
| 62 | 2 | 'int', |
|
| 63 | 2 | true, |
|
| 64 | 2 | false, |
|
| 65 | 2 | null, |
|
| 66 | 2 | true |
|
| 67 | 2 | ); |
|
| 72 |