Passed
Pull Request — master (#20)
by Michal
07:21
created

TranslatorConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 29
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
    public function add(StorageInterface $source, StorageInterface $target, TranslatorInterface $translator): TranslatorConfig
13
    {
14
        $this->something[] = [
15
            $source,
16
            $target,
17
            $translator
18
        ];
19
        return $this;
20
    }
21
22
    public function translate(): int
23
    {
24
        $count = 0;
25
        foreach ($this->something as $something) {
26
            $texts = $something[0]->load();
27
            $newTexts = $something[2]->translate(array_values($texts));
28
29
            $translations = [];
30
            foreach ($texts as $key => $text) {
31
                $translations[$key] = $newTexts[$text] ?? '';
32
                $count++;
33
            }
34
            $something[1]->save($translations);
35
        }
36
        return $count;
37
    }
38
}
39