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

Key   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 46
rs 10
c 1
b 0
f 1
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
A __construct() 0 1 1
A check_exists() 0 5 2
A load() 0 9 2
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