Completed
Push — master ( d9514b...385d29 )
by Nassif
09:34
created

TranslationsSheetCoordinates   A

Complexity

Total Complexity 21

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 0
dl 0
loc 163
ccs 70
cts 80
cp 0.875
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 headerRange() 0 10 1
A fullKeyColumnRange() 0 10 1
A metaColumnsRange() 0 10 1
A dataShortRange() 0 9 2
A dataRange() 0 10 1
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 8
    private function __construct()
20
    {
21 8
    }
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 6
    public static function emptySheet($columnsCount, $localesCount, $headerRowsCount)
38
    {
39 6
        $instance = new self;
40
41 6
        $instance->headerRowsCount = $headerRowsCount;
42 6
        $instance->dataRowsCount = 10;
43 6
        $instance->columnsCount = $columnsCount;
44 6
        $instance->localesCount = $localesCount;
45
46 6
        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 1
    public function headerRange()
69
    {
70
        return [
71 1
            'sheetId' => $this->sheetId,
72 1
            'startRowIndex' => 0,
73 1
            'endRowIndex' => 1,
74 1
            'startColumnIndex' => 0,
75 1
            'endColumnIndex' => $this->getColumnsCount(),
76 1
        ];
77
    }
78
79 1
    public function fullKeyColumnRange()
80
    {
81
        return [
82 1
            'sheetId' => $this->sheetId,
83 1
            'startRowIndex' => 1,
84 1
            'endRowIndex' => $this->getRowsCount(),
85 1
            'startColumnIndex' => 0,
86 1
            'endColumnIndex' => 1,
87 1
        ];
88
    }
89
90 1
    public function metaColumnsRange()
91
    {
92
        return [
93 1
            'sheetId' => $this->sheetId,
94 1
            'startRowIndex' => 1,
95 1
            'endRowIndex' => $this->getRowsCount(),
96 1
            'startColumnIndex' => $this->getLocalesCount() + 1,
97 1
            'endColumnIndex' => $this->getColumnsCount(),
98 1
        ];
99
    }
100
101 2
    public function dataShortRange($firstRow = 2, $noLastRow = false)
102
    {
103 2
        $alphabet = range('A', 'Z');
104 2
        $firstColumn = 'A';
105 2
        $lastColumn = $alphabet[$this->getColumnsCount() - 1];
106 2
        $lastRow = $this->getRowsCount();
107
108 2
        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 3
    public function translationsRange($firstColumn = 1, $rowCount = null)
123
    {
124
        return [
125 3
            'sheetId' => $this->sheetId,
126 3
            'startRowIndex' => 1,
127 3
            'endRowIndex' => $rowCount ?: $this->getRowsCount(),
128 3
            'startColumnIndex' => $firstColumn,
129 3
            'endColumnIndex' => $firstColumn + $this->getLocalesCount(),
130 3
        ];
131
    }
132
133 3
    public function getColumnsCount()
134
    {
135 3
        return $this->columnsCount;
136
    }
137
138 5
    public function getRowsCount()
139
    {
140 5
        return $this->dataRowsCount + $this->headerRowsCount;
141
    }
142
143 3
    public function getLocalesCount()
144
    {
145 3
        return $this->localesCount;
146
    }
147
148 1
    public function namespaceColumnIndex()
149
    {
150 1
        return $this->getLocalesCount() + 1;
151
    }
152
153 1
    public function groupColumnIndex()
154
    {
155 1
        return $this->getLocalesCount() + 2;
156
    }
157
158 1
    public function keyColumnIndex()
159
    {
160 1
        return $this->getLocalesCount() + 3;
161
    }
162
163 1
    public function sourceFileColumnIndex()
164
    {
165 1
        return $this->getLocalesCount() + 4;
166
    }
167
}
168