Completed
Push — 42-formatter ( cff7a4 )
by Nicolas
32:10 queued 28:41
created

InMemoryReader::read()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4286
cc 3
eloc 7
nc 4
nop 2
1
<?php
2
3
namespace Karma\Configuration;
4
5
class InMemoryReader extends AbstractReader
6
{
7
    private
8
        $values;
9
    
10
    public function __construct(array $values = array())
11
    {
12
        parent::__construct();
13
        
14
        $this->values = $values;
15
    }
16
    
17
    protected function readRaw($variable, $environment = null)
18
    {
19
        if($environment === null)
20
        {
21
            $environment = $this->defaultEnvironment;
22
        }
23
        
24
        $key = "$variable:$environment";
25
        
26
        if(array_key_exists($key, $this->values))
27
        {
28
            return $this->values[$key];
29
        }
30
        
31
        return null;
32
    }
33
    
34
    public function getAllVariables()
35
    {
36
        $variables = array_map(function($item){
37
            return explode(':', $item)[0];
38
        }, array_keys($this->values));
39
        
40
        return array_unique($variables);
41
    }
42
}