EnvAwareYaml::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
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