Completed
Push — master ( 79fd8a...81e819 )
by Christian
05:05
created

ExportTranslation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 35
ccs 0
cts 13
cp 0
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 27 5
1
<?php
2
3
namespace Omatech\Mage\Core\Domains\Translations\Jobs;
4
5
use Omatech\Mage\Core\Domains\Translations\Contracts\AllTranslationInterface;
6
use Omatech\Mage\Core\Domains\Translations\Contracts\ExportTranslationInterface;
7
8
class ExportTranslation
9
{
10
    /**
11
     * @param AllTranslationInterface $allTranslationInterface
12
     * @param ExportTranslationInterface $exportTranslationInterface
13
     * @param $locales
14
     * @return string
15
     */
16
    public function make(
17
        AllTranslationInterface $allTranslationInterface,
18
        ExportTranslationInterface $exportTranslationInterface,
19
        $locales
20
    ): string
21
    {
22
        $translations = $allTranslationInterface->get($locales);
23
24
        $parsedTranslations = [];
25
26
        foreach ($translations as $values) {
27
            foreach ($values as $key => $value) {
28
                if (array_key_exists($key, array_flip($locales))) {
29
                    $parsedTranslations[$key][] = [
30
                        'group' => $values['group'],
31
                        'key' => $values['group'] . '.' . $values['key'],
32
                        'value' => $value
33
                    ];
34
                }
35
            }
36
        }
37
38
        foreach ($parsedTranslations as &$translation) {
39
            $translation = collect($translation);
40
        }
41
42
        return $exportTranslationInterface->export($parsedTranslations);
43
    }
44
}
45