Passed
Pull Request — develop_3.0 (#490)
by Adrien
02:41
created

EntityFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 54
ccs 9
cts 15
cp 0.6
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createWriter() 0 4 1
A createRow() 0 7 1
A createRowFromArray() 0 11 1
A createCell() 0 4 1
1
<?php
2
3
namespace Box\Spout\Writer\Common\Creator;
4
5
use Box\Spout\Writer\Common\Entity\Cell;
6
use Box\Spout\Writer\Common\Entity\Row;
7
use Box\Spout\Writer\Common\Entity\Style\Style;
8
use Box\Spout\Writer\Common\Manager\RowManager;
9
use Box\Spout\Writer\Common\Manager\Style\StyleMerger;
10
use Box\Spout\Writer\WriterInterface;
11
12
/**
13
 * Class EntityFactory
14
 * Factory to create external entities
15
 */
16
class EntityFactory
17
{
18
    /**
19
     * This creates an instance of the appropriate writer, given the type of the file to be read
20
     *
21
     * @param  string $writerType Type of the writer to instantiate
22
     * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
23
     * @return WriterInterface
24
     */
25 94
    public static function createWriter($writerType)
26
    {
27 94
        return (new WriterFactory())->create($writerType);
28
    }
29
30
    /**
31
     * @param Cell[] $cells
32
     * @param Style|null $rowStyle
33
     * @return Row
34
     */
35
    public static function createRow(array $cells = [], Style $rowStyle = null)
36
    {
37
        $styleMerger = new StyleMerger();
38
        $rowManager = new RowManager($styleMerger);
39
40
        return new Row($cells, $rowStyle, $rowManager);
41
    }
42
43
    /**
44
     * @param array $cellValues
45
     * @param Style|null $rowStyle
46
     * @return Row
47
     */
48 75
    public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
49
    {
50 75
        $styleMerger = new StyleMerger();
51 75
        $rowManager = new RowManager($styleMerger);
52
53 75
        $cells = array_map(function ($cellValue) {
54 75
            return new Cell($cellValue);
55 75
        }, $cellValues);
56
57 75
        return new Row($cells, $rowStyle, $rowManager);
58
    }
59
60
    /**
61
     * @param mixed $cellValue
62
     * @param Style|null $cellStyle
63
     * @return Cell
64
     */
65
    public static function createCell($cellValue, Style $cellStyle = null)
66
    {
67
        return new Cell($cellValue, $cellStyle);
68
    }
69
}
70