Completed
Push — master ( 318af2...9cd922 )
by Nassif
08:56
created

SheetPuller   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 49
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setTranslationsSheet() 0 6 1
A pull() 0 15 1
A getTranslations() 0 8 1
1
<?php
2
3
namespace Nikaia\TranslationSheet;
4
5
use Nikaia\TranslationSheet\Commands\Output;
6
use Nikaia\TranslationSheet\Sheet\TranslationsSheet;
7
use Nikaia\TranslationSheet\Translation\Writer;
8
9
class SheetPuller
10
{
11
    use Output;
12
13
    /** @var TranslationsSheet */
14
    protected $translationsSheet;
15
16
    /** @var Writer */
17
    protected $writer;
18
19
    public function __construct(Writer $writer)
20
    {
21
        $this->writer = $writer;
22
23
        $this->nullOutput();
24
    }
25
26
    public function setTranslationsSheet(TranslationsSheet $translationsSheet)
27
    {
28
        $this->translationsSheet = $translationsSheet;
29
30
        return $this;
31
    }
32
33
    public function pull()
34
    {
35
        $this->output->writeln("Pulling translations from sheet [<comment>{$this->translationsSheet->getTitle()}</comment>] :");
36
        $translations = $this->getTranslations();
37
38
        $this->output->writeln('    <comment>Writing languages files :</comment>');
39
        $this->writer
40
            ->withOutput($this->output)
41
            ->setTranslationsSheet($this->translationsSheet)
42
            ->setTranslations($translations)
43
            ->write();
44
45
        $this->output->writeln('    <info>Done.</info>');
46
        $this->output->writeln(PHP_EOL);
47
    }
48
49
    public function getTranslations()
50
    {
51
        $header = $this->translationsSheet->getSpreadsheet()->getCamelizedHeader();
52
53
        $translations = $this->translationsSheet->readTranslations();
54
55
        return Util::keyValues($translations, $header);
56
    }
57
}
58