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

AbstractReader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A readFile() 0 13 3
readFromFile() 0 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