Reader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A readFile() 0 10 2
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