TranslatorConfig::translate()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 17
ccs 11
cts 11
cp 1
rs 9.9
cc 4
nc 4
nop 0
crap 4
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
            if (empty($texts = $something[0]->load())) {
27 2
                continue;
28
            }
29 2
            $newTexts = $something[2]->translate(array_values($texts));
30 2
31 2
            $translations = [];
32 2
            foreach ($texts as $key => $text) {
33
                $translations[$key] = $newTexts[$text] ?? '';
34 2
                $count++;
35
            }
36 4
            $something[1]->save($translations);
37
        }
38
        return $count;
39
    }
40
}
41