Passed
Pull Request — develop_3.0 (#495)
by Adrien
02:52
created

ManagerFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 12
dl 0
loc 137
ccs 51
cts 51
cp 1
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B createWorkbookManager() 0 25 1
A createWorksheetManager() 0 21 1
A createSheetManager() 0 6 1
A createRowManager() 0 4 1
A createStyleManager() 0 6 1
A createStyleRegistry() 0 6 1
A createStyleMerger() 0 4 1
A createSharedStringsManager() 0 6 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 $helperFactory */
28
    protected $helperFactory;
29
30
    /**
31
     * @param InternalEntityFactory $entityFactory
32
     * @param HelperFactory $helperFactory
33
     */
34 44
    public function __construct(InternalEntityFactory $entityFactory, HelperFactory $helperFactory)
35
    {
36 44
        $this->entityFactory = $entityFactory;
37 44
        $this->helperFactory = $helperFactory;
38 44
    }
39
40
    /**
41
     * @param OptionsManagerInterface $optionsManager
42
     * @return WorkbookManager
43
     */
44 39
    public function createWorkbookManager(OptionsManagerInterface $optionsManager)
45
    {
46 39
        $workbook = $this->entityFactory->createWorkbook();
47
48 39
        $fileSystemHelper = $this->helperFactory->createSpecificFileSystemHelper($optionsManager, $this->entityFactory);
49 39
        $fileSystemHelper->createBaseFilesAndFolders();
50
51 39
        $xlFolder = $fileSystemHelper->getXlFolder();
52 39
        $sharedStringsManager = $this->createSharedStringsManager($xlFolder);
53
54 39
        $styleMerger = $this->createStyleMerger();
55 39
        $styleManager = $this->createStyleManager($optionsManager);
56 39
        $worksheetManager = $this->createWorksheetManager($optionsManager, $styleManager, $styleMerger, $sharedStringsManager);
57
58 39
        return new WorkbookManager(
59 39
            $workbook,
60 39
            $optionsManager,
61 39
            $worksheetManager,
62 39
            $styleManager,
63 39
            $styleMerger,
64 39
            $fileSystemHelper,
65 39
            $this->entityFactory,
66 39
            $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 39
    private function createWorksheetManager(
78
        OptionsManagerInterface $optionsManager,
79
        StyleManager $styleManager,
80
        StyleMerger $styleMerger,
81
        SharedStringsManager $sharedStringsManager
82
    ) {
83 39
        $rowManager = $this->createRowManager($styleMerger);
84 39
        $stringsEscaper = $this->helperFactory->createStringsEscaper();
85 39
        $stringsHelper = $this->helperFactory->createStringHelper();
86
87 39
        return new WorksheetManager(
88 39
            $optionsManager,
89 39
            $rowManager,
90 39
            $styleManager,
91 39
            $styleMerger,
92 39
            $sharedStringsManager,
93 39
            $stringsEscaper,
94 39
            $stringsHelper,
95 39
            $this->entityFactory
96
        );
97
    }
98
99
    /**
100
     * @return SheetManager
101
     */
102 39
    public function createSheetManager()
103
    {
104 39
        $stringHelper = $this->helperFactory->createStringHelper();
105
106 39
        return new SheetManager($stringHelper);
107
    }
108
109
    /**
110
     * @param StyleMerger $styleMerger
111
     * @return RowManager
112
     */
113 39
    public function createRowManager(StyleMerger $styleMerger)
114
    {
115 39
        return new RowManager($styleMerger);
116
    }
117
118
    /**
119
     * @param OptionsManagerInterface $optionsManager
120
     * @return StyleManager
121
     */
122 39
    private function createStyleManager(OptionsManagerInterface $optionsManager)
123
    {
124 39
        $styleRegistry = $this->createStyleRegistry($optionsManager);
125
126 39
        return new StyleManager($styleRegistry);
127
    }
128
129
    /**
130
     * @param OptionsManagerInterface $optionsManager
131
     * @return StyleRegistry
132
     */
133 39
    private function createStyleRegistry(OptionsManagerInterface $optionsManager)
134
    {
135 39
        $defaultRowStyle = $optionsManager->getOption(Options::DEFAULT_ROW_STYLE);
136
137 39
        return new StyleRegistry($defaultRowStyle);
138
    }
139
140
    /**
141
     * @return StyleMerger
142
     */
143 39
    private function createStyleMerger()
144
    {
145 39
        return new StyleMerger();
146
    }
147
148
    /**
149
     * @param string $xlFolder Path to the "xl" folder
150
     * @return SharedStringsManager
151
     */
152 39
    private function createSharedStringsManager($xlFolder)
153
    {
154 39
        $stringEscaper = $this->helperFactory->createStringsEscaper();
155
156 39
        return new SharedStringsManager($xlFolder, $stringEscaper);
157
    }
158
}
159