Completed
Push — master ( 726362...d621a8 )
by Hong
03:08
created

ReaderAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkPath() 0 16 3
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
use Phossa2\Shared\Exception\NotFoundException;
21
22
/**
23
 * ReaderAbstract
24
 *
25
 * @package Phossa2\Shared
26
 * @author  Hong Zhang <[email protected]>
27
 * @version 2.0.1
28
 * @since   2.0.1 added
29
 */
30
abstract class ReaderAbstract extends StaticAbstract implements ReaderInterface
31
{
32
    /**
33
     * Check path existance & readability
34
     *
35
     * @param  string $path
36
     * @throws NotFoundException if $path not found
37
     * @throws RuntimeException if $path not readable
38
     * @access protected
39
     * @static
40
     */
41
    protected static function checkPath(/*# string */ $path)
42
    {
43
        if (!file_exists($path)) {
44
            throw new NotFoundException(
45
                Message::get(Message::MSG_PATH_NOTFOUND, $path),
46
                Message::MSG_PATH_NOTFOUND
47
            );
48
        }
49
50
        if (!is_readable($path)) {
51
            throw new RuntimeException(
52
                Message::get(Message::MSG_PATH_NONREADABLE, $path),
53
                Message::MSG_PATH_NONREADABLE
54
            );
55
        }
56
    }
57
}
58