Key   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 57
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 1 1
A check_exists() 0 5 2
A get() 0 14 2
A load() 0 9 2
1
<?php
2
3
namespace EasyPay;
4
5
class Key
6
{
7
    public function __construct() {}
8
9
    /**
10
     *      Get content of key file
11
     *      @param string $fname
12
     *      @param string $type
13
     *      @return string
14
     *      @throws Exception\Runtime
15
     */
16
    public function get($fname, $type)
17
    {
18
        try
19
        {
20
            $this->check_exists($fname);
21
22
            $key = $this->load($fname);
23
        }
24
        catch (\Exception $e)
25
        {
26
            throw new Exception\Runtime('The file with the '.$type.' key was '.$e->getMessage().'!', -98);
27
        }
28
29
        return $key;
30
    }
31
32
    /**
33
     *      Check if exist key file
34
     *
35
     *      @param string $fname
36
     *      @throws Exception\Runtime
37
     */
38
    protected function check_exists($fname)
39
    {
40
        if ( ! file_exists($fname))
41
        {
42
            throw new Exception\Runtime('not exists');
43
        }
44
    }
45
46
    /**
47
     *      Load key file
48
     *
49
     *      @param string $fname
50
     *      @return string
51
     *      @throws Exception\Runtime
52
     */
53
    protected function load($fname)
54
    {
55
        $key = @file_get_contents($fname);
56
        if ($key === FALSE)
57
        {
58
            throw new Exception\Runtime('not read');
59
        }
60
61
        return $key;
62
    }
63
}
64