| Total Complexity | 6 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class MultilingualHelper |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @param array $fields |
||
| 15 | * @param callable $transformer |
||
| 16 | * @param array $shortLanguageList |
||
| 17 | * @return array |
||
| 18 | */ |
||
| 19 | public static function fieldsTransformer(array $fields, callable $transformer, array $shortLanguageList = []): array |
||
| 20 | { |
||
| 21 | $output = []; |
||
| 22 | |||
| 23 | if (empty($shortLanguageList)) { |
||
| 24 | $shortLanguageList = Language::shortLanguageList(); |
||
| 25 | } |
||
| 26 | |||
| 27 | foreach ($fields as $fieldKey => $fieldValue) { |
||
| 28 | foreach ($shortLanguageList as $shortLang) { |
||
| 29 | $output[$fieldKey.'_'.$shortLang] = call_user_func($transformer, $fieldValue, $shortLang); |
||
| 30 | } |
||
| 31 | } |
||
| 32 | |||
| 33 | return $output; |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param Model $model |
||
| 38 | * @param array $attributes |
||
| 39 | * @return Model |
||
| 40 | */ |
||
| 41 | public static function fill(Model $model, array $attributes): Model |
||
| 48 | } |
||
| 49 | } |