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

EntityFactory::createCell()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 2
crap 2
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