Completed
Pull Request — master (#11)
by Michal
01:51
created

Tokenizer::addTokenModifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization\Tokenizer;
4
5
use Efabrica\TranslationsAutomatization\FileFinder\FileFinderInterface;
6
use Efabrica\TranslationsAutomatization\TextFinder\TextFinderInterface;
7
use Efabrica\TranslationsAutomatization\TokenModifier\CompositeTokenModifier;
8
use Efabrica\TranslationsAutomatization\TokenModifier\TokenModifierInterface;
9
10
class Tokenizer
11
{
12
    private $fileFinder;
13
14
    private $textFinder;
15
16
    private $tokenModifier;
17
18 10
    public function __construct(
19
        FileFinderInterface $fileFinder,
20
        TextFinderInterface $textFinder
21
    ) {
22 10
        $this->fileFinder = $fileFinder;
23 10
        $this->textFinder = $textFinder;
24 10
        $this->tokenModifier = new CompositeTokenModifier();
25 10
    }
26
27 6
    public function addTokenModifier(TokenModifierInterface $tokenModifier)
28
    {
29 6
        $this->tokenModifier->addTokenModifier($tokenModifier);
30 6
        return $this;
31
    }
32
33
    /**
34
     * @return TokenCollection[]
35
     */
36 10
    public function tokenize(): array
37
    {
38 10
        $tokenCollections = [];
39 10
        foreach ($this->fileFinder->find() as $file) {
40 10
            $texts = $this->textFinder->find(file_get_contents($file));
41 10
            $tokenCollection = new TokenCollection($file);
42 10
            foreach ($texts as $originalBlock => $originalText) {
43 10
                $tokenCollection->addToken(new Token($originalText, $originalBlock));
44
            }
45 10
            $tokenCollections[] = $this->tokenModifier->modifyAll($tokenCollection);
46
        }
47 10
        return $tokenCollections;
48
    }
49
}
50