Failed Conditions
Pull Request — develop_3.0 (#507)
by Adrien
02:47
created

InternalEntityFactory::createSheet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 8
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Options;
7
use Box\Spout\Reader\Common\XMLProcessor;
8
use Box\Spout\Reader\Wrapper\XMLReader;
9
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
10
use Box\Spout\Reader\XLSX\RowIterator;
11
use Box\Spout\Reader\XLSX\Sheet;
12
use Box\Spout\Reader\XLSX\SheetIterator;
13
14
/**
15
 * Class EntityFactory
16
 * Factory to create entities
17
 */
18
class InternalEntityFactory implements InternalEntityFactoryInterface
19
{
20
    /** @var HelperFactory */
21
    private $helperFactory;
22
23
    /** @var ManagerFactory */
24
    private $managerFactory;
25
26
    /**
27
     * @param ManagerFactory $managerFactory
28
     * @param HelperFactory $helperFactory
29
     */
30 50
    public function __construct(ManagerFactory $managerFactory, HelperFactory $helperFactory)
31
    {
32 50
        $this->managerFactory = $managerFactory;
33 50
        $this->helperFactory = $helperFactory;
34 50
    }
35
36
    /**
37
     * @param string $filePath Path of the file to be read
38
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
39
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
40
     * @return SheetIterator
41
     */
42 39
    public function createSheetIterator($filePath, $optionsManager, $sharedStringsManager)
43
    {
44 39
        $sheetManager = $this->managerFactory->createSheetManager($filePath, $optionsManager, $sharedStringsManager, $this);
45
46 39
        return new SheetIterator($sheetManager);
47
    }
48
49
    /**
50
     * @param string $filePath Path of the XLSX file being read
51
     * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
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
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
58
     * @return Sheet
59
     */
60 38
    public function createSheet(
61
        $filePath,
62
        $sheetDataXMLFilePath,
63
        $sheetIndex,
64
        $sheetName,
65
        $isSheetActive,
66
        $isSheetVisible,
67
        $optionsManager,
68
        $sharedStringsManager
69
    ) {
70 38
        $rowIterator = $this->createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager);
71
72 38
        return new Sheet($rowIterator, $sheetIndex, $sheetName, $isSheetActive, $isSheetVisible);
73
    }
74
75
    /**
76
     * @param string $filePath Path of the XLSX file being read
77
     * @param string $sheetDataXMLFilePath Path of the sheet data XML file as in [Content_Types].xml
78
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
79
     * @param SharedStringsManager $sharedStringsManager Manages shared strings
80
     * @return RowIterator
81
     */
82 38
    private function createRowIterator($filePath, $sheetDataXMLFilePath, $optionsManager, $sharedStringsManager)
83
    {
84 38
        $xmlReader = $this->createXMLReader();
85 38
        $xmlProcessor = $this->createXMLProcessor($xmlReader);
86
87 38
        $styleManager = $this->managerFactory->createStyleManager($filePath, $this);
88 38
        $shouldFormatDates = $optionsManager->getOption(Options::SHOULD_FORMAT_DATES);
89 38
        $shouldUse1904Dates = $optionsManager->getOption(Options::SHOULD_USE_1904_DATES);
90
91 38
        $cellValueFormatter = $this->helperFactory->createCellValueFormatter(
92 38
            $sharedStringsManager,
93 38
            $styleManager,
94 38
            $shouldFormatDates,
95 38
            $shouldUse1904Dates
96
        );
97
98 38
        $shouldPreserveEmptyRows = $optionsManager->getOption(Options::SHOULD_PRESERVE_EMPTY_ROWS);
99
100 38
        return new RowIterator(
101 38
            $filePath,
102 38
            $sheetDataXMLFilePath,
103 38
            $shouldPreserveEmptyRows,
104 38
            $xmlReader,
105 38
            $xmlProcessor,
106 38
            $cellValueFormatter
107
        );
108
    }
109
110
    /**
111
     * @return \ZipArchive
112
     */
113 41
    public function createZipArchive()
114
    {
115 41
        return new \ZipArchive();
116
    }
117
118
    /**
119
     * @return XMLReader
120
     */
121 46
    public function createXMLReader()
122
    {
123 46
        return new XMLReader();
124
    }
125
126
    /**
127
     * @param $xmlReader
128
     * @return XMLProcessor
129
     */
130 39
    public function createXMLProcessor($xmlReader)
131
    {
132 39
        return new XMLProcessor($xmlReader);
133
    }
134
}
135