Completed
Pull Request — master (#19)
by Michal
05:19 queued 03:25
created

TranslationMaker::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 2
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