EnvAwareYaml   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 14 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
13
        foreach ($matches[1] as $varName) {
14
            if (!getenv($varName)) {
15
                throw new \RuntimeException('The mandatory env variable (' . $varName . ') from the config file was not set.');
16
            }
17
18
            $fileContent = str_replace('${' . $varName . '}', getenv($varName), $fileContent);
19
        }
20
21
        return Yaml::parse($fileContent);
22
    }
23
}
24