GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5ddc39...1283b7 )
by Denis
03:30
created

SheetXml   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 259
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 31
c 3
b 1
f 1
lcom 2
cbo 1
dl 0
loc 259
rs 9.8

17 Methods

Rating   Name   Duplication   Size   Complexity  
A getXml() 0 4 1
A getSheetPr() 0 8 1
A getWorksheet() 0 6 1
A getSheetViews() 0 13 1
A getCools() 0 8 1
A getDimension() 0 6 1
A getHeaderFooter() 0 9 1
A getPageSetup() 0 8 1
A getPageMargins() 0 4 1
A getPrintOptions() 0 5 1
A getMergeCells() 0 10 2
B getCell() 0 18 10
B checkIntCell() 0 19 5
A getDateCell() 0 9 1
A getCurrencyCell() 0 9 1
A getIntCell() 0 4 1
A getFormulaCell() 0 9 1
1
<?php
2
namespace Ellumilel\Xl\Worksheets;
3
4
use Ellumilel\Helpers\ExcelHelper;
5
6
/**
7
 * @link https://msdn.microsoft.com/en-us/library/bb264572(v=office.12).aspx
8
 *
9
 * Class SheetXml
10
 * @package Ellumilel\Xl\Worksheets
11
 * @author Denis Tikhonov <[email protected]>
12
 */
13
class SheetXml
14
{
15
    /** @var string */
16
    private $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
17
    /** @var string */
18
    private $urlOpenXmlFormat = 'http://schemas.openxmlformats.org/spreadsheetml/2006/main';
19
    /** @var string */
20
    private $urlSchemaFormat = 'http://schemas.openxmlformats.org/officeDocument/2006';
21
22
    /**
23
     * @return string
24
     */
25
    public function getXml()
26
    {
27
        return $this->xml;
28
    }
29
30
    /**
31
     * @return string
32
     */
33
    public function getSheetPr()
34
    {
35
        $sPr = '<sheetPr filterMode="false">';
36
        $sPr .= '<pageSetUpPr fitToPage="false"/>';
37
        $sPr .= '</sheetPr>';
38
39
        return $sPr;
40
    }
41
42
    /**
43
     * @return string
44
     */
45
    public function getWorksheet()
46
    {
47
        $wSheet = '<worksheet xmlns="'.$this->urlOpenXmlFormat.'" xmlns:r="'.$this->urlSchemaFormat.'/relationships">';
48
49
        return $wSheet;
50
    }
51
52
    /**
53
     * @param string $selectedTab
54
     *
55
     * @return string
56
     */
57
    public function getSheetViews($selectedTab)
58
    {
59
        $sViews = '<sheetViews>';
60
        $sViews .= '<sheetView colorId="64" defaultGridColor="true" rightToLeft="false" showFormulas="false"';
61
        $sViews .= ' showGridLines="true" showOutlineSymbols="true" showRowColHeaders="true" showZeros="true"';
62
        $sViews .= ' tabSelected="'.$selectedTab.'" topLeftCell="A1" view="normal" windowProtection="false"';
63
        $sViews .= ' workbookViewId="0" zoomScale="100" zoomScaleNormal="100" zoomScalePageLayoutView="100">';
64
        $sViews .= '<selection activeCell="A1" activeCellId="0" pane="topLeft" sqref="A1"/>';
65
        $sViews .= '</sheetView>';
66
        $sViews .= '</sheetViews>';
67
68
        return $sViews;
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getCools()
75
    {
76
        $sCols = '<cols>';
77
        $sCols .= '<col collapsed="false" hidden="false" max="1025" min="1" style="0" width="11.5"/>';
78
        $sCols .= '</cols>';
79
80
        return $sCols;
81
    }
82
83
    /**
84
     * @param string $maxCell
85
     *
86
     * @return string
87
     */
88
    public function getDimension($maxCell)
89
    {
90
        $sCols = '<dimension ref="A1:'.$maxCell.'"/>';
91
92
        return $sCols;
93
    }
94
95
    /**
96
     * @todo refactor
97
     *
98
     * @return string
99
     */
100
    public function getHeaderFooter()
101
    {
102
        $hf = '<headerFooter differentFirst="false" differentOddEven="false">';
103
        $hf .= '<oddHeader>&amp;C&amp;&quot;Times New Roman,Regular&quot;&amp;12&amp;A</oddHeader>';
104
        $hf .= '<oddFooter>&amp;C&amp;&quot;Times New Roman,Regular&quot;&amp;12Page &amp;P</oddFooter>';
105
        $hf .= '</headerFooter>';
106
107
        return $hf;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getPageSetup()
114
    {
115
        $ps = '<pageSetup blackAndWhite="false" cellComments="none" copies="1" draft="false" firstPageNumber="1"';
116
        $ps .= ' fitToHeight="1" fitToWidth="1" horizontalDpi="300" orientation="portrait" pageOrder="downThenOver"';
117
        $ps .= ' paperSize="1" scale="100" useFirstPageNumber="true" usePrinterDefaults="false" verticalDpi="300"/>';
118
119
        return $ps;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getPageMargins()
126
    {
127
        return '<pageMargins left="0.5" right="0.5" top="1.0" bottom="1.0" header="0.5" footer="0.5"/>';
128
    }
129
130
    /**
131
     * @return string
132
     */
133
    public function getPrintOptions()
134
    {
135
        return '<printOptions headings="false" gridLines="false" gridLinesSet="true" horizontalCentered="false"
136
                verticalCentered="false"/>';
137
    }
138
139
    /**
140
     * @param array $mergeCells
141
     *
142
     * @return string
143
     */
144
    public function getMergeCells(array $mergeCells)
145
    {
146
        $mc = '<mergeCells>';
147
        foreach ($mergeCells as $range) {
148
            $mc .= '<mergeCell ref="'.$range.'"/>';
149
        }
150
        $mc .= '</mergeCells>';
151
152
        return $mc;
153
    }
154
155
    /**
156
     * @param $cellName
157
     * @param $cellIndex
158
     * @param $cellType
159
     * @param $value
160
     *
161
     * @return bool|string
162
     */
163
    public function getCell($cellName, $cellIndex, $cellType, $value)
164
    {
165
        if (!is_scalar($value) || $value === '') {
166
            return '<c r="'.$cellName.'" s="'.$cellIndex.'"/>';
167
        }
168
169
        if (is_string($value) && $value{0} == '=') {
170
            return $this->getFormulaCell($cellName, $cellIndex, $value);
171
        }
172
173
        if ($cellType == 'date' || $cellType == 'datetime') {
174
            return $this->getDateCell($cellName, $cellIndex, $value);
175
        } elseif ($cellType == 'currency' || $cellType == 'percent' || $cellType == 'numeric') {
176
            return $this->getCurrencyCell($cellName, $cellIndex, $value);
177
        }
178
179
        return $this->checkIntCell($cellName, $cellIndex, $value);
180
    }
181
182
    /**
183
     * @param $cellName
184
     * @param $cellIndex
185
     * @param $value
186
     *
187
     * @return bool|string
188
     */
189
    private function checkIntCell($cellName, $cellIndex, $value)
190
    {
191
        if (!is_string($value)) {
192
            return $this->getIntCell($cellName, $cellIndex, $value);
193
        } else {
194
            if ($value{0} != '0' &&
195
                $value{0} != '+' &&
196
                filter_var(
197
                    $value,
198
                    FILTER_VALIDATE_INT,
199
                    ['options' => ['max_range' => ExcelHelper::EXCEL_MAX_RANGE]]
200
                )
201
            ) {
202
                return $this->getIntCell($cellName, $cellIndex, $value);
203
            } else {
204
                return false;
205
            }
206
        }
207
    }
208
209
    /**
210
     * @param $cellName
211
     * @param $cellIndex
212
     * @param $value
213
     *
214
     * @return string
215
     */
216
    private function getDateCell($cellName, $cellIndex, $value)
217
    {
218
        return sprintf(
219
            '<c r="%s" s="%s" t="n"><v>%s</v></c>',
220
            $cellName,
221
            $cellIndex,
222
            ExcelHelper::convertDateTime($value)
223
        );
224
    }
225
226
    /**
227
     * @param $cellName
228
     * @param $cellIndex
229
     * @param $value
230
     *
231
     * @return string
232
     */
233
    private function getCurrencyCell($cellName, $cellIndex, $value)
234
    {
235
        return sprintf(
236
            '<c r="%s" s="%s" t="n"><v>%s</v></c>',
237
            $cellName,
238
            $cellIndex,
239
            ExcelHelper::xmlspecialchars($value)
240
        );
241
    }
242
243
    /**
244
     * @param $cellName
245
     * @param $cellIndex
246
     * @param $value
247
     *
248
     * @return string
249
     */
250
    private function getIntCell($cellName, $cellIndex, $value)
251
    {
252
        return '<c r="'.$cellName.'" s="'.$cellIndex.'" t="n"><v>'.($value * 1).'</v></c>';
253
    }
254
255
    /**
256
     * @param $cellName
257
     * @param $cellIndex
258
     * @param $value
259
     *
260
     * @return string
261
     */
262
    private function getFormulaCell($cellName, $cellIndex, $value)
263
    {
264
        return sprintf(
265
            '<c r="%s" s="%s" t="s"><f>%s</f></c>',
266
            $cellName,
267
            $cellIndex,
268
            ExcelHelper::xmlspecialchars($value)
269
        );
270
    }
271
}
272