RubyConfigFileToken::read()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
ccs 7
cts 8
cp 0.875
rs 9.2
cc 4
eloc 7
nc 3
nop 0
crap 4.0312
1
<?php
2
3
namespace Rs\VersionEye\Authentication;
4
5
/**
6
 * RubyConfigFileToken.
7
 *
8
 * @author Robert Schönthal <[email protected]>
9
 */
10
class RubyConfigFileToken implements Token
11
{
12
    private $file;
13
14
    /**
15
     * @param string $file
16
     */
17 3
    public function __construct($file = null)
18
    {
19 3
        if (null === $file) {
20
            $file = $_SERVER['HOME'] . DIRECTORY_SEPARATOR . '.veye.rc';
21
        }
22
23 3
        $this->file = $file;
24 3
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function read()
30
    {
31 2
        if (!is_readable($this->file)) {
32 1
            return;
33
        }
34
35 1
        $data = file_get_contents($this->file);
36 1
        $data = parse_ini_string(str_replace([': ', ':'], ['= ', ''], $data)); //stupid convert from .rc to .ini
37
38 1
        if (isset($data['api_key']) && $data['api_key']) {
39 1
            return trim($data['api_key']);
40
        }
41
    }
42
}
43