Test Failed
Push — feature/53-multi-sheet-writing ( 58a074 )
by Stefan
07:08 queued 14s
created

Workbook::getDefinedNamesXml()   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\DefaultXml;
6
use OneSheet\Xml\WorkbookXml;
7
8
class Workbook
9
{
10
    /**
11
     * @var int
12
     */
13
    private $printTitleStart;
14
15
    /**
16
     * @var int
17
     */
18
    private $printTitleEnd;
19
20
    /**
21
     * Set the range of rows to repeat when printing the excel file.
22
     * $startRow=1 and $endRow=1 will repeat the first row only.
23
     *
24
     * @param int $startRow
25
     * @param int $endRow
26
     */
27
    public function setPrintTitleRange($startRow, $endRow)
28
    {
29
        if ($startRow <= $endRow && is_numeric($startRow) && is_numeric($endRow)) {
30
            $this->printTitleStart = (int)$startRow;
31
            $this->printTitleEnd = (int)$endRow;
32
        }
33
    }
34
35
    /**
36
     * @param array $sheetIds
37
     * @return string
38
     */
39
    public function getWorkbookXml(array $sheetIds)
40
    {
41
        $sheets = $this->getSheetsXml($sheetIds);
42
        $definedNames = $this->getDefinedNamesXml();
43
44
        return sprintf(WorkbookXml::WORKBOOK_XML, $sheets, $definedNames);
45
    }
46
47
    /**
48
     * @param array $sheetIds
49
     * @return string
50
     */
51 View Code Duplication
    public function getWorkbookRelsXml($sheetIds)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $sheets = '';
54
        foreach ($sheetIds as $key => $sheetId) {
55
            $sheets .= sprintf(WorkbookXml::WORKBOOK_REL_XML, $key + 1, $sheetId);
56
        }
57
58
        return sprintf(WorkbookXml::WORKBOOK_RELS_XML, $sheets);
59
    }
60
61
    /**
62
     * @param array $sheetIds
63
     * @return string
64
     */
65 View Code Duplication
    private function getSheetsXml($sheetIds)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $sheets = '';
68
        foreach ($sheetIds as $key => $sheetId) {
69
            $sheets .= sprintf(WorkbookXml::WORKBOOK_SHEETS_XML, $sheetId, $key + 1, $key + 1);
70
        }
71
72
        return $sheets;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    private function getDefinedNamesXml()
79
    {
80
        $definedNames = '';
81
        if ($this->printTitleStart && $this->printTitleEnd) {
82
            $definedNames = sprintf(
83
                WorkbookXml::DEFINED_NAMES_XML,
84
                $this->printTitleStart,
85
                $this->printTitleEnd
86
            );
87
        }
88
89
        return $definedNames;
90
    }
91
}
92