Completed
Pull Request — master (#19)
by Michal
06:24
created

TranslationMaker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 11 3
A add() 0 8 1
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization\TranslationMaker;
4
5
use Efabrica\TranslationsAutomatization\Storage\StorageInterface;
6
use Efabrica\TranslationsAutomatization\Translator\TranslatorInterface;
7
8
class TranslationMaker
9
{
10
    private $something = [];
11
12
    public function add(StorageInterface $source, StorageInterface $target, TranslatorInterface $translator): TranslationMaker
13
    {
14
        $this->something[] = [
15
            $source,
16
            $target,
17
            $translator
18
        ];
19
        return $this;
20
    }
21
22
    public function make()
23
    {
24
        foreach ($this->something as $something) {
25
            $texts = $something[0]->load();
26
            $newTexts = $something[2]->translate(array_values($texts));
27
28
            $translations = [];
29
            foreach ($texts as $key => $text) {
30
                $translations[$key] = $newTexts[$text] ?? '';
31
            }
32
            $something[1]->save($translations);
33
        }
34
    }
35
}
36