Completed
Push — master ( d19c7e...b4b8ba )
by Michal
02:01
created

OneFileTranslationSaver::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization\Bridge\KdybyTranslation\Saver;
4
5
use Efabrica\TranslationsAutomatization\Saver\SaverInterface;
6
use Efabrica\TranslationsAutomatization\Storage\StorageInterface;
7
use Efabrica\TranslationsAutomatization\Tokenizer\TokenCollection;
8
9
class OneFileTranslationSaver implements SaverInterface
10
{
11
    private $storage;
12
13 14
    public function __construct(StorageInterface $storage)
14
    {
15 14
        $this->storage = $storage;
16 14
    }
17
18 14
    public function save(TokenCollection $tokenCollection): bool
19
    {
20 14
        $texts = [];
21 14
        foreach ($tokenCollection->getTokens() as $token) {
22 10
            $translationKeyParts = explode('.', $token->getTranslationKey());
23 10
            array_shift($translationKeyParts);
24 10
            $texts[implode('.', $translationKeyParts)] = $token->getTargetText();
25
        }
26 14
        return $this->storage->save($texts);
27
    }
28
}
29