Test Setup Failed
Push — feature/issue-46-add-repeatabl... ( 599383 )
by Stefan
06:26
created

Workbook::getWorkbookXml()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 2
nop 0
1
<?php
2
3
namespace OneSheet;
4
5
use OneSheet\Xml\WorkbookXml;
6
7
class Workbook
8
{
9
    /**
10
     * @var int
11
     */
12
    private $printTitleStart;
13
14
    /**
15
     * @var int
16
     */
17
    private $printTitleEnd;
18
19
    /**
20
     * Set the range of rows to repeat when printing the excel file.
21
     * $startRow=1 and $endRow=1 will repeat the first row only.
22
     *
23
     * @param int $startRow
24
     * @param int $endRow
25
     */
26
    public function setPrintTitleRange($startRow, $endRow)
27
    {
28
        if ($startRow <= $endRow && is_numeric($startRow) && is_numeric($endRow)) {
29
            $this->printTitleStart = (int)$startRow;
30
            $this->printTitleEnd = (int)$endRow;
31
        }
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function getWorkbookXml()
38
    {
39
        $definedNames = '';
40
        if ($this->printTitleStart && $this->printTitleEnd) {
41
            $definedNames = sprintf(
42
                WorkbookXml::DEFINED_NAMES_XML,
43
                $this->printTitleStart,
44
                $this->printTitleEnd
45
            );
46
        }
47
48
        return sprintf(WorkbookXml::WORKBOOK_XML, $definedNames);
49
    }
50
}