Completed
Push — master ( bcac64...9b6ee4 )
by Nassif
11:39
created

Puller::getTranslations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
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 Puller
10
{
11
    use Output;
12
13
    /** @var TranslationsSheet */
14
    protected $translationsSheet;
15
16
    /** @var Writer */
17
    protected $writer;
18
19
    public function __construct(TranslationsSheet $translationsSheet, Writer $writer)
20
    {
21
        $this->translationsSheet = $translationsSheet;
22
        $this->writer = $writer;
23
24
        $this->nullOutput();
25
    }
26
27
    public function pull()
28
    {
29
        $this->output->writeln('<comment>Pulling translation from Spreadsheet</comment>');
30
        $translations = $this->getTranslations();
31
32
        $this->output->writeln('<comment>Writing languages files :</comment>');
33
        $this->writer
34
            ->withOutput($this->output)
35
            ->setTranslations($translations)
36
            ->write();
37
38
        $this->output->writeln('<info>Done.</info>');
39
    }
40
41
    public function getTranslations()
42
    {
43
        $header = $this->translationsSheet->getSpreadsheet()->getCamelizedHeader();
44
45
        $translations = $this->translationsSheet->readTranslations();
46
47
        return Util::keyValues($translations, $header);
48
    }
49
}
50