Completed
Push — master ( 602963...93984f )
by Nassif
08:12
created

Spreadsheet::getUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nikaia\TranslationSheet;
4
5
use Illuminate\Support\Str;
6
use Nikaia\TranslationSheet\Client\Api;
7
use Nikaia\TranslationSheet\Sheet\Styles;
8
use Nikaia\TranslationSheet\Sheet\TranslationsSheetCoordinates;
9
10
class Spreadsheet
11
{
12
    /** @var string */
13
    protected $id;
14
15
    /** @var array */
16
    protected $locales;
17
18
    /** @var array */
19
    protected $translations;
20
21
    /** @var Api */
22
    protected $api;
23
24 18
    public function __construct($id, $locales, $api = null)
25
    {
26 18
        $this->id = $id;
27 18
        $this->locales = $locales;
28 18
        $this->api = $api ?: app(Api::class);
29 18
    }
30
31 3
    public function setLocales($locales)
32
    {
33 3
        $this->locales = $locales;
34
35 3
        return $this;
36
    }
37
38 17
    public function setTranslations($translations)
39
    {
40 17
        $this->translations = $translations;
41
42 17
        return $this;
43
    }
44
45 1
    public function getTranslations()
46
    {
47 1
        return $this->translations;
48
    }
49
50 3
    public function getTranslationsCount()
51
    {
52 3
        return count($this->translations);
53
    }
54
55 3
    public function getId()
56
    {
57 3
        return $this->id;
58
    }
59
60 1
    public function getUrl()
61
    {
62 1
        return 'https://docs.google.com/spreadsheets/d/' . $this->id;
63
    }
64
65 10
    public function getLocales()
66
    {
67 10
        return $this->locales;
68
    }
69
70 4
    public function getLocalesCount()
71
    {
72 4
        return count($this->locales);
73
    }
74
75 7
    public function getHeader()
76
    {
77 7
        return array_merge(
78 7
            array_merge(['Full key'], $this->getLocales()),
79 7
            ['Namespace', 'Group', 'Key', 'Source file']
80 7
        );
81
    }
82
83
    public function getCamelizedHeader()
84
    {
85 2
        return array_map(function ($item) {
86 2
            return Str::camel($item);
87 2
        }, $this->getHeader());
88
    }
89
90 4
    public function getHeaderColumnsCount()
91
    {
92 4
        $header = $this->getHeader();
93
94 4
        return count($header);
95
    }
96
97 3
    public function getHeaderRowsCount()
98
    {
99 3
        return 1;
100
    }
101
102
    /**
103
     * @param $sheetId
104
     * @param $sheetTitle
105
     *
106
     * @return TranslationsSheetCoordinates
107
     */
108 1
    public function translationsEmptySheetCoordinates($sheetId, $sheetTitle)
109
    {
110 1
        return TranslationsSheetCoordinates::emptySheet(
111 1
            $this->getHeaderColumnsCount(),
112 1
            $this->getLocalesCount(),
113 1
            $this->getHeaderColumnsCount()
114 1
        )->setSheetId($sheetId)->setSheetTitle($sheetTitle);
115
    }
116
117
    /**
118
     * @param $sheetId
119
     * @param $sheetTitle
120
     * @return TranslationsSheetCoordinates
121
     */
122 2
    public function translationsSheetCoordinates($sheetId, $sheetTitle)
123
    {
124 2
        return TranslationsSheetCoordinates::sheetWithData(
125 2
            $this->getTranslationsCount(),
126 2
            $this->getHeaderColumnsCount(),
127 2
            $this->getLocalesCount(),
128 2
            $this->getHeaderRowsCount()
129 2
        )->setSheetId($sheetId)->setSheetTitle($sheetTitle);
130
    }
131
132 1
    public function sheetStyles()
133
    {
134 1
        return new Styles;
135
    }
136
137
    /**
138
     * Return api instance initialized with the spreadsheet ID.
139
     *
140
     * @return Api
141
     */
142 1
    public function api()
143
    {
144 1
        return $this->api->setSpreadsheetId($this->getId());
145
    }
146
}
147