Completed
Push — develop_3.0 ( e1acdc...8a1c48 )
by Adrien
03:37
created

WriterEntityFactory::createWriter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 99
    public static function createWriter($writerType)
24
    {
25 99
        return (new WriterFactory())->create($writerType);
26
    }
27
28
    /**
29
     * @param Cell[] $cells
30
     * @param Style|null $rowStyle
31
     * @return Row
32
     */
33 2
    public static function createRow(array $cells = [], Style $rowStyle = null)
34
    {
35 2
        return new Row($cells, $rowStyle);
36
    }
37
38
    /**
39
     * @param array $cellValues
40
     * @param Style|null $rowStyle
41
     * @return Row
42
     */
43 78
    public static function createRowFromArray(array $cellValues = [], Style $rowStyle = null)
44
    {
45
        $cells = array_map(function ($cellValue) {
46 78
            return new Cell($cellValue);
47 78
        }, $cellValues);
48
49 78
        return new Row($cells, $rowStyle);
50
    }
51
52
    /**
53
     * @param mixed $cellValue
54
     * @param Style|null $cellStyle
55
     * @return Cell
56
     */
57 2
    public static function createCell($cellValue, Style $cellStyle = null)
58
    {
59 2
        return new Cell($cellValue, $cellStyle);
60
    }
61
}
62