Completed
Pull Request — develop_3.0 (#458)
by Adrien
01:54
created

ManagerFactory::createWorksheetManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Box\Spout\Writer\XLSX\Creator;
4
5
use Box\Spout\Writer\Common\Creator\EntityFactory;
6
use Box\Spout\Writer\Common\Creator\ManagerFactoryInterface;
7
use Box\Spout\Writer\Common\Entity\Options;
8
use Box\Spout\Common\Manager\OptionsManagerInterface;
9
use Box\Spout\Writer\Common\Manager\SheetManager;
10
use Box\Spout\Writer\XLSX\Manager\SharedStringsManager;
11
use Box\Spout\Writer\XLSX\Manager\Style\StyleManager;
12
use Box\Spout\Writer\XLSX\Manager\Style\StyleRegistry;
13
use Box\Spout\Writer\XLSX\Manager\WorkbookManager;
14
use Box\Spout\Writer\XLSX\Manager\WorksheetManager;
15
16
/**
17
 * Class ManagerFactory
18
 * Factory for managers needed by the XLSX Writer
19
 *
20
 * @package Box\Spout\Writer\XLSX\Creator
21
 */
22
class ManagerFactory implements ManagerFactoryInterface
23
{
24
    /** @var EntityFactory */
25
    protected $entityFactory;
26
27
    /** @var HelperFactory $helperFactory */
28
    protected $helperFactory;
29
30
    /**
31
     * @param EntityFactory $entityFactory
32
     * @param HelperFactory $helperFactory
33
     */
34 51
    public function __construct(EntityFactory $entityFactory, HelperFactory $helperFactory)
35
    {
36 51
        $this->entityFactory = $entityFactory;
37 51
        $this->helperFactory = $helperFactory;
38 51
    }
39
40
    /**
41
     * @param OptionsManagerInterface $optionsManager
42
     * @return WorkbookManager
43
     */
44 46
    public function createWorkbookManager(OptionsManagerInterface $optionsManager)
45
    {
46 46
        $workbook = $this->entityFactory->createWorkbook();
47
48 46
        $fileSystemHelper = $this->helperFactory->createSpecificFileSystemHelper($optionsManager, $this->entityFactory);
49 46
        $fileSystemHelper->createBaseFilesAndFolders();
50
51 46
        $xlFolder = $fileSystemHelper->getXlFolder();
52 46
        $sharedStringsManager = $this->createSharedStringsManager($xlFolder);
53
54 46
        $styleManager = $this->createStyleManager($optionsManager);
55 46
        $worksheetManager = $this->createWorksheetManager($optionsManager, $styleManager, $sharedStringsManager);
56
57 46
        return new WorkbookManager(
58 46
            $workbook,
59 46
            $optionsManager,
60 46
            $worksheetManager,
61 46
            $styleManager,
62 46
            $fileSystemHelper,
63 46
            $this->entityFactory,
64 46
            $this
65
        );
66
    }
67
68
    /**
69
     * @param OptionsManagerInterface $optionsManager
70
     * @param StyleManager $styleManager
71
     * @param SharedStringsManager $sharedStringsManager
72
     * @return WorksheetManager
73
     */
74 46
    private function createWorksheetManager(
75
        OptionsManagerInterface $optionsManager,
76
        StyleManager $styleManager,
77
        SharedStringsManager $sharedStringsManager
78
    )
79
    {
80 46
        $stringsEscaper = $this->helperFactory->createStringsEscaper();
81 46
        $stringsHelper = $this->helperFactory->createStringHelper();
82
83 46
        return new WorksheetManager($optionsManager, $styleManager, $sharedStringsManager, $stringsEscaper, $stringsHelper, $this->entityFactory);
84
    }
85
86
    /**
87
     * @return SheetManager
88
     */
89 46
    public function createSheetManager()
90
    {
91 46
        $stringHelper = $this->helperFactory->createStringHelper();
92 46
        return new SheetManager($stringHelper);
93
    }
94
95
    /**
96
     * @param OptionsManagerInterface $optionsManager
97
     * @return StyleManager
98
     */
99 46
    private function createStyleManager(OptionsManagerInterface $optionsManager)
100
    {
101 46
        $styleRegistry = $this->createStyleRegistry($optionsManager);
102 46
        return new StyleManager($styleRegistry);
103
    }
104
105
    /**
106
     * @param OptionsManagerInterface $optionsManager
107
     * @return StyleRegistry
108
     */
109 46
    private function createStyleRegistry(OptionsManagerInterface $optionsManager)
110
    {
111 46
        $defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
112 46
        return new StyleRegistry($defaultRowStyle);
113
    }
114
115
    /**
116
     * @param string $xlFolder Path to the "xl" folder
117
     * @return SharedStringsManager
118
     */
119 46
    private function createSharedStringsManager($xlFolder)
120
    {
121 46
        $stringEscaper = $this->helperFactory->createStringsEscaper();
122 46
        return new SharedStringsManager($xlFolder, $stringEscaper);
123
    }
124
}
125