ManagerFactory::createStyleRegistry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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