RubyConfigFileToken   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 33
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 13 4
A __construct() 0 8 2
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