Passed
Pull Request — develop_3.0 (#510)
by Adrien
02:39
created

InternalEntityFactory::createCell()   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\ODS\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\ODS\RowIterator;
11
use Box\Spout\Reader\ODS\Sheet;
12
use Box\Spout\Reader\ODS\SheetIterator;
13
use Box\Spout\Reader\Wrapper\XMLReader;
14
15
/**
16
 * Class EntityFactory
17
 * Factory to create entities
18
 */
19
class InternalEntityFactory implements InternalEntityFactoryInterface
20
{
21
    /** @var HelperFactory */
22
    private $helperFactory;
23
24
    /** @var ManagerFactory */
25
    private $managerFactory;
26
27
    /**
28
     * @param HelperFactory $helperFactory
29
     * @param ManagerFactory $managerFactory
30
     */
31 34
    public function __construct(HelperFactory $helperFactory, ManagerFactory $managerFactory)
32
    {
33 34
        $this->helperFactory = $helperFactory;
34 34
        $this->managerFactory = $managerFactory;
35 34
    }
36
37
    /**
38
     * @param string $filePath Path of the file to be read
39
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
40
     * @return SheetIterator
41
     */
42 31
    public function createSheetIterator($filePath, $optionsManager)
43
    {
44 31
        $escaper = $this->helperFactory->createStringsEscaper();
45 31
        $settingsHelper = $this->helperFactory->createSettingsHelper($this);
46
47 31
        return new SheetIterator($filePath, $optionsManager, $escaper, $settingsHelper, $this);
48
    }
49
50
    /**
51
     * @param XMLReader $xmlReader XML Reader
52
     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
53
     * @param string $sheetName Name of the sheet
54
     * @param bool $isSheetActive Whether the sheet was defined as active
55
     * @param bool $isSheetVisible Whether the sheet is visible
56
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
57
     * @return Sheet
58
     */
59 29
    public function createSheet($xmlReader, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible, $optionsManager)
60
    {
61 29
        $rowIterator = $this->createRowIterator($xmlReader, $optionsManager);
62
63 29
        return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible);
64
    }
65
66
    /**
67
     * @param XMLReader $xmlReader XML Reader
68
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
69
     * @return RowIterator
70
     */
71 29
    private function createRowIterator($xmlReader, $optionsManager)
72
    {
73 29
        $shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES);
74 29
        $cellValueFormatter = $this->helperFactory->createCellValueFormatter($shouldFormatDates);
75 29
        $xmlProcessor = $this->createXMLProcessor($xmlReader);
76 29
        $rowManager = $this->managerFactory->createRowManager();
77
78 29
        return new RowIterator($xmlReader, $optionsManager, $cellValueFormatter, $xmlProcessor, $rowManager, $this);
79
    }
80
81
    /**
82
     * @param Cell[] $cells
83
     * @return Row
84
     */
85 26
    public function createRow(array $cells)
86
    {
87 26
        return new Row($cells);
88
    }
89
90
    /**
91
     * @param mixed $cellValue
92
     * @return Cell
93
     */
94 26
    public function createCell($cellValue)
95
    {
96 26
        return new Cell($cellValue);
97
    }
98
99
    /**
100
     * @return XMLReader
101
     */
102 31
    public function createXMLReader()
103
    {
104 31
        return new XMLReader();
105
    }
106
107
    /**
108
     * @param $xmlReader
109
     * @return XMLProcessor
110
     */
111 29
    private function createXMLProcessor($xmlReader)
112
    {
113 29
        return new XMLProcessor($xmlReader);
114
    }
115
116
    /**
117
     * @return \ZipArchive
118
     */
119 31
    public function createZipArchive()
120
    {
121 31
        return new \ZipArchive();
122
    }
123
}
124