Completed
Pull Request — develop_3.0 (#595)
by Hura
05:29
created

ReaderEntityFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 27
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createReader() 0 4 1
A createReaderFromFile() 0 4 1
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 6
    public static function createReaderFromFile(string $path)
34
    {
35 6
        return (new ReaderFactory())->createFromFile($path);
36
    }
37
}
38