Passed
Push — develop_3.0 ( a665b9...78b663 )
by Adrien
04:18 queued 01:35
created

createWorkbookRelationshipsManager()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Box\Spout\Reader\XLSX\Creator;
4
5
use Box\Spout\Reader\XLSX\Manager\RowManager;
6
use Box\Spout\Reader\XLSX\Manager\SharedStringsCaching\CachingStrategyFactory;
7
use Box\Spout\Reader\XLSX\Manager\SharedStringsManager;
8
use Box\Spout\Reader\XLSX\Manager\SheetManager;
9
use Box\Spout\Reader\XLSX\Manager\StyleManager;
10
use Box\Spout\Reader\XLSX\Manager\WorkbookRelationshipsManager;
11
12
/**
13
 * Class ManagerFactory
14
 * Factory to create managers
15
 */
16
class ManagerFactory
17
{
18
    /** @var HelperFactory */
19
    private $helperFactory;
20
21
    /** @var CachingStrategyFactory */
22
    private $cachingStrategyFactory;
23
24
    /** @var WorkbookRelationshipsManager */
25
    private $cachedWorkbookRelationshipsManager;
26
27
    /**
28
     * @param HelperFactory $helperFactory Factory to create helpers
29
     * @param CachingStrategyFactory $cachingStrategyFactory Factory to create shared strings caching strategies
30
     */
31 50
    public function __construct(HelperFactory $helperFactory, CachingStrategyFactory $cachingStrategyFactory)
32
    {
33 50
        $this->helperFactory = $helperFactory;
34 50
        $this->cachingStrategyFactory = $cachingStrategyFactory;
35 50
    }
36
37
    /**
38
     * @param string $filePath Path of the XLSX file being read
39
     * @param string $tempFolder Temporary folder where the temporary files to store shared strings will be stored
40
     * @param InternalEntityFactory $entityFactory Factory to create entities
41
     * @return SharedStringsManager
42
     */
43 40
    public function createSharedStringsManager($filePath, $tempFolder, $entityFactory)
44
    {
45 40
        $workbookRelationshipsManager = $this->createWorkbookRelationshipsManager($filePath, $entityFactory);
46
47 40
        return new SharedStringsManager(
48 40
            $filePath,
49 40
            $tempFolder,
50 40
            $workbookRelationshipsManager,
51 40
            $entityFactory,
52 40
            $this->helperFactory,
53 40
            $this->cachingStrategyFactory
54
        );
55
    }
56
57
    /**
58
     * @param string $filePath Path of the XLSX file being read
59
     * @param InternalEntityFactory $entityFactory Factory to create entities
60
     * @return WorkbookRelationshipsManager
61
     */
62 40
    private function createWorkbookRelationshipsManager($filePath, $entityFactory)
63
    {
64 40
        if (!isset($this->cachedWorkbookRelationshipsManager)) {
65 40
            $this->cachedWorkbookRelationshipsManager = new WorkbookRelationshipsManager($filePath, $entityFactory);
66
        }
67
68 40
        return $this->cachedWorkbookRelationshipsManager;
69
    }
70
71
    /**
72
     * @param string $filePath Path of the XLSX file being read
73
     * @param \Box\Spout\Common\Manager\OptionsManagerInterface $optionsManager Reader's options manager
74
     * @param \Box\Spout\Reader\XLSX\Manager\SharedStringsManager $sharedStringsManager Manages shared strings
75
     * @param InternalEntityFactory $entityFactory Factory to create entities
76
     * @return SheetManager
77
     */
78 39
    public function createSheetManager($filePath, $optionsManager, $sharedStringsManager, $entityFactory)
79
    {
80 39
        $escaper = $this->helperFactory->createStringsEscaper();
81
82 39
        return new SheetManager($filePath, $optionsManager, $sharedStringsManager, $escaper, $entityFactory);
83
    }
84
85
    /**
86
     * @param string $filePath Path of the XLSX file being read
87
     * @param InternalEntityFactory $entityFactory Factory to create entities
88
     * @return StyleManager
89
     */
90 38
    public function createStyleManager($filePath, $entityFactory)
91
    {
92 38
        $workbookRelationshipsManager = $this->createWorkbookRelationshipsManager($filePath, $entityFactory);
93
94 38
        return new StyleManager($filePath, $workbookRelationshipsManager, $entityFactory);
95
    }
96
97
    /**
98
     * @param InternalEntityFactory $entityFactory Factory to create entities
99
     * @return RowManager
100
     */
101 38
    public function createRowManager($entityFactory)
102
    {
103 38
        return new RowManager($entityFactory);
104
    }
105
}
106