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

WriterEntityFactory::createODSWriter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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