Failed Conditions
Pull Request — develop_3.0 (#434)
by Hura
03:16
created

EntityFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 55
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createWorkbook() 0 4 1
A createWorksheet() 0 4 1
A createSheet() 0 5 1
A createRow() 0 5 1
1
<?php
2
3
namespace Box\Spout\Writer\Common\Creator;
4
5
use Box\Spout\Writer\Common\Entity\Row;
6
use Box\Spout\Writer\Common\Entity\Sheet;
7
use Box\Spout\Writer\Common\Entity\Style\Style;
8
use Box\Spout\Writer\Common\Entity\Workbook;
9
use Box\Spout\Writer\Common\Entity\Worksheet;
10
11
/**
12
 * Class EntityFactory
13
 * Factory to create entities
14
 *
15
 * @package Box\Spout\Writer\Common\Creator
16
 */
17
class EntityFactory
18
{
19
    /** @var ManagerFactory */
20
    private $managerFactory;
21
22
    /**
23
     * EntityFactory constructor.
24
     *
25
     * @param ManagerFactory $managerFactory
26
     */
27 107
    public function __construct(ManagerFactory $managerFactory)
28
    {
29 107
        $this->managerFactory = $managerFactory;
30 107
    }
31
32
    /**
33
     * @return Workbook
34
     */
35 78
    public function createWorkbook()
36
    {
37 78
        return new Workbook();
38
    }
39
40
    /**
41
     * @param string $worksheetFilePath
42
     * @param Sheet $externalSheet
43
     * @return Worksheet
44
     */
45 78
    public function createWorksheet($worksheetFilePath, Sheet $externalSheet)
46
    {
47 78
        return new Worksheet($worksheetFilePath, $externalSheet);
48
    }
49
50
    /**
51
     * @param int $sheetIndex Index of the sheet, based on order in the workbook (zero-based)
52
     * @param string $associatedWorkbookId ID of the sheet's associated workbook
53
     * @return Sheet
54
     */
55 78
    public function createSheet($sheetIndex, $associatedWorkbookId)
56
    {
57 78
        $sheetManager = $this->managerFactory->createSheetManager();
58 78
        return new Sheet($sheetIndex, $associatedWorkbookId, $sheetManager);
59
    }
60
61
    /**
62
     * @param array $cells
63
     * @param Style|null $style
64
     * @return Row
65
     */
66 1
    public function createRow(array $cells, Style $style = null)
67
    {
68 1
        $rowManager = $this->managerFactory->createRowManager();
69 1
        return new Row($cells, $style, $rowManager);
70
    }
71
}