ExportTranslation::make()   A
last analyzed

Complexity

Conditions 5
Paths 8

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 9.1768
c 0
b 0
f 0
cc 5
nc 8
nop 3
crap 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 2
    public function make(
17
        AllTranslationInterface $allTranslationInterface,
18
        ExportTranslationInterface $exportTranslationInterface,
19
        $locales
20
    ): string {
21 2
        $translations = $allTranslationInterface->get($locales);
22
23 2
        $parsedTranslations = [];
24
25 2
        foreach ($translations as $values) {
26 2
            foreach ($values as $key => $value) {
27 2
                if (array_key_exists($key, array_flip($locales))) {
28 2
                    $parsedTranslations[$key][] = [
29 2
                        'group' => $values['group'],
30 2
                        'key'   => $values['group'].'.'.$values['key'],
31 2
                        'value' => $value,
32
                    ];
33
                }
34
            }
35
        }
36
37 2
        foreach ($parsedTranslations as &$translation) {
38 2
            $translation = collect($translation);
39
        }
40
41 2
        return $exportTranslationInterface->export($parsedTranslations);
42
    }
43
}
44