Passed
Push — master ( 5b937c...6d705d )
by Dmitry
01:38
created

Key::load()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 1
b 0
f 1
1
<?php
2
3
namespace UAPAY;
4
5
use UAPAY\Exception;
6
7
class Key
8
{
9
    public function __construct() {}
10
11
    /**
12
     *      Get content of key file
13
     *      @param string $fname
14
     *      @return string
15
     */
16
    public function get($fname)
17
    {
18
        $this->check_exists($fname);
19
20
        return $this->load($fname);
21
    }
22
23
    /**
24
     *      Check if exist key file
25
     *
26
     *      @param string $fname
27
     *      @throws Exception\Runtime
28
     */
29
    protected function check_exists($fname)
30
    {
31
        if ( ! file_exists($fname))
32
        {
33
            throw new Exception\Runtime('not exists');
34
        }
35
    }
36
37
    /**
38
     *      Load key file
39
     *
40
     *      @param string $fname
41
     *      @return string
42
     *      @throws Exception\Runtime
43
     */
44
    protected function load($fname)
45
    {
46
        $key = @file_get_contents($fname);
47
        if ($key === FALSE)
48
        {
49
            throw new Exception\Runtime('not read');
50
        }
51
52
        return $key;
53
    }
54
}
55