BingTranslateTokenModifier   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 25
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A modifyAll() 0 16 4
A __construct() 0 3 1
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization\TokenModifier;
4
5
use Efabrica\TranslationsAutomatization\Tokenizer\TokenCollection;
6
use Efabrica\TranslationsAutomatization\Translator\BingTranslator;
7
8
/**
9
 * @deprecated Use TranslateTokenModifier instead
10
 */
11
class BingTranslateTokenModifier implements TokenModifierInterface
12 8
{
13
    private $translator;
14 8
15 8
    public function __construct(string $from, string $to)
16
    {
17 6
        $this->translator = new BingTranslator($from, $to);
18
    }
19 6
20 6
    public function modifyAll(TokenCollection $tokenCollection): TokenCollection
21 4
    {
22
        $oldKeys = [];
23
        foreach ($tokenCollection->getTokens() as $token) {
24 6
            $oldKeys[] = $token->getTranslationKey();
25 2
        }
26
27
        if (empty($oldKeys)) {
28 4
            return $tokenCollection;
29 4
        }
30 4
31
        $oldToNewKeys = $this->translator->translate($oldKeys);
32 4
        foreach ($tokenCollection->getTokens() as $token) {
33
            $token->changeTranslationKey($oldToNewKeys[$token->getTranslationKey()] ?? $token->getTranslationKey());
34
        }
35
        return $tokenCollection;
36
    }
37
}
38