| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 25 | public static function resolve($fieldLayout = null): FieldLayout |
||
| 26 | { |
||
| 27 | if ($fieldLayout instanceof FieldLayoutModel) { |
||
| 28 | return $fieldLayout; |
||
| 29 | } |
||
| 30 | |||
| 31 | if (is_numeric($fieldLayout)) { |
||
| 32 | return Craft::$app->getFields()->getLayoutById($fieldLayout); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (is_string($fieldLayout)) { |
||
| 36 | return Craft::$app->getFields()->getLayoutByType($fieldLayout); |
||
| 37 | } |
||
| 38 | |||
| 39 | try { |
||
| 40 | $object = Craft::createObject(FieldLayout::class, [$fieldLayout]); |
||
| 41 | } catch (\Exception $e) { |
||
| 42 | $object = new FieldLayout(); |
||
| 43 | ObjectHelper::populate( |
||
| 44 | $object, |
||
| 45 | $fieldLayout |
||
| 46 | ); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** @var FieldLayout $object */ |
||
| 50 | return $object; |
||
| 51 | } |
||
| 52 | } |
||
| 53 |