Completed
Push — master ( c677c5...b4e9ab )
by Michal
01:40
created

TranslatorConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 29
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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