RubyConfigFileToken::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.032
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