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

ExportTranslation::make()   A

Complexity

Conditions 5
Paths 8

Size

Total Lines 27
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 8
nop 3
dl 0
loc 27
ccs 0
cts 13
cp 0
crap 30
rs 9.5555
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