ReaderEntityFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 56
ccs 8
cts 14
cp 0.5714
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createReaderFromFile() 0 4 1
A createCSVReader() 0 8 2
A createXLSXReader() 0 8 2
A createODSReader() 0 8 2
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