Completed
Push — master ( 519f91...54876d )
by Hong
02:27
created

Reader::readFile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Shared
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Shared\Reader;
16
17
use Phossa2\Shared\Message\Message;
18
use Phossa2\Shared\Base\StaticAbstract;
19
use Phossa2\Shared\Exception\RuntimeException;
20
21
/**
22
 * Reader
23
 *
24
 * Read from file base on the suffix
25
 *
26
 * @package Phossa2\Shared
27
 * @author  Hong Zhang <[email protected]>
28
 * @version 2.0.2
29
 * @since   2.0.2 added
30
 */
31
class Reader extends StaticAbstract implements ReaderInterface
32
{
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public static function readFile(/*# string */ $path)
37
    {
38
        $suffix = substr($path, strpos($path, '.') + 1);
39
        $class  = static::getNameSpace() . '\\' . ucfirst($suffix) . 'Reader';
40
41
        if (class_exists($class)) {
42
            /* @var ReaderInterface $class */;
43
            return $class::readFile($path);
44
        }
45
46
        throw new RuntimeException(
47
            Message::get(Message::MSG_PATH_TYPE_UNKNOWN, $suffix),
48
            Message::MSG_PATH_TYPE_UNKNOWN
49
        );
50
    }
51
}
52