ReaderEntityFactory::createODSReader()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.5

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 2
cts 4
cp 0.5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2.5
1
<?php
2
3
namespace Box\Spout\Reader\Common\Creator;
4
5
use Box\Spout\Common\Exception\UnsupportedTypeException;
6
use Box\Spout\Common\Type;
7
use Box\Spout\Reader\ReaderInterface;
8
9
/**
10
 * Class ReaderEntityFactory
11
 * Factory to create external entities
12
 */
13
class ReaderEntityFactory
14
{
15
    /**
16
     * Creates a reader by file extension
17
     *
18
     * @param string $path The path to the spreadsheet file. Supported extensions are .csv, .ods and .xlsx
19
     * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
20
     * @return ReaderInterface
21
     */
22 7
    public static function createReaderFromFile(string $path)
23
    {
24 7
        return ReaderFactory::createFromFile($path);
25
    }
26
27
    /**
28
     * This creates an instance of a CSV reader
29
     *
30
     * @return \Box\Spout\Reader\CSV\Reader
31
     */
32 1
    public static function createCSVReader()
33
    {
34
        try {
35 1
            return ReaderFactory::createFromType(Type::CSV);
36
        } catch (UnsupportedTypeException $e) {
37
            // should never happen
38
        }
39
    }
40
41
    /**
42
     * This creates an instance of a XLSX reader
43
     *
44
     * @return \Box\Spout\Reader\XLSX\Reader
45
     */
46 47
    public static function createXLSXReader()
47
    {
48
        try {
49 47
            return ReaderFactory::createFromType(Type::XLSX);
50
        } catch (UnsupportedTypeException $e) {
51
            // should never happen
52
        }
53
    }
54
55
    /**
56
     * This creates an instance of a ODS reader
57
     *
58
     * @return \Box\Spout\Reader\ODS\Reader
59
     */
60 33
    public static function createODSReader()
61
    {
62
        try {
63 33
            return ReaderFactory::createFromType(Type::ODS);
64
        } catch (UnsupportedTypeException $e) {
65
            // should never happen
66
        }
67
    }
68
}
69