Completed
Pull Request — develop_3.0 (#633)
by
unknown
04:08
created

WriterEntityFactory   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 73
ccs 10
cts 16
cp 0.625
rs 10
c 0
b 0
f 0

7 Methods

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