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

Tokenizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A tokenize() 0 12 3
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\TokenModifierInterface;
8
9
class Tokenizer
10
{
11
    private $fileFinder;
12
13
    private $textFinder;
14
15
    private $tokenModifier;
16
17 6
    public function __construct(
18
        FileFinderInterface $fileFinder,
19
        TextFinderInterface $textFinder,
20
        TokenModifierInterface $tokenModifier
21
    ) {
22 6
        $this->fileFinder = $fileFinder;
23 6
        $this->textFinder = $textFinder;
24 6
        $this->tokenModifier = $tokenModifier;
25 6
    }
26
27
    /**
28
     * @return TokenCollection[]
29
     */
30 6
    public function tokenize(): array
31
    {
32 6
        $tokenCollections = [];
33 6
        foreach ($this->fileFinder->find() as $file) {
34 6
            $texts = $this->textFinder->find(file_get_contents($file));
35 6
            $tokenCollection = new TokenCollection($file);
36 6
            foreach ($texts as $originalBlock => $originalText) {
37 6
                $tokenCollection->addToken(new Token($originalText, $originalBlock));
38
            }
39 6
            $tokenCollections[] = $this->tokenModifier->modifyAll($tokenCollection);
40
        }
41 6
        return $tokenCollections;
42
    }
43
}
44