Passed
Pull Request — develop_3.0 (#508)
by Adrien
02:50
created

InternalEntityFactory::createRow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Box\Spout\Reader\XLSX\Creator;
4
5
use Box\Spout\Reader\Common\Creator\InternalEntityFactoryInterface;
6
use Box\Spout\Reader\Common\Entity\Cell;
7
use Box\Spout\Reader\Common\Entity\Options;
8
use Box\Spout\Reader\Common\Entity\Row;
9
use Box\Spout\Reader\Common\XMLProcessor;
10
use Box\Spout\Reader\Wrapper\XMLReader;
11
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
12
use Box\Spout\Reader\XLSX\RowIterator;
13
use Box\Spout\Reader\XLSX\Sheet;
14
use Box\Spout\Reader\XLSX\SheetIterator;
15
16
/**
17
 * Class EntityFactory
18
 * Factory to create entities
19
 */
20
class InternalEntityFactory implements InternalEntityFactoryInterface
21
{
22
    /** @var HelperFactory */
23
    private $helperFactory;
24
25
    /** @var ManagerFactory */
26
    private $managerFactory;
27
28
    /**
29
     * @param ManagerFactory $managerFactory
30
     * @param HelperFactory $helperFactory
31
     */
32 56
    public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory)
33
    {
34 56
        $this->managerFactory = $managerFactory;
35 56
        $this->helperFactory = $helperFactory;
36 56
    }
37
38
    /**
39
     * @param string $filePath Path of the file to be read
40
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
41
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
42
     * @return SheetIterator
43
     */
44 39
    public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager)
45
    {
46 39
        $sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this);
47
48 39
        return new SheetIterator($sheetManager);
49
    }
50
51
    /**
52
     * @param string $filePath Path of the XLSX file being read
53
     * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
54
     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
55
     * @param string $sheetName Name of the sheet
56
     * @param bool $isSheetActive Whether the sheet was defined as active
57
     * @param bool $isSheetVisible Whether the sheet is visible
58
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
59
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
60
     * @return Sheet
61
     */
62 38
    public function createSheet(
63
        $filePath,
64
        $sheetDataXMLFilePath,
65
        $sheetIndex,
66
        $sheetName,
67
        $isSheetActive,
68
        $isSheetVisible,
69
        $optionsManager,
70
        $sharedStringsManager
71
    ) {
72 38
        $rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager);
73
74 38
        return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible);
75
    }
76
77
    /**
78
     * @param string $filePath Path of the XLSX file being read
79
     * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
80
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
81
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
82
     * @return RowIterator
83
     */
84 38
    private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager)
85
    {
86 38
        $xmlReader = $this->createXMLReader();
87 38
        $xmlProcessor = $this->createXMLProcessor($xmlReader);
88
89 38
        $styleManager = $this->managerFactory->createStyleManager($filePath, $this);
90 38
        $rowManager = $this->managerFactory->createRowManager($this);
91 38
        $shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES);
92 38
        $shouldUse1904Dates = $optionsManager->getOption(Options::SHOULD_USE_1904_DATES);
93
94 38
        $cellValueFormatter = $this->helperFactory->createCellValueFormatter(
95 38
            $sharedStringsManager,
96 38
            $styleManager,
97 38
            $shouldFormatDates,
98 38
            $shouldUse1904Dates
99
        );
100
101 38
        $shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
102
103 38
        return new RowIterator(
104 38
            $filePath,
105 38
            $sheetDataXMLFilePath,
106 38
            $shouldPreserveEmptyRows,
107 38
            $xmlReader,
108 38
            $xmlProcessor,
109 38
            $cellValueFormatter,
110 38
            $rowManager,
111 38
            $this
112
        );
113
    }
114
115
    /**
116
     * @param Cell[] $cells
117
     * @return Row
118
     */
119 35
    public function createRow(array $cells)
120
    {
121 35
        return new Row($cells);
122
    }
123
124
    /**
125
     * @param mixed $cellValue
126
     * @return Cell
127
     */
128 35
    public function createCell($cellValue)
129
    {
130 35
        return new Cell($cellValue);
131
    }
132
133
    /**
134
     * @return \ZipArchive
135
     */
136 41
    public function createZipArchive()
137
    {
138 41
        return new \ZipArchive();
139
    }
140
141
    /**
142
     * @return XMLReader
143
     */
144 46
    public function createXMLReader()
145
    {
146 46
        return new XMLReader();
147
    }
148
149
    /**
150
     * @param $xmlReader
151
     * @return XMLProcessor
152
     */
153 39
    public function createXMLProcessor($xmlReader)
154
    {
155 39
        return new XMLProcessor($xmlReader);
156
    }
157
}
158