Completed
Push — master ( a163aa...987430 )
by Hong
01:40
created

Reader::readFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Base
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Base\Reader;
13
14
/**
15
 * Reader
16
 *
17
 * @package Phoole\Base
18
 */
19
class Reader implements ReaderInterface
20
{
21
    /**
22
     * supported types
23
     *
24
     * @var    string[]
25
     */
26
    protected $supported = [
27
        'json' => __NAMESPACE__ . '\JsonReader',
28
        'php'  => __NAMESPACE__ . '\PhpReader',
29
        'yml'  => __NAMESPACE__ . '\YamlReader'
30
    ];
31
32
    /**
33
     * {@inheritDoc}
34
     */
35
    public function readFile(string $path)
36
    {
37
        $suffix = substr($path, strpos($path, '.') + 1);
38
39
        if (!isset($this->supported[$suffix])) {
40
            throw new \RuntimeException("non-supported type $suffix");
41
        }
42
43
        return (new $this->supported[$suffix]())->readFile($path);
44
    }
45
}
46