Completed
Pull Request — develop_3.0 (#595)
by Hura
15:36
created

ReaderEntityFactory::createReaderFromFile()   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 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Box\Spout\Reader\Common\Creator;
4
5
use Box\Spout\Reader\ReaderInterface;
6
7
/**
8
 * Class ReaderEntityFactory
9
 * Factory to create external entities
10
 */
11
class ReaderEntityFactory
12
{
13
    /**
14
     * This creates an instance of the appropriate reader, given the type of the file to be read
15
     *
16
     * @param  string $readerType Type of the reader to instantiate
17
     * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
18
     * @return ReaderInterface
19
     */
20 79
    public static function createReader($readerType)
21
    {
22 79
        return (new ReaderFactory())->create($readerType);
23
    }
24
25
    /**
26
     * Creates a reader by file extension
27
     *
28
     * @param string The path to the spreadsheet file. Supported extensions are .csv,.ods and .xlsx
29
     * @throws \Box\Spout\Common\Exception\IOException
30
     * @throws \Box\Spout\Common\Exception\UnsupportedTypeException
31
     * @return ReaderInterface
32
     */
33
    public static function createReaderFromFile(string $path)
34
    {
35
        return (new ReaderFactory())->createFromFile($path);
36
    }
37
}
38