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

Pusher::push()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 13
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
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\Reader;
8
use Nikaia\TranslationSheet\Translation\Transformer;
9
10
class Pusher
11
{
12
    use Output;
13
14
    /** @var Reader */
15
    protected $reader;
16
17
    /** @var TranslationsSheet */
18
    protected $translationsSheet;
19
20
    /** @var Transformer */
21
    protected $transformer;
22
23
    public function __construct(Reader $reader, TranslationsSheet $translationsSheet, Transformer $transformer)
24
    {
25
        $this->reader = $reader;
26
        $this->translationsSheet = $translationsSheet;
27
        $this->transformer = $transformer;
28
29
        $this->nullOutput();
30
    }
31
32
    public function push()
33
    {
34
        $this->output->writeln('<comment>Scanning languages files</comment>');
35
        $translations = $this->getScannedAndTransformedTranslations();
36
37
        $this->output->writeln('<comment>Preparing spreasheet for new write operation</comment>');
38
        $this->translationsSheet->prepareForWrite();
39
40
        $this->output->writeln('<comment>Updating header</comment>');
41
        $this->translationsSheet->updateHeaderRow();
42
43
        $this->output->writeln('<comment>Writing translations in the spreadsheet</comment>');
44
        $this->translationsSheet->writeTranslations($translations->toArray());
45
46
        $this->output->writeln('<comment>Styling document</comment>');
47
        $this->translationsSheet->styleDocument();
48
49
        $this->output->writeln('<info>Done</info>.');
50
    }
51
52
    public function getScannedAndTransformedTranslations()
53
    {
54
        return $this->transformer
55
            ->setLocales($this->translationsSheet->getSpreadsheet()->getLocales())
56
            ->transform($this->reader->scan());
57
    }
58
}
59