Completed
Branch master (1f9106)
by Nils
02:44
created

EnvAwareYaml   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 3
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 13 3
1
<?php
2
3
namespace whm\Smoke\Yaml;
4
5
use Symfony\Component\Yaml\Yaml;
6
7
class EnvAwareYaml
8
{
9
    public static function parse($fileContent)
10
    {
11
        preg_match_all('^\${(.*)}^', $fileContent, $matches);
12
        foreach ($matches[1] as $varName) {
13
            if (!getenv($varName)) {
14
                throw new \RuntimeException('The mandatory env variable (' . $varName . ') from the config file was not set.');
15
            }
16
17
            $fileContent = str_replace('${' . $varName . '}', getenv($varName), $fileContent);
18
        }
19
20
        return Yaml::parse($fileContent);
21
    }
22
}
23