Completed
Push — master ( 0813f7...c7b80b )
by Hong
01:46
created

AbstractReader::readFile()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
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
 * AbstractReader
16
 *
17
 * @package Phoole\Base
18
 */
19
abstract class AbstractReader implements ReaderInterface
20
{
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function readFile(string $path)
25
    {
26
        if (!file_exists($path)) {
27
            throw new \RuntimeException("$path not found");
28
        }
29
30
        if (!is_readable($path)) {
31
            throw new \RuntimeException("$path not readable");
32
        }
33
34
        // read file
35
        return $this->readFromFile($path);
36
    }
37
38
    /**
39
     * Truly read from the file
40
     *
41
     * @param  string $path
42
     * @throws \RuntimeException  if something goes wrong
43
     * @return mixed
44
     */
45
    abstract protected function readFromFile($path);
46
}
47