Completed
Push — master ( 216072...caf6f7 )
by Team eFabrica
02:21
created

TranslationFinder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A translate() 0 14 4
A __construct() 0 3 1
A addTokenizer() 0 4 1
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization;
4
5
use Efabrica\TranslationsAutomatization\Saver\SaverInterface;
6
use Efabrica\TranslationsAutomatization\Tokenizer\Tokenizer;
7
8
class TranslationFinder
9
{
10
    private $saver;
11
12
    private $tokenizers = [];
13
14
    public function __construct(SaverInterface $saver)
15
    {
16
        $this->saver = $saver;
17
    }
18
19
    public function addTokenizer(Tokenizer $tokenizer): TranslationFinder
20
    {
21
        $this->tokenizers[] = $tokenizer;
22
        return $this;
23
    }
24
25
    public function translate()
26
    {
27
        foreach ($this->tokenizers as $tokenizer) {
28
            foreach ($tokenizer->tokenize() as $tokenCollection) {
29
                // tento kod by som mohol dat do nejakeho file updatera
30
                $content = file_get_contents($tokenCollection->getFilePath());
31
                $newTexts = [];
32
                foreach ($tokenCollection->getTokens() as $token) {
33
                    $newTexts[$token->getOriginalBlock()] = str_replace($token->getOriginalText(), $token->getTranslationCode(), $token->getOriginalBlock());
34
                }
35
                $content = str_replace(array_keys($newTexts), array_values($newTexts), $content);
36
                file_put_contents($tokenCollection->getFilePath(), $content);
37
38
                $this->saver->save($tokenCollection);
39
            }
40
        }
41
    }
42
}
43