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

TranslationsSheetCoordinates   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 29.33%

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 0
dl 0
loc 163
ccs 22
cts 75
cp 0.2933
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setSheetId() 0 6 1
A setSheetTitle() 0 6 1
A emptySheet() 0 11 1
A sheetWithData() 0 11 1
A headerShortRange() 0 6 1
A dataRange() 0 10 1
A headerRange() 0 10 1
A fullKeyColumnRange() 0 10 1
A metaColumnsRange() 0 10 1
A dataShortRange() 0 9 2
A translationsRange() 0 10 2
A getColumnsCount() 0 4 1
A getRowsCount() 0 4 1
A getLocalesCount() 0 4 1
A namespaceColumnIndex() 0 4 1
A groupColumnIndex() 0 4 1
A keyColumnIndex() 0 4 1
A sourceFileColumnIndex() 0 4 1
1
<?php
2
3
namespace Nikaia\TranslationSheet\Sheet;
4
5
class TranslationsSheetCoordinates
0 ignored issues
show
Coding Style introduced by
Since you have declared the constructor as private, maybe you should also declare the class as final.
Loading history...
6
{
7
    protected $headerRowsCount = 1;
8
9
    protected $dataRowsCount = 0;
10
11
    protected $columnsCount = 0;
12
13
    protected $localesCount = 1;
14
15
    protected $sheetId;
16
17
    protected $sheetTitle;
18
19 3
    private function __construct()
20
    {
21 3
    }
22
23 3
    public function setSheetId($sheetId)
24
    {
25 3
        $this->sheetId = $sheetId;
26
27 3
        return $this;
28
    }
29
30 3
    public function setSheetTitle($sheetTitle)
31
    {
32 3
        $this->sheetTitle = $sheetTitle;
33
34 3
        return $this;
35
    }
36
37 1
    public static function emptySheet($columnsCount, $localesCount, $headerRowsCount)
38
    {
39 1
        $instance = new self;
40
41 1
        $instance->headerRowsCount = $headerRowsCount;
42 1
        $instance->dataRowsCount = 10;
43 1
        $instance->columnsCount = $columnsCount;
44 1
        $instance->localesCount = $localesCount;
45
46 1
        return $instance;
47
    }
48
49 2
    public static function sheetWithData($dataRowsCount, $columnsCount, $localesCount, $headerRowsCount)
50
    {
51 2
        $instance = new self;
52
53 2
        $instance->headerRowsCount = $headerRowsCount;
54 2
        $instance->dataRowsCount = $dataRowsCount;
55 2
        $instance->columnsCount = $columnsCount;
56 2
        $instance->localesCount = $localesCount;
57
58 2
        return $instance;
59
    }
60
61
    public function headerShortRange()
62
    {
63
        $alphabet = range('A', 'Z');
64
65
        return $this->sheetTitle.'!A1:'.$alphabet[$this->getColumnsCount() - 1].'1';
66
    }
67
68
    public function headerRange()
69
    {
70
        return [
71
            'sheetId' => $this->sheetId,
72
            'startRowIndex' => 0,
73
            'endRowIndex' => 1,
74
            'startColumnIndex' => 0,
75
            'endColumnIndex' => $this->getColumnsCount(),
76
        ];
77
    }
78
79
    public function fullKeyColumnRange()
80
    {
81
        return [
82
            'sheetId' => $this->sheetId,
83
            'startRowIndex' => 1,
84
            'endRowIndex' => $this->getRowsCount(),
85
            'startColumnIndex' => 0,
86
            'endColumnIndex' => 1,
87
        ];
88
    }
89
90
    public function metaColumnsRange()
91
    {
92
        return [
93
            'sheetId' => $this->sheetId,
94
            'startRowIndex' => 1,
95
            'endRowIndex' => $this->getRowsCount(),
96
            'startColumnIndex' => $this->getLocalesCount() + 1,
97
            'endColumnIndex' => $this->getColumnsCount(),
98
        ];
99
    }
100
101
    public function dataShortRange($firstRow = 2, $noLastRow = false)
102
    {
103
        $alphabet = range('A', 'Z');
104
        $firstColumn = 'A';
105
        $lastColumn = $alphabet[$this->getColumnsCount() - 1];
106
        $lastRow = $this->getRowsCount();
107
108
        return $this->sheetTitle.'!'.$firstColumn.$firstRow.':'.$lastColumn.($noLastRow ? '' : $lastRow);
109
    }
110
111
    public function dataRange($endRow, $firstRow = 2)
112
    {
113
        return [
114
            'sheetId' => $this->sheetId,
115
            'startRowIndex' => $firstRow,
116
            'endRowIndex' => $endRow,
117
            'startColumnIndex' => 0,
118
            'endColumnIndex' => $this->getColumnsCount(),
119
        ];
120
    }
121
122
    public function translationsRange($firstColumn = 1, $rowCount = null)
123
    {
124
        return [
125
            'sheetId' => $this->sheetId,
126
            'startRowIndex' => 1,
127
            'endRowIndex' => $rowCount ?: $this->getRowsCount(),
128
            'startColumnIndex' => $firstColumn,
129
            'endColumnIndex' => $firstColumn + $this->getLocalesCount(),
130
        ];
131
    }
132
133
    public function getColumnsCount()
134
    {
135
        return $this->columnsCount;
136
    }
137
138
    public function getRowsCount()
139
    {
140
        return $this->dataRowsCount + $this->headerRowsCount;
141
    }
142
143
    public function getLocalesCount()
144
    {
145
        return $this->localesCount;
146
    }
147
148
    public function namespaceColumnIndex()
149
    {
150
        return $this->getLocalesCount() + 1;
151
    }
152
153
    public function groupColumnIndex()
154
    {
155
        return $this->getLocalesCount() + 2;
156
    }
157
158
    public function keyColumnIndex()
159
    {
160
        return $this->getLocalesCount() + 3;
161
    }
162
163
    public function sourceFileColumnIndex()
164
    {
165
        return $this->getLocalesCount() + 4;
166
    }
167
}
168