ExportTranslation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

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 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