Completed
Pull Request — master (#62)
by Nassif
06:25
created

SheetPuller::setTranslationsSheet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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